diff options
author | Sven Gothel <[email protected]> | 2023-06-18 04:12:34 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-06-18 04:12:34 +0200 |
commit | 7065adb5142911e0b16cbb159150578627712d14 (patch) | |
tree | c5dbd9f385def4c7c6034fd54d146f1e540a2258 /src/java/com/jogamp/gluegen | |
parent | 9dd35877f28f5d3dce5e1817edd33bb8f6dbbe36 (diff) | |
parent | 738c15d654f67ec8aeccec2b46f5a0804c793491 (diff) |
Merge remote-tracking branch 'remotes/Mathieu_Fery/feature/enable_pragma_once'
Diffstat (limited to 'src/java/com/jogamp/gluegen')
-rw-r--r-- | src/java/com/jogamp/gluegen/GlueGen.java | 12 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/pcpp/PCPP.java | 35 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java | 11 |
3 files changed, 47 insertions, 11 deletions
diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index 6dee6f0..50711e9 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -104,7 +104,7 @@ public class GlueGen implements GlueEmitterControls { public static final String __GLUEGEN__ = "__GLUEGEN__"; @SuppressWarnings("unchecked") - public void run(final Reader reader, final String filename, final Class<?> emitterClass, final List<String> includePaths, final List<String> cfgFiles, final String outputRootDir, final boolean copyCPPOutput2Stderr) { + public void run(final Reader reader, final String filename, final Class<?> emitterClass, final List<String> includePaths, final List<String> cfgFiles, final String outputRootDir, final boolean copyCPPOutput2Stderr, final boolean enablePragmaOnce) { try { if(debug) { @@ -131,8 +131,8 @@ public class GlueGen implements GlueEmitterControls { final File out = File.createTempFile("CPPTemp", ".cpp"); final FileOutputStream outStream = new FileOutputStream(out); - // preprocessor = new PCPP(includePaths, debug, copyCPPOutput2Stderr); - preprocessor = new JCPP(includePaths, debug, copyCPPOutput2Stderr); + // preprocessor = new PCPP(includePaths, debug, copyCPPOutput2Stderr, enablePragmaOnce); + preprocessor = new JCPP(includePaths, debug, copyCPPOutput2Stderr, enablePragmaOnce); final String cppName = preprocessor.getClass().getSimpleName(); if(debug) { System.err.println("CPP <"+cppName+"> output at (persistent): " + out.getAbsolutePath()); @@ -375,6 +375,7 @@ public class GlueGen implements GlueEmitterControls { String outputRootDir = null; final List<String> cfgFiles = new ArrayList<String>(); boolean copyCPPOutput2Stderr = false; + boolean enablePragmaOnce = false; final List<String> includePaths = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { @@ -396,6 +397,8 @@ public class GlueGen implements GlueEmitterControls { debug=true; } else if (arg.equals("--dumpCPP")) { copyCPPOutput2Stderr=true; + } else if (arg.equals("--enablePragmaOnce")) { + enablePragmaOnce=true; } else { usage(); } @@ -420,7 +423,7 @@ public class GlueGen implements GlueEmitterControls { try { final Class<?> emitterClass = emitterFQN == null ? null : Class.forName(emitterFQN); - new GlueGen().run(reader, filename, emitterClass, includePaths, cfgFiles, outputRootDir, copyCPPOutput2Stderr); + new GlueGen().run(reader, filename, emitterClass, includePaths, cfgFiles, outputRootDir, copyCPPOutput2Stderr, enablePragmaOnce); } catch (final ClassNotFoundException ex) { throw new RuntimeException("specified emitter class was not in the classpath", ex); } @@ -445,6 +448,7 @@ public class GlueGen implements GlueEmitterControls { out.println("-Cjava-emitter.cfg."); out.println(" --debug enables debug mode"); out.println(" --dumpCPP directs CPP to dump all output to stderr as well"); + out.println(" --enablePragmaOnce allow handle of #pragma once directive during parsing"); exit(1); } } diff --git a/src/java/com/jogamp/gluegen/pcpp/PCPP.java b/src/java/com/jogamp/gluegen/pcpp/PCPP.java index c766634..c4af374 100644 --- a/src/java/com/jogamp/gluegen/pcpp/PCPP.java +++ b/src/java/com/jogamp/gluegen/pcpp/PCPP.java @@ -87,18 +87,21 @@ public class PCPP implements GenericCPP { /** List containing the #include paths as Strings */ private final List<String> includePaths; + private final List<String> alreadyIncludedFiles = new ArrayList<String>(); private ParseState state; private final boolean enableDebugPrint; private final boolean enableCopyOutput2Stderr; + private final boolean enablePragmaOnce; - public PCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr) { + public PCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr, final boolean pragmaOnce) { LOG = Logging.getLogger(PCPP.class.getPackage().getName(), PCPP.class.getSimpleName()); this.includePaths = includePaths; setOut(System.out); enableDebugPrint = debug; enableCopyOutput2Stderr = copyOutput2Stderr; + enablePragmaOnce = pragmaOnce; } @Override @@ -450,6 +453,9 @@ public class PCPP implements GenericCPP { } else if (w.equals("include")) { handleInclude(); shouldPrint = false; + } else if (w.equals("pragma")){ + handlePragma(); + shouldPrint = false; } else { int line = -1; try { @@ -1019,14 +1025,29 @@ public class PCPP implements GenericCPP { if (fullname == null) { throw new RuntimeException("Can't find #include file \"" + filename + "\" at file " + filename() + ", line " + lineNumber()); } - // Process this file in-line - final Reader reader = new BufferedReader(new FileReader(fullname)); - run(reader, fullname); + if ((!enablePragmaOnce || !alreadyIncludedFiles.contains(fullname))) { + // Process this file in-line + final Reader reader = new BufferedReader(new FileReader(fullname)); + run(reader, fullname); + } else { + //System.err.println("INACTIVE BLOCK, SKIPPING " + filename); + } } else { //System.err.println("INACTIVE BLOCK, SKIPPING " + filename); } } + ///////////////////////////////////// + // Handling of #pragma directives // + ///////////////////////////////////// + + private void handlePragma() throws IOException { + final String msg = nextWordOrString(); + if (enablePragmaOnce && msg.equals("once")) { + alreadyIncludedFiles.add(filename()); + } + } + //////////// // Output // //////////// @@ -1128,6 +1149,7 @@ public class PCPP implements GenericCPP { System.err.println("Output goes to standard output. Standard input can be used as input"); System.err.println("by passing '-' as the argument."); System.err.println(" --debug enables debug mode"); + System.err.println(" --enablePragmaOnce enables pragma once management"); System.exit(1); } @@ -1135,6 +1157,7 @@ public class PCPP implements GenericCPP { Reader reader = null; String filename = null; boolean debug = false; + boolean enablePragmaOnce = false; if (args.length == 0) { usage(); @@ -1151,6 +1174,8 @@ public class PCPP implements GenericCPP { } } else if (arg.equals("--debug")) { debug = true; + } else if (arg.equals("--enablePragmaOnce")) { + enablePragmaOnce = true; } else { usage(); } @@ -1169,7 +1194,7 @@ public class PCPP implements GenericCPP { } } - new PCPP(includePaths, debug, debug).run(reader, filename); + new PCPP(includePaths, debug, debug, enablePragmaOnce).run(reader, filename); } } diff --git a/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java b/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java index 13bf418..52c20e0 100644 --- a/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java +++ b/src/java/com/jogamp/gluegen/structgen/CStructAnnotationProcessor.java @@ -98,12 +98,15 @@ public class CStructAnnotationProcessor extends AbstractProcessor { } private static final String STRUCTGENOUTPUT_OPTION = "structgen.output"; + private static final String STRUCTGENPRAGMA_ONCE = "structgen.enable.pragma.once"; private static final String STRUCTGENOUTPUT = PropertyAccess.getProperty("jogamp.gluegen."+STRUCTGENOUTPUT_OPTION, true, "gensrc"); + private static final String STRUCTGENPRAGMAONCE = PropertyAccess.getProperty("jogamp.gluegen."+STRUCTGENPRAGMA_ONCE, true, "false"); private Filer filer; private Messager messager; private Elements eltUtils; private String outputPath; + private boolean enablePragmaOnce; private final static Set<String> generatedStructs = new HashSet<String>(); @@ -118,6 +121,9 @@ public class CStructAnnotationProcessor extends AbstractProcessor { outputPath = processingEnv.getOptions().get(STRUCTGENOUTPUT_OPTION); outputPath = outputPath == null ? STRUCTGENOUTPUT : outputPath; + + final String enablePragmaOnceOpt = processingEnv.getOptions().get(STRUCTGENPRAGMAONCE); + enablePragmaOnce = Boolean.parseBoolean(enablePragmaOnceOpt == null ? STRUCTGENPRAGMAONCE : enablePragmaOnceOpt); } private File locateSource(final String packageName, final String relativeName) { @@ -211,7 +217,7 @@ public class CStructAnnotationProcessor extends AbstractProcessor { headerParent = root0.substring(0, root0.length()-headerFile.getName().length()-1); rootOut = headerParent.substring(0, headerParent.length()-packageName.length()) + ".."; } - System.err.println("CStruct: "+headerFile+", abs: "+headerFile.isAbsolute()+", headerParent "+headerParent+", rootOut "+rootOut); + System.err.println("CStruct: "+headerFile+", abs: "+headerFile.isAbsolute()+", headerParent "+headerParent+", rootOut "+rootOut+", enablePragmaOnce"+enablePragmaOnce); generateStructBinding(element, struct, isPackageOrType, rootOut, packageName, headerFile, headerParent); } catch (final IOException ex) { @@ -276,7 +282,8 @@ public class CStructAnnotationProcessor extends AbstractProcessor { GlueGen.setDebug(true); } new GlueGen().run(reader, filename, AnnotationProcessorJavaStructEmitter.class, - includePaths, cfgFiles, outputPath1, false /* copyCPPOutput2Stderr */); + includePaths, cfgFiles, outputPath1, false /* copyCPPOutput2Stderr */, + enablePragmaOnce /* enablePragmaOnce */); configFile.delete(); generatedStructs.add(finalType); |