public CppReader(final Reader r) { cpp = new Preprocessor(new LexerSource(r, true) { @Override public String getName() { return "<CppReader Input@" + System.identityHashCode(r) + ">"; } }); token = ""; idx = 0; }
public Preprocessor(Source initial) { this(); addInput(initial); }
/** * Defines the given name as a macro. * * This is a convnience method. */ public void addMacro(String name, String value) throws LexerException { cpp.addMacro(name, value); }
/* pp */ void init(Preprocessor pp, LexerSource s) { this.listener = pp.getListener(); this.source = s; setTrigraphs(pp.getFeature(Feature.TRIGRAPHS), pp.getWarning(Warning.TRIGRAPHS)); }
/* pp */ void init(Preprocessor pp) { setListener(pp.getListener()); this.werror = pp.getWarnings().contains(Warning.ERROR); }
Preprocessor pp = new Preprocessor(); pp.addFeature(Feature.DIGRAPHS); pp.addFeature(Feature.TRIGRAPHS); pp.addFeature(Feature.LINEMARKERS); pp.addWarning(Warning.IMPORT); pp.setListener(new PreprocessorListener()); pp.addMacro("__JCPP__"); pp.getSystemIncludePath().add("/usr/local/include"); pp.getSystemIncludePath().add("/usr/include"); pp.getFrameworksPath().add("/System/Library/Frameworks"); pp.getFrameworksPath().add("/Library/Frameworks"); pp.getFrameworksPath().add("/Local/Library/Frameworks"); idx = arg.indexOf('='); if (idx == -1) pp.addMacro(arg); else pp.addMacro(arg.substring(0, idx), arg.substring(idx + 1)); break; case 'U': pp.getMacros().remove(g.getOptarg()); break; case 'I': pp.getSystemIncludePath().add(g.getOptarg()); break; case 0: // --iquote= pp.getQuoteIncludePath().add(g.getOptarg()); break;
throw new BuildException("Output not specified"); Preprocessor cpp = new Preprocessor(); cpp.setListener(listener); for (Macro macro : macros) cpp.addMacro(macro.getName(), macro.getValue()); if (systemincludepath != null) cpp.setSystemIncludePath(Arrays.asList(systemincludepath.list())); if (localincludepath != null) cpp.setQuoteIncludePath(Arrays.asList(localincludepath.list())); cpp.addInput(input); writer = new FileWriter(output); for (;;) { Token tok = cpp.token(); if (tok == null) break;
preprocessor.setProperStringTokensInLinePragmas(true); preprocessor.addFeature(Feature.KEEPCOMMENTS); preprocessor.addFeature(Feature.DIGRAPHS); preprocessor.addFeature(Feature.INCLUDENEXT); preprocessor.addFeature(Feature.OBJCSYNTAX); preprocessor.addFeature(Feature.TRIGRAPHS); preprocessor.addFeature(Feature.LINEMARKERS); preprocessor.addWarning(Warning.IMPORT); } else { preprocessor.getFeatures().clear(); preprocessor.setListener(new PreprocessorListener() { @Override public void handleWarning(Source source, int line, int column, preprocessor.getSystemIncludePath().addAll(includes); preprocessor.getQuoteIncludePath().addAll(includes); preprocessor.getFrameworksPath().addAll(config.frameworksPath); for (Map.Entry<String, String> e : config.getAllMacros().entrySet()) { String name = e.getKey(); preprocessor.addMacro(macro); } else { if (e.getValue() != null) {
p = new Preprocessor(); p.addFeature(Feature.CSYNTAX); p.addInput(sl); try { assertTrue(testError(p)); p = new Preprocessor(); p.addFeature(Feature.CSYNTAX); p.addInput(sl); pl = new PreprocessorListener(); p.setListener(pl); assertNotNull("CPP has listener", p.getListener()); assertTrue(testError(p)); assertTrue("Listener has errors", pl.getErrors() > 0); p = new Preprocessor(); p.addInput(sl); assertTrue(testError(p));
private Token define() throws IOException, LexerException { Token tok = source_token_nonwhite(); if (tok.getType() != IDENTIFIER) { error(tok, "Expected identifier"); return source_skipline(false); error(tok, "Cannot redefine name 'defined'"); return source_skipline(false); Macro m = new Macro(getSource(), name); List<String> args; tok = source_token(); if (tok.getType() == '(') { tok = source_token_nonwhite(); if (tok.getType() != ')') { args = new ArrayList<String>(); case NL: case EOF: error(tok, "Unterminated macro parameter list"); return tok; source_untoken(tok); break; default: error(tok,
public List<String> run() throws SoShaderException { try { final SoShaderPreprocessorJCPP p = SoShaderPreprocessorJCPP.this; this.pp.setSystemIncludePath(p.modules); this.pp.setFileSystem(p.filesystem); this.pp.addInput(p.filesystem.getFile(this.file).getSource()); this.pp.setListener(this); this.setupDefines(); final int bsize = 2 << 14; try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(bsize)) { this.processTokens(bao); return this.processLines(bao); } } catch (final IOException e) { throw new SoShaderExceptionIO(e); } }
public static String preprocessSources(JNAeratorConfig config, Collection<String> includeStrings, Collection<File> files, List<Define> defines, boolean verbose, TypeConversion typeConverter, MacroUseCallback macrosDependenciesOut, Map<String, Macro> macros) throws IOException, LexerException { Preprocessor preProcessor = PreprocessorUtils.createPreProcessor(config.preprocessorConfig, macrosDependenciesOut); for (String content : includeStrings) { preProcessor.addInput(new StringLexerSource(content, true)); preProcessor.addInput(file); preProcessor.addMacro(macro); preProcessor.close(); macros = preProcessor.getMacros();
public void setUp() throws Exception { final PipedOutputStream po = new PipedOutputStream(); writer = new OutputStreamWriter(po); p = new Preprocessor(); p.addInput( new LexerSource( new InputStreamReader( new PipedInputStream(po) ), true ) ); }
+ "PASTE_VAARGS(a) // PASTE_VAARGS 1\n"; LOG.info("Input is:\n" + input); Preprocessor pp = new Preprocessor(); pp.addFeature(Feature.KEEPCOMMENTS); pp.addInput(new StringLexerSource(input, true)); Reader r = new CppReader(pp); String output = CharStreams.toString(r).trim();
Token tok = token(); switch (tok.getType()) { case EOF: warning(tok, "End of file in #" + "pragma"); return tok; case NL: warning(tok, "Empty #" + "pragma"); return tok; break NAME; default: return source_skipline(false); List<Token> value = new ArrayList<Token>(); VALUE: for (;;) { tok = token(); switch (tok.getType()) { case EOF: warning(tok, "End of file in #" + "pragma"); break VALUE; pragma(name, value);
public void execute() { FileWriter writer = null; try { if (input == null) throw new BuildException("Input not specified"); if (output == null) throw new BuildException("Output not specified"); cpp.addInput(this.input); writer = new FileWriter(this.output); for (;;) { Token tok = cpp.token(); if (tok != null && tok.getType() == Token.EOF) break; writer.write(tok.getText()); } } catch (Exception e) { throw new BuildException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } }
Preprocessor pp = new Preprocessor(new File(mainFileName)); pp.setSystemIncludePath(systemInclude);
private void processTokens( final ByteArrayOutputStream bao) throws IOException { try (final PrintStream baos = new PrintStream(bao, false, "UTF-8")) { final OptionalInt version = SoShaderPreprocessorJCPP.this.config.version(); if (version.isPresent()) { baos.printf( "#version %d core\n", Integer.valueOf(version.getAsInt())); } while (true) { final Token tok = this.pp.token(); if (tok.getType() == Token.EOF) { break; } baos.print(tok.getText()); } baos.flush(); } catch (final LexerException e) { throw new IOException(e); } }
return false; while (idx >= token.length()) { Token tok = cpp.token(); switch (tok.getType()) { case EOF: case CCOMMENT: case CPPCOMMENT: if (!cpp.getFeature(Feature.KEEPCOMMENTS)) { token = " "; break;
private void testCppReader(String in, String out) throws Exception { System.out.println("Testing " + in + " => " + out); StringReader r = new StringReader(in); CppReader p = new CppReader(r); p.getPreprocessor().setSystemIncludePath( Collections.singletonList("src/test/resources/input") ); p.getPreprocessor().getFeatures().add(Feature.LINEMARKERS); BufferedReader b = new BufferedReader(p); String line; while ((line = b.readLine()) != null) { System.out.println(" >> " + line); } }