コード例 #1
0
        /* At this point, we have consumed the first M_PASTE.
         * @see Macro#addPaste(Token) */
        private void paste(Token ptok)
        {
            StringBuilder buf = new StringBuilder();
            Token         err = null;

            /* We know here that arg is null or expired,
             * since we cannot paste an expanded arg. */

            int count = 2;

            for (int i = 0; i < count; i++)
            {
                if (!tokens.hasNext())
                {
                    /* XXX This one really should throw. */
                    error(ptok.getLine(), ptok.getColumn(),
                          "Paste at end of expansion");
                    buf.append(' ').append(ptok.getText());
                    break;
                }
                Token tok = tokens.next();
                // System.out.println("Paste " + tok);
                switch (tok.getType())
                {
                case Token.M_PASTE:
                    /* One extra to paste, plus one because the
                     * paste token didn't count. */
                    count += 2;
                    ptok   = tok;
                    break;

                case Token.M_ARG:
                    int idx = (int)tok.getValue();
                    concat(buf, args.get(idx));
                    break;

                /* XXX Test this. */
                case Token.CCOMMENT:
                case Token.CPPCOMMENT:
                    break;

                default:
                    buf.append(tok.getText());
                    break;
                }
            }

            /* Push and re-lex. */

            /*
             * StringBuilder		src = new StringBuilder();
             * escape(src, buf);
             * StringLexerSource	sl = new StringLexerSource(src.toString());
             */
            StringLexerSource sl = new StringLexerSource(buf.toString());

            /* XXX Check that concatenation produces a valid token. */

            arg = new SourceIterator(sl);
        }
コード例 #2
0
ファイル: Macro.cs プロジェクト: ccf19881030/CppNet-2
        /* Paste tokens are inserted before the first of the two pasted
         * tokens, so it's a kind of bytecode notation. This method
         * swaps them around again. We know that there will never be two
         * sequential paste tokens, so a bool is sufficient. */
        public String getText()
        {
            StringBuilder buf   = new StringBuilder();
            bool          paste = false;

            for (int i = 0; i < tokens.Count; i++)
            {
                Token tok = tokens[i];
                if (tok.getType() == Token.M_PASTE)
                {
                    System.Diagnostics.Debug.Assert(paste == false, "Two sequential pastes.");
                    paste = true;
                    continue;
                }
                else
                {
                    buf.Append(tok.getText());
                }
                if (paste)
                {
                    buf.Append(" #" + "# ");
                    paste = false;
                }
                // buf.Append(tokens.get(i));
            }
            return(buf.ToString());
        }
コード例 #3
0
        private void concat(StringBuilder buf, Argument arg)
        {
            Iterator <Token> it = arg.iterator();

            while (it.hasNext())
            {
                Token tok = it.next();
                buf.append(tok.getText());
            }
        }
コード例 #4
0
ファイル: Preprocessor.cs プロジェクト: manu-silicon/CppNet
 /* For #error and #warning. */
 private void error(Token pptok, bool is_error)
 {
     StringBuilder	buf = new StringBuilder();
     buf.Append('#').Append(pptok.getText()).Append(' ');
     /* Peculiar construction to ditch first whitespace. */
     Token		tok = source_token_nonwhite();
     for (;;) {
     switch (tok.getType()) {
         case Token.NL:
         case Token.EOF:
             goto BREAK_ERROR;
         default:
             buf.Append(tok.getText());
             break;
     }
     tok = source_token();
     }
     BREAK_ERROR:
     if (is_error)
     error(pptok, buf.ToString());
     else
     warning(pptok, buf.ToString());
 }
コード例 #5
0
ファイル: Preprocessor.cs プロジェクト: manu-silicon/CppNet
 protected void pragma(Token name, List<Token> value)
 {
     warning(name, "Unknown #" + "pragma: " + name.getText());
 }
コード例 #6
0
ファイル: Preprocessor.cs プロジェクト: manu-silicon/CppNet
        private Token toWhitespace(Token tok)
        {
            String	text = tok.getText();
            int len = text.Length;
            bool	cr = false;
            int		nls = 0;

            for (int i = 0; i < len; i++) {
            char	c = text[i];

            switch (c) {
                case '\r':
                    cr = true;
                    nls++;
                    break;
                case '\n':
                    if (cr) {
                        cr = false;
                        break;
                    }
                    goto case '\u2028';
                /* fallthrough */
                case '\u2028':
                case '\u2029':
                case '\u000B':
                case '\u000C':
                case '\u0085':
                    cr = false;
                    nls++;
                    break;
            }
            }

            char[] cbuf = new char[nls];
            for(int i = 0; i < nls; i++) { cbuf[i] = '\n'; }

            return new Token(Token.WHITESPACE,
                tok.getLine(), tok.getColumn(),
                new String(cbuf));
        }
コード例 #7
0
ファイル: MacroTokenSource.cs プロジェクト: tanis2000/CppNet
	/* At this point, we have consumed the first M_PASTE.
	 * @see Macro#addPaste(Token) */
	private void paste(Token ptok)  {
		StringBuilder	buf = new StringBuilder();
		Token			err = null;
		/* We know here that arg is null or expired,
		 * since we cannot paste an expanded arg. */

		int	count = 2;
		for (int i = 0; i < count; i++) {
			if (!tokens.hasNext()) {
				/* XXX This one really should throw. */
				error(ptok.getLine(), ptok.getColumn(),
						"Paste at end of expansion");
				buf.append(' ').append(ptok.getText());
				break;
			}
			Token	tok = tokens.next();
			// System.out.println("Paste " + tok);
			switch (tok.getType()) {
				case Token.M_PASTE:
					/* One extra to paste, plus one because the
					 * paste token didn't count. */
					count += 2;
					ptok = tok;
					break;
                case Token.M_ARG:
					int idx = (int)tok.getValue();
					concat(buf, args.get(idx));
					break;
				/* XXX Test this. */
                case Token.CCOMMENT:
                case Token.CPPCOMMENT:
					break;
				default:
					buf.append(tok.getText());
					break;
			}
		}

		/* Push and re-lex. */
		/*
		StringBuilder		src = new StringBuilder();
		escape(src, buf);
		StringLexerSource	sl = new StringLexerSource(src.toString());
		*/
		StringLexerSource	sl = new StringLexerSource(buf.toString());

		/* XXX Check that concatenation produces a valid token. */

		arg = new SourceIterator(sl);
	}