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

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


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 42c055a1
......@@ -12,6 +12,7 @@ import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList.IsIdenticalResult;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
......@@ -31,6 +32,8 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
private Location signatureLocation = null;
private boolean isFinal;
private boolean isAbstract;
private FormalParameterList formalParameterList;
private Assignment_type assignmentType;
public Def_AbsFunction(final Identifier identifier, final FormalParameterList formalParameters, final Reference runsOnRef,
final Reference mtcReference, final Reference systemReference, final Reference portReference,
......@@ -41,7 +44,9 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
super(identifier);
this.isFinal = isFinal;
this.isAbstract = isAbstract;
// TODO Auto-generated constructor stub
formalParameterList = formalParameters;
assignmentType = (returnType == null) ? Assignment_type.A_FUNCTION : (returnsTemplate ? Assignment_type.A_FUNCTION_RTEMP
: Assignment_type.A_FUNCTION_RVAL);
}
@Override
......@@ -93,8 +98,7 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
@Override
public Assignment_type getAssignmentType() {
// TODO Auto-generated method stub
return null;
return assignmentType;
}
@Override
......
......@@ -7,18 +7,24 @@
******************************************************************************/
package org.eclipse.titan.designer.AST.TTCN3.definitions;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
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.NamedBridgeScope;
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.TTCN3.definitions.FormalParameterList.IsIdenticalResult;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
......@@ -31,12 +37,26 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
*
*/
public class Def_Constructor extends Definition implements IParameterisedAssignment, IFunctionBase {
private static final String DOESNOTHAVESUPERCLASS = "Class type `{0}'' does not have a superclass";
private static final String CONSTRUCTORREFERENCEEXPECTED = "Reference to constructor was expected instead of {0}";
private static final String CONSTRUCTORCALLEXPECTED = "Expected call to constructor of class type `{0}'', instead of class type `{1}''";
private static final String MISSINGSUPERCONSTRUCTORCALL = "Missing super-constructor call";
private static final String EXTERNALWITHBODY = "The constructor of an external class cannot have a body";
private static final String MISSINGBODY = "Missing constructor body";
private final StatementBlock statementBlock;
private Map<Identifier,Boolean> uninitializedMembers = new HashMap<>();
private FormalParameterList formalParameterList;
private Assignment_type assignmentType;
final private Assignment_type assignmentType = Assignment_type.A_FUNCTION_RVAL;
private Reference baseRef;
/** Location of the function's signature (from 'function' keyword up to the return value)
* Used when we want to report errors/warnings for a whole function but underlining the
* entire definition (including the body and finally block) looks ugly
*/
private Location signatureLocation = null;
private NamedBridgeScope bridgeScope;
public Def_Constructor(FormalParameterList fpl, Reference baseCall, StatementBlock sb) {
super(new Identifier(Identifier_type.ID_TTCN, "create"));
......@@ -51,6 +71,32 @@ public class Def_Constructor extends Definition implements IParameterisedAssignm
((Referenced_Type)baseCall).getReference() : null,
sb);
}
@Override
/** {@inheritDoc} */
public void setMyScope(final Scope scope) {
if (bridgeScope != null && bridgeScope.getParentScope() == scope) {
return;
}
bridgeScope = new NamedBridgeScope();
bridgeScope.setParentScope(scope);
scope.addSubScope(getLocation(), bridgeScope);
bridgeScope.setScopeMacroName(identifier.getDisplayName());
super.setMyScope(bridgeScope);
if (formalParameterList != null) {
formalParameterList.setMyScope(bridgeScope);
bridgeScope.addSubScope(formalParameterList.getLocation(), formalParameterList);
}
if (baseRef != null) {
baseRef.setMyScope(formalParameterList);
}
if (statementBlock != null) {
statementBlock.setMyScope(formalParameterList);
}
}
public synchronized void addUninitializedMember(Identifier identifier, boolean isTemplate) {
uninitializedMembers.put(identifier, isTemplate);
......@@ -103,11 +149,61 @@ public class Def_Constructor extends Definition implements IParameterisedAssignm
}
lastTimeChecked = timestamp;
if (statementBlock != null) {
statementBlock.check(timestamp);
}
final Class_Type myClass = getMyScope().getScopeClass();
formalParameterList.check(timestamp, getAssignmentType());
for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
final FormalParameter fp = formalParameterList.getParameterByIndex(i);
if (fp.hasDefaultValue()) {
//fp.getDefaultParameter().checkDefaultParameterInClass(myClass.hasDefaultConstructor(), false, false);
}
}
final Class_Type baseClass = myClass.getBaseClass();
if (baseRef != null) {
if (baseClass == null) {
baseRef.getLocation().reportSemanticError(
MessageFormat.format(DOESNOTHAVESUPERCLASS, myClass.getTypeRefdLast(timestamp).getTypename()));
} else {
final Assignment baseCallAssignment = baseRef.getRefdAssignment(timestamp, false);
if (baseCallAssignment != null) {
if (baseCallAssignment.getAssignmentType() != Assignment_type.A_CONSTRUCTOR) {
baseRef.getLocation().reportSemanticError(
MessageFormat.format(CONSTRUCTORREFERENCEEXPECTED, baseCallAssignment.getAssignmentName()));
} else {
final Class_Type baseCallClass = baseCallAssignment.getMyScope().getScopeClass();
if (baseCallClass != baseClass) {
baseRef.getLocation().reportSemanticError(
MessageFormat.format(CONSTRUCTORCALLEXPECTED, myClass.getTypename(),
baseCallClass.getTypename()));
} // TODO : baseRef parameters
}
}
}
} else if (baseClass != null && !myClass.isExternal()) {
final Def_Constructor baseConstructor = baseClass.getConstructor(timestamp);
if (baseConstructor != null && !baseConstructor.getFormalParameterList().hasOnlyDefaultValues()) {
signatureLocation.reportSemanticError(MISSINGSUPERCONSTRUCTORCALL);
}
}
// reset 'usage found' flag for the constructor's formal parameters with default values
// (usage in the base constructor call doesn't count for these)
for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
final FormalParameter fp = formalParameterList.getParameterByIndex(i);
if (fp.hasDefaultValue()) {
fp.reset();
}
}
if (statementBlock != null) {
if (myClass.isExternal()) {
statementBlock.getLocation().reportSemanticError(EXTERNALWITHBODY);
}
statementBlock.check(timestamp);
} else if (!myClass.isExternal()) {
signatureLocation.reportSemanticError(MISSINGBODY);
}
}
@Override
......@@ -136,13 +232,23 @@ public class Def_Constructor extends Definition implements IParameterisedAssignm
@Override
public Location getSignatureLocation() {
// TODO Auto-generated method stub
return null;
return signatureLocation;
}
@Override
public void setSignatureLocation(Location signatureLocation) {
// TODO Auto-generated method stub
this.signatureLocation = signatureLocation;
}
@Override
/** {@inheritDoc} */
protected boolean memberAccept(final ASTVisitor v) {
if (!super.memberAccept(v)) {
return false;
}
if (formalParameterList != null && !formalParameterList.accept(v)) {
return false;
}
return true;
}
}
......@@ -175,6 +175,11 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
}
return true;
}
@Override
public Class_Type getScopeClass() {
return parentClass;
}
@Override
public String chainedDescription() {
......
......@@ -646,6 +646,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
}
final ParameterisedSubReference paramSubRef = new ParameterisedSubReference(classId, parsedApList);
paramSubRef.setLocation(NULL_Location.INSTANCE);
final List<ISubReference> subrefs = new ArrayList<>();
subrefs.add(paramSubRef);
baseCall = new Reference(baseClass.getMyScope().getParentScope().getModuleScope().getIdentifier().newInstance(),
......@@ -1162,13 +1163,13 @@ public final class Class_Type extends Type implements ITypeWithComponents {
lastTimeChecked = null;
boolean handled = false;
if (getLocation() != null) {
if (reparser.envelopsDamage(getLocation())) {
updateSyntax(reparser, true);
reparser.updateLocation(getLocation());
handled = true;
}
}
// if (getLocation() != null) {
// if (reparser.envelopsDamage(getLocation())) {
// updateSyntax(reparser, true);
// reparser.updateLocation(getLocation());
// handled = true;
// }
// }
if (subType != null) {
subType.updateSyntax(reparser, false);
......@@ -1397,4 +1398,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return true;
}
public boolean hasDefaultConstructor() {
return defaultConstructor;
}
}
\ 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