Search in sources :

Example 76 with Reference

use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.

the class NotequalesExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    // TODO actually a bit more complicated
    boolean isOptional1 = false;
    boolean isOptional2 = false;
    final IValue temp = value1.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
    if (temp instanceof Omit_Value) {
        isOptional1 = true;
    } else if (temp instanceof Referenced_Value) {
        final Reference reference = ((Referenced_Value) temp).getReference();
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
            isOptional1 = true;
        }
    }
    final IValue temp2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
    if (temp2 instanceof Omit_Value) {
        isOptional2 = true;
    } else if (temp2 instanceof Referenced_Value) {
        final Reference reference = ((Referenced_Value) temp2).getReference();
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
            isOptional2 = true;
        }
    }
    if (isOptional1) {
        expression.expression.append("!(");
        value1.generateCodeExpression(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value2.generateCodeExpression(aData, expression, true);
        expression.expression.append(" ))");
    } else if (isOptional2) {
        expression.expression.append("!(");
        value2.generateCodeExpression(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value1.generateCodeExpression(aData, expression, true);
        expression.expression.append(" ))");
    } else {
        expression.expression.append("!(");
        value1.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".operatorEquals( ");
        value2.generateCodeExpressionMandatory(aData, expression, false);
        expression.expression.append(" ))");
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 77 with Reference

use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.

the class TTCN3ReferenceAnalyzer method parseForCompletion.

/**
 * Parses the provided elements. If the contents of an editor are to be parsed,
 *  than the file parameter is only used to report the errors to.
 *
 * @param file the file to parse, and report the errors to
 * @param code the contents of an editor, or null.
 */
public Reference parseForCompletion(final IFile file, final String code) {
    Reference reference = null;
    Reader reader = new StringReader(code);
    CharStream charStream = new UnbufferedCharStream(reader);
    Ttcn3KeywordlessLexer lexer = new Ttcn3KeywordlessLexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    lexer.initRootInterval(code.length());
    lexer.removeErrorListeners();
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    Ttcn3Parser parser = new Ttcn3Parser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    lexer.setActualFile(file);
    parser.setActualFile(file);
    parser.setProject(file.getProject());
    parser.removeErrorListeners();
    final Pr_UnifiedReferenceParserContext root = parser.pr_UnifiedReferenceParser();
    ParserUtilities.logParseTree(root, parser);
    reference = root.reference;
    return reference;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) Pr_UnifiedReferenceParserContext(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Parser.Pr_UnifiedReferenceParserContext) Reference(org.eclipse.titan.designer.AST.Reference) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Example 78 with Reference

use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.

the class ConsecutiveAssignments method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof StatementBlock)) {
        return;
    }
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    int count = 0;
    boolean limitReached = false;
    Location smellLoc = null;
    Assignment_Statement lastAs = null;
    Assignment toMatch = null;
    final StatementBlock sb = (StatementBlock) node;
    // iterate statements in block
    for (int i = 0; i < sb.getSize(); i++) {
        final Statement s = sb.getStatementByIndex(i);
        if (!(s instanceof Assignment_Statement)) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        final Assignment_Statement as = (Assignment_Statement) s;
        final Reference ref = as.getReference();
        final Assignment a = ref.getRefdAssignment(timestamp, false);
        if (a == null) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        // consecutive assignments: consecutive Assignment_Statements have the same definition
        if (toMatch == null) {
            toMatch = a;
        } else if (toMatch != a) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = a;
        }
        if (count == 0) {
            smellLoc = new Location(as.getLocation());
        }
        lastAs = as;
        count++;
        if (count >= minCountToMark) {
            limitReached = true;
        }
    }
    if (limitReached) {
        smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
        problems.report(smellLoc, ERROR_MESSAGE);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Reference(org.eclipse.titan.designer.AST.Reference) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 79 with Reference

use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Set_Seq_Choice_BaseType method checkSetSeqRawCodingAttributes.

/**
 * Check the raw coding attributes of TTCN3 record and set types.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 */
protected void checkSetSeqRawCodingAttributes(final CompilationTimeStamp timestamp) {
    // check raw attributes
    if (rawAttribute != null) {
        if (rawAttribute.taglist != null) {
            for (int c = 0; c < rawAttribute.taglist.size(); c++) {
                final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
                final Identifier fieldname = singleTag.fieldName;
                if (!hasComponentWithName(fieldname.getName())) {
                    fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
                    continue;
                }
                if (singleTag.keyList != null) {
                    for (int a = 0; a < singleTag.keyList.size(); a++) {
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(fieldname));
                        for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
                            reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
                        }
                        final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                        if (t != null) {
                            final Value v = singleTag.keyList.get(a).v_value;
                            if (v != null) {
                                v.setMyScope(getMyScope());
                                v.setMyGovernor(t);
                                final IValue tempValue = t.checkThisValueRef(timestamp, v);
                                t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                            }
                        }
                    }
                }
            }
        }
        if (rawAttribute.ext_bit_groups != null) {
            for (int a = 0; a < rawAttribute.ext_bit_groups.size(); a++) {
                final rawAST_ext_bit_group tempExtBitGroup = rawAttribute.ext_bit_groups.get(a);
                final Identifier fromIdentifier = tempExtBitGroup.from;
                final Identifier toIdentifier = tempExtBitGroup.to;
                boolean foundError = false;
                if (!hasComponentWithName(fromIdentifier.getName())) {
                    fromIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", fromIdentifier.getDisplayName(), getTypename()));
                    foundError = true;
                }
                if (!hasComponentWithName(toIdentifier.getName())) {
                    toIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", toIdentifier.getDisplayName(), getTypename()));
                    foundError = true;
                }
                if (!foundError) {
                    boolean foundStart = false;
                    for (int i = 0; i < getNofComponents(); i++) {
                        final Identifier tempId = getComponentByIndex(i).getIdentifier();
                        if (tempId.equals(fromIdentifier)) {
                            foundStart = true;
                        } else if (tempId.equals(toIdentifier)) {
                            if (!foundStart) {
                                getLocation().reportSemanticError(MessageFormat.format("Invalid field order in RAW parameter EXTENSION_BIT_GROUP for type `{0}'': `{1}'', `{2}''", getTypename(), fromIdentifier.getDisplayName(), toIdentifier.getDisplayName()));
                            }
                            break;
                        }
                    }
                }
            }
        }
        if (rawAttribute.paddall != RawAST.XDEFDEFAULT) {
            for (int i = 0; i < getNofComponents(); i++) {
                final CompField cField = getComponentByIndex(i);
                final Type fieldType = cField.getType();
                RawAST fieldRawAttribute = fieldType.rawAttribute;
                if (fieldRawAttribute == null) {
                    IType t = fieldType;
                    if (t instanceof Referenced_Type) {
                        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
                        referenceChain.release();
                    }
                    while (t.getRawAttribute() == null && t instanceof Referenced_Type) {
                        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
                        referenceChain.release();
                    }
                    fieldRawAttribute = new RawAST(t.getRawAttribute(), fieldType.getDefaultRawFieldLength());
                    fieldType.setRawAttributes(fieldRawAttribute);
                }
                if (fieldRawAttribute.padding == 0) {
                    fieldRawAttribute.padding = rawAttribute.padding;
                }
                if (fieldRawAttribute.prepadding == 0) {
                    fieldRawAttribute.prepadding = rawAttribute.prepadding;
                }
                if (fieldRawAttribute.padding_pattern_length == 0 && rawAttribute.padding_pattern_length > 0) {
                    fieldRawAttribute.padding_pattern = rawAttribute.padding_pattern;
                    fieldRawAttribute.padding_pattern_length = rawAttribute.padding_pattern_length;
                }
            }
        }
        if (rawAttribute.fieldorder != RawAST.XDEFDEFAULT) {
            for (int i = 0; i < getNofComponents(); i++) {
                final CompField cField = getComponentByIndex(i);
                final Type fieldType = cField.getType();
                RawAST fieldRawAttribute = fieldType.rawAttribute;
                if (fieldRawAttribute == null) {
                    fieldRawAttribute = new RawAST(fieldType.getDefaultRawFieldLength());
                    fieldType.setRawAttributes(fieldRawAttribute);
                }
                if (fieldRawAttribute.fieldorder == RawAST.XDEFDEFAULT) {
                    fieldRawAttribute.fieldorder = rawAttribute.fieldorder;
                }
            }
        }
    }
    if (rawAttribute != null && rawAttribute.presence != null) {
        if (rawAttribute.presence.keyList != null) {
            for (int a = 0; a < rawAttribute.presence.keyList.size(); a++) {
                final rawAST_tag_field_value tempTagFieldValue = rawAttribute.presence.keyList.get(a);
                final Reference reference = new Reference(null);
                reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
                for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
                    reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
                }
                final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                if (t != null) {
                    final Value v = tempTagFieldValue.v_value;
                    if (v != null) {
                        v.setMyScope(getMyScope());
                        v.setMyGovernor(t);
                        final IValue tempValue = t.checkThisValueRef(timestamp, v);
                        t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                    }
                }
            }
        }
    }
    // number of bits used to store all previous fields
    int usedBits = 0;
    for (int i = 0; i < getNofComponents(); i++) {
        final CompField cField = getComponentByIndex(i);
        final Type fieldType = cField.getType();
        fieldType.forceRaw(timestamp);
        final RawAST rawPar = fieldType.rawAttribute;
        if (rawPar != null) {
            final Identifier fieldId = cField.getIdentifier();
            final IType fieldTypeLast = fieldType.getTypeRefdLast(timestamp);
            if (rawPar.prepadding != 0) {
                usedBits = (usedBits + rawPar.prepadding - 1) / rawPar.prepadding * rawPar.prepadding;
            }
            if (rawPar.intX && fieldTypeLast.getTypetype() == Type_type.TYPE_INTEGER) {
                if (usedBits % 8 != 0 && (rawAttribute == null || rawAttribute.fieldorder != RawAST.XDEFMSB)) {
                    getLocation().reportSemanticError(MessageFormat.format("Using RAW parameter IntX in a record/set with FIELDORDER set to 'lsb' is only supported if the IntX field starts at the beginning of a new octet. There are {0} unused bits in the last octet before field {1}.", 8 - (usedBits % 8), fieldId.getDisplayName()));
                }
            } else if (rawPar.fieldlength > 0) {
                usedBits += rawPar.fieldlength;
            }
            if (rawPar.padding != 0) {
                usedBits = (usedBits + rawPar.padding - 1) / rawPar.padding * rawPar.padding;
            }
            if (rawPar.lengthto != null) {
                for (int j = 0; j < rawPar.lengthto.size(); j++) {
                    final Identifier id = rawPar.lengthto.get(j);
                    if (!hasComponentWithName(id.getName())) {
                        id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                    }
                }
            }
            if (rawPar.lengthto != null) {
                switch(fieldTypeLast.getTypetype()) {
                    case TYPE_INTEGER:
                    case TYPE_INTEGER_A:
                        break;
                    case TYPE_TTCN3_CHOICE:
                        for (int fi = 0; fi < ((TTCN3_Choice_Type) fieldTypeLast).getNofComponents(); fi++) {
                            final Type_type tt = ((TTCN3_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
                            if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
                                getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
                            }
                        }
                        break;
                    case TYPE_ASN1_CHOICE:
                        for (int fi = 0; fi < ((ASN1_Choice_Type) fieldTypeLast).getNofComponents(timestamp); fi++) {
                            final Type_type tt = ((ASN1_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
                            if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
                                getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
                            }
                        }
                        break;
                    case TYPE_ANYTYPE:
                    case TYPE_OPENTYPE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_ASN1_SEQUENCE:
                    case TYPE_TTCN3_SET:
                    case TYPE_ASN1_SET:
                        if (rawPar.lengthindex != null) {
                            // will be checked in the next step
                            break;
                        }
                    default:
                        getLocation().reportSemanticError(MessageFormat.format("The LENGTHTO field must be an integer or union type instead of `{0}''", fieldTypeLast.getTypename()));
                        break;
                }
            }
            if (rawPar.lengthto != null && rawPar.lengthindex != null) {
                final Identifier id = rawPar.lengthindex.names.get(0);
                switch(fieldTypeLast.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id.getName())) {
                            id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                        }
                        break;
                    case TYPE_ASN1_CHOICE:
                    case TYPE_ASN1_SEQUENCE:
                    case TYPE_ASN1_SET:
                        if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id)) {
                            id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                        }
                        break;
                    default:
                        fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter LENGTHINDEX for field {0}.", fieldId.getDisplayName()));
                        break;
                }
            }
            if (rawPar.pointerto != null) {
                final Identifier id = rawPar.pointerto;
                boolean errorFound = false;
                int pointed = 0;
                if (!hasComponentWithName(id.getName())) {
                    id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter POINTERTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
                    errorFound = true;
                }
                if (!errorFound) {
                    pointed = getComponentIndexByName(id);
                    if (pointed <= i) {
                        id.getLocation().reportSemanticError(MessageFormat.format("Pointer must precede the pointed field. Incorrect field name `{0}'' in RAW parameter POINTERTO for field `{1}''", id.getDisplayName(), fieldId.getDisplayName()));
                        errorFound = true;
                    }
                }
                if (!errorFound && rawPar.ptrbase != null) {
                    final Identifier idf2 = rawPar.ptrbase;
                    if (!hasComponentWithName(idf2.getName())) {
                        idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
                        errorFound = true;
                    }
                    if (!errorFound && getComponentIndexByName(idf2) > pointed) {
                        idf2.getLocation().reportSemanticError(MessageFormat.format("Pointer base must precede the pointed field. Incorrect field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
                    }
                }
            }
            if (rawPar.presence != null && rawPar.presence.keyList != null) {
                for (int a = 0; a < rawPar.presence.keyList.size(); a++) {
                    final rawAST_tag_field_value tempTagFieldValue = rawPar.presence.keyList.get(a);
                    final Reference reference = new Reference(null);
                    reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
                    for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
                        reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
                    }
                    final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                    if (t != null) {
                        final Value v = tempTagFieldValue.v_value;
                        if (v != null) {
                            v.setMyScope(getMyScope());
                            v.setMyGovernor(t);
                            final IValue tempValue = t.checkThisValueRef(timestamp, v);
                            t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                        }
                    }
                }
            }
            if (rawPar.crosstaglist != null) {
                for (int c = 0; c < rawPar.crosstaglist.size(); c++) {
                    final rawAST_single_tag singleTag = rawPar.crosstaglist.get(c);
                    final Identifier idf = singleTag.fieldName;
                    switch(fieldTypeLast.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf.getName())) {
                                idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
                            }
                            break;
                        case TYPE_ASN1_CHOICE:
                        case TYPE_ASN1_SEQUENCE:
                        case TYPE_ASN1_SET:
                            if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf)) {
                                idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
                            }
                            break;
                        default:
                            fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
                            break;
                    }
                    if (singleTag.keyList != null) {
                        for (int a = 0; a < singleTag.keyList.size(); a++) {
                            IType t2 = this;
                            boolean errorFound = false;
                            boolean allow_omit = false;
                            final rawAST_tag_field_value tagField = singleTag.keyList.get(a);
                            for (int b = 0; b < tagField.keyField.names.size() && !errorFound; b++) {
                                final Identifier idf2 = tagField.keyField.names.get(b);
                                CompField cf2 = null;
                                switch(t2.getTypetype()) {
                                    case TYPE_TTCN3_CHOICE:
                                    case TYPE_TTCN3_SEQUENCE:
                                    case TYPE_TTCN3_SET:
                                        if (!((TTCN3_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2.getName())) {
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
                                            errorFound = true;
                                        } else {
                                            cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2.getName());
                                        }
                                        break;
                                    case TYPE_ASN1_CHOICE:
                                    case TYPE_ASN1_SEQUENCE:
                                    case TYPE_ASN1_SET:
                                        if (!((ASN1_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2)) {
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
                                            errorFound = true;
                                        } else {
                                            cf2 = ((ASN1_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2);
                                        }
                                        break;
                                    default:
                                        fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
                                        errorFound = true;
                                        break;
                                }
                                if (b == 0) {
                                    final int fieldIndex = getComponentIndexByName(idf2);
                                    if (fieldIndex == i) {
                                        idf2.getLocation().reportSemanticError(MessageFormat.format("RAW parameter CROSSTAG for field `{0}'' cannot refer to the field itself", idf2.getDisplayName()));
                                        errorFound = true;
                                    } else if (fieldIndex > i) {
                                        if (cField.isOptional()) {
                                            // TODO || fieldType.getRawLength() < 0
                                            idf2.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' that CROSSTAG refers to must precede field `{1}'' or field `{1}'' must be mandatory with fixed length", idf2.getDisplayName(), fieldId.getDisplayName()));
                                            errorFound = true;
                                        }
                                    }
                                }
                                if (!errorFound) {
                                    t2 = cf2.getType().getTypeRefdLast(timestamp);
                                    if (b == tagField.keyField.names.size() - 1 && cf2.isOptional()) {
                                        allow_omit = true;
                                    }
                                }
                            }
                            if (!errorFound) {
                                final Value v = singleTag.keyList.get(a).v_value;
                                if (v != null) {
                                    v.setMyScope(getMyScope());
                                    v.setMyGovernor(t2);
                                    final IValue tempValue = t2.checkThisValueRef(timestamp, v);
                                    t2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, allow_omit, false, false, false));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Reference(org.eclipse.titan.designer.AST.Reference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) RawAST.rawAST_ext_bit_group(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_ext_bit_group) IType(org.eclipse.titan.designer.AST.IType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ASN1_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) RawAST.rawAST_tag_field_value(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_tag_field_value) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag)

Example 80 with Reference

use of org.eclipse.titan.designer.AST.Reference 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()));
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7