/** * Returns the File currently being lexed. * * If this Source is not a {@link FileLexerSource}, then * it will ask the parent Source, and so forth recursively. * If no Source on the stack is a FileLexerSource, returns null. */ public String getPath() { Source parent = getParent(); if (parent != null) return parent.getPath(); return null; }
/** * Returns true if this Source is expanding the given macro. * * This is used to prevent macro recursion. */ /* pp */ boolean isExpanding(Macro m) { Source parent = getParent(); if (parent != null) return parent.isExpanding(m); return false; }
/** * Returns an NL or an EOF token. * * The metadata on the token will be correct, which is better * than generating a new one. * * This method can, as of recent patches, return a P_LINE token. */ private Token source_skipline(boolean white) throws IOException, LexerException { // (new Exception("skipping line")).printStackTrace(System.out); Source s = getSource(); Token tok = s.skipline(white); /* XXX Refactor with source_token() */ if (tok.getType() == EOF && s.isAutopop()) { // System.out.println("Autopop " + s); pop_source(); Source t = getSource(); if (getFeature(Feature.LINEMARKERS) && s.isNumbered() && t != null) { /* We actually want 'did the nested source * contain a newline token', which isNumbered() * approximates. This is not perfect, but works. */ return line_token(t.getLine() + 1, t.getName(), " 2"); } } return tok; }
listener.handleSourceChange(this.source, SourceChangeEvent.POP); Source s = this.source; this.source = s.getParent(); s.close(); if (listener != null && this.source != null) listener.handleSourceChange(this.source, SourceChangeEvent.RESUME); && s.isNumbered() && t != null) { return line_token(t.getLine(), t.getName(), " 2");
protected void pragma_once(@Nonnull Token name) throws IOException, LexerException { Source s = this.source; if (!onceseenpaths.add(s.getPath())) { Token mark = pop_source(true); // FixedTokenSource should never generate a linemarker on exit. if (mark != null) push_source(new FixedTokenSource(Arrays.asList(mark)), true); } }
/** * Sets the PreprocessorListener which handles events for * this Preprocessor. * * The listener is notified of warnings, errors and source * changes, amongst other things. */ public void setListener(PreprocessorListener listener) { this.listener = listener; Source s = source; while (s != null) { // s.setListener(listener); s.init(this); s = s.getParent(); } }
/** * Pushes a Source onto the input stack. * * @see #getSource() * @see #pop_source() */ protected void push_source(Source source, boolean autopop) { source.init(this); source.setParent(this.source, autopop); // source.setListener(listener); if (listener != null) listener.handleSourceChange(this.source, "suspend"); this.source = source; if (listener != null) listener.handleSourceChange(this.source, "push"); }
try { source.setActive(false); tok = source_token(); source.setActive(true); if (m == null) return tok; if (source.isExpanding(m)) return tok; if (macro(m, tok))
/** * Handles an error. * * The behaviour of this method is defined by the * implementation. It may simply record the error message, or * it may throw an exception. */ public void handleError(Source source, int line, int column, String msg) throws LexerException { errors++; print(source.getName() + ":" + line + ":" + column + ": error: " + msg); }
/** * Returns an NL or an EOF token. * * The metadata on the token will be correct, which is better * than generating a new one. * * This method can, as of recent patches, return a P_LINE token. */ private Token source_skipline(boolean white) throws IOException, LexerException { // (new Exception("skipping line")).printStackTrace(System.out); Source s = getSource(); Token tok = s.skipline(white); /* XXX Refactor with source_token() */ if (tok.getType() == EOF && s.isAutopop()) { // System.out.println("Autopop " + s); Token mark = pop_source(true); if (mark != null) return mark; } return tok; }
@Override /* pp */ boolean isExpanding(Macro m) { /* When we are expanding an arg, 'this' macro is not * being expanded, and thus we may re-expand it. */ if (/* XXX this.arg == null && */ this.macro == m) return true; return super.isExpanding(m); }
/** * Adds input for the Preprocessor. * * Inputs are processed in the order in which they are added. */ public void addInput(Source source) { source.init(this); inputs.add(source); }