use of org.eclipse.titan.designer.AST.Scope in project titan.EclipsePlug-ins by eclipse.
the class DecvalueUnicharExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final ExpressionStruct expression1 = new ExpressionStruct();
final ExpressionStruct expression2 = new ExpressionStruct();
reference1.generateCode(aData, expression1);
reference2.generateCode(aData, expression2);
final Assignment tempAssignment = reference2.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
final IType type = tempAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
final IType fieldType = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (expression1.preamble.length() > 0) {
expression.preamble.append(expression1.preamble);
}
if (expression2.preamble.length() > 0) {
expression.preamble.append(expression2.preamble);
}
String v3_code;
if (value3 == null) {
v3_code = "\"UTF-8\"";
} else {
final ExpressionStruct tempExpression = new ExpressionStruct();
value3.generateCodeExpressionMandatory(aData, tempExpression, true);
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanCharString {0} = {1};\n", tempID, tempExpression.expression));
expression.preamble.append(MessageFormat.format("if ({0}.operatorNotEquals(\"UTF-8\") && {0}.operatorNotEquals(\"UTF-16\") && {0}.operatorNotEquals(\"UTF-16LE\") && {0}.operatorNotEquals(\"UTF-16BE\") && {0}.operatorNotEquals(\"UTF-32\") && {0}.operatorNotEquals(\"UTF-32LE\") && {0}.operatorNotEquals(\"UTF-32BE\")) '{'\n", tempID));
expression.preamble.append(MessageFormat.format("throw new TtcnError(MessageFormat.format(\"decvalue_unichar: Invalid encoding parameter: '{'0'}'\", {0}));\n", tempID));
expression.preamble.append("}\n");
v3_code = tempID;
}
final Scope scope = reference2.getMyScope();
final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
final ExpressionStruct expression3 = new ExpressionStruct();
// TODO add support for 4th parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", fieldType.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String bufferID = aData.getTemporaryVariableName();
final String returnValueID = aData.getTemporaryVariableName();
// TOOD add handling for non-built-in encoding
expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);\n");
expression.preamble.append("TTCN_EncDec.clear_error();\n");
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString(AdditionalFunctions.unichar2oct({1}, {2}));\n", bufferID, expression1.expression, v3_code));
expression.preamble.append(MessageFormat.format("TitanInteger {0} = new TitanInteger({1}_decoder({2}, {3}{4}, {5}));\n", returnValueID, fieldType.getGenNameCoder(aData, expression.expression, scope), bufferID, expression2.expression, isOptional ? ".get()" : "", expression3.expression));
expression.preamble.append(MessageFormat.format("if ({0}.operatorEquals(0)) '{'\n", returnValueID));
expression.preamble.append(MessageFormat.format("{0} = AdditionalFunctions.oct2unichar({1}, {2});\n", expression1.expression, bufferID, v3_code));
expression.preamble.append("}\n");
// TOOD add handling for non-built-in encoding
expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_DEFAULT);\n");
expression.preamble.append("TTCN_EncDec.clear_error();\n");
expression.expression.append(returnValueID);
if (expression1.postamble.length() > 0) {
expression.postamble.append(expression1.postamble);
}
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
use of org.eclipse.titan.designer.AST.Scope in project titan.EclipsePlug-ins by eclipse.
the class EncodeExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final boolean isValue = templateInstance.getTemplateBody().isValue(CompilationTimeStamp.getBaseTimestamp());
final ExpressionStruct expression2 = new ExpressionStruct();
if (isValue) {
templateInstance.getTemplateBody().getValue().generateCodeExpressionMandatory(aData, expression2, true);
} else {
templateInstance.generateCode(aData, expression2, Restriction_type.TR_NONE);
}
final Scope scope = templateInstance.getTemplateBody().getMyScope();
final IType governor = templateInstance.getTemplateBody().getMyGovernor();
if (expression2.preamble.length() > 0) {
expression.postamble.append(expression2.preamble);
}
final ExpressionStruct expression3 = new ExpressionStruct();
// FIXME handle third parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", governor.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString();\n", tempID));
expression.preamble.append(MessageFormat.format("{0}_encoder({1}{2}, {3}, {4});\n", governor.getGenNameCoder(aData, expression.expression, scope), expression2.expression, isValue ? "" : ".valueOf()", tempID, expression3.expression));
expression.expression.append(MessageFormat.format("AdditionalFunctions.oct2bit({0})", tempID));
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
use of org.eclipse.titan.designer.AST.Scope in project titan.EclipsePlug-ins by eclipse.
the class EncvalueUnicharExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final boolean isValue = templateInstance1.getTemplateBody().isValue(CompilationTimeStamp.getBaseTimestamp());
final ExpressionStruct expression2 = new ExpressionStruct();
if (isValue) {
templateInstance1.getTemplateBody().getValue().generateCodeExpressionMandatory(aData, expression2, true);
} else {
templateInstance1.generateCode(aData, expression2, Restriction_type.TR_NONE);
}
String v2_code;
if (value2 == null) {
v2_code = "\"UTF-8\"";
} else {
final ExpressionStruct tempExpression = new ExpressionStruct();
value2.generateCodeExpressionMandatory(aData, tempExpression, true);
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanCharString {0} = {1};\n", tempID, tempExpression.expression));
expression.preamble.append(MessageFormat.format("if ({0}.operatorNotEquals(\"UTF-8\") && {0}.operatorNotEquals(\"UTF-16\") && {0}.operatorNotEquals(\"UTF-16LE\") && {0}.operatorNotEquals(\"UTF-16BE\") && {0}.operatorNotEquals(\"UTF-32\") && {0}.operatorNotEquals(\"UTF-32LE\") && {0}.operatorNotEquals(\"UTF-32BE\")) '{'\n", tempID));
expression.preamble.append(MessageFormat.format("throw new TtcnError(MessageFormat.format(\"decvalue_unichar: Invalid encoding parameter: '{'0'}'\", {0}));\n", tempID));
expression.preamble.append("}\n");
v2_code = tempID;
}
final Scope scope = templateInstance1.getTemplateBody().getMyScope();
final IType governor = templateInstance1.getTemplateBody().getMyGovernor();
if (expression2.preamble.length() > 0) {
expression.postamble.append(expression2.preamble);
}
final ExpressionStruct expression3 = new ExpressionStruct();
// FIXME handle 4th parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", governor.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString();\n", tempID));
expression.preamble.append(MessageFormat.format("{0}_encoder({1}{2}, {3}, {4});\n", governor.getGenNameCoder(aData, expression.expression, scope), expression2.expression, isValue ? "" : ".valueOf()", tempID, expression3.expression));
expression.expression.append(MessageFormat.format("AdditionalFunctions.oct2unichar({0}, {1})", tempID, v2_code));
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
use of org.eclipse.titan.designer.AST.Scope in project titan.EclipsePlug-ins by eclipse.
the class OccurencesMarker method findOccurrencesReferenceBased.
/**
* Finds the occurrences of the element located on the given offset.
* This solution can be used, when the locations are not correct. (e.g.
* in case of an ASN.1 file)
*
* @param document
* @param reference
* @param module
* The module to search the occurrences in
* @param offset
* An offset in the module
* @return The found references. Includes the definition of the element.
*/
protected List<Hit> findOccurrencesReferenceBased(final IDocument document, final Reference reference, final Module module, final int offset) {
Scope scope = module.getSmallestEnclosingScope(offset);
if (scope == null) {
removeOccurences(false);
error(document, offset, "Can not determine the smallest enclosing scope.");
return new ArrayList<ReferenceFinder.Hit>();
}
reference.setMyScope(scope);
if (reference.getId() == null) {
removeOccurences(false);
error(document, offset, "The identifier of the reference is null.");
return new ArrayList<ReferenceFinder.Hit>();
}
if (reference.getSubreferences().size() > 1) {
// highlighting the subreferences is not yet supported
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
ReferenceFinder referenceFinder;
List<Hit> result = null;
boolean found = false;
if (scope.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), reference.getId()) || (scope.getModuleScope().hasImportedAssignmentWithID(CompilationTimeStamp.getBaseTimestamp(), reference.getId()))) {
Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
error(document, offset, "The assignment could not be determined from the reference: " + reference.getDisplayName());
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
if (!assignment.shouldMarkOccurrences()) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
try {
referenceFinder = new ReferenceFinder(assignment);
} catch (final IllegalArgumentException e) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
result = referenceFinder.findReferencesInModule(module);
// Hack to eliminate false positive results
if (assignment.getLocation().containsOffset(offset)) {
found = true;
} else {
for (Hit hit : result) {
if (hit.identifier.getLocation().containsOffset(offset)) {
found = true;
break;
}
}
}
if (found && assignment.getMyScope().getModuleScope() == module && assignment.getIdentifier() != null) {
result.add(new Hit(assignment.getIdentifier()));
}
}
if (!found) {
// Check if the reference points to a field of a type
// definition
referenceFinder = new ReferenceFinder();
referenceFinder.detectAssignmentDataByOffset(module, offset, editor, false, false);
Assignment assignment = referenceFinder.assignment;
if (assignment == null) {
removeOccurences(false);
error(document, offset, "Could not detect the assignment.");
return new ArrayList<ReferenceFinder.Hit>();
}
if (assignment.getAssignmentType() != null && assignment.getAssignmentType() != Assignment_type.A_TYPE || referenceFinder.fieldId == null || !assignment.shouldMarkOccurrences()) {
removeOccurences(false);
return new ArrayList<ReferenceFinder.Hit>();
}
result = referenceFinder.findReferencesInModule(module);
if (referenceFinder.fieldId != null) {
result.add(new Hit(referenceFinder.fieldId));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.Scope in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclarationHelper method findVisibleDeclarations.
public static DeclarationCollector findVisibleDeclarations(final IEditorPart targetEditor, final IReferenceParser referenceParser, final IDocument document, final int offset, final boolean reportErrors) {
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
if (reportErrors) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEFILE);
}
return null;
}
Reference reference = null;
referenceParser.setErrorReporting(reportErrors);
reference = referenceParser.findReferenceForOpening(file, offset, document);
if (reference == null) {
if (reportErrors) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
}
return null;
}
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (ResourceExclusionHelper.isExcluded(file)) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
return null;
}
final Module tempModule = projectSourceParser.containedModule(file);
if (tempModule == null) {
if (reportErrors) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(NOTFOUNDMODULE, file.getFullPath()));
}
return null;
}
final Scope scope = tempModule.getSmallestEnclosingScope(offset);
if (scope == null) {
if (reportErrors) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLESCOPE);
}
return null;
}
reference.setMyScope(scope);
reference.detectModid();
if (reference.getId() == null) {
if (reportErrors) {
ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
}
return null;
}
final DeclarationCollector declarationCollector = new DeclarationCollector(reference);
scope.addDeclaration(declarationCollector);
return declarationCollector;
}
Aggregations