diff options
author | Sven Gothel <[email protected]> | 2014-06-19 06:12:10 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-19 06:12:10 +0200 |
commit | 6cb643671578aa912d16dd17e773d92f4667118b (patch) | |
tree | f343ad298c8a17a81738c0e5d50f31379549425f /src/antlr/com/jogamp/gluegen/cgram | |
parent | 0b0f6f4d17f1ace3d3856428194126b4e3f06df0 (diff) |
GlueGen: Add support for compound-array in structs (accessors) ; Allow using C-Enum values for array length
- Parser (HeaderParser.g): Support using C-Enum values for array length specification
- Will throw an exception if enum identifier is unknown or exceeds int-size
- Add StructEmitter supports for compound-arrays
- Add Debug stderr verbose info:
- Struct Emitter prefix 'SE.' - to analyze emitting struct fields (offset+size and accessors)
- Struct Layout prefix 'SL.' - to analyze memory layout (based on MachineDescription.StaticConfig.X86_64_UNIX)
Tested via test1.[ch] BaseClass ..
Diffstat (limited to 'src/antlr/com/jogamp/gluegen/cgram')
-rw-r--r-- | src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g | 15 |
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; + } ; |