Search in sources :

Example 1 with TITANMarker

use of org.eclipse.titan.common.parsers.TITANMarker in project titan.EclipsePlug-ins by eclipse.

the class ProjectConfigurationParser method checkMacroErrors.

/**
 * Checks if all the collected macros are valid,
 * puts error markers if needed
 * @param aMacros collected macro references
 * @param aDefines definitions from the [DEFINE] sections
 * @param aEnv environment variables
 */
public void checkMacroErrors(final List<Macro> aMacros, final Map<String, CfgDefinitionInformation> aDefines, final Map<String, String> aEnv) {
    for (final Macro macro : aMacros) {
        final String value = getDefinitionValue(macro.getMacroName(), aDefines, aEnv);
        if (value == null) {
            final IFile file = macro.getFile();
            if (file != null && file.isAccessible()) {
                final TITANMarker marker = macro.getErrorMarker();
                final Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                location.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
            }
        }
    }
}
Also used : TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) IFile(org.eclipse.core.resources.IFile) Macro(org.eclipse.titan.common.parsers.cfg.CfgParseResult.Macro) CfgLocation(org.eclipse.titan.common.parsers.cfg.CfgLocation) Location(org.eclipse.titan.designer.AST.Location)

Example 2 with TITANMarker

use of org.eclipse.titan.common.parsers.TITANMarker in project titan.EclipsePlug-ins by eclipse.

the class ProjectSourceSemanticAnalyzer method analyzeMultipleProjectsSemantically.

/**
 * Internal function.
 * <p>
 * Does the semantic checking of the modules located in multiple projects.
 * It is important to call this function after the
 * {@link #internalDoAnalyzeSyntactically(IProgressMonitor, CompilationTimeStamp)}
 * function was executed on all involved projects, as the out-dated markers will be cleared here.
 *
 * @param tobeSemanticallyAnalyzed the list of projects to be analyzed.
 * @param monitor
 *                the progress monitor to provide feedback to the user
 *                about the progress.
 * @param compilationCounter
 *            the timestamp of the actual build cycle.
 *
 * @return the status of the operation when it finished.
 */
