use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_Type_Visit_Handler method visitDefTypeNodes.
public void visitDefTypeNodes(IVisitableNode node) {
Def_Type typeNode = (Def_Type) node;
String nodeName = typeNode.getIdentifier().toString();
myASTVisitor.currentFileName = nodeName;
myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
Type type = typeNode.getType(compilationCounter);
if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
// record
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "record");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "set");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "union");
parentName = nodeName;
} else if (type instanceof Integer_Type) {
Def_Type_Integer_Writer.getInstance(typeNode);
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "INTEGER");
parentName = nodeName;
isInteger = true;
} else if (type instanceof CharString_Type) {
Def_Type_Charstring_Writer.getInstance(typeNode);
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "CHARSTRING");
parentName = nodeName;
} else if (type instanceof TTCN3_Enumerated_Type) {
Def_Type_Enum_Writer.getInstance(typeNode);
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "enum");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_SET_OF)) {
waitForSetOfFieldType = true;
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "setof");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
waitForRecordOfFieldType = true;
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "recordof");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_PORT)) {
Def_Type_Port_Writer.getInstance(typeNode);
waitingForPortAttriburtes = true;
currentPortName = nodeName;
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "port");
parentName = nodeName;
} else if (type.getTypetype().equals(TYPE_COMPONENT)) {
Def_Type_Component_Writer.getInstance(typeNode);
waitForCompReference = true;
AstWalkerJava.componentList.add(nodeName);
myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "component");
parentName = nodeName;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method checkVariants.
/**
* Checks the type's variant attributes (when using the new codec handling).
*/
public void checkVariants(final CompilationTimeStamp timestamp) {
if (isAsn() || ownerType != TypeOwner_type.OT_TYPE_DEF) {
return;
}
WithAttributesPath globalAttributesPath;
final Def_Type def = (Def_Type) owner;
final Group nearest_group = def.getParentGroup();
if (nearest_group == null) {
// no group, use the module
Module myModule = myScope.getModuleScope();
globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
} else {
globalAttributesPath = nearest_group.getAttributePath();
}
if (globalAttributesPath != null) {
// process all global variants, not just the closest group
final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
checkThisVariant(timestamp, singleWithAttribute, true);
}
}
}
// check local variant attributes second, so they overwrite global ones if they
// conflict with each other
final WithAttributesPath attributePath = getAttributePath();
if (attributePath != null) {
final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
if (multipleWithAttributes != null) {
for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
}
final Reference reference = new Reference(null, fieldsOrArrays);
final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
if (type != null) {
if (type.getMyScope() != myScope) {
qualifier.getLocation().reportSemanticWarning("Variant attribute is ignored, because it refers to a type from a different type definition");
} else {
type.checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
} else {
checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
}
}
// check the coding attributes set by the variants
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
checkCodingAttributes(timestamp, chain);
chain.release();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method checkActualParameterList.
/**
* Check if a list of parsed actual parameters is semantically correct
* according to a list of formal parameters (the called entity).
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parsedParameters
* the parsed actual parameters (may contain named, and
* unnamed parts too).
* @param actualParameters
* the list of actual parameters returned for later
* usage.
*
* @return true if a semantic error was found, false otherwise
*/
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
parsedParameters.setFormalParList(this);
checkUniqueness(timestamp);
boolean isErroneous = false;
final TemplateInstances unnamed = parsedParameters.getInstances();
final NamedParameters named = parsedParameters.getNamedParameters();
int nofLocated = unnamed.getNofTis();
final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
for (int i = 0, size = parameters.size(); i < size; i++) {
formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
}
final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
for (int i = 0, size = named.getNofParams(); i < size; i++) {
final NamedParameter namedParameter = named.getParamByIndex(i);
if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
final int isAt = formalParameterMap.get(formalParameter);
if (isAt >= nofLocated) {
for (; nofLocated < isAt; nofLocated++) {
final NotUsed_Template temp = new NotUsed_Template();
if (!parameters.get(nofLocated).hasDefaultValue()) {
temp.setIsErroneous(true);
}
final TemplateInstance instance = new TemplateInstance(null, null, temp);
instance.setLocation(parsedParameters.getLocation());
finalUnnamed.addTemplateInstance(instance);
}
finalUnnamed.addTemplateInstance(namedParameter.getInstance());
nofLocated++;
} else {
isErroneous = true;
if (isAt >= unnamed.getNofTis()) {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
} else {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
}
}
} else {
String name;
switch(myDefinition.getAssignmentType()) {
case A_TYPE:
switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
case TYPE_FUNCTION:
name = "Function reference";
break;
case TYPE_ALTSTEP:
name = "Altstep reference";
break;
case TYPE_TESTCASE:
name = "Testcase reference";
break;
default:
name = "";
break;
}
break;
default:
name = myDefinition.getAssignmentName();
break;
}
isErroneous = true;
namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
}
}
if (isErroneous) {
return false;
}
finalUnnamed.setLocation(parsedParameters.getLocation());
return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkSignatureReference.
/**
* Checks a reference to see if it really references a valid signature
* type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param reference
* the reference to check.
*
* @return the referenced signature type, or null if there were
* problems.
*/
public static Signature_Type checkSignatureReference(final CompilationTimeStamp timestamp, final Reference reference) {
if (reference == null) {
return null;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
return null;
}
if (!Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED1, assignment.getAssignmentName()));
return null;
}
IType result = ((Def_Type) assignment).getType(timestamp);
if (result == null) {
return null;
}
result = result.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (result == null) {
return null;
}
result = result.getTypeRefdLast(timestamp);
switch(result.getTypetype()) {
case TYPE_SIGNATURE:
return (Signature_Type) result;
case TYPE_PORT:
reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED2, result.getTypename()));
return null;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED3, result.getTypename()));
return null;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
if (selection instanceof Def_Type) {
final Def_Type df = (Def_Type) selection;
type = df.getType(CompilationTimeStamp.getBaseTimestamp());
}
final DefinitionVisitor vis = new DefinitionVisitor(type);
module.accept(vis);
final NavigableSet<ILocateableNode> nodes = vis.getLocations();
if (nodes.isEmpty()) {
return null;
}
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
ErrorReporter.logExceptionStackTrace(ce);
}
if (!rootEdit.hasChildren()) {
return null;
}
tfc.setEdit(rootEdit);
return tfc;
}
Aggregations