use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofTemplatesNotAnyornone.
/**
* Calculates the number of list members which are not the any or none
* symbol.
*
* @return the number calculated.
*/
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
int result = 0;
if (allFrom == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
if (!((SpecificValue_Template) allFrom).isReference()) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
// isReference branch:
final Reference reference = ((SpecificValue_Template) allFrom).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
allFrom.getLocation().reportSemanticError("Assignment not found");
allFrom.setIsErroneous(true);
return result;
}
ITTCN3Template body = null;
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
body = ((Def_Template) assignment).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
body = ((Def_Var_Template) assignment).getInitialValue();
break;
case A_CONST:
final IValue value = ((Def_Const) assignment).getValue();
return getNofValues(value, timestamp);
case A_MODULEPAR:
final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
return getNofValues(mvalue, timestamp);
case A_MODULEPAR_TEMPLATE:
body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
break;
default:
return result;
}
if (body == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
allFrom.setIsErroneous(true);
return result;
}
result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class LogArgument method checkReference.
/**
* Does the semantic checking of the log argument. Once it was
* determined that it is a reference.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param reference
* the reference contained in the log argument.
*/
private void checkReference(final CompilationTimeStamp timestamp, final Reference reference) {
if (reference == null) {
return;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null || assignment.getIsErroneous()) {
return;
}
switch(assignment.getAssignmentType()) {
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
{
reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_CONST:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
if (assignment instanceof Def_Const) {
((Def_Const) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
} else {
((Value_Assignment) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
}
chain.release();
}
break;
}
case A_TEMPLATE:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
((Def_Template) assignment).getTemplate(timestamp).getReferencedSubTemplate(timestamp, reference, chain);
chain.release();
}
break;
}
case A_MODULEPAR_TEMPLATE:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_VAR_TEMPLATE:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_PORT:
{
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
}
case A_TIMER:
{
final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
}
case A_PAR_TIMER:
case A_PAR_PORT:
if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was ecpected instead of a call of {0}, which does not have a return type", assignment.getDescription()));
isErroneous = true;
break;
default:
getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was expected instead of {0}", assignment.getDescription()));
isErroneous = true;
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method hasTemplateImpliciteOmit.
/**
* Returns whether in the chain of referenced templates there is one
* which was defined to have the implicit omit attribute set
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param referenceChain
* the ReferenceChain used to detect circular references
*
* @return true if it has, false otherwise.
*/
private boolean hasTemplateImpliciteOmit(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
boolean result = false;
if (reference != null) {
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass != null && ass.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final Def_Template templateDefinition = (Def_Template) ass;
if (templateDefinition.hasImplicitOmitAttribute(timestamp)) {
result = true;
} else {
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
final ITTCN3Template refd = getTemplateReferenced(timestamp, tempReferenceChain);
if (refd != this && refd instanceof Referenced_Template) {
result = ((Referenced_Template) refd).hasTemplateImpliciteOmit(timestamp, referenceChain);
}
} else {
setIsErroneous(true);
}
tempReferenceChain.previousState();
}
}
}
if (newChain) {
tempReferenceChain.release();
}
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
if (useSingleExpressionForInit() && hasSingleExpression()) {
source.append(MessageFormat.format("{0}.assign({1});\n", name, getSingleExpression(aData, false)));
return;
}
final ExpressionStruct expression = new ExpressionStruct();
boolean useReferenceForCodegeneration = true;
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
// the referencing template is a part of a non-parameterized template
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
// FIXME implement formal par check
if (((Def_Template) assignment).getFormalParameterList() != null) {
// the referred template is parameterized
// generate the initialization sequence first for all dependent
// non-parameterized templates
reArrangeInitCode(aData, source, myScope.getModuleScope());
} else if (assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
// the referred template is non-parameterized
// use a different algorithm for code generation
generateRearrangeInitCodeReferenced(aData, source, expression);
useReferenceForCodegeneration = false;
}
}
}
if (useReferenceForCodegeneration) {
reference.generateConstRef(aData, expression);
}
if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
// the expressions within reference need temporary objects
source.append("{\n");
source.append(expression.preamble);
// FIXME handle the needs conversion case
source.append(MessageFormat.format("{0}.assign({1});\n", name, expression.expression));
source.append(expression.postamble);
source.append("}\n");
} else {
// FIXME handle needs conversion case
source.append(MessageFormat.format("{0}.assign({1});\n", name, expression.expression));
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
Aggregations