use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Reference method getRefdAssignment.
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList, final IReferenceChain referenceChain) {
if (myScope == null || getId() == null) {
return null;
}
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp) && !checkParameterList) {
return referredAssignment;
}
lastTimeChecked = timestamp;
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
isErroneous = false;
detectedModuleId = false;
detectModid();
referredAssignment = myScope.getAssBySRef(timestamp, this, referenceChain);
if (referredAssignment == null) {
isErroneous = true;
return referredAssignment;
}
referredAssignment.check(timestamp, tempReferenceChain);
referredAssignment.setUsed();
if (referredAssignment instanceof Definition) {
final String referingModuleName = getMyScope().getModuleScope().getName();
if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
((Definition) referredAssignment).referingHere.add(referingModuleName);
}
}
if (checkParameterList) {
FormalParameterList formalParameterList = null;
if (referredAssignment instanceof IParameterisedAssignment) {
formalParameterList = ((IParameterisedAssignment) referredAssignment).getFormalParameterList();
}
if (formalParameterList == null) {
if (!subReferences.isEmpty() && subReferences.get(0) instanceof ParameterisedSubReference) {
final String message = MessageFormat.format("The referenced {0} cannot have actual parameters", referredAssignment.getDescription());
getLocation().reportSemanticError(message);
setIsErroneous(true);
}
} else if (!subReferences.isEmpty()) {
final ISubReference firstSubReference = subReferences.get(0);
if (firstSubReference instanceof ParameterisedSubReference) {
formalParameterList.check(timestamp, referredAssignment.getAssignmentType());
isErroneous = ((ParameterisedSubReference) firstSubReference).checkParameters(timestamp, formalParameterList);
} else {
// default values
if (!Assignment.Assignment_type.A_TEMPLATE.semanticallyEquals(referredAssignment.getAssignmentType()) || !formalParameterList.hasOnlyDefaultValues()) {
final String message = MessageFormat.format("Reference to parameterized definition `{0}'' without actual parameter list", referredAssignment.getIdentifier().getDisplayName());
getLocation().reportSemanticError(message);
setIsErroneous(true);
}
}
}
}
return referredAssignment;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ReferenceFinder method detectSmallestScope.
/**
* Detect the smallest scope where the references should be searched
*
* @param assignment
* The assignment
* @return The detected scope
*/
private Scope detectSmallestScope(final Assignment assignment) {
Scope localScope = assignment.getMyScope();
final Module module = localScope.getModuleScope();
if (localScope instanceof StatementBlock) {
final StatementBlock statementBlock = (StatementBlock) localScope;
if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
localScope = localScope.getParentScope();
}
if (statementBlock.hasEnclosingLoopOrAltguard()) {
localScope = localScope.getParentScope();
}
}
if (localScope instanceof NamedBridgeScope) {
localScope = localScope.getParentScope();
}
// control,function,testcase,altstep then it is global
if (localScope instanceof Assignments && localScope.getParentScope() == module) {
localScope = module;
} else // treat it as global definition
if (localScope instanceof ComponentTypeBody) {
// FIXME this still does not make them global, that is something completely different.
localScope = module;
} else // search for actual named parameters everywhere
if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
localScope = module;
} else // For_Statement that must be searched
if (localScope instanceof For_Loop_Definitions) {
localScope = localScope.getParentScope();
}
return localScope;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ASTNode method getT3Doc.
// FIXME: this does not belong here, ASTNodes in general don't have comments
public T3Doc getT3Doc(final Location location) {
if (this instanceof Def_ModulePar) {
final String st1 = this.getFullName().toString();
final String st = st1.substring(st1.lastIndexOf('.') + 1);
return new T3Doc(this.getCommentLocation(), st);
}
if (this.getCommentLocation() != null) {
return new T3Doc(this.getCommentLocation());
}
if (this instanceof ILocateableNode) {
final ILocateableNode iloc = (ILocateableNode) this;
// ToDo check scopes that do not matter
final Scope scope = this.getMyScope();
final Assignment assignment = scope.getModuleScope().getEnclosingAssignment(iloc.getLocation().getOffset());
if (assignment == null || assignment == this || assignment.getMyScope() instanceof Definitions) {
return null;
}
final T3Doc parentT3doc = assignment.getT3Doc(location);
if (parentT3doc != null) {
// if it is a type assignment/definition then detect if we are in a field
if (assignment.getAssignmentType() == Assignment_type.A_TYPE) {
final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
if (type == null) {
return null;
}
// Reference finder - wonderful
final ReferenceFinder rf = new ReferenceFinder(assignment);
rf.scope = this.getMyScope().getModuleScope().getSmallestEnclosingScope(iloc.getLocation().getOffset());
rf.type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
type.getEnclosingField(location.getOffset(), rf);
String st = null;
if (rf.fieldId != null) {
st = rf.fieldId.getDisplayName();
} else {
final String st1 = this.getFullName().toString();
st = st1.substring(st1.lastIndexOf('.') + 1);
}
// Get member information if available
if (parentT3doc.getMembers() != null) {
final String desc = parentT3doc.getMembers().get(st);
if (desc != null) {
return new T3Doc(desc);
}
}
} else if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final String st1 = this.getFullName().toString();
final String st = st1.substring(st1.lastIndexOf('.') + 1);
String desc = null;
if (parentT3doc.getMembers() != null) {
desc = parentT3doc.getMembers().get(st);
}
if (parentT3doc.getParams() != null) {
desc = parentT3doc.getParams().get(st);
}
if (desc != null) {
return new T3Doc(desc);
}
} else if (assignment.getAssignmentType() == Assignment_type.A_FUNCTION || assignment.getAssignmentType() == Assignment_type.A_FUNCTION_RTEMP || assignment.getAssignmentType() == Assignment_type.A_FUNCTION_RVAL) {
final String st1 = this.getFullName().toString();
final String st = st1.substring(st1.lastIndexOf('.') + 1);
if (parentT3doc.getParams() != null) {
final String desc = parentT3doc.getParams().get(st);
if (desc != null) {
return new T3Doc(desc);
}
}
}
}
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(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(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(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);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Return_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
genRestrictionCheck = false;
final Definition definition = myStatementBlock.getMyDefinition();
if (definition == null) {
location.reportSemanticError(USAGEINCONTROLPART);
return;
}
switch(definition.getAssignmentType()) {
case A_FUNCTION:
if (template != null) {
template.getLocation().reportSemanticError(UNEXPECTEDRETURNVALUE);
}
break;
case A_FUNCTION_RVAL:
final Type returnType = ((Def_Function) definition).getType(timestamp);
if (template == null) {
location.reportSemanticError(MessageFormat.format(MISSINGVALUE, returnType.getTypename()));
break;
}
if (!template.isValue(timestamp)) {
template.getLocation().reportSemanticError(SPECIFICVALUEEXPECTED);
break;
}
// General:
template.setMyGovernor(returnType);
final IValue value = template.getValue();
if (value != null) {
value.setMyGovernor(returnType);
returnType.checkThisValueRef(timestamp, value);
returnType.checkThisValue(timestamp, value, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
}
break;
case A_FUNCTION_RTEMP:
if (template == null) {
location.reportSemanticError(MessageFormat.format(MISSINGTEMPLATE, ((Def_Function) definition).getType(timestamp).getTypename()));
} else {
final Type returnType1 = ((Def_Function) definition).getType(timestamp);
template.setMyGovernor(returnType1);
final ITTCN3Template temporalTemplate1 = returnType1.checkThisTemplateRef(timestamp, template, Expected_Value_type.EXPECTED_TEMPLATE, null);
temporalTemplate1.checkThisTemplateGeneric(timestamp, returnType1, true, /* isModified */
true, /* allowOmit */
true, /* allowAnyOrOmit */
true, /* subCheck */
true, /* implicitOmit */
null);
genRestrictionCheck = TemplateRestriction.check(timestamp, definition, temporalTemplate1, null);
}
break;
case A_ALTSTEP:
if (template != null) {
template.getLocation().reportSemanticError(ALTSTEPRETURNINGVALUE);
}
break;
default:
location.reportSemanticError(MessageFormat.format(UNEXPETEDRETURNSTATEMENT, definition.getAssignmentName()));
break;
}
}
Aggregations