Commit 2329d438 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: inherint parent constructor parameters for implicit constructor


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 387be469
......@@ -459,7 +459,7 @@ function f_with_exception(integer pl_int) return integer exception(integer) {
}
testcase tc_basicSyntax() runs on CT {
var GrandSubClass vl_gsc := GrandSubClass.create(1, { a := 10 });
var GrandSubClass vl_gsc := GrandSubClass.create(1, 1, 1, { a := 10 });
var integer vl_int1 := vl_gsc.vl_c; // correct : own class member
var integer vl_int2 := vl_gsc.vl_b; // correct : inherited from direct parent
......
......@@ -120,6 +120,27 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
}
}
public FormalParameterList(final FormalParameterList parameters) {
for (int i = 0; i < parameters.getNofParameters() ; i++) {
final FormalParameter parameter = parameters.getParameterByIndex(i);
if (parameter != null && parameter.getIdentifier() != null) {
this.parameters.add(parameter);
parameter.setFullNameParent(this);
parameter.setFormalParamaterList(this);
}
}
}
/**
* Adds a formal parameter list to the existing list
* @param addList
*/
public void addFormalParameterList(FormalParameterList addList) {
for (int i = 0; i < addList.getNofParameters(); i++) {
parameters.add(addList.getParameterByIndex(i));
}
}
@Override
/** {@inheritDoc} */
public final StringBuilder getFullName(final INamedNode child) {
......
......@@ -162,6 +162,10 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
return defs;
}
public List<Definition> getOwnDefinitions() {
return definitions.getDefinitions();
}
public Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference) {
return getAssBySRef(timestamp, reference, null);
}
......
......@@ -63,6 +63,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
reference.setFullNameParent(this);
}
public List<Reference> getReferenceList() {
return classReferences;
}
public void setParentClass(Class_Type parentClass) {
this.myClass = parentClass;
}
......
......@@ -64,6 +64,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String UNKNOWNFIELD = "Unknown field reference";
private static final String PRIVATEINACCESSIBLE = "Private member is inaccessible due to its protection level";
private Class_Type superClass = null;
private final ClassTypeBody classBody;
private final boolean isAbstract;
......@@ -75,6 +77,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private final Reference runsOnRef;
private final Reference mtcRef;
private final Reference systemRef;
private final ClassTypeReferenceList refs;
private Component_Type runsOnType;
private Component_Type mtcType;
......@@ -87,7 +90,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
public Class_Type(ClassTypeBody classBody, boolean isAbstract, boolean isFinal, boolean isTrait, boolean isExternal,
Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef,
StatementBlock finallyBlock) {
ClassTypeReferenceList refs, StatementBlock finallyBlock) {
this.classBody = classBody;
this.isAbstract = isAbstract;
......@@ -99,6 +102,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
this.runsOnRef = runsOnRef;
this.mtcRef = mtcRef;
this.systemRef = systemRef;
this.refs = refs;
if (classBody != null) {
classBody.setFullNameParent(this);
......@@ -121,7 +125,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
public Class_Type() {
this(null, true, false, false, false, null, null, null, null, null);
this(null, true, false, false, false, null, null, null, null, null, null);
}
@Override
......@@ -237,6 +241,18 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return;
}
if (refs != null) {
for (Reference ref : refs.getReferenceList()) {
final Assignment ass = ref.getRefdAssignment(timestamp, false);
final IType type = ass.getType(timestamp);
if (type instanceof Class_Type) {
Class_Type parent = (Class_Type)type;
if (parent.isTrait == false) {
superClass = parent;
}
}
}
}
runsOnType = null;
mtcType = null;
systemType = null;
......@@ -279,7 +295,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
// add default implicit constructor
final List<FormalParameter> fpList = new ArrayList<FormalParameter>();
final StatementBlock sb = new StatementBlock();
for (final Definition def : classBody.getDefinitions()) {
for (final Definition def : classBody.getOwnDefinitions()) {
if (def instanceof Def_Var || def instanceof Def_Var_Template ||
def instanceof Def_Const || def instanceof Def_Template) {
boolean isTemplate = false;
......@@ -338,7 +354,17 @@ public final class Class_Type extends Type implements ITypeWithComponents {
sb.addStatement(assignment);
}
}
final FormalParameterList pl = new FormalParameterList(fpList);
FormalParameterList pl = null;
if (superClass != null) {
FormalParameterList parentFpList = superClass.getConstructorFormalParameterList();
if (parentFpList != null) {
pl = new FormalParameterList(parentFpList);
pl.addFormalParameterList(new FormalParameterList(fpList));
}
}
if (pl == null) {
pl = new FormalParameterList(fpList);
}
Def_Function constructor = new Def_Function(new Identifier(Identifier_type.ID_TTCN, "create"), pl, null);
constructor.setLocation(NULL_Location.INSTANCE);
classBody.addDefinition(constructor);
......@@ -505,4 +531,18 @@ public final class Class_Type extends Type implements ITypeWithComponents {
public boolean hasExplicitConstructor() {
return hasExplicitContructor;
}
private FormalParameterList getConstructorFormalParameterList() {
if (classBody == null) {
return null;
}
for (Definition def : classBody.getOwnDefinitions()) {
if (def instanceof Def_Function) {
if (def.getIdentifier().getName().equals("create")) {
return ((Def_Function)def).getFormalParameterList();
}
}
}
return null;
}
}
\ No newline at end of file
......@@ -9259,7 +9259,7 @@ pr_ClassTypeDef returns[Def_Type def_type]
if (body == null) {
body = new ClassTypeBody($i.identifier, refs);
}
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, modifierLocation, runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, finallyBlock);
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, modifierLocation, runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, refs, finallyBlock);
type.setLocation(getLocation($start, getLastVisibleToken()));
$def_type = new Def_Type($i.identifier, type);
$def_type.setLocation(getLocation($kw.start, $i.stop));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment