summaryrefslogtreecommitdiffstats
path: root/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
diff options
context:
space:
mode:
Diffstat (limited to 'src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g')
-rw-r--r--src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
index 75cf413..01f10c3 100644
--- a/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
+++ b/src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g
@@ -297,7 +297,7 @@ options {
private void handleArrayExpr(TypeBox tb, AST t) {
if (t != null) {
try {
- int len = parseIntConstExpr(t);
+ final int len = parseIntConstExpr(t);
tb.setType(canonicalize(new ArrayType(tb.type(), SizeThunk.mul(SizeThunk.constant(len), tb.type().getSize()), len, 0)));
return;
} catch (RecognitionException e) {
@@ -782,4 +782,17 @@ nonemptyAbstractDeclarator[TypeBox tb]
constants. Can be made more complicated as necessary. */
intConstExpr returns [int i] { i = -1; }
: n:Number { return Integer.parseInt(n.getText()); }
+ | e:ID {
+ final String enumName = e.getText();
+ final EnumType enumType = enumHash.get(enumName);
+ if( null == enumType ) {
+ throw new IllegalArgumentException("Error: intConstExpr ID "+enumName+" recognized, but no containing enum-type found");
+ }
+ final long enumValue = enumType.getEnumValue(enumName);
+ System.err.println("INFO: intConstExpr: enum[Type "+enumType.getName()+", name "+enumName+", value "+enumValue+"]");
+ if( (long)Integer.MIN_VALUE > enumValue || (long)Integer.MAX_VALUE < enumValue ) {
+ throw new IndexOutOfBoundsException("Error: intConstExpr ID "+enumName+" enum-value "+enumValue+" out of int range");
+ }
+ return (int)enumValue;
+ }
;