static IStatus analyzeMultipleProjectsSemantically(final List<IProject> tobeSemanticallyAnalyzed, final IProgressMonitor monitor, final CompilationTimeStamp compilationCounter) {
    for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
        if (!tobeSemanticallyAnalyzed.get(i).isAccessible() || !TITANNature.hasTITANNature(tobeSemanticallyAnalyzed.get(i))) {
            return Status.CANCEL_STATUS;
        }
    }
    final long semanticCheckStart = System.nanoTime();
    for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
        ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
        synchronized (semanticAnalyzer.outdatedModuleMap) {
            semanticAnalyzer.outdatedModuleMap.clear();
        }
        semanticAnalyzer.moduleMap.clear();
    }
    // Semantic checking starts here
    SubMonitor progress = SubMonitor.convert(monitor, 1);
    progress.setTaskName("On-the-fly semantic checking of everything ");
    progress.subTask("Checking the importations of the modules");
    try {
        // clean the instantiated parameterized assignments,
        // from their instances
        Ass_pard.resetAllInstanceCounters();
        // check for duplicated module names
        HashMap<String, Module> uniqueModules = new HashMap<String, Module>();
        Set<String> duplicatedModules = new HashSet<String>();
        // collect all modules and semantically checked modules to work on.
        final List<Module> allModules = new ArrayList<Module>();
        final List<String> semanticallyChecked = new ArrayList<String>();
        // remove module name duplication markers. It shall be done before starting the next for-loop!
        for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
            final ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
            for (Module module : semanticAnalyzer.fileModuleMap.values()) {
                if (module instanceof TTCN3Module) {
                    MarkerHandler.markAllSemanticMarkersForRemoval(module.getIdentifier());
                }
            }
        }
        for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
            final ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
            for (Module module : semanticAnalyzer.fileModuleMap.values()) {
                final String name = module.getIdentifier().getName();
                allModules.add(module);
                // ASN1 modules are not been analyzed incrementally, therefore their markers can be removed in one step:
                if (module instanceof ASN1Module) {
                    MarkerHandler.markAllSemanticMarkersForRemoval(module.getLocation().getFile());
                }
                if (uniqueModules.containsKey(name)) {
                    final Location location = uniqueModules.get(name).getIdentifier().getLocation();
                    final Location location2 = module.getIdentifier().getLocation();
                    location.reportSemanticError(MessageFormat.format(DUPLICATEMODULE, module.getIdentifier().getDisplayName()));
                    location2.reportSemanticError(MessageFormat.format(DUPLICATEMODULE, module.getIdentifier().getDisplayName()));
                    duplicatedModules.add(name);
                    semanticAnalyzer.semanticallyUptodateModules.remove(name);
                } else {
                    uniqueModules.put(name, module);
                    semanticAnalyzer.moduleMap.put(name, module);
                    if (semanticAnalyzer.semanticallyUptodateModules.contains(name)) {
                        semanticallyChecked.add(name);
                    }
                }
            }
        }
        int nofModulesTobeChecked = 0;
        if (allModules.size() > semanticallyChecked.size()) {
            // check and build the import hierarchy of the modules
            ModuleImportationChain referenceChain = new ModuleImportationChain(CIRCULARIMPORTCHAIN, false);
            // remove markers from import lines
            for (Module module : allModules) {
                if (module instanceof TTCN3Module) {
                    List<ImportModule> imports = ((TTCN3Module) module).getImports();
                    for (ImportModule imp : imports) {
                        MarkerHandler.markAllSemanticMarkersForRemoval(imp.getLocation());
                    }
                }
            // markers are removed in one step in ASN1 modules
            }
            for (Module module : allModules) {
                module.checkImports(compilationCounter, referenceChain, new ArrayList<Module>());
                referenceChain.clear();
            }
            progress.subTask("Calculating the list of modules to be checked");
            BrokenPartsViaReferences selectionMethod = new BrokenPartsViaReferences(compilationCounter);
            SelectionMethodBase selectionMethodBase = (SelectionMethodBase) selectionMethod;
            selectionMethodBase.setModules(allModules, semanticallyChecked);
            selectionMethod.execute();
            if (OutOfMemoryCheck.isOutOfMemory()) {
                OutOfMemoryCheck.outOfMemoryEvent();
                return Status.CANCEL_STATUS;
            }
            BrokenPartsChecker brokenPartsChecker = new BrokenPartsChecker(progress.newChild(1), compilationCounter, selectionMethodBase);
            brokenPartsChecker.doChecking();
            // re-enable the markers on the skipped modules.
            for (Module module2 : selectionMethodBase.getModulesToSkip()) {
                MarkerHandler.reEnableAllMarkers((IFile) module2.getLocation().getFile());
            }
            nofModulesTobeChecked = selectionMethodBase.getModulesToCheck().size();
        } else {
            // re-enable all markers
            for (Module module2 : allModules) {
                MarkerHandler.reEnableAllMarkers((IFile) module2.getLocation().getFile());
            }
        }
        // Not supported markers are handled here, at the and of checking. Otherwise they would be deleted
        final IPreferencesService preferenceService = Platform.getPreferencesService();
        final String option = preferenceService.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNSUPPORTEDCONSTRUCTS, GeneralConstants.WARNING, null);
        for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
            // report the unsupported constructs in the project
            ProjectSourceSyntacticAnalyzer syntacticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSyntacticAnalyzer();
            for (IFile file : syntacticAnalyzer.unsupportedConstructMap.keySet()) {
                List<TITANMarker> markers = syntacticAnalyzer.unsupportedConstructMap.get(file);
                if (markers != null && file.isAccessible()) {
                    for (TITANMarker marker : markers) {
                        Location location = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
                        location.reportConfigurableSemanticProblem(option, marker.getMessage());
                    }
                }
            }
        }
        if (preferenceService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
            MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
            TITANDebugConsole.println("  ** Had to start checking at " + nofModulesTobeChecked + " modules. ", stream);
            TITANDebugConsole.println("  **On-the-fly semantic checking of projects (" + allModules.size() + " modules) took " + (System.nanoTime() - semanticCheckStart) * (1e-9) + " seconds", stream);
        }
        progress.subTask("Cleanup operations");
        for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
            ProjectSourceSemanticAnalyzer semanticAnalyzer = GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer();
            synchronized (semanticAnalyzer.semanticallyUptodateModules) {
                semanticAnalyzer.semanticallyUptodateModules.clear();
                semanticAnalyzer.semanticallyUptodateModules.addAll(semanticAnalyzer.moduleMap.keySet());
                for (String name : duplicatedModules) {
                    semanticAnalyzer.semanticallyUptodateModules.remove(name);
                }
            }
        }
    } catch (Exception e) {
        // This catch is extremely important, as it is supposed
        // to protect the project parser, from whatever might go
        // wrong inside the analysis.
        ErrorReporter.logExceptionStackTrace(e);
    }
    progress.done();
    for (int i = 0; i < tobeSemanticallyAnalyzed.size(); i++) {
        GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).setLastTimeChecked(compilationCounter);
        ProjectStructureDataCollector collector = GlobalProjectStructureTracker.getDataCollector(tobeSemanticallyAnalyzed.get(i));
        for (Module module : GlobalParser.getProjectSourceParser(tobeSemanticallyAnalyzed.get(i)).getSemanticAnalyzer().moduleMap.values()) {
            collector.addKnownModule(module.getIdentifier());
            module.extractStructuralInformation(collector);
        }
        MarkerHandler.removeAllOnTheFlyMarkedMarkers(tobeSemanticallyAnalyzed.get(i));
    }
    return Status.OK_STATUS;
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) SelectionMethodBase(org.eclipse.titan.designer.AST.brokenpartsanalyzers.SelectionMethodBase) BrokenPartsChecker(org.eclipse.titan.designer.AST.brokenpartsanalyzers.BrokenPartsChecker) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) HashSet(java.util.HashSet) BrokenPartsViaReferences(org.eclipse.titan.designer.AST.brokenpartsanalyzers.BrokenPartsViaReferences) SubMonitor(org.eclipse.core.runtime.SubMonitor) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) ModuleImportationChain(org.eclipse.titan.designer.AST.ModuleImportationChain) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Location(org.eclipse.titan.designer.AST.Location)

