use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Def_Var method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
isUsed = false;
wasAssigned = false;
if (getMyScope() instanceof ComponentTypeBody) {
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_COMPONENT_VARIABLE, identifier, this);
} else {
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_VARIABLE, identifier, this);
}
NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
if (type == null) {
return;
}
type.setGenName("_T_", getGenName());
type.check(timestamp);
final IType lastType = type.getTypeRefdLast(timestamp);
switch(lastType.getTypetype()) {
case TYPE_PORT:
location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
break;
case TYPE_SIGNATURE:
location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
break;
default:
break;
}
if (initialValue != null) {
initialValue.setMyGovernor(type);
final IValue temporalValue = type.checkThisValueRef(timestamp, initialValue);
if (isLocal()) {
type.checkThisValue(timestamp, temporalValue, this, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, true, false, false));
} else {
type.checkThisValue(timestamp, temporalValue, this, new ValueCheckingOptions(Expected_Value_type.EXPECTED_STATIC_VALUE, true, false, true, false, false));
}
initialValue.setGenNameRecursive(getGenName());
initialValue.setCodeSection(CodeSectionType.CS_INLINE);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST_Action method exportDebugAST.
private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(out, 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(out, padding + 1, " contains definitions:");
if (map != null) {
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(out, 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);
}
});
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
out.closeEntry();
}
use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkConnectionEndpoint.
/**
* Checks a reference to see if it really references a valid component
* type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the statement to report an error to, in case it is in
* a control part.
* @param componentReference
* the reference of the component to be checked.
* @param portReference
* the reference to a port of the component to be
* checked.
* @param allowSystem
* tells if the system component should be allowed or not
* as an endpoint.
*
* @return the referenced component type, or null if there were
* problems.
*/
public static IType checkConnectionEndpoint(final CompilationTimeStamp timestamp, final Statement source, final Value componentReference, final PortReference portReference, final boolean allowSystem) {
final IType componentType = checkComponentReference(timestamp, source, componentReference, true, allowSystem);
if (portReference == null) {
return componentType;
}
if (componentType == null) {
// the component type can not be determined
final List<ISubReference> subreferences = portReference.getSubreferences();
if (subreferences.size() > 1) {
// check array indices
for (int i = 0; i < subreferences.size(); i++) {
final ISubReference subreference = subreferences.get(i);
if (subreference instanceof ArraySubReference) {
final Value value = ((ArraySubReference) subreference).getValue();
value.setLoweridToReference(timestamp);
final Type_type temporalType1 = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType1) {
case TYPE_INTEGER:
{
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last1 = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
referenceChain.release();
if (!last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
if (((Integer_Value) last1).signum() < 0) {
value.getLocation().reportSemanticError(ArraySubReference.NATIVEINTEGEREXPECTED);
value.setIsErroneous(true);
}
}
break;
}
case TYPE_UNDEFINED:
value.setIsErroneous(true);
break;
default:
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
value.setIsErroneous(true);
}
break;
}
}
}
}
return null;
}
final ComponentTypeBody componentBody = ((Component_Type) componentType).getComponentBody();
portReference.setBaseScope(componentBody);
portReference.setComponent((Component_Type) componentType);
// for compatibility
portReference.getRefdAssignment(timestamp, false);
final Identifier portIdentifier = portReference.getId();
if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
return null;
}
final Assignment assignment = componentBody.getLocalAssignmentById(portIdentifier);
if (assignment == null) {
return null;
}
if (!Assignment_type.A_PORT.semanticallyEquals(assignment.getAssignmentType())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(DEFINITIONNOTPORT, portIdentifier.getDisplayName(), componentType.getTypename(), assignment.getAssignmentName()));
return null;
}
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, portReference, "port", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (portReference.getSubreferences().size() > 1) {
portReference.getLocation().reportSemanticError(MessageFormat.format("Port `{0}'' is not an array. The reference cannot have field or array sub-references", portIdentifier.getDisplayName()));
}
Port_Type portType = ((Def_Port) assignment).getType(timestamp);
if (portType != null) {
final PortTypeBody portBody = portType.getPortBody();
if (PortType_type.PT_USER.equals(portBody.getPortType())) {
final IType providerType = portBody.getProviderType();
if (providerType instanceof Port_Type) {
portType = (Port_Type) providerType;
}
}
}
return portType;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.
the class PortReference method getRefdAssignment.
@Override
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList) {
if (myScope == null || componentType == null) {
return null;
}
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return referredAssignment;
}
// just for error compatibility with...
super.getRefdAssignment(timestamp, checkParameterList);
final Identifier portIdentifier = getId();
final ComponentTypeBody componentBody = componentType.getComponentBody();
if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
setIsErroneous(true);
referredAssignment = null;
lastTimeChecked = timestamp;
return null;
}
referredAssignment = componentBody.getLocalAssignmentById(portIdentifier);
if (referredAssignment != null) {
referredAssignment.check(timestamp);
referredAssignment.setUsed();
if (referredAssignment instanceof Definition) {
final String referingModuleName = getMyScope().getModuleScope().getName();
if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
((Definition) referredAssignment).referingHere.add(referingModuleName);
}
}
}
lastTimeChecked = timestamp;
return referredAssignment;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Function_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (last == null || last.getIsErroneous(timestamp)) {
return selfReference;
}
last.setMyGovernor(this);
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return selfReference;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return selfReference;
}
break;
default:
break;
}
Assignment assignment = null;
switch(last.getValuetype()) {
case FUNCTION_REFERENCE_VALUE:
assignment = ((Function_Reference_Value) last).getReferredFunction();
if (assignment == null) {
value.setIsErroneous(true);
return selfReference;
}
assignment.check(timestamp);
break;
case TTCN3_NULL_VALUE:
value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
return selfReference;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
return selfReference;
default:
value.getLocation().reportSemanticError(FUNCTIONREFERENCEVALUEEXPECTED);
value.setIsErroneous(true);
return selfReference;
}
// external functions do not have runs on clauses
if (assignment instanceof Def_Function) {
formalParList.checkCompatibility(timestamp, ((Def_Function) assignment).getFormalParameterList(), value.getLocation());
final IType tempRunsOnType = ((Def_Function) assignment).getRunsOnType(timestamp);
if (tempRunsOnType != null) {
if (runsOnSelf) {
// check against the runs on component type of the scope of the value
final Scope valueScope = value.getMyScope();
if (valueScope == null) {
value.setIsErroneous(true);
value.setLastTimeChecked(timestamp);
return selfReference;
}
final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
if (runsOnScope != null) {
final Component_Type componentType = runsOnScope.getComponentType();
if (!tempRunsOnType.isCompatible(timestamp, componentType, null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope expects " + "component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
}
} else {
// compatibility using this component type as the scope
if (valueScope instanceof ComponentTypeBody) {
final ComponentTypeBody body = (ComponentTypeBody) valueScope;
if (!tempRunsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current component definition " + "is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' " + "clause and the current scope does not have a `runs on'' clause, but {1} runs on `{2}''", getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
}
}
} else {
if (runsOnRef == null) {
value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
value.setIsErroneous(true);
} else {
if (runsOnType != null && !tempRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
value.setIsErroneous(true);
}
}
}
}
}
switch(assignment.getAssignmentType()) {
case A_FUNCTION:
case A_EXT_FUNCTION:
if (returnType != null) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a {1} of type `{2}'', but {3} does not have a return type", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription()));
}
break;
case A_FUNCTION_RTEMP:
{
final Restriction_type restriction = ((Def_Function) assignment).getTemplateRestriction();
if (!templateRestriction.equals(restriction)) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
}
if (returnType != null) {
final IType tempReturnType = assignment.getType(timestamp);
if (!returnType.isIdentical(timestamp, tempReturnType)) {
value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
} else if (!returnsTemplate) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
}
break;
}
case A_EXT_FUNCTION_RTEMP:
{
final Restriction_type restriction = ((Def_Extfunction) assignment).getTemplateRestriction();
if (!templateRestriction.equals(restriction)) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
}
if (returnType != null) {
final IType tempReturnType = assignment.getType(timestamp);
if (!returnType.isIdentical(timestamp, tempReturnType)) {
value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
} else if (!returnsTemplate) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
}
break;
}
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (returnType != null) {
final IType tempReturnType = assignment.getType(timestamp);
if (!returnType.isIdentical(timestamp, tempReturnType)) {
value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}''," + " but {3} returns a value of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
} else if (returnsTemplate) {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template of type `{1}'', but {2} returns a value", getTypename(), returnType.getTypename(), assignment.getDescription()));
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a value of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
}
break;
default:
break;
}
if (valueCheckingOptions.sub_check) {
// there is no parent type to check
if (subType != null) {
subType.checkThisValue(timestamp, last);
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
Aggregations