Commit a8db12b5 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

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


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 84417ca9
......@@ -37,6 +37,7 @@ import org.eclipse.titan.designer.AST.Value;
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.attributes.Types;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_AbsFunction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Constructor;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
......@@ -47,6 +48,8 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions;
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.IsIdenticalResult;
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;
......@@ -94,6 +97,9 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String SHADOWSRUNSON = "`{0}'' shadows a definition in runs-on component type `{1}''";
private static final String SHADOWSMTC = "`{0}'' shadows a definition in mtc component type `{1}''";
private static final String SHADOWSSYSTEM = "`{0}'' shadows a definition in system component type `{1}''";
private static final String DIFFERSFROMOBJECTMETHOD = "The prototype of method `{0}'' is not identical " +
"to that of the method inherited from the 'object' class";
private static final String SHADOWSOBJECTMETHOD = "`{0}'' shadows a method inherited from the 'object' class";
private static final String ABSTRACTCANNOTBEFINAL = "An absract class cannot be final";
private static final String TRAITCANNOTBEFINAL = "A trait class cannot be final";
......@@ -101,7 +107,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String TRAITWITHFINALLY = "A trait class should not define a finally block";
private static final String UNKNOWNFIELD = "Unknown field reference";
private static final String PRIVATEINACCESSIBLE = "Private member is inaccessible due to its protection level";
private static final String PARAMNAMEDIFFERS = "One or more parameter names differ from previous definition";
/**
* The superclass of this class
* (the only non-trait class that this class extends)
......@@ -149,7 +155,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
this.runsOnRef = runsOnRef;
this.mtcRef = mtcRef;
this.systemRef = systemRef;
this.members = members;
this.members = members != null ? members : new Definitions();
this.baseTraits = baseTraits;
if (classBody != null) {
......@@ -344,7 +350,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
baseType = t;
baseClass = tClass;
if (baseClass.isFinal) {
baseClass.getLocation().reportSemanticError(BASECANNOTBEFINAL);
baseClass.getModifierLocation().reportSemanticError(BASECANNOTBEFINAL);
}
if (isExternal && ! baseClass.isExternal) {
baseClass.getLocation().reportSemanticError(EXTERNALEXTENDINTERNAL);
......@@ -464,6 +470,9 @@ public final class Class_Type extends Type implements ITypeWithComponents {
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment ass = members.getAssignmentByIndex(i);
if (ass == null) {
continue;
}
switch(ass.getAssignmentType()) {
case A_CONST:
case A_VAR:
......@@ -521,6 +530,52 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
}
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment def = members.getAssignmentByIndex(i);
if (! (def instanceof IParameterisedAssignment)) {
continue;
}
final Identifier id = def.getIdentifier();
final FormalParameterList fpl = getObjectMethodFormalParameterList(id.getName());
if (fpl != null) {
IsIdenticalResult identical = IsIdenticalResult.RES_DIFFERS;
final FormalParameterList fpl2 = ((IParameterisedAssignment)def).getFormalParameterList();
if (fpl2 != null) {
identical = fpl.isIdentical(timestamp, fpl2);
} else if (fpl.getNofParameters() == 0) {
identical = IsIdenticalResult.RES_IDENTICAL;
}
switch(def.getAssignmentType()) {
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (def.getVisibility() == VisibilityModifier.Public && identical != IsIdenticalResult.RES_DIFFERS) {
if (! (def instanceof Def_AbsFunction)) {
if (def.getType(timestamp).isIdentical(timestamp, getObjectMethodReturnType(id.getName()))) {
if (identical == IsIdenticalResult.RES_NAME_DIFFERS) {
fpl2.getLocation().reportSemanticWarning(PARAMNAMEDIFFERS);
}
break; // in order
}
}
}
// no break on purpose
case A_FUNCTION:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RTEMP:
// currently all 'object' methods return a value, so these are erroneous by default
def.getLocation().reportSemanticError(
MessageFormat.format(DIFFERSFROMOBJECTMETHOD, def.getDescription()));
break;
default:
def.getLocation().reportSemanticError(
MessageFormat.format(SHADOWSOBJECTMETHOD, def.getDescription()));
nameClash = true;
break;
}
}
}
if (isAbstract && isFinal) {
modifierLocation.reportSemanticError(ABSTRACTCANNOTBEFINAL);
setIsErroneous(true);
......@@ -687,6 +742,42 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return nameClash;
}
/**
* Gets the formal parameter list of default object methods
* @param methodName
* @return
*/
public static FormalParameterList getObjectMethodFormalParameterList(final String methodName) {
final List<FormalParameter> fplist = new ArrayList<>();
switch (methodName) {
case "toString":
return new FormalParameterList(fplist);
case "equals":
FormalParameter param = new FormalParameter(Restriction_type.TR_NONE, Assignment_type.A_PAR_VAL_IN,
new Class_Type(), new Identifier(Identifier_type.ID_TTCN, "obj"), null, null);
fplist.add(param);
return new FormalParameterList(fplist);
default:
return null;
}
}
/**
* Gets the return type of default object methods
* @param methodName
* @return
*/
public static Type getObjectMethodReturnType(final String methodName) {
switch (methodName) {
case "toString":
return new UniversalCharstring_Type();
case "equals":
return new Boolean_Type();
default:
return null;
}
}
private boolean isParentClass(final Class_Type pclass, CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
check(timestamp);
......@@ -885,6 +976,10 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return systemType;
}
public Location getModifierLocation() {
return modifierLocation;
}
@Override
public Identifier getComponentIdentifierByName(Identifier identifier) {
// TODO Auto-generated method stub
......
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