Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Accessing members of super class(Subclass cannot access member of superclass)
Accessing members of super class [message #1851555] Fri, 08 April 2022 12:07 Go to next message
Fabian Sow is currently offline Fabian SowFriend
Messages: 9
Registered: January 2022
Junior Member
Hello,

I am having problems accessing members of a superclass. I tried a simple example, to see if members can be accessed from subclasses.
In this simple example it works, while in my actual code it does not

# Example 1
type class @abstract DeviceController runs on MTC{
  var charstring v_dummy := "";	  	
  public function @abstract f_do_sth();       
}

type class Device extends DeviceController runs on MTC{
  public function f_do_sth() {
    log(v_dummy);
  }
}

# Example 2
In my actual project, I get an error in a subclass, where the compiler complains that the member was not defined. But it is exactly defined as in the above example.

module CellularCommonDeviceController {
...
public type class @abstract CellularDeviceController runs on Cellular_Node_CT {	  	 	    
  var charstring cmd := "";
...
}
}

module Cs {
...
type class @final CsGr851 extends CellularDeviceController runs on Cellular_Node_CT {
  var ModemCapability v_cap;
  create():CellularDeviceController("") {
    v_cap := {3, 0, false}
  }
}
...
}


In the generated c++ code I see that cmd is a protected member in the superclass. I can access the member from the class itself, but accessing it from a subclass seems to be a problem somehow. Accessing methods is not a problem.

Cs .cc:334:33: error: 'cmd' is not a member of 'CellularCommonDeviceController'
334 | CellularCommonDeviceController::cmd = cs_20;

##
I have various imports, but nowhere another variable with that name is declared. Declaring a local variable cmd in the subclass works without any issues.

Does someone know by what that behavior might be caused?
Re: Accessing members of super class [message #1851558 is a reply to message #1851555] Fri, 08 April 2022 12:44 Go to previous messageGo to next message
Miklos Magyari is currently offline Miklos MagyariFriend
Messages: 5
Registered: March 2022
Junior Member
Hello,

can you double check your names?
You are extending CellularDeviceController class, but in the generated code, it is CellularCommonDeviceController (note the extra "Common").
Re: Accessing members of super class [message #1851559 is a reply to message #1851558] Fri, 08 April 2022 12:56 Go to previous messageGo to next message
Fabian Sow is currently offline Fabian SowFriend
Messages: 9
Registered: January 2022
Junior Member
I checked the names again. `CellularCommonDeviceController` is the module name and 'CellularDeviceController' is the class name.

Also for the first example I showed, the code is generated in the form
<module-name>::<member_variable> 

and not
<class_name>::<member_variable>


I think that this should be alright.
Re: Accessing members of super class [message #1851569 is a reply to message #1851559] Fri, 08 April 2022 16:46 Go to previous messageGo to next message
Miklos Magyari is currently offline Miklos MagyariFriend
Messages: 5
Registered: March 2022
Junior Member
hi,

you are right, the generated code has an issue if the parent class and the subclass are defined in different modules.
For inherited fields, a <module-name>:: prefix is added (mistakenly). It should be simply the field name with no prefix.

The example probably works as the parent and child classes are in the same module and in this case, the generated code is this->cmd

We will look at this issue.

br,
Miki

[Updated on: Fri, 08 April 2022 16:46]

Report message to a moderator

Re: Accessing members of super class [message #1851618 is a reply to message #1851569] Mon, 11 April 2022 11:00 Go to previous messageGo to next message
Fabian Sow is currently offline Fabian SowFriend
Messages: 9
Registered: January 2022
Junior Member
Thank you.
Can you already estimate when this will be fixed?

Br,
Fabian

[Updated on: Wed, 13 April 2022 14:27]

Report message to a moderator

Re: Accessing members of super class [message #1851886 is a reply to message #1851618] Thu, 21 April 2022 07:25 Go to previous messageGo to next message
Adam Knapp is currently offline Adam KnappFriend
Messages: 50
Registered: November 2020
Member
Hi Fabian,

The issue is fixed, see the details in: https://gitlab.eclipse.org/eclipse/titan/titan.core/-/issues/599
Please don't hesitate to contact us if you face further issues.

BR, Adam

[Updated on: Thu, 21 April 2022 09:31]

Report message to a moderator

Re: Accessing members of super class [message #1852043 is a reply to message #1851886] Wed, 27 April 2022 08:26 Go to previous messageGo to next message
Fabian Sow is currently offline Fabian SowFriend
Messages: 9
Registered: January 2022
Junior Member
Thank you for the timely update. However, I am now facing different issues which might not be caused by this fix tough, since I
upgrade from the 8.0.0 release to the latest commit.

I have the following setup of classes:
CellularInterface -> abstract class with only abstract methods
NbInterface -> abstract class extending cellular interface but only having abstract methods as well
CellularDeviceController runs on Node_CT -> abstract class implementing NbInterface, but leaving some methods abstract to be implemented by the concrete class
Cs runs on Node_CT -> final class implementing CellularDeviceController

I use this component:
Node_CT -> has different port types and the above mentioned interface types, e.g. NbInterface

In a separate module I am using a component variable of type NbInterface (vc_nb) and instantiate the concrete class `Cs`
vc_nb := csGr851.create();

With the titan release with Tag 8.0.0 all builds and executes.
When I pull to the latest commit and build titan again, I get errors in the generated code, telling me that I can't call new on my concrete class, because there appears to be pure virtual functions in my class. These methods that are complained about, are however implemented in the class.
CommonFunctionality.cc:167:79: error: invalid new-expression of abstract class type 'cs::csGr851'
  167 | CommonInterface::Node__CT_component_vc__nbiot = new cs::csGr851();
      |                                                                               ^
cs.hh:68:7: note:   because the following virtual functions are pure within 'cs::csGr851':
   68 | class csGr851 :  public CellularCommonDeviceController::CellularDeviceController {
      |       ^~~~~~~
CommonInterface.hh:133:14: note: 	'virtual void CommonInterface::CellularInterface::f__select__operator(const BOOLEAN&, CommonInterface::CellularInterface_defpar_type_0)'
  133 | virtual void f__select__operator(const BOOLEAN& auto_, CellularInterface_defpar_type_0 plmn_defpar) = 0;
      |              ^~~~~~~~~~~~~~~~~~~


Do you have an idea, what change might cause this behavior or what might go wrong?

Best regards
Re: Accessing members of super class [message #1852046 is a reply to message #1852043] Wed, 27 April 2022 13:10 Go to previous messageGo to next message
Adam Knapp is currently offline Adam KnappFriend
Messages: 50
Registered: November 2020
Member
Hi Fabian,

Can you attach the relevant part of your code or a simple example with this issue? Thank you!
I tried to reproduce the class hierarchy you described, but I was able to build the executable. The generated code seems fine.
Re: Accessing members of super class [message #1852061 is a reply to message #1852046] Thu, 28 April 2022 08:12 Go to previous messageGo to next message
Fabian Sow is currently offline Fabian SowFriend
Messages: 9
Registered: January 2022
Junior Member
Hi Adam,

I tried to reproduced the issue with a minimal example and could reproduce the issue. The problem is, that that in one of the methods of the abstract classes I used a default argument. When removing the default value from the abstract classes (and from the ones inheriting from it), it builds and executes.

I attached the example.

  • Attachment: test.zip
    (Size: 5.25KB, Downloaded 82 times)
Re: Accessing members of super class [message #1852111 is a reply to message #1852061] Fri, 29 April 2022 13:11 Go to previous messageGo to next message
Adam Knapp is currently offline Adam KnappFriend
Messages: 50
Registered: November 2020
Member
Hi Fabian,

Thanks for the code! It already identified two possible bugs. Both seems to be related to the default values of function parameters. We will investigate them.
Till that I suggest to avoid using default values.
Re: Accessing members of super class [message #1852388 is a reply to message #1852111] Fri, 13 May 2022 12:58 Go to previous message
Adam Knapp is currently offline Adam KnappFriend
Messages: 50
Registered: November 2020
Member
Hi Fabian,

We fixed the issues. You can find the details in the related ticket: https://gitlab.eclipse.org/eclipse/titan/titan.core/-/issues/604
Previous Topic:Titan 8.2.0 release notification
Next Topic:Improving logging of match failures
Goto Forum:
  


Current Time: Tue Apr 23 12:26:38 GMT 2024

Powered by FUDForum. Page generated in 0.03982 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top