use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class Scope method checkRunsOnScope.
/**
* Checks that operations that can only be executed in definitions that
* have a runs on scope, are really executed in such a definition. And
* that the required runs on component is compatible with the runs on
* component of the definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param type
* the fat type to check (used or referred to by the
* location).
* @param errorLocation
* the location to report the error to.
* @param operation
* the name of the operation.
*/
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final IType type, final ILocateableNode errorLocation, final String operation) {
if (type == null) {
return;
}
Component_Type referencedComponent;
String typename;
switch(type.getTypetype()) {
case TYPE_FUNCTION:
referencedComponent = ((Function_Type) type).getRunsOnType(timestamp);
typename = "function";
break;
case TYPE_ALTSTEP:
referencedComponent = ((Altstep_Type) type).getRunsOnType(timestamp);
typename = "altstep";
break;
default:
return;
}
if (referencedComponent == null) {
return;
}
final RunsOnScope runsOnScope = getScopeRunsOn();
if (runsOnScope == null) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED2, operation, typename, type.getTypename(), referencedComponent.getTypename()));
} else {
final Component_Type localType = runsOnScope.getComponentType();
if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH2, localType.getTypename(), operation, typename, type.getTypename(), referencedComponent.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class Scope method checkRunsOnScope.
/**
* Checks that operations that can only be executed in definitions that
* have a runs on scope, are really executed in such a definition. And
* that the required runs on component is compatible with the runs on
* component of the definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param assignment
* the assignment to check (used or referred to by the
* statement).
* @param errorLocation
* the location to report the error to.
* @param operation
* the name of the operation.
*/
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
Component_Type referencedComponent;
switch(assignment.getAssignmentType()) {
case A_ALTSTEP:
referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
break;
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
break;
case A_TESTCASE:
referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
break;
default:
return;
}
if (referencedComponent == null) {
return;
}
final RunsOnScope runsOnScope = getScopeRunsOn();
if (runsOnScope == null) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
} else {
final Component_Type localType = runsOnScope.getComponentType();
if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method addAssignments.
/**
* Adds assignments (right now only definitions) the this component type
* body.
*
* @param assignments the assignments to be added.
*/
public void addAssignments(final List<Definition> assignments) {
for (final Definition def : assignments) {
if (def != null && def.getIdentifier() != null && def.getIdentifier().getLocation() != null) {
definitions.add(def);
def.setFullNameParent(this);
def.setMyScope(this);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions 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.Definitions 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("*************************");
}
Aggregations