use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class Def_Template method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
T3Doc.check(this.getCommentLocation(), KIND);
isUsed = false;
if (isLocal()) {
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TEMPLATE, identifier, this);
} else {
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TEMPLATE, identifier, this);
}
NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
if (type == null) {
return;
}
type.setGenName("_T_", getGenName());
type.check(timestamp, refChain);
if (withAttributesPath != null) {
withAttributesPath.checkGlobalAttributes(timestamp, true);
withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp, refChain).getTypetype());
}
if (body == null) {
return;
}
final IType lastType = type.getTypeRefdLast(timestamp);
switch(lastType.getTypetype()) {
case TYPE_PORT:
location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
break;
default:
break;
}
body.setMyGovernor(type);
realBody = body;
// Needed in case of universal charstring templates
if (body.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
realBody = body.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
// FIXME implement setting the pattern type, once
// universal charstring pattern are supported.
}
if (formalParList != null) {
formalParList.reset();
formalParList.check(timestamp, getAssignmentType());
if (isLocal()) {
location.reportSemanticError(MessageFormat.format(PARAMETRIZED_LOCAL_TEMPLATE, getIdentifier()));
}
}
final ITTCN3Template tempBody = type.checkThisTemplateRef(timestamp, realBody);
checkDefault(timestamp);
checkModified(timestamp);
checkRecursiveDerivation(timestamp);
tempBody.checkThisTemplateGeneric(timestamp, type, derivedReference != null, true, true, true, hasImplicitOmitAttribute(timestamp), null);
checkErroneousAttributes(timestamp);
final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(CIRCULAREMBEDDEDRECURSION, true);
tempReferenceChain.add(this);
tempBody.checkRecursions(timestamp, tempReferenceChain);
tempReferenceChain.release();
if (templateRestriction != TemplateRestriction.Restriction_type.TR_NONE) {
generateRestrictionCheck = TemplateRestriction.check(timestamp, this, tempBody, null);
if (formalParList != null && templateRestriction != TemplateRestriction.Restriction_type.TR_PRESENT) {
final int nofFps = formalParList.getNofParameters();
for (int i = 0; i < nofFps; i++) {
final FormalParameter fp = formalParList.getParameterByIndex(i);
// parameters
if (fp.getAssignmentType() != Assignment.Assignment_type.A_PAR_TEMP_IN) {
continue;
}
final TemplateRestriction.Restriction_type fpTemplateRestriction = fp.getTemplateRestriction();
switch(templateRestriction) {
case TR_VALUE:
case TR_OMIT:
switch(fpTemplateRestriction) {
case TR_VALUE:
case TR_OMIT:
// allowed
break;
case TR_PRESENT:
fp.getLocation().reportSemanticError(MessageFormat.format(WITHTEMPRESTNOTALLOWED, fpTemplateRestriction.getDisplayName()));
break;
case TR_NONE:
fp.getLocation().reportSemanticError(WITHOUTTEMPRESTNOTALLOWED);
break;
default:
break;
}
break;
default:
break;
}
}
}
}
if (formalParList != null) {
formalParList.setGenName(getGenName());
}
// body.setGenNamePrefix("template_");//currently does not need the prefix
body.setGenNameRecursive(getGenName());
body.setCodeSection(CodeSectionType.CS_POST_INIT);
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method checkTemplateRestriction.
/**
* Checks the template restriction on the assignment referenced on the left hand side.
*
* @param timestamp the time stamp of the actual semantic check cycle.
*/
private void checkTemplateRestriction(final CompilationTimeStamp timestamp) {
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
return;
}
switch(ass.getAssignmentType()) {
case A_VAR_TEMPLATE:
templateRestriction = ((Def_Var_Template) ass).getTemplateRestriction();
break;
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
templateRestriction = ((FormalParameter) ass).getTemplateRestriction();
break;
default:
templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
break;
}
templateRestriction = TemplateRestriction.getSubRestriction(templateRestriction, timestamp, reference);
generateRestrictionCheck = TemplateRestriction.check(timestamp, (Definition) ass, template, reference);
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class SpecificValue_Template method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
return;
}
final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
if (realTemplate != null && realTemplate != this) {
realTemplate.generateCodeExpression(aData, expression, templateRestriction);
return;
}
if (lengthRestriction == null && !isIfpresent && templateRestriction == Restriction_type.TR_NONE) {
// The single expression must be tried first because this rule might cover some referenced templates.
if (hasSingleExpression()) {
expression.expression.append(MessageFormat.format("new {0}(", genName));
if (governor.getTypetype() == Type_type.TYPE_ARRAY) {
final Array_Type array_type = (Array_Type) governor;
expression.expression.append(MessageFormat.format(" {0}.class, ", array_type.getElementType().getGenNameTemplate(aData, expression.expression, myScope)));
}
expression.expression.append(getSingleExpression(aData, true));
expression.expression.append(')');
return;
}
expression.expression.append(MessageFormat.format("new {0}(", genName));
specificValue.generateCodeExpression(aData, expression, false);
expression.expression.append(')');
return;
}
final String tempId = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", governor.getGenNameTemplate(aData, expression.expression, myScope), tempId));
generateCodeInit(aData, expression.preamble, tempId);
if (templateRestriction != Restriction_type.TR_NONE) {
TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
}
expression.expression.append(tempId);
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method generateCode.
/**
* Add generated java code on this level.
* @param aData the structure to put imports into and get temporal variable names from.
* @param expression the expression code generated
* @param templateRestriction the template restriction to check in runtime
*/
public void generateCode(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
if (derivedReference != null) {
final ExpressionStruct derivedExpression = new ExpressionStruct();
derivedReference.generateCode(aData, derivedExpression);
final String tempId = aData.getTemporaryVariableName();
expression.preamble.append(derivedExpression.preamble);
expression.preamble.append(MessageFormat.format("{0} {1} = new {0}({2});\n", templateBody.getMyGovernor().getGenNameTemplate(aData, expression.expression, myScope), tempId, derivedExpression.expression));
// perform the modifications on the temporary variable
templateBody.generateCodeInit(aData, expression.preamble, tempId);
// TODO implement runtime restriction check
expression.expression.append(tempId);
} else {
// TODO handle decoded redirect
templateBody.generateCodeExpression(aData, expression, templateRestriction);
// TODO handle decoded redirect
}
}
Aggregations