Commit 5e441d4e authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: synch with titan core (10) (issue #487)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 22a0a62c
......@@ -175,7 +175,7 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
this.modid = modid;
detectedModuleId = modid != null;
this.subReferences = new ArrayList<ISubReference>(subReferences);
this.subReferences = new ArrayList<ISubReference>(subrefs);
this.subReferences.trimToSize();
for (int i = 0; i < subReferences.size(); i++) {
......
......@@ -7,6 +7,10 @@
******************************************************************************/
package org.eclipse.titan.designer.AST.TTCN3.definitions;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.titan.designer.AST.INamedNode;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
......@@ -27,16 +31,31 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
*/
public class Def_Constructor extends Definition implements IParameterisedAssignment, IFunctionBase {
private final StatementBlock statementBlock;
private Map<Identifier,Boolean> uninitializedMembers = new HashMap<>();
private FormalParameterList formalParameterList;
public Def_Constructor(FormalParameterList fpl, Reference baseCall, StatementBlock sb) {
super(new Identifier(Identifier_type.ID_TTCN, "create"));
formalParameterList = fpl;
statementBlock = sb;
}
public synchronized void addUninitializedMember(Identifier identifier, boolean isTemplate) {
uninitializedMembers.put(identifier, isTemplate);
}
@Override
public String getOutlineIcon() {
return "function.gif";
}
@Override
public FormalParameterList getFormalParameterList() {
return formalParameterList;
}
@Override
public String getProposalKind() {
......@@ -104,12 +123,6 @@ public class Def_Constructor extends Definition implements IParameterisedAssignm
return null;
}
@Override
public FormalParameterList getFormalParameterList() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setSignatureLocation(Location signatureLocation) {
// TODO Auto-generated method stub
......
......@@ -155,6 +155,12 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
}
}
public void addFormalparameter(FormalParameter addParamater) {
if (! isExistingFormalParameter(parameters, addParamater)) {
parameters.add(addParamater);
}
}
private boolean isExistingFormalParameter(List<FormalParameter> list, FormalParameter fp) {
for (final FormalParameter param : list) {
if (param.getFullName().equals(fp.getFullName())) {
......
......@@ -10,6 +10,7 @@ package org.eclipse.titan.designer.AST.TTCN3.types;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -17,6 +18,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.FieldSubReference;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.ISubReference;
......@@ -29,6 +31,7 @@ import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.NULL_Location;
import org.eclipse.titan.designer.AST.ParameterisedSubReference;
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.Type;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo;
......@@ -54,6 +57,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList.IsId
import org.eclipse.titan.designer.AST.TTCN3.definitions.IFunctionBase;
import org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment;
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.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.templates.ParsedActualParameters;
......@@ -115,8 +119,11 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String SHADOWSINHERITEDMEMBER = "`{0}'' shadows inherited member `{1}''";
private static final String SHADOWSINHERITED2 = "`{0}'' shadows inherited {1} `{2}''";
private static final String TRAITNOCONSTRUCTOR = "Trait class type `{0}'' cannot have a constructor";
private static final String TRAITWITHFINALLY = "A trait class should not define a finally block";
private static final String TRAITCANNOTHAVEFINALLY = "Trait class type `{0}'' cannot have a destructor";
private static final String EXTERNALCANNOTCONTAIN = "An external class cannot contain a {0}";
private static final String EXTERNALCANNOTHAVEFINALLY = "An external class cannot have a destructor";
private static final String MISSINGABSIMPLEMENTATION = "Missing implementation of abstract method `{0}''";
private static final String UNKNOWNFIELD = "Unknown field reference";
private static final String PRIVATEINACCESSIBLE = "Private member is inaccessible due to its protection level";
......@@ -150,6 +157,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private Class_Type baseClass;
private Def_Constructor constructor;
private Map<FormalParameter,String> defaultParameterList;
private Map<String,Def_AbsFunction> abstractFunctions = new HashMap<>();
private boolean defaultConstructor;
public enum ClassRelation {
Identical, Related, Unrelated
......@@ -316,6 +325,18 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return systemRef;
}
public int getNofAbstractFunctions() {
return abstractFunctions.size();
}
public synchronized void addAbstractFunction(String key, Def_AbsFunction value) {
abstractFunctions.put(key, value);
}
public Map<String, Def_AbsFunction> getAbstractFunctions() {
return abstractFunctions;
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -663,21 +684,171 @@ public final class Class_Type extends Type implements ITypeWithComponents {
FormalParameter fp = new FormalParameter(
Restriction_type.TR_NONE, isTemplate ? Assignment_type.A_PAR_TEMP_IN : Assignment_type.A_PAR_VAL_IN,
(Type)member.getType(timestamp), id, defVal, parameterEvaluationType.NORMAL_EVAL);
fpl.addFormalparameter(fp);
// add a statement, that assigns the parameter's value to the member
final Identifier id1 = id.newInstance();
final Reference refLeft = new Reference(new Identifier(Identifier_type.ID_TTCN, id1.getName()), Ref_Type.REF_THIS);
final FieldSubReference subref = new FieldSubReference(id1);
refLeft.addSubReference(subref);
final Reference refRight = new Reference(new Identifier(Identifier_type.ID_TTCN, id.newInstance().getName()));
final Referenced_Value refdVal = new Referenced_Value(refRight);
final SpecificValue_Template valTemplate = new SpecificValue_Template(refdVal);
final Assignment_Statement assignment = new Assignment_Statement(refLeft, valTemplate);
block.addStatement(assignment);
}
}
constructor = new Def_Constructor(fpl, baseCall, block);
constructor.setMyScope(getClassTypeBody());
// TODO setFulName
defaultConstructor = true;
constructor.check(timestamp);
}
if (isTrait && finallyBlock != null) {
finallyBlock.getLocation().reportSemanticError(TRAITWITHFINALLY);
setIsErroneous(true);
if (constructor != null && !defaultConstructor && !nameClash && !isTrait) {
// make sure constants and templates are initialized
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment member = members.getAssignmentByIndex(i);
boolean needsInitCheck = false;
boolean isTemplate = false;
switch(member.getAssignmentType()) {
case A_CONST:
needsInitCheck = ((Def_Const)member).getValue() == null;
break;
case A_TEMPLATE:
needsInitCheck = ((Def_Template)member).getTemplate(timestamp) == null;
isTemplate = true;
break;
default:
break;
}
if (needsInitCheck) {
constructor.addUninitializedMember(member.getIdentifier(), isTemplate);
}
}
}
initAttributes(timestamp);
if (finallyBlock != null) {
finallyBlock.check(timestamp);
if (isTrait) {
finallyBlock.getLocation().reportSemanticError(
MessageFormat.format(TRAITCANNOTHAVEFINALLY, getTypename()));
}
}
if (isExternal) {
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment member = members.getAssignmentByIndex(i);
switch(member.getAssignmentType()) {
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
case A_CONSTRUCTOR:
break;
default:
member.getLocation().reportSemanticError(
MessageFormat.format(EXTERNALCANNOTCONTAIN, member.getAssignmentName()));
break;
}
}
if (finallyBlock != null) {
finallyBlock.getLocation().reportSemanticError(
MessageFormat.format(EXTERNALCANNOTHAVEFINALLY, getTypename()));
}
}
if (isAbstract || isTrait) {
// create a map of all abstract functions (including inherited ones)
if (baseClass != null && baseClass.isAbstract) {
for (Map.Entry<String, Def_AbsFunction> absFunc : baseClass.getAbstractFunctions().entrySet()) {
addAbstractFunction(absFunc.getKey(), absFunc.getValue());
}
}
if (baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null) {
final Class_Type baseTraitClass = baseTrait.getTypeRefdLast(timestamp).getClassType();
for (Map.Entry<String, Def_AbsFunction> traitAbs : baseTraitClass.getAbstractFunctions().entrySet()) {
if (! abstractFunctions.containsKey(traitAbs.getKey())) {
addAbstractFunction(traitAbs.getKey(), traitAbs.getValue());
}
}
}
}
}
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment member = members.getAssignmentByIndex(i);
switch(member.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
final Def_AbsFunction defAbsFunc = (Def_AbsFunction)member;
if (defAbsFunc != null) {
final String defName = defAbsFunc.getIdentifier().getName();
if (!abstractFunctions.containsKey(defName)) {
addAbstractFunction(defName, defAbsFunc);
}
}
break;
default:
break;
}
}
}
if (!isAbstract && !isTrait) {
// all abstract methods from the base class and base traits have to be implemented in this class
if (baseClass != null && baseClass.isAbstract) {
for (Map.Entry<String, Def_AbsFunction> absFuncs : baseClass.getAbstractFunctions().entrySet()) {
final Def_AbsFunction defAbsFunc = absFuncs.getValue();
final Assignment ass = getLocalAssignmentByID(defAbsFunc.getIdentifier(), timestamp);
switch(ass.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
if (ass instanceof Def_AbsFunction) {
getLocation().reportSemanticError(
MessageFormat.format(MISSINGABSIMPLEMENTATION, defAbsFunc.getFullName()));
}
// whether the new function is identical to the abstract one has
// already been checked
break;
default:
// it's either an external function (which is OK), or
// it's shadowed by a member (error has already been reported)
break;
}
}
}
if (baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null) {
final Class_Type baseTraitClass = baseTrait.getTypeRefdLast(timestamp).getClassType();
for (Map.Entry<String, Def_AbsFunction> absFuncs : baseTraitClass.getAbstractFunctions().entrySet()) {
final Assignment ass = getLocalAssignmentByID(absFuncs.getValue().getIdentifier(), timestamp);
switch(ass.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
if (ass instanceof Def_AbsFunction) {
getLocation().reportSemanticError(
MessageFormat.format(MISSINGABSIMPLEMENTATION, absFuncs.getValue().getFullName()));
}
// whether the new function is identical to the abstract one has
// already been checked
break;
default:
// it's either an external function (which is OK), or
// it's shadowed by a member (error has already been reported)
break;
}
}
}
}
}
}
lastTimeChecked = timestamp;
}
......@@ -925,8 +1096,10 @@ public final class Class_Type extends Type implements ITypeWithComponents {
public List<Definition> getDefinitions() {
List<Definition> definitions = new ArrayList<>();
for (Map.Entry<String,Definition> defs : members.getDefinitionMap().entrySet()) {
definitions.add(defs.getValue());
if (members.getDefinitionMap() != null) {
for (Map.Entry<String,Definition> defs : members.getDefinitionMap().entrySet()) {
definitions.add(defs.getValue());
}
}
return definitions;
......
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