use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class SetOf_Value method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final boolean forceObject) {
if (canGenerateSingleExpression()) {
expression.expression.append(generateSingleExpression(aData));
return;
}
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
final String tempId = aData.getTemporaryVariableName();
final String genName = myLastSetGovernor.getGenNameValue(aData, expression.expression, myScope);
expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", genName, tempId));
setGenNamePrefix(tempId);
generateCodeInit(aData, expression.preamble, tempId);
expression.expression.append(tempId);
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class SetOf_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return null;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value arrayIndex = ((ArraySubReference) subreference).getValue();
final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, refChain);
if (valueIndex.isUnfoldable(timestamp)) {
return null;
}
if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
final BigInteger index = ((Integer_Value) valueIndex).getValueValue();
if (index.compareTo(BigInteger.ZERO) == -1) {
arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NONNEGATIVEINDEXEXPECTED, index, type.getTypename()));
return null;
}
if (isIndexed()) {
for (int i = 0; i < values.getNofIndexedValues(); i++) {
IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
indexedValue = indexedValue.getValueRefdLast(timestamp, refChain);
if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).getValueValue().compareTo(index) == 0) {
return values.getIndexedValueByIndex(i).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
}
arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
} else if (index.compareTo(BigInteger.valueOf(values.getNofValues())) >= 0) {
arrayIndex.getLocation().reportSemanticError(MessageFormat.format(INDEXOVERFLOW, type.getTypename(), index, values.getNofValues()));
} else {
return values.getValueByIndex(index.intValue()).getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
}
arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Function_Reference_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Function_Reference_Value method generateSingleExpression.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateSingleExpression(final JavaGenData aData) {
final StringBuilder result = new StringBuilder();
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null || referredFunction == null) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
return result;
}
final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final Function_Type functionType = (Function_Type) lastGovernor;
final Type returnType = functionType.getReturnType();
final String moduleName = referredFunction.getMyScope().getModuleScope().getName();
final String functionName = referredFunction.getIdentifier().getName();
result.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, result, myScope)));
result.append("@Override\n");
result.append("public String getModuleName() {\n");
result.append(MessageFormat.format("return \"{0}\";\n", moduleName));
result.append("}\n");
result.append("@Override\n");
result.append("public String getDefinitionName() {\n");
result.append(MessageFormat.format("return \"{0}\";\n", functionName));
result.append("}\n");
result.append("@Override\n");
result.append("public ");
final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
if (returnType == null) {
result.append("void");
} else {
if (functionType.returnsTemplate()) {
result.append(returnType.getGenNameTemplate(aData, result, myScope));
} else {
result.append(returnType.getGenNameValue(aData, result, myScope));
}
}
result.append(" invoke(");
functionType.getFormalParameters().generateCode(aData, result);
result.append(") {\n");
result.append(MessageFormat.format("{0}{1}.{2}({3});\n", returnType == null ? "" : "return ", moduleName, functionName, actualParList));
result.append("}\n");
if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
aData.addBuiltinTypeImport("TitanComponent");
result.append("@Override\n");
result.append("public void start(final TitanComponent component_reference");
if (functionType.getFormalParameters().getNofParameters() > 0) {
result.append(", ");
functionType.getFormalParameters().generateCode(aData, result);
}
result.append(") {\n");
result.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
if (actualParList != null && actualParList.length() > 0) {
result.append(MessageFormat.format(", {0}", actualParList));
}
result.append(");\n");
result.append("}\n");
}
result.append("})\n");
return result;
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class NamedValue method getDeclaration.
@Override
public /**
* {@inheritDoc}
*/
Declaration getDeclaration() {
INamedNode inamedNode = getNameParent();
while (!(inamedNode instanceof IValue)) {
if (inamedNode == null) {
// FIXME: this is just a temp solution! find the reason!
return null;
}
inamedNode = inamedNode.getNameParent();
}
final IValue iValue = (IValue) inamedNode;
IType type = iValue.getMyGovernor();
if (type == null) {
return null;
}
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof ITypeWithComponents) {
final Identifier id = ((ITypeWithComponents) type).getComponentIdentifierByName(getName());
return Declaration.createInstance(type.getDefiningAssignment(), id);
}
return null;
}
Aggregations