public class CppLanguageFeatureParser extends CLikeLanguageFeatureParserBase
Modifier and Type | Field and Description |
---|---|
static java.util.EnumSet<ETokenType> |
ADDITIONAL_TYPE_TOKENS
All token types that can be used to specify a type.
|
static java.util.EnumSet<ETokenType> |
PRIMITIVE_TYPE_TOKENS
All token types that can be used to specify a type.
|
static java.util.HashSet<java.lang.String> |
STD_LIB_PROGRAM_TERMINATION_FUNCTIONS
Names of functions in the C++ standard lib that cause program termination.
|
static java.util.regex.Pattern |
VALID_IDENTIFIER_PATTERN
Regular expression describing a valid C/C++ identifier.
|
CONDITIONAL_OPERATOR_TYPES, packageSeparator, packageSeparatorText, POINTER_TYPES, primitiveTypeTokens, TYPE_MODIFICATIONS, typeTokens, useExtractor, validIdentifiers, variableSplitType
Constructor and Description |
---|
CppLanguageFeatureParser()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.util.List<IToken>> |
getAliasMapping(java.util.List<IToken> tokens)
Extracts a mapping of types regarding the typedef instructions found in the
given tokens.
|
java.lang.String |
getImportName(ShallowEntity entity)
Returns the imported name of the given import shallow entity.
|
protected int |
getMethodOpeningParenthesisIndex(java.util.List<IToken> methodTokens)
Returns the index of the opening parenthesis of a method from the given
tokens.
|
boolean |
hasVoidReturnType(ShallowEntity method)
Returns whether the given method has a void return type.
|
static boolean |
isCaseOrDefaultExitStatement(ShallowEntity entity,
java.util.Set<java.lang.String> additionalExitNames,
boolean isNestedSwitch)
Returns whether the given entity is a valid exit statement for a case
statement also considering if we are in a nested switch statement or not
|
static boolean |
isConstant(ShallowEntity entity)
Returns whether the given entity is a constant
|
static boolean |
isCpp(java.lang.String uniformPath,
java.util.List<IToken> tokens)
Returns
true if the given uniform path has C++ related file
extension or the given list of tokens contains either
ETokenType.SCOPE or ETokenType.CLASS . |
static boolean |
isCpp11DeletedFunctionOrConstructor(ShallowEntity entity)
Returns whether the given
ShallowEntity is a function, operator, or
constructor declaration that has the C++11
TRAILING_RETURN_TYPE_TOKENS_PATTERN . |
static boolean |
isCppMethod(ShallowEntity entity)
A C++ method outside of a class/struct must be scoped with ::.
|
static boolean |
isFunctionDeclaration(ShallowEntity entity)
Returns whether the given entity is a function declaration
|
boolean |
isImport(ShallowEntity entity)
Returns whether the given entity is an import.
|
static boolean |
isNoreturn(ShallowEntity entity)
Returns whether the given shallow entity is marked as "_Noreturn".
|
static boolean |
isPointerDeclaration(ShallowEntity entity)
Returns true if a variable is declared as a pointer.
|
static boolean |
isTopLevelClass(ShallowEntity entity)
Returns whether the given entity is a top-level class.
|
static boolean |
isUnconditionalSwitchExit(ShallowEntity lastEntity,
java.util.Set<java.lang.String> additionalExitNames,
boolean isNestedSwitch)
Returns whether the given entity is an unconditional exit statement for a
case statement.
|
static boolean |
isVirtual(ShallowEntity entity)
Returns whether the given shallow entity is virtual.
|
static java.util.List<IToken> |
resolveAliases(java.util.List<IToken> tokens,
java.util.Map<java.lang.String,java.util.List<IToken>> aliasMapping)
Replaces the aliases introduced by typedefs and usings with their respective
original type.
|
protected int |
reverseSkipToType(java.util.List<IToken> tokens)
Skips from the end of the given token list (that represents a variable
definition) to the token after the last token that specifies the variables
type.
|
int |
skipGeneric(java.util.List<IToken> tokens,
int startIndex)
Skips a generic or template declaration in the given token list that begins
at the given start index.
|
int |
skipGenericReverse(java.util.List<IToken> tokens,
int startIndex)
Skips a generic parameter (nested < and >) in reverse direction and
returns the index of the first opening < token.
|
collectTokenFromTypePart, collectTokensFromModifiers, collectTokensFromPointers, collectTokensFromPrimitiveType, collectTokensFromType, collectTokensFromTypeAndModifications, extractConditionTokens, extractParameterTokens, filterGenericTokens, getBaseTypeName, getGenericNamesForMethod, getGenericNamesForType, getGenericTypeNames, getImportedNames, getLanguage, getModifiersAndTypeFromTokens, getParameterTokens, getParameterTypeNames, getPlainTypeName, getReturnType, getSplitParameterTokens, getTypeNameFromCatchTokens, getTypeNameStartIndex, getVariableNameFromCatchTokens, getVariableNameFromTokens, getVariableNamesFromTokens, getVariableReadsFromTokens, getVariableTokensFromForLikeTokens, getVariableTypeFromTokens, getVariableUsesFromTokens, getVariableWritesFromTokens, hasOnlyStaticMembers, hasVariableLengthArgumentList, isPrimitiveTypeToken, isStatic, isTypeToken, isVariableDeclaration, matchesFullQualifiedTypeName, splitVariableTokens
public static final java.util.EnumSet<ETokenType> ADDITIONAL_TYPE_TOKENS
public static final java.util.EnumSet<ETokenType> PRIMITIVE_TYPE_TOKENS
public static final java.util.regex.Pattern VALID_IDENTIFIER_PATTERN
public static final java.util.HashSet<java.lang.String> STD_LIB_PROGRAM_TERMINATION_FUNCTIONS
public CppLanguageFeatureParser()
public static boolean isCpp11DeletedFunctionOrConstructor(ShallowEntity entity)
ShallowEntity
is a function, operator, or
constructor declaration that has the C++11
TRAILING_RETURN_TYPE_TOKENS_PATTERN
.
For example foobar(const foobar&) = delete;
declares a deleted
constructor that can't be called (typically it must be declared because of
inheritance).public boolean isImport(ShallowEntity entity)
isImport
in class CLikeLanguageFeatureParserBase
public java.lang.String getImportName(ShallowEntity entity)
getImportName
in class CLikeLanguageFeatureParserBase
public boolean hasVoidReturnType(ShallowEntity method)
hasVoidReturnType
in class CLikeLanguageFeatureParserBase
public static boolean isVirtual(ShallowEntity entity)
public static boolean isNoreturn(ShallowEntity entity)
public static boolean isConstant(ShallowEntity entity)
public static boolean isPointerDeclaration(ShallowEntity entity)
public static boolean isCppMethod(ShallowEntity entity)
public static boolean isCpp(java.lang.String uniformPath, java.util.List<IToken> tokens)
true
if the given uniform path has C++ related file
extension or the given list of tokens contains either
ETokenType.SCOPE
or ETokenType.CLASS
. This is a heuristic
method to distinguish C from C++.public static boolean isTopLevelClass(ShallowEntity entity)
protected int reverseSkipToType(java.util.List<IToken> tokens)
CLikeLanguageFeatureParserBase
reverseSkipToType
in class CLikeLanguageFeatureParserBase
public int skipGeneric(java.util.List<IToken> tokens, int startIndex)
ETokenType.LT
. The index of the matching closing token is returned.
In C++ constructs like "std::vector<SomeType<(1>2)>>" are
allowed, thus we cannot simply skip to the matching closing token.skipGeneric
in class CLikeLanguageFeatureParserBase
public int skipGenericReverse(java.util.List<IToken> tokens, int startIndex)
ETokenType.GT
. The index of the matching
opening token is returned.
In C++ constructs like "std::vector<SomeType<(1>2)>>" are
allowed, thus we cannot simply skip to the matching closing token.skipGenericReverse
in class CLikeLanguageFeatureParserBase
protected int getMethodOpeningParenthesisIndex(java.util.List<IToken> methodTokens)
CLikeLanguageFeatureParserBase
getMethodOpeningParenthesisIndex
in class CLikeLanguageFeatureParserBase
public static boolean isFunctionDeclaration(ShallowEntity entity)
public static boolean isCaseOrDefaultExitStatement(ShallowEntity entity, java.util.Set<java.lang.String> additionalExitNames, boolean isNestedSwitch)
public static boolean isUnconditionalSwitchExit(ShallowEntity lastEntity, java.util.Set<java.lang.String> additionalExitNames, boolean isNestedSwitch)
isCaseOrDefaultExitStatement(ShallowEntity, Set, boolean)
, but also
recurses in case of blocks and conditionals.additionalExitNames
- names of functions that we know are unconditional exits.public static java.util.Map<java.lang.String,java.util.List<IToken>> getAliasMapping(java.util.List<IToken> tokens)
tokens
- the tokens that may contain typedefspublic static java.util.List<IToken> resolveAliases(java.util.List<IToken> tokens, java.util.Map<java.lang.String,java.util.List<IToken>> aliasMapping)
tokens
- The tokens in which the aliases are resolvedaliasMapping
- The resolved alias returned by @getAliasMapping(List)
.