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
private Class_Type myType;
private Location location;
private boolean hasExplicitContructor = false;
private CompilationTimeStamp lastUniquenessCheck;
private CompilationTimeStamp lastCompilationTimeStamp;
......@@ -91,7 +92,6 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
if (extendsReferences != null) {
extendsReferences.setFullNameParent(this);
}
}
......@@ -104,12 +104,19 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
public void addAssignments(final List<Definition> assignments) {
for (final Definition def : assignments) {
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);
def.setFullNameParent(this);
def.setMyScope(this);
}
}
}
public void setMyType(final Class_Type type) {
myType = type;
......@@ -482,4 +489,12 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
// 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;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
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.Scope;
import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo;
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.TemplateRestriction.Restriction_type;
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.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
......@@ -72,6 +76,11 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private Component_Type mtcType;
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,
Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef,
StatementBlock finallyBlock) {
......@@ -90,6 +99,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
if (classBody != null) {
classBody.setFullNameParent(this);
classBody.setMyType(this);
classBody.setMyScope(myScope);
}
if (runsOnRef != null) {
runsOnRef.setFullNameParent(this);
......@@ -266,6 +276,30 @@ public final class Class_Type extends Type implements ITypeWithComponents {
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;
}
......@@ -410,4 +444,12 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
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