Commit ae2d6fd7 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: better handling for function modifiers


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 65e6d53a
......@@ -147,8 +147,11 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private final boolean isClassFunction;
private final boolean isAbstract;
private final boolean isFinal;
private final boolean isDeterministic;
private final boolean isControl;
private final Location modifierLocation;
private final Location classModifierLocation;
private final Location funcModifierLocation;
// stores whether this function can be started or not
private boolean isStartable;
......@@ -158,7 +161,8 @@ public final class Def_Function extends Definition implements IParameterisedAssi
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,
boolean isClassFunction, boolean isAbstract, boolean isFinal, Location modifierLocation) {
final boolean isClassFunction, final boolean isAbstract, final boolean isFinal, final Location classModifierLocation,
final boolean isDeterministic, final boolean isControl, final Location funcModifierLocation) {
super(identifier);
assignmentType = (returnType == null) ? Assignment_type.A_FUNCTION : (returnsTemplate ? Assignment_type.A_FUNCTION_RTEMP
: Assignment_type.A_FUNCTION_RVAL);
......@@ -179,7 +183,10 @@ public final class Def_Function extends Definition implements IParameterisedAssi
this.isClassFunction = isClassFunction;
this.isAbstract = isAbstract;
this.isFinal = isFinal;
this.modifierLocation = modifierLocation;
this.classModifierLocation = classModifierLocation;
this.isDeterministic = isDeterministic;
this.isControl = isControl;
this.funcModifierLocation = funcModifierLocation;
this.exceptions = exceptions;
this.prototype = EncodingPrototype_type.NONE;
......@@ -216,9 +223,11 @@ 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 SignatureExceptions exceptions, final StatementBlock block, final StatementBlock finallyBlock) {
final SignatureExceptions exceptions, final StatementBlock block, final StatementBlock finallyBlock,
final boolean isDeterministic, final boolean isControl, final Location funcModifierLocation) {
this(identifier, formalParameters, runsOnRef, mtcReference, systemReference, portReference, returnType,
returnsTemplate, templateRestriction, exceptions, block, finallyBlock, false, false, false, null);
returnsTemplate, templateRestriction, exceptions, block, finallyBlock, false, false, false, null,
isDeterministic, isControl, funcModifierLocation);
}
/**
......@@ -227,7 +236,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, null, null);
this(identifier, formalParameters, null, null, null, null, returnType, false, null, null, null, null, false, false, null);
}
public boolean isStartable() {
......@@ -457,7 +466,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
if (parent instanceof ClassTypeBody) {
final Class_Type myclass = ((ClassTypeBody)parent).getMyType();
if (! (myclass.isAbstract() || myclass.isTrait())) {
modifierLocation.reportSemanticError(ABSTRACTFUNCTION);
classModifierLocation.reportSemanticError(ABSTRACTFUNCTION);
}
}
}
......
......@@ -2790,9 +2790,16 @@ pr_FunctionDef returns[Def_Function def_func]
TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
SignatureExceptions exceptions = null;
StatementBlock finallyBlock = null;
boolean isDeterministic = false;
boolean isControl = false;
Location modifierLocation;
}:
( col = pr_FunctionKeyword
( pr_DeterministicModifier | pr_ControlModifier )?
fm = pr_FunctionModifier {
isControl = $fm.isControl;
isDeterministic = $fm.isDeterministic;
modifierLocation = getLocation( $fm.start, $fm.stop );
}
i = pr_Identifier
start1 = pr_LParen
( p = pr_FunctionFormalParList { parameters = $p.parList; } )?
......@@ -2822,12 +2829,24 @@ pr_FunctionDef returns[Def_Function def_func]
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, exceptions, statementBlock, finallyBlock);
$def_func = new Def_Function($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, portReference, returnType, returnsTemplate,
templateRestriction, exceptions, statementBlock, finallyBlock, isDeterministic, isControl, modifierLocation);
$def_func.setLocation(getLocation( $col.start, $s.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
}
};
pr_FunctionModifier returns[boolean isControl, boolean isDeterministic]
@init {
$isControl = false;
$isDeterministic = false;
}:
(
DETERMINISTICKEYWORD { $isDeterministic = true;}
| CONTROLMODIFIER { $isControl = true; }
)*
;
pr_FunctionKeyword:
FUNCTION
;
......@@ -9333,7 +9352,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, exceptions, statementBlock, null, true, isAbstract, isFinal, modifierLocation);
portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock, null, true, isAbstract, isFinal, modifierLocation, false, false, null);
$def_func.setLocation(getLocation( $col.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