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 {
private function f_dummy(in integer x) return integer {
return 1;
}
}
}
create (charstring p1, charstring p2) {
m_var1 := p2;
}
}
type class @trait AbstractMembersClass {
......@@ -135,9 +139,13 @@ type class SubClass4 extends SuperBaseClass {
}
}
// basic instantiation
// basic instantiation and constructor calls
testcase tc_basicSyntax() runs on CT {
var object vl_obj := 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 {
......
......@@ -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.TTCN3.Expected_Value_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.values.Expression_Value;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
......@@ -57,17 +59,20 @@ public class UndefCreateExpression extends Expression_Value {
private Value name;
private Value location;
private boolean isAlive;
private ParsedActualParameters parameters;
private Expression_Value realExpression;
private CompilationTimeStamp checkCreateTimestamp;
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.name = name;
this.location = location;
this.isAlive = isAlive;
this.parameters = parameters;
if (reference != null) {
reference.setFullNameParent(this);
......@@ -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
/** {@inheritDoc} */
public Operation_type getOperationType() {
......@@ -179,42 +192,64 @@ public class UndefCreateExpression extends Expression_Value {
* */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue,
final IReferenceChain referenceChain) {
setIsErroneous(false);
checkCreate(timestamp);
if (name != null) {
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 (componentReference == null) {
return;
}
final Assignment assignment = componentReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType assignmentType = assignment.getType(timestamp);
if (assignmentType instanceof Component_Type) {
if (name != null) {
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) {
final IValue last = location.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(SECONDOPERANDERROR);
setIsErroneous(true);
break;
if (location != null) {
final IValue last = location.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(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
}
}
checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
realExpression = new ComponentCreateExpression(componentReference, name, location, isAlive);
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
......@@ -233,15 +268,9 @@ public class UndefCreateExpression extends Expression_Value {
return lastValue;
}
checkCreate(timestamp);
checkExpressionOperands(timestamp, expectedValue, referenceChain);
realExpression = new ComponentCreateExpression(componentReference, name, location, isAlive);
realExpression.setMyScope(getMyScope());
realExpression.setFullNameParent(this);
realExpression.setLocation(getLocation());
realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
checkCreate(timestamp);
return lastValue;
}
private Component_Type checkCreate(final CompilationTimeStamp timestamp) {
......
......@@ -2887,7 +2887,8 @@ pr_FunctionStatementOrDefList returns[List<Statement> statements]
$statements = null;
}:
(
( s = pr_FunctionStatementOrDef
(
s = pr_FunctionStatementOrDef
{ if($statements == null) {$statements = $s.statements;}
else if ($s.statements != null) { $statements.addAll($s.statements); }
}
......@@ -4752,20 +4753,24 @@ pr_CreateOpEnd [Reference temporalReference]
b = pr_RParen { endcol = $b.stop; }
)?
( c = ALIVE { endcol = $c; isAlive = true; } )?
{
$value = new UndefCreateExpression($temporalReference, name, location, isAlive);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
}
|
col2 = pr_Dot
a2 = pr_CreateKeyword { endcol = $a2.stop; }
( pr_LParen
(
pr_FunctionActualParList
par = pr_FunctionActualParList
)
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]
......
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