public class ConstantDefinition extends AliasedSymbol.AliasedSymbolImpl implements TypeComparator.AliasedSemanticSymbol, ASTLocusTag.ASTLocusTagProvider
getNativeExpr()
and the optional ConstantDefinition.CNumber
representation, see getNumber()
.
The representation of the equivalent java expression including
the result type is covered by ConstantDefinition.JavaExpr
,
which can be computed via computeJavaExpr(Map)
.
This class and its sub-classes define and convert all native expressions to Java space.
Modifier and Type | Class and Description |
---|---|
static class |
ConstantDefinition.CNumber
A Number, either integer, optionally [long, unsigned],
or floating point, optionally [double].
|
static class |
ConstantDefinition.JavaExpr
A valid java expression, including its result type,
usually generated from a native [C] expression,
see
JavaExpr#create(ConstantDefinition) . |
AliasedSymbol.AliasedSymbolImpl, AliasedSymbol.NoneAliasedSymbol
Modifier and Type | Field and Description |
---|---|
static Pattern |
patternCPPOperand
One of:
+ - * / | & ( ) << >> |
static Pattern |
patternDecimalNumber
Complete pattern for
floating point number,
compatible and described in Double.valueOf(String) . |
static Pattern |
patternDecimalOrIntNumber
Complete pattern for
floating point and integer number,
covering patternDecimalNumber and patternIntegerNumber . |
static Pattern |
patternHexNumber
Complete pattern for
hexadecimal number,
including an optional sign [+-] and optional suffixes [uUlL] . |
static Pattern |
patternIntegerNumber
Complete pattern for
integer number,
including an optional sign [+-] and optional suffixes [uUlL] . |
static long |
UNSIGNED_INT_MAX_VALUE |
static BigInteger |
UNSIGNED_LONG_MAX_VALUE |
Constructor and Description |
---|
ConstantDefinition(String name,
String nativeExpr,
ConstantDefinition.CNumber number,
ASTLocusTag astLocus)
Constructor for plain const-values, non-enumerates.
|
ConstantDefinition(String name,
String nativeExpr,
ConstantDefinition.CNumber number,
String enumName,
ASTLocusTag astLocus)
Constructor for enumerates
|
Modifier and Type | Method and Description |
---|---|
ConstantDefinition.JavaExpr |
computeJavaExpr(Map<String,ConstantDefinition.JavaExpr> constMap)
Computes the
java expression based on this instance,
see JavaExpr#create(ConstantDefinition) . |
static ConstantDefinition.CNumber |
decodeANumber(String v)
|
static ConstantDefinition.CNumber |
decodeDecimalNumber(String v)
If the given string
isDecimalNumber(String) ,
return the decoded floating-point value, represented as a ANumber object,
otherwise returns null . |
static ConstantDefinition.CNumber |
decodeIntegerNumber(String v)
If the given string
isIntegerNumber(String) ,
return the decoded integer value, represented as a ANumber ,
otherwise returns null . |
boolean |
equals(Object arg)
Equality test by its given
name . |
boolean |
equalSemantics(TypeComparator.SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given
name . |
ASTLocusTag |
getASTLocusTag()
Returns this instance's
ASTLocusTag , if available,
otherwise returns null . |
String |
getEnumName()
Returns
null if this definition was not part of an
enumeration, or if the enumeration is anonymous. |
String |
getNativeExpr()
Returns the original [native] expression.
|
ConstantDefinition.CNumber |
getNumber()
Returns the parsed
ConstantDefinition.CNumber of the native expression ,
or null if the latter does not comprise a single number,
i.e. |
int |
hashCode()
Hash by its given
name . |
int |
hashCodeSemantics()
Semantic hashcode for Types exclusive its given
name . |
boolean |
hasNumber()
|
static boolean |
isConstantExpression(String value) |
static boolean |
isCPPOperand(String s)
Matches pattern for valid CPP operands, see
patternCPPOperand . |
static boolean |
isDecimalNumber(String s)
Matches pattern for
floating point number,
compatible and described in Double.valueOf(String) . |
static boolean |
isDecimalOrIntNumber(String s)
Complete pattern for
floating point and integer number,
covering patternDecimalNumber and patternIntegerNumber . |
boolean |
isEnum() |
static boolean |
isHexNumber(String s)
Matches
patternHexNumber . |
static boolean |
isIdentifier(String value) |
static boolean |
isIntegerNumber(String s)
Matches
isHexNumber(String) or patternIntegerNumber . |
static boolean |
isNumber(String s)
Matches
isHexNumber(String) or isDecimalOrIntNumber(String) . |
String |
toString() |
addAliasedName, getAliasedNames, getAliasedString, getName, getOrigName, hasAliases, rename
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAliasedName, getAliasedNames, getAliasedString, getName, getOrigName, hasAliases, rename
public static final long UNSIGNED_INT_MAX_VALUE
public static final BigInteger UNSIGNED_LONG_MAX_VALUE
public static Pattern patternHexNumber
hexadecimal
number,
including an optional sign [+-]
and optional suffixes [uUlL]
.public static final Pattern patternDecimalNumber
floating point
number,
compatible and described in Double.valueOf(String)
.public static final Pattern patternDecimalOrIntNumber
floating point
and integer
number,
covering patternDecimalNumber
and patternIntegerNumber
.public static final Pattern patternIntegerNumber
integer
number,
including an optional sign [+-]
and optional suffixes [uUlL]
.public static Pattern patternCPPOperand
public ConstantDefinition(String name, String nativeExpr, ConstantDefinition.CNumber number, ASTLocusTag astLocus)
name
- unique name of this constant expressionnativeExpr
- original [native] expressionnumber
- optional ConstantDefinition.CNumber
representing this constant.
If null
, implementation attempts to derive a ConstantDefinition.CNumber
of the given nativeExpr
.astLocus
- AST location of the represented constant.public ConstantDefinition(String name, String nativeExpr, ConstantDefinition.CNumber number, String enumName, ASTLocusTag astLocus)
name
- unique name of this constant expressionnativeExpr
- original [native] expressionnumber
- optional ConstantDefinition.CNumber
representing this constant.
If null
, implementation attempts to derive a ConstantDefinition.CNumber
of the given nativeExpr
.enumName
- optional name of the represented enumerationastLocus
- AST location of the represented constant.public ASTLocusTag getASTLocusTag()
ASTLocusTag.ASTLocusTagProvider
ASTLocusTag
, if available,
otherwise returns null
.getASTLocusTag
in interface ASTLocusTag.ASTLocusTagProvider
public final int hashCodeSemantics()
TypeComparator.SemanticEqualityOp
name
.hashCodeSemantics
in interface TypeComparator.SemanticEqualityOp
#equalSemantics(SemanticEqualityOp)
public final boolean equalSemantics(TypeComparator.SemanticEqualityOp arg)
TypeComparator.SemanticEqualityOp
name
.equalSemantics
in interface TypeComparator.SemanticEqualityOp
TypeComparator.SemanticEqualityOp.hashCodeSemantics()
public String getNativeExpr()
public ConstantDefinition.CNumber getNumber()
ConstantDefinition.CNumber
of the native expression
,
or null
if the latter does not comprise a single number,
i.e. is a complex expression.public boolean hasNumber()
public String getEnumName()
null
if this definition was not part of an
enumeration, or if the enumeration is anonymous.public boolean isEnum()
public final ConstantDefinition.JavaExpr computeJavaExpr(Map<String,ConstantDefinition.JavaExpr> constMap)
java expression
based on this instance,
see JavaExpr#create(ConstantDefinition)
.public static boolean isConstantExpression(String value)
public static boolean isIdentifier(String value)
public static ConstantDefinition.CNumber decodeANumber(String v)
v
- public static ConstantDefinition.CNumber decodeIntegerNumber(String v)
isIntegerNumber(String)
,
return the decoded integer value, represented as a ANumber
,
otherwise returns null
.
Method strips off sign prefix +
and integer modifier suffixes [uUlL]
before utilizing Long.decode(String)
.
v
- public static ConstantDefinition.CNumber decodeDecimalNumber(String v)
isDecimalNumber(String)
,
return the decoded floating-point value, represented as a ANumber
object,
otherwise returns null
.
Method utilizes Double.valueOf(String)
.
v
- isDouble
- return value for double
flagpublic static boolean isNumber(String s)
isHexNumber(String)
or isDecimalOrIntNumber(String)
.public static boolean isIntegerNumber(String s)
isHexNumber(String)
or patternIntegerNumber
.public static boolean isHexNumber(String s)
patternHexNumber
.public static boolean isDecimalNumber(String s)
floating point
number,
compatible and described in Double.valueOf(String)
.public static boolean isDecimalOrIntNumber(String s)
floating point
and integer
number,
covering patternDecimalNumber
and patternIntegerNumber
.public static boolean isCPPOperand(String s)
patternCPPOperand
.