Commit 03731fad authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: initial implementation of implicit constructor


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 8335ffab
...@@ -81,6 +81,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -81,6 +81,7 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
private Class_Type myType; private Class_Type myType;
private Location location; private Location location;
private boolean hasExplicitContructor = false;
private CompilationTimeStamp lastUniquenessCheck; private CompilationTimeStamp lastUniquenessCheck;
private CompilationTimeStamp lastCompilationTimeStamp; private CompilationTimeStamp lastCompilationTimeStamp;
...@@ -91,7 +92,6 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -91,7 +92,6 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
if (extendsReferences != null) { if (extendsReferences != null) {
extendsReferences.setFullNameParent(this); extendsReferences.setFullNameParent(this);
} }
} }
...@@ -104,12 +104,19 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -104,12 +104,19 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
public void addAssignments(final List<Definition> assignments) { public void addAssignments(final List<Definition> assignments) {
for (final Definition def : assignments) { for (final Definition def : assignments) {
if (def != null && def.getIdentifier() != null && def.getIdentifier().getLocation() != null) { if (def != null && def.getIdentifier() != null && def.getIdentifier().getLocation() != null) {
addDefinition(def);
if (isConstructor(def)) {
hasExplicitContructor = true;
}
}
}
}
public void addDefinition(Definition def) {
definitions.add(def); definitions.add(def);
def.setFullNameParent(this); def.setFullNameParent(this);
def.setMyScope(this); def.setMyScope(this);
} }
}
}
public void setMyType(final Class_Type type) { public void setMyType(final Class_Type type) {
myType = type; myType = type;
...@@ -482,4 +489,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl ...@@ -482,4 +489,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/**
* checks whether the class has an explicit constructor
* @return
*/
public boolean hasConstructor() {
return hasExplicitContructor;
}
} }
\ No newline at end of file
...@@ -27,13 +27,17 @@ import org.eclipse.titan.designer.AST.ITypeWithComponents; ...@@ -27,13 +27,17 @@ import org.eclipse.titan.designer.AST.ITypeWithComponents;
import org.eclipse.titan.designer.AST.Identifier; import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type; import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
import org.eclipse.titan.designer.AST.Location; import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.NULL_Location;
import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Scope; import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.Type; import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo; import org.eclipse.titan.designer.AST.TypeCompatibilityInfo;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo.Chain; import org.eclipse.titan.designer.AST.TypeCompatibilityInfo.Chain;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition; import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter; import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList; import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
...@@ -72,6 +76,11 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -72,6 +76,11 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private Component_Type mtcType; private Component_Type mtcType;
private Component_Type systemType; private Component_Type systemType;
/** Indicates if the class has an explicitly declared constructor
* If not, an implicit default constructor should be generated
*/
private boolean hasExplicitContructor = false;
public Class_Type(ClassTypeBody classBody, boolean isAbstract, boolean isFinal, boolean isTrait, boolean isExternal, public Class_Type(ClassTypeBody classBody, boolean isAbstract, boolean isFinal, boolean isTrait, boolean isExternal,
Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef, Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef,
StatementBlock finallyBlock) { StatementBlock finallyBlock) {
...@@ -90,6 +99,7 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -90,6 +99,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
if (classBody != null) { if (classBody != null) {
classBody.setFullNameParent(this); classBody.setFullNameParent(this);
classBody.setMyType(this); classBody.setMyType(this);
classBody.setMyScope(myScope);
} }
if (runsOnRef != null) { if (runsOnRef != null) {
runsOnRef.setFullNameParent(this); runsOnRef.setFullNameParent(this);
...@@ -266,6 +276,30 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -266,6 +276,30 @@ public final class Class_Type extends Type implements ITypeWithComponents {
finallyBlock.check(timestamp); finallyBlock.check(timestamp);
} }
if (classBody != null) {
if (classBody.hasConstructor() == true) {
hasExplicitContructor = true;
} else {
// add default implicit constructor
final List<FormalParameter> fpList = new ArrayList<FormalParameter>();
for (final Definition def : classBody.getDefinitions()) {
if (def instanceof Def_Var || def instanceof Def_Template) {
String name = def.getIdentifier().getName();
if (! name.startsWith("pl_")) {
name = "pl_" + name;
}
final FormalParameter fp = new FormalParameter(Restriction_type.TR_NONE, def.getAssignmentType(),
(Type)def.getType(timestamp), new Identifier(Identifier_type.ID_TTCN, name), null, null);
fpList.add(fp);
}
}
final FormalParameterList 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);
}
}
lastTimeChecked = timestamp; lastTimeChecked = timestamp;
} }
...@@ -410,4 +444,12 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -410,4 +444,12 @@ public final class Class_Type extends Type implements ITypeWithComponents {
} }
return false; return false;
} }
/** checks whether the class has an explicit constructor
*
* @return
*/
public boolean hasExplicitConstructor() {
return hasExplicitContructor;
}
} }
\ No newline at end of file
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