use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Altstep_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;
}
Def_Altstep altstep = null;
switch(last.getValuetype()) {
case ALTSTEP_REFERENCE_VALUE:
altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
if (altstep == null) {
setIsErroneous(true);
return selfReference;
}
altstep.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(ALTSTEPREFERENCEVALUEEXPECTED);
value.setIsErroneous(true);
return selfReference;
}
formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
if (temporalRunsOnType != 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);
return selfReference;
}
final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
if (runsOnScope != null) {
final Component_Type componentType = runsOnScope.getComponentType();
if (!runsOnType.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(), altstep.getDescription(), temporalRunsOnType.getTypename()));
}
} else {
// compatibility using this component type as the scope
if (valueScope instanceof ComponentTypeBody) {
final ComponentTypeBody body = (ComponentTypeBody) valueScope;
if (!runsOnType.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(), altstep.getDescription(), temporalRunsOnType.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(), altstep.getDescription(), temporalRunsOnType.getTypename()));
}
}
} else {
if (runsOnRef == null) {
value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
value.setIsErroneous(true);
} else {
if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
value.setIsErroneous(true);
}
}
}
}
if (valueCheckingOptions.sub_check) {
// there is no parent type to check
if (subType != null) {
subType.checkThisValue(timestamp, value);
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class CompField method getDeclaration.
@Override
public /**
* {@inheritDoc}
*/
Declaration getDeclaration() {
INamedNode inamedNode = getNameParent();
while (!(inamedNode instanceof Definition)) {
if (inamedNode == null) {
// FIXME: this is just a temp solution! find the reason!
return null;
}
inamedNode = inamedNode.getNameParent();
}
final Definition namedTemplList = (Definition) inamedNode;
IType tempType = namedTemplList.getType(CompilationTimeStamp.getBaseTimestamp());
if (tempType == null) {
return null;
}
tempType = tempType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (tempType instanceof ITypeWithComponents) {
final Identifier resultId = ((ITypeWithComponents) tempType).getComponentIdentifierByName(getIdentifier());
return Declaration.createInstance(tempType.getDefiningAssignment(), resultId);
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
throw new ReParseException();
}
for (final Definition definition : definitions) {
definition.updateSyntax(reparser, false);
reparser.updateLocation(definition.getLocation());
if (!definition.getLocation().equals(definition.getCumulativeDefinitionLocation())) {
reparser.updateLocation(definition.getCumulativeDefinitionLocation());
}
}
if (extendsReferences != null) {
extendsReferences.updateSyntax(reparser, false);
reparser.updateLocation(extendsReferences.getLocation());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method collectDefinitionsFromAttributeExtends.
/**
* Collects the definitions coming from extends attributes.
* In reality no collection is done, but it is checked that the actual component has all definitions from the extended component.
*/
private void collectDefinitionsFromAttributeExtends() {
final List<ComponentTypeBody> parents = getAttributeExtendsInheritedComponentBodies();
for (final ComponentTypeBody parent : parents) {
for (final Definition definition : parent.getDefinitions()) {
final Identifier id = definition.getIdentifier();
final String name = id.getName();
// Check if we have inherited 2 different definitions with the same name
if (extendsGainedDefinitions.containsKey(name)) {
final Definition myDefinition = extendsGainedDefinitions.get(name);
if (definition != myDefinition) {
location.reportSemanticError(MessageFormat.format(INHERITANCECOLLISSION, id.getDisplayName(), definition.getMyScope().getFullName(), myDefinition.getMyScope().getFullName()));
}
continue;
}
if (!definitions.hasDefinition(name)) {
location.reportSemanticError(MessageFormat.format("Missing local definition of `{0}'', which was inherited from component type `{1}''", id.getDisplayName(), definition.getMyScope().getFullName()));
continue;
}
attributeGainedDefinitions.put(name, definition);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method generateCode.
/**
* Add generated java code on this level.
*
* @param aData only used to update imports if needed
* @param source the source code generated
*/
public void generateCode(final JavaGenData aData, final StringBuilder source) {
final StringBuilder init_comp = aData.getInitComp();
init_comp.append("if(\"").append(identifier.getDisplayName()).append("\".equals(component_type)) {\n");
if (extendsReferences != null) {
boolean hasBaseComponents = false;
for (final ComponentTypeBody cb : compatibleBodies) {
if (cb.definitions.size() > 0) {
if (!hasBaseComponents) {
init_comp.append("if(init_base_comps) {\n");
hasBaseComponents = true;
}
// TODO get_scope_mod_gen
if (getModuleScope().equals(cb.getModuleScope())) {
init_comp.append("init_comp_type(\"");
init_comp.append(cb.getIdentifier().getDisplayName());
init_comp.append("\", false);\n");
} else {
init_comp.append("//TODO implement Module_List");
init_comp.append("Module_List::initialize_component(\"");
init_comp.append(cb.getModuleScope().getIdentifier().getDisplayName());
init_comp.append("\", \"");
init_comp.append(cb.getIdentifier().getDisplayName());
init_comp.append("\", false);\n");
}
}
}
if (hasBaseComponents) {
init_comp.append("}\n");
}
}
for (final Definition def : definitions) {
if (extendsGainedDefinitions.containsKey(def.getIdentifier().getName())) {
def.generateCodeInitComp(aData, init_comp, extendsGainedDefinitions.get(def.getIdentifier().getName()));
} else {
def.generateCode(aData, true);
}
}
init_comp.append("return true;\n");
init_comp.append("} else ");
}
Aggregations