Commit 298e14a2 authored by Miklos Magyari's avatar Miklos Magyari

OOP: added basic parsing support for constructor calls

Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 83f14986
...@@ -92,7 +92,11 @@ type class VariousMembers { ...@@ -92,7 +92,11 @@ type class VariousMembers {
private function f_dummy(in integer x) return integer { private function f_dummy(in integer x) return integer {
return 1; return 1;
} }
} }
create (charstring p1, charstring p2) {
m_var1 := p2;
}
} }
type class @trait AbstractMembersClass { type class @trait AbstractMembersClass {
...@@ -135,9 +139,13 @@ type class SubClass4 extends SuperBaseClass { ...@@ -135,9 +139,13 @@ type class SubClass4 extends SuperBaseClass {
} }
} }
// basic instantiation // basic instantiation and constructor calls
testcase tc_basicSyntax() runs on CT { testcase tc_basicSyntax() runs on CT {
var object vl_obj := MinimalClass.create;
var MinimalClass vl_minimalClass := MinimalClass.create; var MinimalClass vl_minimalClass := MinimalClass.create;
var ClassWithThis vl_thisClass := ClassWithThis.create(12, 13);
var VariousMembers vl_various := VariousMembers.create("abc", "def");
} }
control { control {
......
...@@ -39,6 +39,8 @@ import org.eclipse.titan.designer.AST.ReferenceFinder.Hit; ...@@ -39,6 +39,8 @@ import org.eclipse.titan.designer.AST.ReferenceFinder.Hit;
import org.eclipse.titan.designer.AST.IValue; import org.eclipse.titan.designer.AST.IValue;
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.definitions.Def_Type; import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type;
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; import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type;
import org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value; import org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp; import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
...@@ -57,17 +59,20 @@ public class UndefCreateExpression extends Expression_Value { ...@@ -57,17 +59,20 @@ public class UndefCreateExpression extends Expression_Value {
private Value name; private Value name;
private Value location; private Value location;
private boolean isAlive; private boolean isAlive;
private ParsedActualParameters parameters;
private Expression_Value realExpression; private Expression_Value realExpression;
private CompilationTimeStamp checkCreateTimestamp; private CompilationTimeStamp checkCreateTimestamp;
private Component_Type checkCreateCache; private Component_Type checkCreateCache;
public UndefCreateExpression(final Reference reference, final Value name, final Value location, final boolean isAlive) { public UndefCreateExpression(final Reference reference, final Value name, final Value location,
final boolean isAlive, final ParsedActualParameters parameters) {
this.componentReference = reference; this.componentReference = reference;
this.name = name; this.name = name;
this.location = location; this.location = location;
this.isAlive = isAlive; this.isAlive = isAlive;
this.parameters = parameters;
if (reference != null) { if (reference != null) {
reference.setFullNameParent(this); reference.setFullNameParent(this);
...@@ -80,6 +85,14 @@ public class UndefCreateExpression extends Expression_Value { ...@@ -80,6 +85,14 @@ public class UndefCreateExpression extends Expression_Value {
} }
} }
public UndefCreateExpression(final Reference reference, final Value name, final Value location, final boolean isAlive) {
this(reference, name, location, isAlive, null);
}
public UndefCreateExpression(final Reference reference, final ParsedActualParameters parameters) {
this(reference, null, null, false, parameters);
}
@Override @Override
/** {@inheritDoc} */ /** {@inheritDoc} */
public Operation_type getOperationType() { public Operation_type getOperationType() {
...@@ -179,42 +192,64 @@ public class UndefCreateExpression extends Expression_Value { ...@@ -179,42 +192,64 @@ public class UndefCreateExpression extends Expression_Value {
* */ * */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue,
final IReferenceChain referenceChain) { final IReferenceChain referenceChain) {
setIsErroneous(false);
checkCreate(timestamp); checkCreate(timestamp);
if (name != null) { if (componentReference == null) {
final IValue last = name.setLoweridToReference(timestamp); return;
final Type_type typeType = last.getExpressionReturntype(timestamp, expectedValue); }
if (!last.getIsErroneous(timestamp)) {
switch (typeType) { final Assignment assignment = componentReference.getRefdAssignment(timestamp, true);
case TYPE_CHARSTRING: if (assignment == null) {
last.getValueRefdLast(timestamp, referenceChain); setIsErroneous(true);
break; return;
case TYPE_UNDEFINED: }
break;
default: IType assignmentType = assignment.getType(timestamp);
name.getLocation().reportSemanticError(FIRSTOPERANDERROR); if (assignmentType instanceof Component_Type) {
setIsErroneous(true); if (name != null) {
break; final IValue last = name.setLoweridToReference(timestamp);
final Type_type typeType = last.getExpressionReturntype(timestamp, expectedValue);
if (!last.getIsErroneous(timestamp)) {
switch (typeType) {
case TYPE_CHARSTRING:
last.getValueRefdLast(timestamp, referenceChain);
break;
case TYPE_UNDEFINED:
break;
default:
name.getLocation().reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
} }
} }
} if (location != null) {
if (location != null) { final IValue last = location.setLoweridToReference(timestamp);
final IValue last = location.setLoweridToReference(timestamp); final Type_type typeType = last.getExpressionReturntype(timestamp, expectedValue);
final Type_type typeType = last.getExpressionReturntype(timestamp, expectedValue); if (!last.getIsErroneous(timestamp)) {
if (!last.getIsErroneous(timestamp)) { switch (typeType) {
switch (typeType) { case TYPE_CHARSTRING:
case TYPE_CHARSTRING: last.getValueRefdLast(timestamp, referenceChain);
last.getValueRefdLast(timestamp, referenceChain); break;
break; case TYPE_UNDEFINED:
case TYPE_UNDEFINED: break;
break; default:
default: name.getLocation().reportSemanticError(SECONDOPERANDERROR);
name.getLocation().reportSemanticError(SECONDOPERANDERROR); setIsErroneous(true);
setIsErroneous(true); break;
break; }
} }
} }
} realExpression = new ComponentCreateExpression(componentReference, name, location, isAlive);
checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false); realExpression.setMyScope(getMyScope());
realExpression.setFullNameParent(this);
realExpression.setLocation(getLocation());
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
} else if (assignmentType instanceof Class_Type) {
}
} }
@Override @Override
...@@ -233,15 +268,9 @@ public class UndefCreateExpression extends Expression_Value { ...@@ -233,15 +268,9 @@ public class UndefCreateExpression extends Expression_Value {
return lastValue; return lastValue;
} }
checkCreate(timestamp);
checkExpressionOperands(timestamp, expectedValue, referenceChain); checkExpressionOperands(timestamp, expectedValue, referenceChain);
realExpression = new ComponentCreateExpression(componentReference, name, location, isAlive); checkCreate(timestamp);
realExpression.setMyScope(getMyScope());
realExpression.setFullNameParent(this);
realExpression.setLocation(getLocation());
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
return lastValue; return lastValue;
} }
private Component_Type checkCreate(final CompilationTimeStamp timestamp) { private Component_Type checkCreate(final CompilationTimeStamp timestamp) {
......
...@@ -2887,7 +2887,8 @@ pr_FunctionStatementOrDefList returns[List<Statement> statements] ...@@ -2887,7 +2887,8 @@ pr_FunctionStatementOrDefList returns[List<Statement> statements]
$statements = null; $statements = null;
}: }:
( (
( s = pr_FunctionStatementOrDef (
s = pr_FunctionStatementOrDef
{ if($statements == null) {$statements = $s.statements;} { if($statements == null) {$statements = $s.statements;}
else if ($s.statements != null) { $statements.addAll($s.statements); } else if ($s.statements != null) { $statements.addAll($s.statements); }
} }
...@@ -4752,20 +4753,24 @@ pr_CreateOpEnd [Reference temporalReference] ...@@ -4752,20 +4753,24 @@ pr_CreateOpEnd [Reference temporalReference]
b = pr_RParen { endcol = $b.stop; } b = pr_RParen { endcol = $b.stop; }
)? )?
( c = ALIVE { endcol = $c; isAlive = true; } )? ( c = ALIVE { endcol = $c; isAlive = true; } )?
{
$value = new UndefCreateExpression($temporalReference, name, location, isAlive);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
}
| |
col2 = pr_Dot col2 = pr_Dot
a2 = pr_CreateKeyword { endcol = $a2.stop; } a2 = pr_CreateKeyword { endcol = $a2.stop; }
( pr_LParen ( pr_LParen
( (
pr_FunctionActualParList par = pr_FunctionActualParList
) )
b2 = pr_RParen { endcol = $b2.stop; } b2 = pr_RParen { endcol = $b2.stop; }
{
$value = new UndefCreateExpression($temporalReference, $par.parsedParameters);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
}
)? )?
) )
{
$value = new UndefCreateExpression($temporalReference, name, location, isAlive);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
}
; ;
pr_SystemOp returns[SystemComponentExpression value] pr_SystemOp returns[SystemComponentExpression value]
......
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