use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
isErroneous = false;
selfReference = false;
templateRestriction = Restriction_type.TR_NONE;
generateRestrictionCheck = false;
if (reference == null) {
return;
}
reference.setUsedOnLeftHandSide();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null || assignment.getIsErroneous()) {
isErroneous = true;
return;
}
if (template == null) {
return;
}
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(reference);
if (template.isValue(timestamp)) {
// TODO: isValue should be checked within the previous line! This is double check!
final IValue temporalValue = template.getValue();
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
// TODO: convert (x) to x to compilation!
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_PAR_VAL:
((FormalParameter) assignment).setWritten();
if (template.isValue(timestamp)) {
// TODO: isValue should be checked within the previous line! This is double check!
final IValue temporalValue = template.getValue();
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
// TODO: convert (x) to x to compilation!
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
// break
case A_VAR:
((Def_Var) assignment).setWritten();
if (template.getIsErroneous(timestamp)) {
return;
}
final IValue temporalValue = template.getValue();
if (temporalValue != null) {
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
case A_PAR_TEMP_IN:
((FormalParameter) assignment).useAsLValue(reference);
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(VARIABLEREFERENCEEXPECTED, assignment.getAssignmentName()));
reference.setIsErroneous(true);
isErroneous = true;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method getTemplateReferenced.
/**
* Calculates the referenced template, and while doing so checks the
* reference too.
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param referenceChain
* the reference chain used to detect cyclic references.
*
* @return the template referenced
*/
private ITTCN3Template getTemplateReferenced(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
if (reference == null) {
setIsErroneous(true);
return null;
}
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
setIsErroneous(true);
return this;
}
ITTCN3Template template = null;
switch(ass.getAssignmentType()) {
case A_TEMPLATE:
template = ((Def_Template) ass).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) ass).check(timestamp);
template = ((Def_Var_Template) ass).getInitialValue();
break;
case A_MODULEPAR_TEMPLATE:
template = ((Def_ModulePar_Template) ass).getDefaultTemplate();
break;
default:
setIsErroneous(true);
return this;
}
if (template != null) {
template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
}
final List<ISubReference> subreferences = reference.getSubreferences();
if (template != null) {
return template;
} else if (subreferences != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
// some array indices could not be evaluated
} else if (reference.getUsedInIsbound()) {
return this;
} else {
setIsErroneous(true);
}
return this;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method generateCode.
/**
* Add generated java code on this level.
* @param aData only used to update imports if needed
* @param source the source code generated
*
* FIXME the implementation only serves as a minimal testing setup
*/
public void generateCode(final JavaGenData aData, final StringBuilder source) {
final String genName = myType.getGenNameOwn();
final Scope myScope = myType.getMyScope();
final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
if (inMessages != null) {
for (int i = 0; i < inMessages.getNofTypes(); i++) {
final IType inType = inMessages.getTypeByIndex(i);
final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
portDefinition.inMessages.add(info);
}
}
if (outMessages != null) {
for (int i = 0; i < outMessages.getNofTypes(); i++) {
final IType outType = outMessages.getTypeByIndex(i);
final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
portDefinition.outMessages.add(info);
}
}
if (inSignatures != null) {
for (int i = 0; i < inSignatures.getNofTypes(); i++) {
final IType outType = inSignatures.getTypeByIndex(i);
final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
portDefinition.inProcedures.add(info);
}
}
if (outSignatures != null) {
for (int i = 0; i < outSignatures.getNofTypes(); i++) {
final IType outType = outSignatures.getTypeByIndex(i);
final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
portDefinition.outProcedures.add(info);
}
}
switch(testportType) {
case TP_REGULAR:
portDefinition.testportType = TestportType.NORMAL;
break;
case TP_INTERNAL:
portDefinition.testportType = TestportType.INTERNAL;
break;
case TP_ADDRESS:
portDefinition.testportType = TestportType.ADDRESS;
portDefinition.addressName = "TitanAddress";
break;
default:
portDefinition.testportType = TestportType.NORMAL;
}
if (vardefs != null) {
portDefinition.varDefs = new StringBuilder();
portDefinition.varInit = new StringBuilder();
for (int i = 0; i < vardefs.getNofAssignments(); i++) {
final Definition def = vardefs.getAssignmentByIndex(i);
String type = "";
switch(def.getAssignmentType()) {
case A_VAR:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
if (((Def_Var) def).getInitialValue() == null) {
portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
} else {
def.generateCodeInitComp(aData, portDefinition.varInit, def);
}
break;
case A_CONST:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
def.generateCodeInitComp(aData, portDefinition.varInit, def);
break;
case A_VAR_TEMPLATE:
type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
if (((Def_Var_Template) def).getInitialValue() == null) {
portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
} else {
def.generateCodeInitComp(aData, portDefinition.varInit, def);
}
break;
default:
// FATAL ERROR
break;
}
portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
}
}
PortGenerator.generateClass(aData, source, portDefinition);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class TypenameInDef method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
return;
}
final Definition s = (Definition) node;
check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Parameter_Redirect method checkVariableReference.
/**
* Check whether the reference points to a variable of the provided
* type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param reference
* the reference to check
* @param type
* the type the parameter is expected to have.
*/
public final void checkVariableReference(final CompilationTimeStamp timestamp, final Reference reference, final IType type) {
if (reference == null) {
return;
}
final IType variableType = reference.checkVariableReference(timestamp);
if (type != null && variableType != null && !type.isIdentical(timestamp, variableType)) {
final String message = MessageFormat.format("Type mismatch in parameter redirect: A variable of type `{0}'' was expected instead of `{1}''", type.getTypename(), variableType.getTypename());
reference.getLocation().reportSemanticError(message);
return;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment != null) {
switch(assignment.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
((FormalParameter) assignment).setWritten();
break;
case A_VAR:
((Def_Var) assignment).setWritten();
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
break;
default:
break;
}
}
}
Aggregations