forked from phoedos/pmd
Remove Modelica processing stages
This commit is contained in:
@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A time tracker class to measure time spent on different sections of PMD analysis.
|
||||
@ -157,6 +158,18 @@ public final class TimeTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public static void bench(String label, Runnable runnable) {
|
||||
try (TimedOperation to = startOperation(TimedOperationCategory.LANGUAGE_SPECIFIC_PROCESSING, label)) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T bench(String label, Supplier<T> runnable) {
|
||||
try (TimedOperation to = startOperation(TimedOperationCategory.LANGUAGE_SPECIFIC_PROCESSING, label)) {
|
||||
return runnable.get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An entry in the open timers queue. Defines an operation that has started and hasn't finished yet.
|
||||
*/
|
||||
|
@ -13,11 +13,11 @@ import java.util.Iterator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.NodeStream;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
|
||||
import net.sourceforge.pmd.lang.java.internal.JavaAstProcessor;
|
||||
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
|
||||
import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
|
||||
import net.sourceforge.pmd.lang.java.symbols.table.JSymbolTable;
|
||||
@ -57,7 +57,7 @@ final class AstDisambiguationPass {
|
||||
*/
|
||||
public static void disambigWithCtx(NodeStream<? extends JavaNode> nodes, ReferenceCtx ctx) {
|
||||
assert ctx != null : "Null context";
|
||||
JavaAstProcessor.bench("AST disambiguation", () -> nodes.forEach(it -> it.acceptVisitor(DisambigVisitor.INSTANCE, ctx)));
|
||||
TimeTracker.bench("AST disambiguation", () -> nodes.forEach(it -> it.acceptVisitor(DisambigVisitor.INSTANCE, ctx)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,13 +6,10 @@ package net.sourceforge.pmd.lang.java.internal;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||
import net.sourceforge.pmd.benchmark.TimedOperation;
|
||||
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.NodeStream;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
@ -136,7 +133,7 @@ public final class JavaAstProcessor {
|
||||
*/
|
||||
public void process(ASTCompilationUnit acu) {
|
||||
|
||||
SymbolResolver knownSyms = bench("Symbol resolution", () -> SymbolResolutionPass.traverse(this, acu));
|
||||
SymbolResolver knownSyms = TimeTracker.bench("Symbol resolution", () -> SymbolResolutionPass.traverse(this, acu));
|
||||
|
||||
// Now symbols are on the relevant nodes
|
||||
this.symResolver = SymbolResolver.layer(knownSyms, this.symResolver);
|
||||
@ -145,9 +142,9 @@ public final class JavaAstProcessor {
|
||||
// as scopes depend on type resolution in some cases.
|
||||
InternalApiBridge.initTypeResolver(acu, this, typeInferenceLogger);
|
||||
|
||||
bench("2. Symbol table resolution", () -> SymbolTableResolver.traverse(this, acu));
|
||||
bench("3. AST disambiguation", () -> InternalApiBridge.disambigWithCtx(NodeStream.of(acu), ReferenceCtx.root(this, acu)));
|
||||
bench("4. Comment assignment", () -> InternalApiBridge.assignComments(acu));
|
||||
TimeTracker.bench("2. Symbol table resolution", () -> SymbolTableResolver.traverse(this, acu));
|
||||
TimeTracker.bench("3. AST disambiguation", () -> InternalApiBridge.disambigWithCtx(NodeStream.of(acu), ReferenceCtx.root(this, acu)));
|
||||
TimeTracker.bench("4. Comment assignment", () -> InternalApiBridge.assignComments(acu));
|
||||
bench("5. Usage resolution", () -> InternalApiBridge.usageResolution(this, acu));
|
||||
bench("6. Override resolution", () -> InternalApiBridge.overrideResolution(this, acu));
|
||||
}
|
||||
@ -202,15 +199,4 @@ public final class JavaAstProcessor {
|
||||
);
|
||||
}
|
||||
|
||||
public static void bench(String label, Runnable runnable) {
|
||||
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.LANGUAGE_SPECIFIC_PROCESSING, label)) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T bench(String label, Supplier<T> runnable) {
|
||||
try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.LANGUAGE_SPECIFIC_PROCESSING, label)) {
|
||||
return runnable.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,9 @@ package net.sourceforge.pmd.lang.modelica;
|
||||
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ModelicaParser;
|
||||
import net.sourceforge.pmd.lang.modelica.internal.ModelicaProcessingStage;
|
||||
|
||||
public class ModelicaHandler extends AbstractPmdLanguageVersionHandler {
|
||||
|
||||
public ModelicaHandler() {
|
||||
super(ModelicaProcessingStage.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Parser getParser() {
|
||||
return new ModelicaParser();
|
||||
|
@ -4,10 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.modelica.ast;
|
||||
|
||||
import net.sourceforge.pmd.benchmark.TimeTracker;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter;
|
||||
import net.sourceforge.pmd.lang.modelica.resolver.ModelicaSymbolFacade;
|
||||
|
||||
|
||||
public class ModelicaParser extends JjtreeParserAdapter<ASTStoredDefinition> {
|
||||
@ -19,7 +21,9 @@ public class ModelicaParser extends JjtreeParserAdapter<ASTStoredDefinition> {
|
||||
|
||||
@Override
|
||||
protected ASTStoredDefinition parseImpl(CharStream cs, ParserTask task) throws ParseException {
|
||||
return new ModelicaParserImpl(cs).StoredDefinition().makeTaskInfo(task);
|
||||
ASTStoredDefinition root = new ModelicaParserImpl(cs).StoredDefinition().makeTaskInfo(task);
|
||||
TimeTracker.bench("Modelica symbols", () -> ModelicaSymbolFacade.process(root));
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.modelica.internal;
|
||||
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.AstAnalysisContext;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.modelica.ModelicaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition;
|
||||
import net.sourceforge.pmd.lang.modelica.resolver.ModelicaSymbolFacade;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public enum ModelicaProcessingStage implements AstProcessingStage<ModelicaProcessingStage> {
|
||||
SYMBOL_RESOLUTION("Symbol resolution") {
|
||||
@Override
|
||||
public void processAST(RootNode rootNode, AstAnalysisContext configuration) {
|
||||
new ModelicaSymbolFacade().initializeWith((ASTStoredDefinition) rootNode);
|
||||
}
|
||||
};
|
||||
|
||||
private final String displayName;
|
||||
|
||||
ModelicaProcessingStage(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return LanguageRegistry.getLanguage(ModelicaLanguageModule.NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
@ -4,10 +4,17 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.modelica.resolver;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition;
|
||||
|
||||
public class ModelicaSymbolFacade {
|
||||
public void initializeWith(ASTStoredDefinition node) {
|
||||
@InternalApi
|
||||
public final class ModelicaSymbolFacade {
|
||||
|
||||
private ModelicaSymbolFacade() {
|
||||
// util class
|
||||
}
|
||||
|
||||
public static void process(ASTStoredDefinition node) {
|
||||
ScopeAndDeclarationFinder sc = new ScopeAndDeclarationFinder();
|
||||
node.acceptVisitor(sc, null);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.modelica.ast.InternalModelicaNodeApi;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ModelicaNode;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ModelicaParserVisitorAdapter;
|
||||
|
||||
public class ScopeAndDeclarationFinder extends ModelicaParserVisitorAdapter {
|
||||
class ScopeAndDeclarationFinder extends ModelicaParserVisitorAdapter {
|
||||
private final Deque<AbstractModelicaScope> scopes = new ArrayDeque<>();
|
||||
|
||||
ScopeAndDeclarationFinder() {
|
||||
|
@ -6,11 +6,9 @@ package net.sourceforge.pmd.lang.modelica.rule;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.AstProcessingStage;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.modelica.ModelicaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.modelica.ast.ModelicaParserVisitor;
|
||||
import net.sourceforge.pmd.lang.modelica.internal.ModelicaProcessingStage;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
|
||||
/**
|
||||
@ -26,11 +24,4 @@ public abstract class AbstractModelicaRule extends AbstractRule implements Model
|
||||
target.acceptVisitor(this, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dependsOn(AstProcessingStage<?> stage) {
|
||||
if (!(stage instanceof ModelicaProcessingStage)) {
|
||||
throw new IllegalArgumentException("Processing stage wasn't a Modelica one: " + stage);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user