From 6cb643671578aa912d16dd17e773d92f4667118b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 19 Jun 2014 06:12:10 +0200 Subject: 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 .. --- src/antlr/com/jogamp/gluegen/cgram/HeaderParser.g | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/antlr/com/jogamp') 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; + } ; -- cgit v1.2.3