Search in sources :

Example 1 with ASN1Assignment

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

the class AssignmentHandlerAFTRerences method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof ASN1Assignment) {
        final ASN1Assignment assignment = (ASN1Assignment) node;
        if (assignment.getAssPard() != null) {
            return V_SKIP;
        }
    }
    if (node instanceof StatementBlock) {
        final ReferenceCollector referenceCollector = new ReferenceCollector();
        node.accept(referenceCollector);
        // TODO: broken if reference does not point anywhere
        final Set<Reference> references = referenceCollector.getReferences();
        addNonContagiousReferences(computeReferences(references));
        if (containsErroneousReference(references)) {
            setIsInfected(true);
        }
        return V_SKIP;
    }
    if (node instanceof Reference) {
        final Identifier identifier = ((Reference) node).getId();
        if (identifier != null) {
            addContagiousReference(identifier.getDisplayName());
        }
        if (((Reference) node).getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
            setIsInfected(true);
            setIsContagious(true);
            return V_CONTINUE;
        }
        final Assignment assignment = ((Reference) node).getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false, null);
        if (assignment == null || assignment.getIdentifier() == null || !assignment.getIdentifier().equals(identifier)) {
            setIsInfected(true);
            setIsContagious(true);
            return V_CONTINUE;
        }
    }
    return V_CONTINUE;
}
Also used : ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 2 with ASN1Assignment

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

the class Reference method refersToSettingType.

/**
 * Checks if the reference is actually refering to a setting of the
 * provided type, or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param settingType
 *                the setting type to check the reference against.
 * @param referenceChain
 *                a referencechain to detect cyclic references.
 *
 * @return true if the reference refers to a setting of the provided
 *         kind, false otherwise.
 */
public boolean refersToSettingType(final CompilationTimeStamp timestamp, final Setting_type settingType, final IReferenceChain referenceChain) {
    if (myScope == null) {
        return Setting_type.S_ERROR.equals(settingType);
    }
    final Assignment assignment = getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return false;
    }
    if (!(assignment instanceof ASN1Assignment)) {
        getLocation().reportSemanticError(ASN1SETTINGEXPECTED);
        setIsErroneous(true);
        return false;
    }
    final ASN1Assignment asnAssignment = (ASN1Assignment) assignment;
    switch(settingType) {
        case S_OC:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_OC, referenceChain);
        case S_T:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_TYPE, referenceChain);
        case S_O:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_OBJECT, referenceChain);
        case S_V:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_CONST, referenceChain);
        case S_OS:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_OS, referenceChain);
        case S_VS:
            return asnAssignment.isAssignmentType(timestamp, Assignment_type.A_VS, referenceChain);
        case S_ERROR:
            return asnAssignment.getIsErroneous();
        default:
            // FATAL_ERROR
            return false;
    }
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)

Example 3 with ASN1Assignment

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

the class SpecialASN1Module method createSpecAsss.

/**
 * Creates the special assignments by parsing the strings as if they
 * were coming from an internal file and creating a module around them.
 *
 * @return the module of the special assignments created.
 */
private static ASN1Module createSpecAsss() {
    if (null != specialAssignmentsModule) {
        return specialAssignmentsModule;
    }
    final ASN1Assignments parsedAssignments = new ASN1Assignments();
    ASN1Assignment actualAssignment;
    for (String[] assignment : INTERNAL_ASSIGNMENTS) {
        actualAssignment = SpecialASN1Module.parseSpecialInternalAssignment(assignment[1], new Identifier(Identifier_type.ID_ASN, assignment[0]));
        parsedAssignments.addAssignment(actualAssignment);
    }
    // null as a project might not be a good idea
    specialAssignmentsModule = new ASN1Module(new Identifier(Identifier_type.ID_ASN, INTERNAL_MODULE), null, Tag_types.AUTOMATIC_TAGS, false);
    specialAssignmentsModule.setExports(new Exports(true));
    specialAssignmentsModule.setImports(new Imports());
    specialAssignmentsModule.setAssignments(parsedAssignments);
    specialAssignmentsModule.setLocation(NULL_Location.INSTANCE);
    specialAssignmentsModule.setScopeName(INTERNAL_MODULE);
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
    specialAssignmentsModule.checkImports(timestamp, referenceChain, new ArrayList<Module>());
    specialAssignmentsModule.check(timestamp);
    return specialAssignmentsModule;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ASN1Assignments(org.eclipse.titan.designer.AST.ASN1.ASN1Assignments) ModuleImportationChain(org.eclipse.titan.designer.AST.ModuleImportationChain) Module(org.eclipse.titan.designer.AST.Module) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)

