Commit 45f80db8 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: initial support for class properties (issue #417, issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 5a514e34
......@@ -316,6 +316,19 @@ type class ClassWithPrivateExt extends ClassWithPrivate {
}
}
// class properties
type class CorrectWithProperty {
private var integer heightVal;
private var integer @property width;
var integer @property height {
@get => heightVal;
@set {
if (value > 0) {
heightVal := value;
}
}
}
}
testcase tc_basicSyntax() runs on CT {
var object vl_obj := MinimalClass.create;
......
......@@ -101,6 +101,8 @@ public interface IType extends IGovernor, IIdentifierContainer, IVisitableNode,
TYPE_PORT,
/** class (TTCN-3 extension) */
TYPE_CLASS,
/** property (TTCN-3 OOP extension) */
TYPE_PROPERTY,
/** anytype (TTCN-3). */
TYPE_ANYTYPE,
......
......@@ -28,6 +28,7 @@ import org.eclipse.titan.designer.AST.INamedNode;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.ISubReference;
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.NULL_Location;
import org.eclipse.titan.designer.AST.NamedBridgeScope;
......@@ -35,17 +36,21 @@ import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.ReferenceFinder;
import org.eclipse.titan.designer.AST.ReferenceFinder.Hit;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax;
import org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable;
import org.eclipse.titan.designer.AST.TTCN3.TTCN3Scope;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter.parameterEvaluationType;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.AST.TTCN3.statements.Statement.Statement_type;
import org.eclipse.titan.designer.AST.TTCN3.types.ClassTypeBody;
import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.SkeletonTemplateProposal;
......@@ -65,6 +70,7 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Reparser.Pr_reparse_F
*
* @author Kristof Szabados
* @author Arpad Lovassy
* @author Miklos Magyari
*/
public final class StatementBlock extends TTCN3Scope implements ILocateableNode, IIncrementallyUpdateable {
private static final String FULLNAMEPART = ".statement_";
......@@ -122,6 +128,9 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
* interleave, altstep, call).
*/
private boolean ownerIsAltguard;
/** Indicates it is a statement block of a class property */
private boolean ownerIsProperty;
/**
* Caches whether this function has return statement or not. Used to
......@@ -144,6 +153,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
ownerIsLoop = false;
ownerIsAltguard = false;
ownerIsDestructor = false;
ownerIsProperty = false;
}
@Override
......@@ -239,6 +249,13 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
public void setOwnerIsDestructor() {
ownerIsDestructor = true;
}
/**
* Sets indication that it is a statement block of a class property.
**/
public void setOwnerIsProperty() {
ownerIsProperty = true;
}
/**
* Adds a statement to the list of statements stored in this statement
......@@ -564,7 +581,7 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
if (labelMap != null) {
labelMap.clear();
}
checkLabels(timestamp);
boolean unreachableFound = false;
......
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
/**
* property type (TTCN-3 OOP extension)
*
* @author Miklos Magyari
*/
package org.eclipse.titan.designer.AST.TTCN3.types;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.ITypeWithComponents;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Reference;
import org.eclipse.titan.designer.AST.Type;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo;
import org.eclipse.titan.designer.AST.TypeCompatibilityInfo.Chain;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
/**
* Represents TTCN3 properties of the OOP extension
*
* @author Miklos Magyari
* */
public final class Property_Type extends Type {
private Type myType;
private StatementBlock getStatementBlock;
private StatementBlock setStatementBlock;
public Property_Type(Type type) {
this.myType = type;
this.setStatementBlock = null;
this.getStatementBlock = null;
}
/**
* Sets the statement block for the property getter
* @param sb
*/
public void setStatementBlockGetter(StatementBlock sb) {
getStatementBlock = sb;
if (getStatementBlock != null) {
getStatementBlock.setOwnerIsProperty();
getStatementBlock.setFullNameParent(this);
}
}
/**
* Sets the statement block for the property setter
* @param sb
*/
public void setStatementBlockSetter(StatementBlock sb) {
setStatementBlock = sb;
if (setStatementBlock != null) {
setStatementBlock.setOwnerIsProperty();
setStatementBlock.setFullNameParent(this);
}
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
if (getStatementBlock != null) {
// getStatementBlock.check(timestamp);
}
if (setStatementBlock != null) {
// setStatementBlock.check(timestamp);
}
}
@Override
public Type_type getTypetype() {
return Type_type.TYPE_PROPERTY;
}
@Override
public String getTypename() {
return "property";
}
@Override
public String getOutlineIcon() {
// TODO Auto-generated method stub
return null;
}
@Override
public IType getFieldType(CompilationTimeStamp timestamp, Reference reference, int actualSubReference,
Expected_Value_type expectedIndex, IReferenceChain refChain, boolean interruptIfOptional) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean checkThisTemplate(CompilationTimeStamp timestamp, ITTCN3Template template, boolean isModified,
boolean implicitOmit, Assignment lhs) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isCompatible(CompilationTimeStamp timestamp, IType otherType, TypeCompatibilityInfo info,
Chain leftChain, Chain rightChain) {
// TODO Auto-generated method stub
return false;
}
@Override
public Type_type getTypetypeTtcn3() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean generatesOwnClass(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
return false;
}
@Override
public void generateCode(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
}
@Override
public String getGenNameValue(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getGenNameTemplate(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getGenNameTypeDescriptor(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
return null;
}
}
......@@ -4544,14 +4544,15 @@ pr_SingleVarInstance[Type type, parameterEvaluationType eval] returns[Def_Var de
Value value = null;
ArrayDimensions dimensions = null;
boolean isProperty = false;
Property_Type prop = null;
}:
( ( PROPERTYKEYWORD { isProperty = true; } )?
( ( prop = pr_PropertyKeyword { isProperty = true; } )?
i = pr_Identifier
( d = pr_ArrayDef { dimensions = $d.dimensions; })?
( pr_AssignmentChar
v = pr_VarInitialValue { value = $v.value; }
)?
pr_PropertyBody?
( body = pr_PropertyBody[type] { prop = $body.prop; } )?
)
{
if ($i.identifier != null) {
......@@ -4562,11 +4563,19 @@ pr_SingleVarInstance[Type type, parameterEvaluationType eval] returns[Def_Var de
type2.setLocation(getLocation( $d.start, $d.stop));
}
}
if (isProperty) {
type2 = prop == null ? new Property_Type(type) : prop;
type2.setLocation(getLocation( $prop.start, getLastVisibleToken()));
}
$definition = new Def_Var( $i.identifier, type2, value, $eval );
$definition.setLocation(getLocation( $start, getLastVisibleToken()));
}
};
pr_PropertyKeyword:
PROPERTYKEYWORD
;
pr_VarInitialValue returns[Value value]
@init {
$value = null;
......@@ -6278,6 +6287,7 @@ pr_Value returns[Value value]
}:
( v1 = pr_PredefinedValue { $value = $v1.value; }
| v2 = pr_ReferencedValue { $value = $v2.value; }
| VALUE { $value = null; }
);
pr_PredefinedValue returns [Value value]
......@@ -9398,16 +9408,21 @@ pr_SelectClassCase:
SEMICOLON?
);
pr_PropertyBody:
pr_PropertyBody[Type type] returns[Property_Type prop]
@init {
$prop = new Property_Type(type);
}:
(
pr_BeginChar
( pr_PropertyGetter pr_PropertySetter?
| pr_PropertySetter pr_PropertyGetter?
( sbg1 = pr_PropertyGetter { $prop.setStatementBlockGetter( $sbg1.statementblock ); }
( sbs1 = pr_PropertySetter { $prop.setStatementBlockSetter( $sbs1.statementblock ); } )?
| sbs2 = pr_PropertySetter { $prop.setStatementBlockSetter( $sbs2.statementblock ); }
(sbg2 = pr_PropertyGetter { $prop.setStatementBlockGetter( $sbg2.statementblock ); } )?
)
pr_EndChar
);
pr_PropertyGetter:
pr_PropertyGetter returns[StatementBlock statementblock]:
(
( PUBLIC | PRIVATE )?
( pr_AbstractModifier | pr_FinalModifier )?
......@@ -9417,13 +9432,13 @@ pr_PropertyGetter:
(
CLASSCASTING
pr_TemplateBody
| pr_StatementBlock
| sb = pr_StatementBlock { $statementblock = $sb.statementblock; }
)
)?
SEMICOLON?
);
pr_PropertySetter:
pr_PropertySetter returns[StatementBlock statementblock]:
(
( PUBLIC | PRIVATE )?
( pr_AbstractModifier | pr_FinalModifier )?
......@@ -9432,7 +9447,7 @@ pr_PropertySetter:
(
( CLASSCASTING
pr_TemplateBody
| pr_StatementBlock
| sb = pr_StatementBlock { $statementblock = $sb.statementblock; }
)
)?
SEMICOLON?
......
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