public String toString() { StringBuilder buf = new StringBuilder(name); if (args != null) { buf.append('('); Iterator<String> it = args.iterator(); while (it.hasNext()) { buf.append(it.next()); if (it.hasNext()) buf.append(", "); else if (isVariadic()) buf.append("..."); } buf.append(')'); } if (!tokens.isEmpty()) { buf.append(" => ").append(getText()); } return buf.toString(); }
/** * Adds a Macro to this Preprocessor. * * The given {@link Macro} object encapsulates both the name * and the expansion. */ public void addMacro(Macro m) throws LexerException { // System.out.println("Macro " + m); String name = m.getName(); /* Already handled as a source error in macro(). */ if ("defined".equals(name)) throw new LexerException("Cannot redefine name 'defined'"); macros.put(m.getName(), m); }
/* pp */ MacroTokenSource(Macro m, List<Argument> args) { this.macro = m; this.tokens = m.getTokens().iterator(); this.args = args; this.arg = null; }
Macro m = new Macro(getSource(), name); List<String> args; error(tok, "ellipsis must be on last argument"); m.setVariadic(true); break ARGS; case ')': m.setArgs(args); space = false; paste = true; m.addPaste(new Token(M_PASTE, tok.getLine(), tok.getColumn(), "#" + "#", null)); m.addToken(Token.space); space = false; Token la = source_token_nonwhite(); if (la.getType() == IDENTIFIER && ((idx = args.indexOf(la.getText())) != -1)) { m.addToken(new Token(M_STRING, la.getLine(), la.getColumn(), "#" + la.getText(), m.addToken(tok); m.addToken(Token.space);
if (m.isFunctionLike()) { OPEN: for (;;) { if (tok.getType() != ')' || m.getArgs() > 0) { args = new ArrayList<Argument>(); if (m.isVariadic() && /* We are building the last arg. */ args.size() == m.getArgs() - 1) { if (args.size() != m.getArgs()) { if (m.isVariadic()) { if (args.size() == m.getArgs() - 1) { args.add(new Argument()); } else { error(tok, "variadic macro " + m.getName() + " has at least " + (m.getArgs() - 1) + " parameters " + "but given " + args.size() + " args"); return false; "macro " + m.getName() + " has " + m.getArgs() + " parameters " + "but given " + args.size() + " args");
static void addDefines(JNAeratorConfig config, Map<String, Macro> macros, List<Define> defines, boolean verbose, TypeConversion typeConverter) { for (Map.Entry<String, Macro> e : macros.entrySet()) { Macro macro = e.getValue(); if (macro.getText() == null) { continue; if (macro.isFunctionLike() && macro.getArgs() > 0) { continue; String preprocessedMacro = preprocessSources(config, Collections.singletonList(macro.getText()), Collections.EMPTY_LIST, null, verbose, typeConverter, null, macros); Expression expression = new JNAeratorParser().newObjCppParser(typeConverter, preprocessedMacro, verbose, null).expression();//.expr; if (expression == null) { if (macro.getSource() != null) { define.setElementFile(macro.getSource().getPath());
/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. * * @throws LexerException if the definition fails or is otherwise illegal. */ public void addMacro(@Nonnull String name, @Nonnull String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
/** * Returns true if the given argumentIndex is the last argument of a variadic macro. * * @param argumentIndex The index of the argument to inspect. * @return true if the given argumentIndex is the last argument of a variadic macro. */ private boolean isVariadicArgument(@Nonnegative int argumentIndex) { if (!macro.isVariadic()) return false; return argumentIndex == args.size() - 1; }
Macro m = new Macro(getSource(), name); List<String> args; error(tok, "ellipsis must be on last argument"); m.setVariadic(true); break ARGS; case ')': m.setArgs(args); space = false; paste = true; m.addPaste(new Token(M_PASTE, tok.getLine(), tok.getColumn(), "#" + "#", null)); m.addToken(Token.space); space = false; Token la = source_token_nonwhite(); if (la.getType() == IDENTIFIER && ((idx = args.indexOf(la.getText())) != -1)) { m.addToken(new Token(M_STRING, la.getLine(), la.getColumn(), "#" + la.getText(), m.addToken(tok); m.addToken(Token.space);
if (m.isFunctionLike()) { OPEN: for (;;) { tok = source_token(); if (tok.getType() != ')' || m.getArgs() > 0) { args = new ArrayList<Argument>(); if (m.isVariadic() && args.size() == m.getArgs() - 1) { if (args.size() != m.getArgs()) { error(tok, "macro " + m.getName() + " has " + m.getArgs() + " parameters " + "but given " + args.size() + " args");
static void addDefines(JNAeratorConfig config, Map<String, Macro> macros, List<Define> defines, boolean verbose, TypeConversion typeConverter) { for (Map.Entry<String, Macro> e : macros.entrySet()) { Macro macro = e.getValue(); if (macro.getText() == null) { continue; if (macro.isFunctionLike() && macro.getArgs() > 0) { continue; String preprocessedMacro = preprocessSources(config, Collections.singletonList(macro.getText()), Collections.EMPTY_LIST, null, verbose, typeConverter, null, macros); Expression expression = new JNAeratorParser().newObjCppParser(typeConverter, preprocessedMacro, verbose, null).expression();//.expr; if (expression == null) { if (macro.getSource() != null) { define.setElementFile(macro.getSource().getPath());
/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. */ public void addMacro(String name, String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
Macro m = new Macro(getSource(), name); List<String> args; error(tok, "ellipsis must be on last argument"); m.setVariadic(true); break ARGS; case ')': m.setArgs(args); } else { space = false; paste = true; m.addPaste(new Token(M_PASTE, tok.getLine(), tok.getColumn(), "#" + "#", null)); m.addToken(Token.space); space = false; Token la = source_token_nonwhite(); if (la.getType() == IDENTIFIER && ((idx = args.indexOf(la.getText())) != -1)) { m.addToken(new Token(M_STRING, la.getLine(), la.getColumn(), "#" + la.getText(), Integer.valueOf(idx))); } else { m.addToken(tok);
if (m.isFunctionLike()) { OPEN: for (;;) { tok = source_token(); if (tok.getType() != ')' || m.getArgs() > 0) { args = new ArrayList<Argument>(); if (m.isVariadic() && args.size() == m.getArgs() - 1) { if (args.size() != m.getArgs()) { error(tok, "macro " + m.getName() + " has " + m.getArgs() + " parameters " + "but given " + args.size() + " args");
public String toString() { StringBuilder buf = new StringBuilder(name); if (args != null) { buf.append('('); Iterator<String> it = args.iterator(); while (it.hasNext()) { buf.append(it.next()); if (it.hasNext()) buf.append(", "); else if (isVariadic()) buf.append("..."); } buf.append(')'); } if (!tokens.isEmpty()) { buf.append(" => ").append(getText()); } return buf.toString(); }
/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. */ public void addMacro(String name, String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
/** * Adds a Macro to this Preprocessor. * * The given {@link Macro} object encapsulates both the name * and the expansion. */ public void addMacro(Macro m) throws LexerException { // System.out.println("Macro " + m); String name = m.getName(); /* Already handled as a source error in macro(). */ if ("defined".equals(name)) throw new LexerException("Cannot redefine name 'defined'"); macros.put(m.getName(), m); }
/* pp */ MacroTokenSource(Macro m, List<Argument> args) { this.macro = m; this.tokens = m.getTokens().iterator(); this.args = args; this.arg = null; }