Commit 2d8135f2 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: implemented bnf changes for function defs


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent ba953f8b
......@@ -346,6 +346,48 @@ type class CorrectWithProperty {
}
/***************************
exception handling
****************************/
function f_example() {
}
type integer MyInteger;
type integer MyRange (0 .. 255);
// function with multiple catch blocks
function f_example2() {
f_example();
} catch (MyInteger e) {
} catch (MyRange e) {
} catch (integer e) {
}
function f_with_finally() {
// function body
} finally {
// finally block
}
function f_with_catches_and_finally(in charstring pl_chr) {
return;
} catch (MyRange e) {
} catch (integer e) {
} finally {
// finally block
}
// function with a @control modifier
function @control f_example3(in integer pl_int) {
}
testcase tc_basicSyntax() runs on CT {
var object vl_obj := MinimalClass.create;
......
......@@ -18,6 +18,7 @@ import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType;
......@@ -53,6 +54,7 @@ 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.Port_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.Stylers;
......@@ -117,6 +119,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private static final String CLASSNOMTC = "Class functions cannot have an `mtc` clause";
private static final String CLASSNOSYSTEM = "Class functions cannot have a `system` clause";
private static final String ABSTRACTFUNCTION = "Abstract function can only be declared in an abstract or trait class";
private static final String EXCEPTIONSOOP = "Function exceptions are only supported in the OOP extension";
private static final String KIND = "function";
......@@ -138,6 +141,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private Type inputType;
private Type outputType;
private final SignatureExceptions exceptions;
private final boolean isClassFunction;
private final boolean isAbstract;
private final boolean isFinal;
......@@ -151,7 +155,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
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 StatementBlock block,
final SignatureExceptions exceptions, final StatementBlock block,
boolean isClassFunction, boolean isAbstract, boolean isFinal, Location modifierLocation) {
super(identifier);
assignmentType = (returnType == null) ? Assignment_type.A_FUNCTION : (returnsTemplate ? Assignment_type.A_FUNCTION_RTEMP
......@@ -173,6 +177,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
this.isAbstract = isAbstract;
this.isFinal = isFinal;
this.modifierLocation = modifierLocation;
this.exceptions = exceptions;
this.prototype = EncodingPrototype_type.NONE;
inputType = null;
......@@ -203,9 +208,9 @@ public final class Def_Function extends Definition implements IParameterisedAssi
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 StatementBlock block) {
final SignatureExceptions exceptions, final StatementBlock block) {
this(identifier, formalParameters, runsOnRef, mtcReference, systemReference, portReference, returnType,
returnsTemplate, templateRestriction, block, false, false, false, null);
returnsTemplate, templateRestriction, exceptions, block, false, false, false, null);
}
/**
......@@ -214,7 +219,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
* @param returnType
*/
public Def_Function(final Identifier identifier, final FormalParameterList formalParameters, final Type returnType) {
this(identifier, formalParameters, null, null, null, null, returnType, false, null, null);
this(identifier, formalParameters, null, null, null, null, returnType, false, null, null, null);
}
public boolean isStartable() {
......@@ -416,6 +421,13 @@ public final class Def_Function extends Definition implements IParameterisedAssi
portType = null;
isStartable = false;
if (exceptions != null) {
final boolean isOopEnabled = Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.ENABLEOOPEXTENSION);
if (! isOopEnabled) {
exceptions.getLocation().reportSemanticError(EXCEPTIONSOOP);
}
}
if (isClassFunction) {
if (runsOnRef != null) {
runsOnRef.getLocation().reportSemanticError(CLASSNORUNSON);
......
......@@ -53,7 +53,7 @@ public final class CodeScanner extends RuleBasedScanner {
public static final String[] OOP_TITANSPECIFICKEYWORDS = new String[] {
/* Because some OOP keywords start with @, they are added here temporarily
* as TITANSPECIFICKEYWORDS have special handling of the @ character */
"@abstract", "@final", "@trait", "@property"
"@abstract", "@control", "@final", "@property", "@trait"
};
public static final String[] TEMPLATE_MATCH = new String[] { "complement", "decmatch", "ifpresent", "subset", "superset", "permutation" };
......
......@@ -51,7 +51,7 @@ public final class TTCN3Keywords {
public static final String[] OOP_ALL_AVAILABLE = new String[] {
/* OOP extension keywords */
"class", "@abstract", "@final", "@trait", "@property", "this", "super", "finally"
"class", "@abstract", "@control", "@final", "@trait", "@property", "this", "super", "finally"
};
public static final String[] FORMAL_PARAMETER_SCOPE = new String[] { "in", "inout", "out", "template" };
......
......@@ -552,6 +552,7 @@ NOCASEKEYWORD: '@nocase';
LAZYKEYWORD: '@lazy';
DECODEDKEYWORD: '@decoded';
DETERMINISTICKEYWORD: '@deterministic';
CONTROLMODIFIER: '@control' { isOopEnabled }? ;
FUZZYKEYWORD: '@fuzzy';
INDEXKEYWORD: '@index';
LOCALKEYWORD: '@local';
......
......@@ -2780,9 +2780,11 @@ pr_FunctionDef returns[Def_Function def_func]
Type returnType = null;
boolean returnsTemplate = false;
TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
SignatureExceptions exceptions = null;
StatementBlock finallyBlock = null;
}:
( col = pr_FunctionKeyword
pr_DeterministicModifier?
( pr_DeterministicModifier | pr_ControlModifier )?
i = pr_Identifier
start1 = pr_LParen
( p = pr_FunctionFormalParList { parameters = $p.parList; } )?
......@@ -2801,13 +2803,18 @@ pr_FunctionDef returns[Def_Function def_func]
}
}
)?
( exc = pr_ExceptionSpec { exceptions = $exc.exceptions; } )?
s = pr_StatementBlock { statementBlock = $s.statementblock; }
pr_CatchBlockList?
fd = pr_FinallyDef {
finallyBlock = $fd.statementBlock;
}
)
{
if($i.identifier != null && statementBlock != null) {
if(parameters == null) { parameters = new FormalParameterList(new ArrayList<FormalParameter>()); }
parameters.setLocation(getLocation( $start1.start, $end.stop));
$def_func = new Def_Function($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, portReference, returnType, returnsTemplate, templateRestriction, statementBlock);
$def_func = new Def_Function($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock);
$def_func.setLocation(getLocation( $col.start, $s.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
}
......@@ -4393,6 +4400,10 @@ pr_ControlKeyword:
CONTROL
;
pr_ControlModifier:
CONTROLMODIFIER
;
pr_ModuleControlBody returns [StatementBlock block]
@init {
$block = null;
......@@ -9237,6 +9248,7 @@ pr_ClassFunctionDef returns[Def_Function def_func]
boolean isFinal = false;
boolean isTrait = false;
Location modifierLocation = null;
SignatureExceptions exceptions = null;
}:
(
pr_ExtKeyword?
......@@ -9262,6 +9274,7 @@ pr_ClassFunctionDef returns[Def_Function def_func]
}
}
)?
( exc = pr_ExceptionSpec { exceptions = $exc.exceptions; } )?
( sb=pr_StatementBlock { statementBlock = $sb.statementblock; })?
)
{
......@@ -9269,7 +9282,7 @@ pr_ClassFunctionDef returns[Def_Function def_func]
if(parameters == null) { parameters = new FormalParameterList(new ArrayList<FormalParameter>()); }
parameters.setLocation(getLocation( $start1.start, $end.stop));
$def_func = new Def_Function($id.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference,
portReference, returnType, returnsTemplate, templateRestriction, statementBlock, true, isAbstract, isFinal, modifierLocation);
portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock, true, isAbstract, isFinal, modifierLocation);
$def_func.setLocation(getLocation( $col.start, $sb.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
}
......@@ -9307,7 +9320,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, statementBlock, true, false, false, null);
$def_func = new Def_Function(id, parameters, null, null, null, null, null, false, null, null, statementBlock, true, false, false, null);
$def_func.setLocation(getLocation( $id.start, $sb.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
};
......@@ -9484,3 +9497,15 @@ pr_PropertySetter returns[StatementBlock statementblock, TTCN3Template template]
)?
SEMICOLON?
);
pr_CatchBlock:
CATCH
pr_LParen
pr_Type pr_Identifier
pr_RParen
pr_StatementBlock
;
pr_CatchBlockList:
pr_CatchBlock+
;
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