Example 3 with TITANMarker

use of org.eclipse.titan.common.parsers.TITANMarker in project titan.EclipsePlug-ins by eclipse.

the class ProjectSourceSyntacticAnalyzer method postFileBasedGeneralAnalysis.

/**
 * Uses the parsed data structure to decide if the module found can be
 * inserted into the list of known modules. And inserts it if possible.
 *
 * @param parsedData
 *                the parsed data to insert into the semantic database.
 */
private void postFileBasedGeneralAnalysis(final TemporalParseData parsedData) {
    final Module module = parsedData.getModule();
    if (module != null && module.getIdentifier() != null && module.getLocation() != null) {
        sourceParser.getSemanticAnalyzer().addModule(module);
        final IFile file = parsedData.getFile();
        fileMap.put(file, module.getName());
        uptodateFiles.put(file, module.getName());
        final List<TITANMarker> unsupportedConstructs = parsedData.getUnsupportedConstructs();
        if (unsupportedConstructs != null && !unsupportedConstructs.isEmpty()) {
            unsupportedConstructMap.put(file, unsupportedConstructs);
        }
        if (module.getLocation().getEndOffset() == -1 && parsedData.hadParseErrors()) {
            if (parsedData.getDocument() == null) {
                module.getLocation().setEndOffset((int) new File(file.getLocationURI()).length());
            } else {
                module.getLocation().setEndOffset(parsedData.getDocument().getLength());
            }
        }
    } else {
        syntacticallyOutdated = true;
        highlySyntaxErroneousFiles.add(parsedData.getFile());
    }
}
Also used : TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) IFile(org.eclipse.core.resources.IFile) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Module(org.eclipse.titan.designer.AST.Module) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 4 with TITANMarker

