use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method getValueRefdLast.
@Override
public /**
* {@inheritDoc}
*/
IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return referencedValue;
}
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
referencedValue = this;
isErroneous = false;
if (reference == null) {
return referencedValue;
}
reference.setIsErroneous(false);
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
isErroneous = true;
return referencedValue;
}
switch(ass.getAssignmentType()) {
case A_OBJECT:
case A_OS:
{
final ISetting setting = reference.getRefdSetting(timestamp);
if (setting == null || setting.getIsErroneous(timestamp)) {
isErroneous = true;
} else if (!Setting_type.S_V.equals(setting.getSettingtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(INFORMATIONFROMOBJECTNOTVALUE, reference));
isErroneous = true;
} else {
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
referencedValue = ((IValue) setting).getValueRefdLast(timestamp, expectedValue, referenceChain);
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
}
break;
}
case A_CONST:
{
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
if (ass instanceof Def_Const) {
referencedValue = ((Def_Const) ass).getValue();
} else if (ass instanceof Value_Assignment) {
referencedValue = ((Value_Assignment) ass).getValue();
} else {
isErroneous = true;
}
if (referencedValue != null && !isErroneous) {
referencedValue = referencedValue.getReferencedSubValue(timestamp, reference, 1, tempReferenceChain);
} else {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
}
if (referencedValue != null) {
referencedValue = referencedValue.getValueRefdLast(timestamp, tempReferenceChain);
} else if (reference.hasUnfoldableIndexSubReference(timestamp)) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else if (reference.getUsedInIsbound()) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else {
isErroneous = true;
}
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
break;
}
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_INOUT:
case A_PAR_TEMP_OUT:
referencedValue = this;
break;
case A_TEMPLATE:
case A_VAR_TEMPLATE:
// the referred definition is not a constant
// errors will be reported in Types.java
referencedValue = this;
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
reference.getLocation().reportSemanticError(MessageFormat.format(VALUERETURNEXPECTED, ass.getDescription()));
isErroneous = true;
break;
default:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT1, ass.getDescription()));
} else {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
isErroneous = true;
break;
}
if (newChain) {
tempReferenceChain.release();
}
lastTimeChecked = timestamp;
if (referencedValue == null) {
referencedValue = this;
isErroneous = true;
}
return referencedValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Macro_Value method evaluateMacro.
/**
* Evaluates the value of the macro.
*
* @param expectedValue the kind of the value to be expected
*
* @return the actual or the evaluated value
*/
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
lastTimeChecked = timestamp;
lastValue = this;
switch(value) {
case MODULEID:
if (myScope != null && myScope.getModuleScope() != null) {
final Module module = myScope.getModuleScope();
if (module.getIdentifier() != null) {
lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
break;
case DEFINITIONID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition != null) {
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
setIsErroneous(true);
}
break;
case TESTCASEID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition == null) {
location.reportSemanticError(TESCASEIDINCONTROLPART);
setIsErroneous(true);
} else {
if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
// folding is possible in testcases only
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
location.reportSemanticError(TESTCASEIDNOTALLOWED);
setIsErroneous(true);
}
} else {
setIsErroneous(true);
}
break;
case FILENAME:
case BFILENAME:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(location.getFile().getName());
lastValue.copyGeneralProperties(this);
}
break;
case FILEPATH:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
String canonicalPath;
final IPath absolutePath = location.getFile().getLocation();
if (absolutePath == null) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
} else {
final File file = absolutePath.toFile();
try {
canonicalPath = file.getCanonicalPath();
} catch (IOException e) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
}
}
lastValue = new Charstring_Value(canonicalPath);
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(Long.toString(location.getLine()));
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER_C:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Integer_Value(location.getLine());
lastValue.copyGeneralProperties(this);
}
break;
case SCOPE:
if (myScope != null) {
lastValue = new Charstring_Value(myScope.getScopeMacroName());
lastValue.copyGeneralProperties(this);
} else {
location.reportSemanticError(UNDETERMINABLESCOPE);
setIsErroneous(true);
}
break;
default:
setIsErroneous(true);
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Def_Extfunction method checkPrototype.
/**
* Checks the prototype attribute set for this external function
* definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*/
private void checkPrototype(final CompilationTimeStamp timestamp) {
if (EncodingPrototype_type.NONE.equals(prototype)) {
return;
}
// checking formal parameter list
if (EncodingPrototype_type.CONVERT.equals(prototype)) {
if (formalParList.getNofParameters() == 1) {
final FormalParameter parameter = formalParList.getParameterByIndex(0);
switch(parameter.getRealAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
inputType = parameter.getType(timestamp);
break;
default:
{
final String message = MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName());
parameter.getLocation().reportSemanticError(message);
break;
}
}
} else {
final String message = MessageFormat.format("The external function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName());
formalParList.getLocation().reportSemanticError(message);
}
} else if (formalParList.getNofParameters() == 2) {
final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
if (EncodingPrototype_type.SLIDING.equals(prototype)) {
if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
final Type firstParameterType = firstParameter.getType(timestamp);
final IType last = firstParameterType.getTypeRefdLast(timestamp);
if (last.getIsErroneous(timestamp)) {
inputType = firstParameterType;
} else {
switch(last.getTypetypeTtcn3()) {
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_BITSTRING:
inputType = firstParameterType;
break;
default:
{
final String message = MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName());
firstParameter.getLocation().reportSemanticError(message);
break;
}
}
}
} else {
firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
}
} else {
if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(firstParameter.getRealAssignmentType())) {
inputType = firstParameter.getType(timestamp);
} else {
firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
}
}
final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
outputType = secondParameter.getType(timestamp);
} else {
secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
}
} else {
formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
}
// checking the return type
if (EncodingPrototype_type.FAST.equals(prototype)) {
if (returnType != null) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The external function cannot have return type fo attribute `prototype({0})''", prototype.getName()));
}
} else {
if (returnType == null) {
location.reportSemanticError(MessageFormat.format("The external function must have a return type for attribute `prototype({0})''", prototype.getName()));
} else {
if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The external function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
}
if (EncodingPrototype_type.CONVERT.equals(prototype)) {
outputType = returnType;
} else {
final IType last = returnType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST_Action method exportDebugAST.
private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(out, padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(out, padding + 1, " contains definitions:");
if (map != null) {
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(out, padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
out.closeEntry();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method generateCodeExpressionInvoke.
private void generateCodeExpressionInvoke(final JavaGenData aData, final ExpressionStruct expression) {
if (value == null || actualParameter_list == null) {
return;
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
final Definition function = ((Function_Reference_Value) last).getReferredFunction();
expression.expression.append(MessageFormat.format("{0}(", function.getGenNameFromScope(aData, expression.expression, myScope, "")));
actualParameter_list.generateCodeAlias(aData, expression);
} else {
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".invoke(");
IType governor = value.getMyGovernor();
if (governor == null) {
governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
return;
}
actualParameter_list.generateCodeAlias(aData, expression);
}
expression.expression.append(')');
}
Aggregations