Example 4 with ASN1Assignment

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

the class SpecialASN1Module method parseSpecialInternalAssignment.

/**
 * Parses the special internal assignments to build their semantic
 * representation.
 *
 * @param inputCode
 *                the code to parse.
 * @param identifier
 *                the identifier for the assignment to be created.
 *
 * @return the parsed assignment.
 */
public static ASN1Assignment parseSpecialInternalAssignment(final String inputCode, final Identifier identifier) {
    ASN1Assignment assignment = null;
    final StringReader reader = new StringReader(inputCode);
    final CharStream charStream = new UnbufferedCharStream(reader);
    final Asn1Lexer lexer = new Asn1Lexer(charStream);
    lexer.setTokenFactory(new TokenWithIndexAndSubTokensFactory(true));
    final ASN1Listener lexerListener = new ASN1Listener();
    // remove ConsoleErrorListener
    lexer.removeErrorListeners();
    lexer.addErrorListener(lexerListener);
    final ModuleLevelTokenStreamTracker tracker = new ModuleLevelTokenStreamTracker(lexer);
    tracker.discard(Asn1Lexer.WS);
    tracker.discard(Asn1Lexer.MULTILINECOMMENT);
    tracker.discard(Asn1Lexer.SINGLELINECOMMENT);
    final Asn1Parser parser = new Asn1Parser(tracker);
    parser.setBuildParseTree(false);
    final ASN1Listener parserListener = new ASN1Listener(parser);
    // remove ConsoleErrorListener
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    assignment = parser.pr_TITAN_special_Assignment(identifier).assignment;
    if (!parser.getErrorStorage().isEmpty()) {
        ErrorReporter.INTERNAL_ERROR(PARSINGFAILED);
        for (SyntacticErrorStorage temp : parser.getErrorStorage()) {
            ErrorReporter.logError(temp.message);
        }
    }
    return assignment;
}
Also used : Asn1Parser(org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser) Asn1Lexer(org.eclipse.titan.designer.parsers.asn1parser.Asn1Lexer) SyntacticErrorStorage(org.eclipse.titan.common.parsers.SyntacticErrorStorage) StringReader(java.io.StringReader) ASN1Listener(org.eclipse.titan.designer.parsers.asn1parser.ASN1Listener) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) ModuleLevelTokenStreamTracker(org.eclipse.titan.designer.parsers.asn1parser.ModuleLevelTokenStreamTracker) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) TokenWithIndexAndSubTokensFactory(org.eclipse.titan.designer.parsers.asn1parser.TokenWithIndexAndSubTokensFactory) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Example 5 with ASN1Assignment

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

the class BrokenPartsViaReferences method getAssignmentsFrom.

public List<AssignmentHandler> getAssignmentsFrom(final Module module) {
    final List<AssignmentHandler> assignmentHandlers = new ArrayList<AssignmentHandler>();
    final Assignments assignments = module.getAssignments();
    for (int d = 0; d < assignments.getNofAssignments(); ++d) {
        final Assignment assignment = assignments.getAssignmentByIndex(d);
        final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(assignment);
        if (assignment instanceof Undefined_Assignment) {
            final ASN1Assignment realAssignment = ((Undefined_Assignment) assignment).getRealAssignment(CompilationTimeStamp.getBaseTimestamp());
            if (realAssignment != null) {
                realAssignment.accept(assignmentHandler);
            } else {
                // TODO: re-fine this branch
                assignment.accept(assignmentHandler);
            }
        } else {
            assignment.accept(assignmentHandler);
        }
        assignmentHandlers.add(assignmentHandler);
    }
    return assignmentHandlers;
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)

Aggregations

ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)5 Assignment (org.eclipse.titan.designer.AST.Assignment)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 CharStream (org.antlr.v4.runtime.CharStream)1 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1 ASN1Assignments (org.eclipse.titan.designer.AST.ASN1.ASN1Assignments)1 Undefined_Assignment (org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment)1 Assignments (org.eclipse.titan.designer.AST.Assignments)1 Module (org.eclipse.titan.designer.AST.Module)1 ModuleImportationChain (org.eclipse.titan.designer.AST.ModuleImportationChain)1 Reference (org.eclipse.titan.designer.AST.Reference)1 IParameterisedAssignment (org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment)1 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)1 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)1 ASN1Listener (org.eclipse.titan.designer.parsers.asn1parser.ASN1Listener)1 Asn1Lexer (org.eclipse.titan.designer.parsers.asn1parser.Asn1Lexer)1 Asn1Parser (org.eclipse.titan.designer.parsers.asn1parser.Asn1Parser)1