Commit 9d0bf15f authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: improvements for implicit constructor


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 03731fad
...@@ -6,18 +6,13 @@ ...@@ -6,18 +6,13 @@
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/ ******************************************************************************/
/**
* class type (TTCN-3 extension)
*
* @author Miklos Magyari
*/
package org.eclipse.titan.designer.AST.TTCN3.types; package org.eclipse.titan.designer.AST.TTCN3.types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.titan.designer.AST.Assignment; import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.FieldSubReference;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type; import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.IReferenceChain; import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.ISubReference; import org.eclipse.titan.designer.AST.ISubReference;
...@@ -29,26 +24,32 @@ import org.eclipse.titan.designer.AST.Identifier.Identifier_type; ...@@ -29,26 +24,32 @@ 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.NULL_Location;
import org.eclipse.titan.designer.AST.Reference; import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Reference.Ref_Type;
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.TemplateRestriction.Restriction_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const;
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_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template;
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;
import org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier; import org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier;
import org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock; import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template;
import org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value;
import org.eclipse.titan.designer.compiler.JavaGenData; import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp; import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
/** /**
* Represents the TTCN3 class type. * Represents the TTCN3 class type (TTCN-3 extension).
* *
* @author Miklos Magyari * @author Miklos Magyari
* */ * */
...@@ -282,15 +283,48 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -282,15 +283,48 @@ public final class Class_Type extends Type implements ITypeWithComponents {
} else { } else {
// add default implicit constructor // add default implicit constructor
final List<FormalParameter> fpList = new ArrayList<FormalParameter>(); final List<FormalParameter> fpList = new ArrayList<FormalParameter>();
final StatementBlock sb = new StatementBlock();
for (final Definition def : classBody.getDefinitions()) { for (final Definition def : classBody.getDefinitions()) {
if (def instanceof Def_Var || def instanceof Def_Template) { if (def instanceof Def_Var || def instanceof Def_Var_Template ||
def instanceof Def_Const || def instanceof Def_Template) {
boolean isTemplate = false;
if (def instanceof Def_Template || def instanceof Def_Var_Template) {
isTemplate = true;
}
if (def instanceof Def_Const) {
final Def_Const con = (Def_Const)def;
if (con.getValue() != null) {
continue;
}
}
if (def instanceof Def_Template) {
final Def_Template tpl = (Def_Template)def;
if (tpl.getTemplate(timestamp) != null) {
continue;
}
}
final IType deftype = def.getType(timestamp);
if (deftype instanceof Property_Type) {
if (((Property_Type)deftype).isInternal()) {
continue;
}
}
String name = def.getIdentifier().getName(); String name = def.getIdentifier().getName();
if (! name.startsWith("pl_")) { if (! name.startsWith("pl_")) {
name = "pl_" + name; name = "pl_" + name;
} }
final FormalParameter fp = new FormalParameter(Restriction_type.TR_NONE, def.getAssignmentType(), final FormalParameter fp = new FormalParameter(Restriction_type.TR_NONE,
isTemplate ? Assignment_type.A_PAR_TEMP_IN : Assignment_type.A_PAR_VAL_IN,
(Type)def.getType(timestamp), new Identifier(Identifier_type.ID_TTCN, name), null, null); (Type)def.getType(timestamp), new Identifier(Identifier_type.ID_TTCN, name), null, null);
fpList.add(fp); fpList.add(fp);
Reference refLeft = new Reference(new Identifier(Identifier_type.ID_TTCN, def.getIdentifier().getName()), Ref_Type.REF_THIS);
FieldSubReference subref = new FieldSubReference(def.getIdentifier());
refLeft.addSubReference(subref);
Reference refRight = new Reference(new Identifier(Identifier_type.ID_TTCN, def.getIdentifier().getName()));
Referenced_Value refdVal = new Referenced_Value(refRight);
SpecificValue_Template valTemplate = new SpecificValue_Template(refdVal);
Assignment_Statement assignment = new Assignment_Statement(refLeft, valTemplate);
sb.addStatement(assignment);
} }
} }
final FormalParameterList pl = new FormalParameterList(fpList); final FormalParameterList pl = new FormalParameterList(fpList);
...@@ -300,7 +334,7 @@ public final class Class_Type extends Type implements ITypeWithComponents { ...@@ -300,7 +334,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
} }
} }
lastTimeChecked = timestamp; lastTimeChecked = timestamp;;
} }
@Override @Override
......
...@@ -387,4 +387,8 @@ public final class Property_Type extends Type { ...@@ -387,4 +387,8 @@ public final class Property_Type extends Type {
setterStatementBlock.setMyDefinition(definition); setterStatementBlock.setMyDefinition(definition);
} }
} }
public boolean isInternal() {
return isInternal;
}
} }
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