Search in sources :

Example 1 with ErroneousAttributeSpecification

use of org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification in project titan.EclipsePlug-ins by eclipse.

the class Definition method parseErrAttrSpecString.

private static ErroneousAttributeSpecification parseErrAttrSpecString(final AttributeSpecification aAttrSpec) {
    String code = aAttrSpec.getSpecification();
    if (code == null) {
        return null;
    }
    final Location location = aAttrSpec.getLocation();
    // code must be transformed, according to
    // compiler2/ttcn3/charstring_la.l
    // TODO
    code = Ttcn3CharstringLexer.parseCharstringValue(code, location);
    final Reader reader = new StringReader(code);
    final CharStream charStream = new UnbufferedCharStream(reader);
    final Ttcn3Lexer lexer = new Ttcn3Lexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    // needs to be shifted by one because of the \" of the string
    lexer.setCharPositionInLine(0);
    // lexer and parser listener
    final TitanListener parserListener = new TitanListener();
    // remove ConsoleErrorListener
    lexer.removeErrorListeners();
    lexer.addErrorListener(parserListener);
    // 1. Previously it was UnbufferedTokenStream(lexer), but it was changed to BufferedTokenStream, because UnbufferedTokenStream seems to be unusable. It is an ANTLR 4 bug.
    // Read this: https://groups.google.com/forum/#!topic/antlr-discussion/gsAu-6d3pKU
    // pr_PatternChunk[StringBuilder builder, boolean[] uni]:
    // $builder.append($v.text); <-- exception is thrown here: java.lang.UnsupportedOperationException: interval 85..85 not in token buffer window: 86..341
    // 2. Changed from BufferedTokenStream to CommonTokenStream, otherwise tokens with "-> channel(HIDDEN)" are not filtered out in lexer.
    final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    final Ttcn3Reparser parser = new Ttcn3Reparser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    final IFile file = (IFile) location.getFile();
    parser.setActualFile(file);
    parser.setOffset(location.getOffset());
    parser.setLine(location.getLine());
    // remove ConsoleErrorListener
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
    final Pr_ErroneousAttributeSpecContext root = parser.pr_ErroneousAttributeSpec();
    ParserUtilities.logParseTree(root, parser);
    final ErroneousAttributeSpecification returnValue = root.errAttrSpec;
    final List<SyntacticErrorStorage> errors = parser.getErrors();
    final List<TITANMarker> warnings = parser.getWarnings();
    final List<TITANMarker> unsupportedConstructs = parser.getUnsupportedConstructs();
    // add markers
    if (errors != null) {
        for (int i = 0; i < errors.size(); i++) {
            final Location temp = new Location(location);
            temp.setOffset(temp.getOffset());
            ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errors.get(i), IMarker.SEVERITY_ERROR, temp);
        }
    }
    if (warnings != null) {
        for (final TITANMarker marker : warnings) {
            if (file.isAccessible()) {
                final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
    if (unsupportedConstructs != null) {
        for (final TITANMarker marker : unsupportedConstructs) {
            if (file.isAccessible()) {
                final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
    return returnValue;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) IFile(org.eclipse.core.resources.IFile) ErroneousAttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification) Ttcn3Reparser(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Reparser) Ttcn3Lexer(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Lexer) Reader(java.io.Reader) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) CharStream(org.antlr.v4.runtime.CharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) Pr_ErroneousAttributeSpecContext(org.eclipse.titan.designer.parsers.ttcn3parser.Ttcn3Reparser.Pr_ErroneousAttributeSpecContext) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Location(org.eclipse.titan.designer.AST.Location)

Example 2 with ErroneousAttributeSpecification

use of org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification in project titan.EclipsePlug-ins by eclipse.

the class Definition method checkErroneousAttributes.

protected void checkErroneousAttributes(final CompilationTimeStamp timestamp) {
    erroneousAttributes = null;
    if (withAttributesPath != null) {
        final MultipleWithAttributes attribs = withAttributesPath.getAttributes();
        if (attribs == null) {
            return;
        }
        for (int i = 0; i < attribs.getNofElements(); i++) {
            final SingleWithAttribute actualAttribute = attribs.getAttribute(i);
            if (actualAttribute.getAttributeType() == Attribute_Type.Erroneous_Attribute) {
                final int nofQualifiers = (actualAttribute.getQualifiers() == null) ? 0 : actualAttribute.getQualifiers().getNofQualifiers();
                final List<IType> referencedTypeArray = new ArrayList<IType>(nofQualifiers);
                final List<ArrayList<Integer>> subrefsArrayArray = new ArrayList<ArrayList<Integer>>(nofQualifiers);
                final List<ArrayList<IType>> typeArrayArray = new ArrayList<ArrayList<IType>>(nofQualifiers);
                if (nofQualifiers == 0) {
                    actualAttribute.getLocation().reportSemanticError("At least one qualifier must be specified for the `erroneous' attribute");
                } else {
                    // existing fields
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                        final IType definitionType = getType(timestamp);
                        // construct a reference
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(identifier));
                        for (int ri = 0; ri < actualQualifier.getNofSubReferences(); ri++) {
                            reference.addSubReference(actualQualifier.getSubReferenceByIndex(ri));
                        }
                        reference.setLocation(actualQualifier.getLocation());
                        reference.setMyScope(getMyScope());
                        IType fieldType = definitionType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                        ArrayList<Integer> subrefsArray = null;
                        ArrayList<IType> typeArray = null;
                        if (fieldType != null) {
                            subrefsArray = new ArrayList<Integer>();
                            typeArray = new ArrayList<IType>();
                            final boolean validIndexes = definitionType.getSubrefsAsArray(timestamp, reference, 1, subrefsArray, typeArray);
                            if (!validIndexes) {
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                            if (reference.refersToStringElement()) {
                                actualQualifier.getLocation().reportSemanticError("Reference to a string element cannot be used in this context");
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                        }
                        referencedTypeArray.add(fieldType);
                        subrefsArrayArray.add(subrefsArray);
                        typeArrayArray.add(typeArray);
                    }
                }
                // parse the attr. spec.
                final ErroneousAttributeSpecification errAttributeSpecification = parseErrAttrSpecString(actualAttribute.getAttributeSpecification());
                if (errAttributeSpecification != null) {
                    if (erroneousAttributes == null) {
                        erroneousAttributes = new ErroneousAttributes(getType(timestamp));
                    }
                    erroneousAttributes.addSpecification(errAttributeSpecification);
                    errAttributeSpecification.check(timestamp, getMyScope());
                    // err.attr.spec. pairs
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        if (referencedTypeArray.get(qi) != null && errAttributeSpecification.getIndicator() != Indicator_Type.Invalid_Indicator) {
                            final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                            erroneousAttributes.addFieldErr(actualQualifier, errAttributeSpecification, subrefsArrayArray.get(qi), typeArrayArray.get(qi));
                        }
                    }
                }
            }
        }
        if (erroneousAttributes != null) {
            erroneousAttributes.check(timestamp);
        }
    }
}
Also used : ErroneousAttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) ErroneousAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributes) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) IType(org.eclipse.titan.designer.AST.IType) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)

Aggregations

ErroneousAttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)1 IFile (org.eclipse.core.resources.IFile)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)1 TitanListener (org.eclipse.titan.common.parsers.TitanListener)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 Location (org.eclipse.titan.designer.AST.Location)1 Reference (org.eclipse.titan.designer.AST.Reference)1 ErroneousAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributes)1 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)1 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)1 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)1