Commit 71fb3d93 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: raise exception statement; function finally blocks (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent b12a5766
......@@ -137,6 +137,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private final boolean returnsTemplate;
private final TemplateRestriction.Restriction_type templateRestriction;
private final StatementBlock block;
private final StatementBlock finallyBlock;
private EncodingPrototype_type prototype;
private Type inputType;
private Type outputType;
......@@ -155,7 +156,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 SignatureExceptions exceptions, final StatementBlock block,
final SignatureExceptions exceptions, final StatementBlock block, final StatementBlock finallyBlock,
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 +174,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
this.returnsTemplate = returnsTemplate;
this.templateRestriction = templateRestriction;
this.block = block;
this.finallyBlock = finallyBlock;
this.isClassFunction = isClassFunction;
this.isAbstract = isAbstract;
this.isFinal = isFinal;
......@@ -187,6 +189,11 @@ public final class Def_Function extends Definition implements IParameterisedAssi
block.setMyDefinition(this);
block.setFullNameParent(this);
}
if (finallyBlock != null) {
finallyBlock.setMyDefinition(this);
finallyBlock.setFullNameParent(this);
finallyBlock.setOwnerIsDestructor();
}
if (runsOnRef != null) {
runsOnRef.setFullNameParent(this);
}
......@@ -208,9 +215,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 SignatureExceptions exceptions, final StatementBlock block) {
final SignatureExceptions exceptions, final StatementBlock block, final StatementBlock finallyBlock) {
this(identifier, formalParameters, runsOnRef, mtcReference, systemReference, portReference, returnType,
returnsTemplate, templateRestriction, exceptions, block, false, false, false, null);
returnsTemplate, templateRestriction, exceptions, block, finallyBlock, false, false, false, null);
}
/**
......@@ -219,7 +226,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);
this(identifier, formalParameters, null, null, null, null, returnType, false, null, null, null, null);
}
public boolean isStartable() {
......@@ -344,6 +351,9 @@ public final class Def_Function extends Definition implements IParameterisedAssi
if (block != null) {
block.setMyScope(formalParList);
}
if (finallyBlock != null) {
finallyBlock.setMyScope(formalParList);
}
if (block != null) {
bridgeScope.addSubScope(block.getLocation(), block);
}
......@@ -574,6 +584,10 @@ public final class Def_Function extends Definition implements IParameterisedAssi
block.postCheck();
block.setCodeSection(CodeSectionType.CS_INLINE);
}
if (finallyBlock != null) {
finallyBlock.check(timestamp);
}
}
/**
......
package org.eclipse.titan.designer.AST.TTCN3.statements;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
import org.eclipse.titan.designer.AST.TTCN3.statements.Statement.Statement_type;
import org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance;
/**
* Represents the raise exception statement (TTCN3 OOP extension)
*
* @author Miklos Magyari
* */
public class RaiseException_Statement extends Statement {
private static final String RAISEINFINALLY = "Raise statement cannot be used in a finally block";
private static final String STATEMENT_NAME = "raise exception";
private final TemplateInstance exception;
public RaiseException_Statement(TemplateInstance exception) {
this.exception = exception;
}
@Override
public Statement_type getType() {
return Statement_type.S_RAISE;
}
@Override
public String getStatementName() {
return STATEMENT_NAME;
}
@Override
public void check(CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
if (myStatementBlock.hasDestructor()) {
location.reportSemanticError(RAISEINFINALLY);
return;
}
}
@Override
public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException {
// TODO Auto-generated method stub
}
@Override
public void setCodeSection(CodeSectionType codeSection) {
// TODO Auto-generated method stub
}
@Override
public void generateCode(JavaGenData aData, StringBuilder source) {
// TODO Auto-generated method stub
}
@Override
protected boolean memberAccept(ASTVisitor v) {
// TODO Auto-generated method stub
return false;
}
}
......@@ -122,6 +122,8 @@ public abstract class Statement extends ASTNode implements ILocateableNode, IApp
S_REPLY,
/** raise. */
S_RAISE,
/** raise exception. */
S_RAISE_EXCEPTION,
/** getcall. */
S_GETCALL,
/** getreply. */
......
......@@ -2822,7 +2822,7 @@ 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);
$def_func = new Def_Function($i.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference, portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock, finallyBlock);
$def_func.setLocation(getLocation( $col.start, $s.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
}
......@@ -6920,6 +6920,10 @@ pr_BehaviourStatements returns[Statement statement]
{ $statement = new Continue_Statement();
$statement.setLocation(getLocation( $CONTINUE));
}
| s9 = pr_RaiseExceptionStatement {
$statement = new RaiseException_Statement($s9.instance);
$statement.setLocation(getLocation( $s9.start, $s9.stop));
}
);
pr_VerdictStatements returns[Statement statement]
......@@ -9300,7 +9304,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, true, isAbstract, isFinal, modifierLocation);
portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock, null, true, isAbstract, isFinal, modifierLocation);
$def_func.setLocation(getLocation( $col.start, $sb.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
}
......@@ -9338,7 +9342,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, null, statementBlock, true, false, false, null);
$def_func = new Def_Function(id, parameters, null, null, null, null, null, false, null, null, statementBlock, null, true, false, false, null);
$def_func.setLocation(getLocation( $id.start, $sb.stop));
$def_func.setCommentLocation( getLastCommentLocation( $start ) );
};
......@@ -9624,6 +9628,12 @@ pr_CatchBlockList:
pr_CatchBlock+
;
pr_RaiseExceptionStatement returns[TemplateInstance instance]:
(
RAISE
inst = pr_TemplateInstance { $instance = $inst.templateInstance; }
);
pr_ConjunctionMatch returns[ListOfTemplates templates]
@init {
$templates = null;
......
......@@ -65,7 +65,7 @@ public class Syntactical_errors_tests {
//ReturnValueTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(5);
int lineNum = 37;
markersToCheck.add(new MarkerToCheck("mismatched input '..' expecting {'action', 'activate', 'all', 'alt', 'and', 'and4b', 'any', 'break', 'connect', 'const', 'continue', 'deactivate', 'disconnect', 'do', 'execute', 'for', 'goto', 'if', 'ifpresent', 'implies', 'interleave', 'kill', 'label', 'length', 'log', 'map', 'mod', 'mtc', 'or', 'or4b', 'port', 'rem', 'repeat', 'return', 'select', 'self', 'setverdict', 'stop', 'super', 'template', 'testcase', 'this', 'timer', 'unmap', 'value', 'var', 'while', 'xor', 'xor4b', 'int2enum', 'string2ttcn', IDENTIFIER, '@try', '@update', ';', '{', '}', '<', '>', '!=', '>=', '<=', '==', '+', '-', '*', '/', '<<', '>>', '<@', '@>', '&'}", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("mismatched input '..' expecting {'action', 'activate', 'all', 'alt', 'and', 'and4b', 'any', 'break', 'connect', 'const', 'continue', 'deactivate', 'disconnect', 'do', 'execute', 'for', 'goto', 'if', 'ifpresent', 'implies', 'interleave', 'kill', 'label', 'length', 'log', 'map', 'mod', 'mtc', 'or', 'or4b', 'port', 'raise', 'rem', 'repeat', 'return', 'select', 'self', 'setverdict', 'stop', 'super', 'template', 'testcase', 'this', 'timer', 'unmap', 'value', 'var', 'while', 'xor', 'xor4b', 'int2enum', 'string2ttcn', IDENTIFIER, '@try', '@update', ';', '{', '}', '<', '>', '!=', '>=', '<=', '==', '+', '-', '*', '/', '<<', '>>', '<@', '@>', '&'}", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("mismatched input 'function' expecting {<EOF>, 'with', ';'}", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
......
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