Class CPPAnnotationParser
java.lang.Object
org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
org.variantsync.diffdetective.feature.cpp.CPPAnnotationParser
- All Implemented Interfaces:
AnnotationParser
Parses a C preprocessor statement.
For example, given the annotation
"#if defined(A) || B()",
this class extracts the type AnnotationType.If with the formula new Or(new Literal("A"), new Literal("B")).
The extractor detects if, ifdef, ifndef, elif, elifdef, elifndef, else and endif annotations.
All other annotations are considered source code.
The given CPP statement might also be a line in a diff (i.e., preceded by a - or +).- Author:
- Paul Bittner, Sören Viegener, Benjamin Moosherr, Alexander Schultheiß
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Patternprivate static final Stringprivate org.antlr.v4.runtime.tree.ParseTreeVisitor<org.prop4j.Node> Fields inherited from class org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
annotationPattern -
Constructor Summary
ConstructorsConstructorDescriptionCPPAnnotationParser(org.antlr.v4.runtime.tree.ParseTreeVisitor<org.prop4j.Node> formulaVisitor) -
Method Summary
Modifier and TypeMethodDescriptionorg.prop4j.NodeparseFormula(String directive, String formula) Parses the feature formula of a preprocessor annotation line.Methods inherited from class org.variantsync.diffdetective.feature.PreprocessorAnnotationParser
parseAnnotation, parseAnnotationType
-
Field Details
-
CPP_ANNOTATION_REGEX
- See Also:
-
CPP_ANNOTATION_PATTERN
-
formulaVisitor
private org.antlr.v4.runtime.tree.ParseTreeVisitor<org.prop4j.Node> formulaVisitor
-
-
Constructor Details
-
CPPAnnotationParser
public CPPAnnotationParser(org.antlr.v4.runtime.tree.ParseTreeVisitor<org.prop4j.Node> formulaVisitor) -
CPPAnnotationParser
public CPPAnnotationParser()
-
-
Method Details
-
parseFormula
public org.prop4j.Node parseFormula(String directive, String formula) throws UnparseableFormulaException Description copied from class:PreprocessorAnnotationParserParses the feature formula of a preprocessor annotation line. It should abstract complex formulas (e.g., if they contain arithmetics or macro calls) as desired. For example, for the line"#if A && B == C", this method is should be called likeparseFormula("if", "A && B == C")(the exact arguments are determined byPreprocessorAnnotationParser.annotationPatternand it should return something likeand(var("A"), var("B==C")).This method is only called if
directiveactually requires a formula as determined byPreprocessorAnnotationParser.parseAnnotationType(java.lang.String).- Specified by:
parseFormulain classPreprocessorAnnotationParser- Parameters:
directive- as matched by the named capture groupdirectiveofPreprocessorAnnotationParser.annotationPatternformula- as matched by the named capture groupformulaofPreprocessorAnnotationParser.annotationPattern- Returns:
- the feature mapping
- Throws:
UnparseableFormulaException- ifformulais ill-formed.
-