summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-09 07:02:43 +0100
committerSven Gothel <[email protected]>2015-03-09 07:02:43 +0100
commit5dd12c17bf5037c7ac6a2ac73caf4d61443c4749 (patch)
treec7d236cfbf44544852fcdab31ad44130471032f0 /src
parent8efdf71e2de6392344326ba6a28e8f8fa7e3e8e5 (diff)
Bug 1134 - Add ASTLocusTagProvider for Define and fix newline in c-parser (Expose source location for log/error messages)
Diffstat (limited to 'src')
-rw-r--r--src/antlr/com/jogamp/gluegen/cgram/GnuCParser.g3
-rw-r--r--src/antlr/com/jogamp/gluegen/cgram/StdCParser.g15
-rw-r--r--src/java/com/jogamp/gluegen/GlueGen.java3
-rw-r--r--src/java/com/jogamp/gluegen/cgram/Define.java16
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test1.h1
5 files changed, 29 insertions, 9 deletions
diff --git a/src/antlr/com/jogamp/gluegen/cgram/GnuCParser.g b/src/antlr/com/jogamp/gluegen/cgram/GnuCParser.g
index e8ca8c5..bf01b12 100644
--- a/src/antlr/com/jogamp/gluegen/cgram/GnuCParser.g
+++ b/src/antlr/com/jogamp/gluegen/cgram/GnuCParser.g
@@ -23,6 +23,7 @@ header {
import antlr.CommonAST;
import antlr.DumpASTVisitor;
+ import com.jogamp.gluegen.ASTLocusTag;
}
@@ -715,7 +716,7 @@ tokens {
public void addDefine(String name, String value)
{
- defines.add(new Define(name, value));
+ defines.add(new Define(name, value, new ASTLocusTag(lineObject.getSource(), lineObject.getLine()+deferredLineCount, -1, name)));
}
/** Returns a list of Define objects corresponding to the
diff --git a/src/antlr/com/jogamp/gluegen/cgram/StdCParser.g b/src/antlr/com/jogamp/gluegen/cgram/StdCParser.g
index 7b34656..26da996 100644
--- a/src/antlr/com/jogamp/gluegen/cgram/StdCParser.g
+++ b/src/antlr/com/jogamp/gluegen/cgram/StdCParser.g
@@ -1131,11 +1131,12 @@ options {
nw:NonWhitespace
("\r\n" | "\r" | "\n") ) {
if (n != null) {
- //System.out.println("addDefine: #define " + i.getText() + " " + n.getText());
+ // System.out.println("addDefine: #define " + i.getText() + " " + n.getText()+" @ "+lineObject.getSource()+":"+(lineObject.line+deferredLineCount));
addDefine(i.getText(), n.getText());
} else {
setPreprocessingDirective("#define " + i.getText() + " " + nw.getText());
}
+ deferredNewline();
}
| (~'\n')* { setPreprocessingDirective(getText()); }
)
@@ -1165,15 +1166,19 @@ protected LineDirective
}
:
{
- lineObject = new LineObject();
- deferredLineCount = 0;
+ lineObject = new LineObject();
+ deferredLineCount = 0;
}
("line")? //this would be for if the directive started "#line", but not there for GNU directives
(Space)+
- n:Number { lineObject.setLine(Integer.parseInt(n.getText())); }
+ n:Number {
+ lineObject.setLine(Integer.parseInt(n.getText()));
+ }
(Space)+
( fn:StringLiteral { try {
- lineObject.setSource(fn.getText().substring(1,fn.getText().length()-1));
+ final String newSource = fn.getText().substring(1,fn.getText().length()-1);
+ // System.out.println("line: "+lineObject.getSource()+" -> "+newSource+", line "+(lineObject.line+deferredLineCount));
+ lineObject.setSource(newSource);
}
catch (StringIndexOutOfBoundsException e) { /*not possible*/ }
}
diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java
index c4eb1c5..778ed75 100644
--- a/src/java/com/jogamp/gluegen/GlueGen.java
+++ b/src/java/com/jogamp/gluegen/GlueGen.java
@@ -220,8 +220,7 @@ public class GlueGen implements GlueEmitterControls {
}
for (final Object elem : lexer.getDefines()) {
final Define def = (Define) elem;
- // TODO: Add ASTLocusTag
- allConstants.add(new ConstantDefinition(def.getName(), def.getValue(), null));
+ allConstants.add(new ConstantDefinition(def.getName(), def.getValue(), def.getASTLocusTag()));
}
allFunctions = headerParser.getParsedFunctions();
diff --git a/src/java/com/jogamp/gluegen/cgram/Define.java b/src/java/com/jogamp/gluegen/cgram/Define.java
index 797cf6f..23caabd 100644
--- a/src/java/com/jogamp/gluegen/cgram/Define.java
+++ b/src/java/com/jogamp/gluegen/cgram/Define.java
@@ -39,18 +39,32 @@
package com.jogamp.gluegen.cgram;
+import com.jogamp.gluegen.ASTLocusTag;
+import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider;
+
/** Represents a #define of a literal to a value (a number represented
in string form.) */
-public class Define {
+public class Define implements ASTLocusTagProvider {
private final String name;
private final String value;
+ private final ASTLocusTag astLocus;
public Define(final String name, final String value) {
this.name = name;
this.value = value;
+ this.astLocus = null;
+ }
+
+ public Define(final String name, final String value, final ASTLocusTag astLocus) {
+ this.name = name;
+ this.value = value;
+ this.astLocus = astLocus;
}
public String getName() { return name; }
public String getValue() { return value; }
+
+ @Override
+ public ASTLocusTag getASTLocusTag() { return astLocus; }
}
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
index 459bf8c..b176f3a 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h
@@ -44,6 +44,7 @@ typedef void * AnonBuffer; // Non Opaque
// #define DEFINE_01 1235 // Duplicate w/ diff value ERROR
#define DEFINE_01_EXT 1234 // Renamed Duplicate w/ same value (ignored)
// #define DEFINE_01_EXT 1235 // Renamed Duplicate w/ diff value ERROR
+// #define DEFINE_01 1235 // Duplicate w/ diff value ERROR
#define DEFINE_02 ( (int ) 3 )
// #define DEFINE_02 ( (int ) 3 ) // Duplicate w/ same value ERROR (PCPP redefine)