use of org.eclipse.titan.common.parsers.TITANMarker in project titan.EclipsePlug-ins by eclipse.

the class TTCN3ReparseUpdater method parse.

public int parse(final ITTCN3ReparseBase userDefined) {
    if (modificationStartOffset == modificationEndOffset + shift) {
        return 0;
    }
    // double wideparsing = System.nanoTime();
    mErrors = null;
    warnings = null;
    Iterator<TITANMarker> iterator = unsupportedConstructs.iterator();
    while (iterator.hasNext()) {
        TITANMarker marker = iterator.next();
        if ((marker.getOffset() > modificationStartOffset && marker.getOffset() <= modificationEndOffset) || (marker.getEndOffset() > modificationStartOffset && marker.getEndOffset() <= modificationEndOffset)) {
            iterator.remove();
        }
    }
    MarkerHandler.markAllOnTheFlyMarkersForRemoval(file, modificationStartOffset, modificationEndOffset + shift);
    if (code == null) {
        return Integer.MAX_VALUE;
    }
    int line = getLineOfOffset(code, modificationStartOffset);
    String substring;
    if (code.length() <= modificationEndOffset + shift) {
        substring = code.substring(modificationStartOffset);
    } else {
        substring = code.substring(modificationStartOffset, modificationEndOffset + shift);
    }
    Reader reader = new StringReader(substring);
    CharStream charStream = new UnbufferedCharStream(reader);
    Ttcn3Lexer lexer = new Ttcn3Lexer(charStream);
    lexer.setTokenFactory(new CommonTokenFactory(true));
    lexer.initRootInterval(modificationEndOffset - modificationStartOffset + 1);
    // lexer and parser listener
    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);
    Ttcn3Reparser parser = new Ttcn3Reparser(tokenStream);
    ParserUtilities.setBuildParseTree(parser);
    lexer.setActualFile(file);
    parser.setActualFile(file);
    parser.setProject(file.getProject());
    parser.setOffset(modificationStartOffset);
    parser.setLine(line + 1);
    // remove ConsoleErrorListener
    parser.removeErrorListeners();
    parser.addErrorListener(parserListener);
    userDefined.reparse(parser);
    mErrors = parserListener.getErrorsStored();
    warnings = parser.getWarnings();
    unsupportedConstructs.addAll(parser.getUnsupportedConstructs());
    int result = measureIntervallDamage();
    if (!parser.isErrorListEmpty()) {
        ++result;
    }
    return result;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) Reader(java.io.Reader) StringReader(java.io.StringReader) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) StringReader(java.io.StringReader) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream)

Example 5 with TITANMarker

use of org.eclipse.titan.common.parsers.TITANMarker in project titan.EclipsePlug-ins by eclipse.

the class PreprocessedTokenStream method eofCheck.

/**
 * Checks if at the EOF the state stack is empty, otherwise creates
 * error marker(s).
 */
public void eofCheck() {
    for (ConditionalStateMachine csm : stateStack) {
        TITANMarker marker = new TITANMarker(MessageFormat.format("{0} directive was not terminated", csm.beginDirective.type.getName()), csm.beginDirective.line, -1, -1, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL);
        unsupportedConstructs.add(marker);
    }
}
Also used : TITANMarker(org.eclipse.titan.common.parsers.TITANMarker)

Aggregations

TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)12 Location (org.eclipse.titan.designer.AST.Location)7 IFile (org.eclipse.core.resources.IFile)6 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 CharStream (org.antlr.v4.runtime.CharStream)4 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)4 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)3 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)3 IDocument (org.eclipse.jface.text.IDocument)3 TitanListener (org.eclipse.titan.common.parsers.TitanListener)3 Module (org.eclipse.titan.designer.AST.Module)3 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)2 CfgLocation (org.eclipse.titan.common.parsers.cfg.CfgLocation)2 ISemanticTITANEditor (org.eclipse.titan.designer.editors.ISemanticTITANEditor)2 File (java.io.File)1