use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method getLocalAssignmentById.
/**
* Returns the assignment of this component fitting the provided identifier.
*
* @param identifier the identifier of the assignment
* @return the assignment identified, or null in case of an error.
*/
public Definition getLocalAssignmentById(final Identifier identifier) {
if (lastUniquenessCheck == null) {
checkUniqueness(CompilationTimeStamp.getBaseTimestamp());
}
final String name = identifier.getName();
Definition definition = definitions.getDefinition(name);
if (definition != null) {
return definition;
}
definition = extendsGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return definition;
} else {
identifier.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, identifier.getDisplayName(), this.identifier.getDisplayName()));
}
}
definition = attributeGainedDefinitions.get(name);
if (definition != null) {
if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
return definition;
} else {
identifier.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, identifier.getDisplayName(), this.identifier.getDisplayName()));
}
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method addDefinitionsOfExtendsParents.
private void addDefinitionsOfExtendsParents(final CompilationTimeStamp timestamp) {
extendsGainedDefinitions.clear();
if (extendsReferences == null) {
return;
}
extendsReferences.check(timestamp);
final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULAREXTENSIONCHAIN, true);
if (referenceChain.add(this)) {
extendsReferences.checkRecursion(referenceChain);
}
referenceChain.release();
initCompatibility(extendsReferences);
// collect definitions
final List<ComponentTypeBody> bodies = getExtendsInheritedComponentBodies();
for (final ComponentTypeBody body : bodies) {
final Map<String, Definition> subDefinitionMap = body.getDefinitionMap();
for (final Definition definition : subDefinitionMap.values()) {
final String name = definition.getIdentifier().getName();
if (definitions.hasDefinition(name)) {
final Definition localDefinition = definitions.getDefinition(name);
localDefinition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(LOCALINHERTANCECOLLISSION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
} else if (extendsGainedDefinitions.containsKey(name)) {
final Definition previousDefinition = extendsGainedDefinitions.get(name);
if (!previousDefinition.equals(definition)) {
// it is not the same definition inherited on two paths
if (this.equals(previousDefinition.getMyScope())) {
previousDefinition.getLocation().reportSemanticError(MessageFormat.format(LOCALINHERTANCECOLLISSION, previousDefinition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
definition.getIdentifier().getLocation().reportSemanticWarning(MessageFormat.format(INHERITEDLOCATION, definition.getIdentifier().getDisplayName()));
} else if (identifier != null && identifier.getLocation() != null) {
identifier.getLocation().reportSemanticError(MessageFormat.format(INHERITANCECOLLISSION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName(), previousDefinition.getMyScope().getFullName()));
definition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
previousDefinition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, previousDefinition.getIdentifier().getDisplayName(), previousDefinition.getMyScope().getFullName()));
}
}
} else {
extendsGainedDefinitions.put(name, definition);
if (!definition.getMyScope().getModuleScope().equals(parentScope.getModuleScope())) {
if (parentScope.hasAssignmentWithId(timestamp, definition.getIdentifier())) {
if (identifier != null && identifier.getLocation() != null) {
identifier.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, definition.getIdentifier().getDisplayName()));
final List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(definition.getIdentifier()));
final Reference reference = new Reference(null, subReferences);
final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
if (assignment != null && assignment.getLocation() != null) {
assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, definition.getIdentifier().getDisplayName()));
}
definition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
}
} else if (parentScope.isValidModuleId(definition.getIdentifier())) {
definition.getLocation().reportSingularSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, definition.getIdentifier().getDisplayName()));
}
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefinitionContainer method checkUniqueness.
public void checkUniqueness() {
definitionMap.clear();
for (final Definition definition : definitions) {
final String definitionName = definition.getIdentifier().getName();
if (definitionMap.containsKey(definitionName)) {
definitionMap.get(definitionName).getIdentifier().getLocation().reportSingularSemanticError(MessageFormat.format(CompFieldMap.DUPLICATEFIELDNAMEFIRST, definition.getIdentifier().getDisplayName()));
definition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(CompFieldMap.DUPLICATEFIELDNAMEREPEATED, definition.getIdentifier().getDisplayName()));
} else {
definitionMap.put(definitionName, definition);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class SpecificValue_Template method isValue.
@Override
public /**
* {@inheritDoc}
*/
boolean isValue(final CompilationTimeStamp timestamp) {
if (lengthRestriction != null || isIfpresent || getIsErroneous(timestamp)) {
return false;
}
if (realTemplate != null && realTemplate != this) {
return realTemplate.isValue(timestamp);
}
if (Value_type.FUNCTION_REFERENCE_VALUE.equals(specificValue.getValuetype())) {
final IType governor = ((Function_Reference_Value) specificValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (governor == null) {
return true;
}
final IType last = governor.getTypeRefdLast(timestamp);
if (Type_type.TYPE_FUNCTION.equals(last.getTypetype()) && ((Function_Type) last).returnsTemplate()) {
return false;
}
} else if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
final Reference reference = ((Referenced_Value) specificValue).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
return true;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_TIMER:
case A_EXT_CONST:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_VAR:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
case A_MODULEPAR:
case A_MODULEPAR_TEMPLATE:
// runtime evaluation!
return true;
case A_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_INOUT:
case A_FUNCTION_RTEMP:
case A_VAR_TEMPLATE:
boolean result = true;
final Restriction_type rt = ((Definition) assignment).getTemplateRestriction();
if (TemplateRestriction.Restriction_type.TR_OMIT.equals(rt) || TemplateRestriction.Restriction_type.TR_PRESENT.equals(rt)) {
result = false;
}
final TTCN3Template ttemplate = getTemplateReferencedLast(timestamp);
if ((!ttemplate.equals(this)) && (ttemplate.isValue(timestamp))) {
// ok
return result;
} else {
return false;
}
default:
return false;
}
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method checkValueomitRestriction.
@Override
public /**
* {@inheritDoc}
*/
boolean checkValueomitRestriction(final CompilationTimeStamp timestamp, final String definitionName, final boolean omitAllowed, final Location usageLocation) {
if (reference == null) {
if (omitAllowed) {
checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_OMIT, usageLocation);
} else {
checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_VALUE, usageLocation);
}
} else {
// if (reference != null):
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (Assignment_type.A_TEMPLATE == ass.getAssignmentType()) {
final ITTCN3Template templateLast = getTemplateReferencedLast(timestamp);
if (!this.equals(templateLast)) {
templateLast.checkValueomitRestriction(timestamp, getTemplateTypeName(), omitAllowed, usageLocation);
}
}
switch(ass.getAssignmentType()) {
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_EXT_FUNCTION_RTEMP:
case A_FUNCTION_RTEMP:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
if (ass instanceof Definition) {
TemplateRestriction.Restriction_type refdTemplateRestriction = ((Definition) ass).getTemplateRestriction();
refdTemplateRestriction = TemplateRestriction.getSubRestriction(refdTemplateRestriction, timestamp, reference);
// if restriction is not satisfied issue warning
if (TemplateRestriction.isLessRestrictive(omitAllowed ? TemplateRestriction.Restriction_type.TR_OMIT : TemplateRestriction.Restriction_type.TR_VALUE, refdTemplateRestriction)) {
getLocation().reportSemanticWarning(MessageFormat.format(INADEQUATETEMPLATERESTRICTION, ass.getAssignmentName(), reference.getDisplayName()));
return true;
}
}
return false;
default:
return false;
}
}
return false;
}
Aggregations