Commit 877be60a authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: improved constructor check


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 9d0bf15f
......@@ -421,7 +421,7 @@ testcase tc_basicSyntax() runs on CT {
var MinimalClass vl_minimalClass := MinimalClass.create;
// constructor call with empty parameter list
var MinimalClass vl_minimalClass2 := MinimalClass.create();
var ClassWithThis vl_thisClass := ClassWithThis.create(12, 13);
var ClassWithThis vl_thisClass := ClassWithThis.create(12, 13.0);
var VariousMembers vl_various := VariousMembers.create("abc", "def");
// class member access
......
......@@ -134,7 +134,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private Component_Type systemType = null;
private final Reference portReference;
private IType portType = null;
private final Type returnType;
private Type returnType;
private final boolean returnsTemplate;
private final TemplateRestriction.Restriction_type templateRestriction;
private final StatementBlock block;
......@@ -152,6 +152,8 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private final Location classModifierLocation;
private final Location funcModifierLocation;
private boolean isConstructor = false;
// stores whether this function can be started or not
private boolean isStartable;
......@@ -218,6 +220,9 @@ public final class Def_Function extends Definition implements IParameterisedAssi
returnType.setOwnertype(TypeOwner_type.OT_FUNCTION_DEF, this);
returnType.setFullNameParent(this);
}
if (isClassFunction && identifier.getName().equals("create")) {
isConstructor = true;
}
}
public Def_Function(final Identifier identifier, final FormalParameterList formalParameters, final Reference runsOnRef,
......@@ -230,6 +235,16 @@ public final class Def_Function extends Definition implements IParameterisedAssi
isDeterministic, isControl, funcModifierLocation);
}
public Def_Function(final Identifier identifier, final FormalParameterList formalParameters, final Reference runsOnRef,
final Reference mtcReference, final Reference systemReference, final Reference portReference,
final Type returnType, final boolean returnsTemplate, final TemplateRestriction.Restriction_type templateRestriction,
final SignatureExceptions exceptions, final StatementBlock block, final StatementBlock finallyBlock,
final boolean isDeterministic, final boolean isControl, final Location funcModifierLocation, final boolean isClassFunction) {
this(identifier, formalParameters, runsOnRef, mtcReference, systemReference, portReference, returnType,
returnsTemplate, templateRestriction, exceptions, block, finallyBlock, true, false, false, null,
isDeterministic, isControl, funcModifierLocation);
}
/**
* Constructor for functions defined by 'object'
* @param identifier
......@@ -434,6 +449,13 @@ public final class Def_Function extends Definition implements IParameterisedAssi
}
lastTimeChecked = timestamp;
if (isClassFunction && identifier.getName().equals("create")) {
INamedNode node = getNameParent();
if (node instanceof ClassTypeBody) {
Class_Type classType = ((ClassTypeBody)node).getMyType();
returnType = classType;
}
}
T3Doc.check(this.getCommentLocation(), KIND);
isUsed = false;
......@@ -576,7 +598,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
if (block != null) {
block.check(timestamp);
if (returnType != null) {
if (returnType != null && isConstructor == false) {
// check the presence of return statements
switch (block.hasReturn(timestamp)) {
case RS_NO:
......
......@@ -268,14 +268,6 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
initAttributes(timestamp);
if (classBody != null) {
classBody.check(timestamp);
}
if (finallyBlock != null) {
finallyBlock.check(timestamp);
}
if (classBody != null) {
if (classBody.hasConstructor() == true) {
......@@ -333,6 +325,14 @@ public final class Class_Type extends Type implements ITypeWithComponents {
classBody.addDefinition(constructor);
}
}
if (classBody != null) {
classBody.check(timestamp);
}
if (finallyBlock != null) {
finallyBlock.check(timestamp);
}
lastTimeChecked = timestamp;;
}
......
......@@ -12,7 +12,11 @@ import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.IValue;
import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.templates.ParsedActualParameters;
import org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
......@@ -22,7 +26,14 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
* @author Miklos Magyari
**/
public class ClassConstructorExpression extends Expression_Value {
final private Reference classReference;
final ParsedActualParameters parameters;
public ClassConstructorExpression(Reference classReference, ParsedActualParameters parameters) {
this.classReference = classReference;
this.parameters = parameters;
}
@Override
public Operation_type getOperationType() {
return Operation_type.CLASS_CONSTRUCTOR_OPERATION;
......@@ -44,6 +55,12 @@ public class ClassConstructorExpression extends Expression_Value {
lastValue = this;
return lastValue;
}
@Override
/** {@inheritDoc} */
public void setMyScope(final Scope scope) {
myScope = scope;
}
@Override
public Type_type getExpressionReturntype(CompilationTimeStamp timestamp, Expected_Value_type expectedValue) {
......
......@@ -35,10 +35,15 @@ import org.eclipse.titan.designer.AST.Value;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
import org.eclipse.titan.designer.AST.ReferenceFinder.Hit;
import org.eclipse.titan.designer.AST.IValue;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.AST.TTCN3.templates.ParsedActualParameters;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type;
......@@ -58,10 +63,11 @@ public class UndefCreateExpression extends Expression_Value {
private static final String ABSTRACTINSTANTIATED = "An abstract class cannot be instantiated";
private static final String OPERATIONNAME = "create()";
private Reference componentReference;
private Value name;
private Value location;
private boolean isAlive;
final private Reference componentReference;
final private Value name;
final private Value location;
final private boolean isAlive;
final private ParsedActualParameters parameters;
private Expression_Value realExpression;
......@@ -74,6 +80,7 @@ public class UndefCreateExpression extends Expression_Value {
this.name = name;
this.location = location;
this.isAlive = isAlive;
this.parameters = parameters;
if (reference != null) {
reference.setFullNameParent(this);
......@@ -121,6 +128,9 @@ public class UndefCreateExpression extends Expression_Value {
if (location != null) {
location.setMyScope(scope);
}
if (parameters != null) {
parameters.setMyScope(scope);
}
}
@Override
......@@ -259,11 +269,16 @@ public class UndefCreateExpression extends Expression_Value {
getLocation().reportSemanticError(ABSTRACTINSTANTIATED);
setIsErroneous(true);
}
realExpression = new ClassConstructorExpression();
realExpression = new ClassConstructorExpression(componentReference, parameters);
realExpression.setMyScope(getMyScope());
realExpression.setFullNameParent(this);
realExpression.setLocation(getLocation());
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
final ActualParameterList tempActualParameters = new ActualParameterList();
final Assignment constructorAssignment = classInstance.getClassBody().getAssByIdentifier(timestamp, new Identifier(Identifier_type.ID_TTCN, "create"));
FormalParameterList fpList = ((Def_Function)constructorAssignment).getFormalParameterList();
fpList.checkActualParameterList(timestamp, parameters, tempActualParameters);
// FIXME : implement
}
}
......
......@@ -4924,24 +4924,40 @@ pr_CreateOpEnd [Reference temporalReference]
Value name = null;
Value location = null;
boolean isAlive = false;
ParsedActualParameters params = null;
ParsedActualParameters params = new ParsedActualParameters();
}:
( col = pr_Dot
a = pr_CreateKeyword { endcol = $a.stop; }
( pr_LParen
( pr_NotUsedSymbol
pr_Comma
l = pr_SingleExpression { location = $l.value; }
| n = pr_SingleExpression { name = $n.value; }
l = pr_SingleExpression {
location = $l.value;
}
| n = pr_SingleExpression {
name = $n.value;
TTCN3Template template = new SpecificValue_Template(name);
template.setLocation(getLocation( $n.start, $n.stop));
TemplateInstance instance = new TemplateInstance(null, null, template);
params.addUnnamedParameter(instance);
params.setLocation(getLocation( $n.start, $n.stop));
}
( pr_Comma
l2 = pr_SingleExpression { location = $l2.value; }
l2 = pr_SingleExpression {
location = $l2.value;
TTCN3Template template2 = new SpecificValue_Template(location);
template2.setLocation(getLocation( $l2.start, $l2.stop));
TemplateInstance instance2 = new TemplateInstance(null, null, template2);
params.addUnnamedParameter(instance2);
params.setLocation(getLocation( $n.start, $l2.stop));
}
)?
)
b = pr_RParen { endcol = $b.stop; }
)?
( c = ALIVE { endcol = $c; isAlive = true; } )?
{
$value = new UndefCreateExpression($temporalReference, name, location, isAlive);
$value = new UndefCreateExpression($temporalReference, name, location, isAlive, params);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
}
| col2 = pr_Dot
......@@ -9485,7 +9501,7 @@ pr_ClassConstructorDef returns[Def_Function def_func]
if(parameters == null) { parameters = new FormalParameterList(new ArrayList<FormalParameter>()); }
parameters.setLocation(getLocation( $pstart.start, $pstop.stop));
Identifier id = new Identifier( Identifier_type.ID_TTCN, "create", getLocation($id.start, $id.stop ) );
$def_func = new Def_Function(id, parameters, null, null, null, null, null, false, null, null, statementBlock, null, false, false, null);
$def_func = new Def_Function(id, parameters, null, null, null, null, null, false, null, null, statementBlock, null, false, false, null, true);
$def_func.setLocation(getLocation( $id.start, $sb.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
};
......
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