use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.
the class Component_Type method checkExpressionOperandComponentRefernce.
/**
* Checks if the provided value is a reference to a component or not.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expected_value the value kind expected from the actual parameter.
*/
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
switch(value.getValuetype()) {
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, chain);
chain.release();
if (last == null || last.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
return;
}
IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
}
break;
}
case REFERENCED_VALUE:
{
final Reference reference = ((Referenced_Value) value).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
value.setIsErroneous(true);
return;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
{
IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
IValue tempValue = ((Def_Const) assignment).getValue();
if (tempValue == null) {
return;
}
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
chain.release();
if (tempValue == null) {
return;
}
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
}
if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
return;
}
switch(((Expression_Value) tempValue).getOperationType()) {
case MTC_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
value.setIsErroneous(true);
return;
case COMPONENT_NULL_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
case SYSTEM_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
value.setIsErroneous(true);
return;
default:
break;
}
break;
}
case A_EXT_CONST:
{
IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_MODULEPAR:
{
IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_VAR:
{
IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_FUNCTION_RVAL:
{
IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_EXT_FUNCTION_RVAL:
{
IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
{
IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
default:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
value.setIsErroneous(true);
return;
}
break;
}
default:
// the error was already reported if possible.
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.
the class TypenameInDef method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
return;
}
final Definition s = (Definition) node;
check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method createModuleParListForSaving.
public String createModuleParListForSaving() {
if (modulePars == null || modulePars.isEmpty()) {
return "<empty>";
}
final List<ModuleParListRecord> records = new ArrayList<ModuleParListRecord>();
for (Def_ModulePar def : modulePars) {
final IResource f = def.getLocation().getFile();
if (!(f instanceof IFile)) {
ErrorReporter.logError("ExtractModulePar/SelectionFinder: IResource `" + f.getName() + "' is not an IFile.");
continue;
}
final Identifier id = def.getIdentifier();
final Type t = def.getType(CompilationTimeStamp.getBaseTimestamp());
records.add(new ModuleParListRecord(def.getMyScope().getModuleScope().getIdentifier().getDisplayName(), id.getDisplayName(), t.getTypename()));
}
//
Collections.sort(records);
final StringBuilder sb = new StringBuilder();
for (ModuleParListRecord rec : records) {
sb.append(rec.toString()).append('\n');
}
return sb.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method perform.
public void perform() {
modulePars = new HashSet<Def_ModulePar>();
final Collection<Module> modules = GlobalParser.getProjectSourceParser(project).getModules();
for (Module m : modules) {
final ModuleParFinder vis = new ModuleParFinder();
m.accept(vis);
modulePars.addAll(vis.getModulePars());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar 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;
}
Aggregations