Commit 4613da1c authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Mark the generated tokens in the token stream.

parent 064201ff
...@@ -660,9 +660,9 @@ bool Preprocessor::markGeneratedTokens(bool markGeneratedTokens, ...@@ -660,9 +660,9 @@ bool Preprocessor::markGeneratedTokens(bool markGeneratedTokens,
dot = _dot; dot = _dot;
if (_markGeneratedTokens) if (_markGeneratedTokens)
_result->append("\n#pragma push(gen)"); _result->append("\n#gen true");
else else
_result->append("\n#pragma pop(gen)"); _result->append("\n#gen false");
processNewline(/*force = */ true); processNewline(/*force = */ true);
......
...@@ -182,8 +182,10 @@ void TranslationUnit::tokenize() ...@@ -182,8 +182,10 @@ void TranslationUnit::tokenize()
pushLineOffset(0); pushLineOffset(0);
pushPreprocessorLine(0, 1, fileId()); pushPreprocessorLine(0, 1, fileId());
Identifier *lineId = control()->findOrInsertIdentifier("line"); Identifier *lineId = control()->findOrInsertIdentifier("line");
Identifier *genId = control()->findOrInsertIdentifier("gen");
bool generated = false;
Token tk; Token tk;
do { do {
lex(&tk); lex(&tk);
...@@ -192,16 +194,29 @@ void TranslationUnit::tokenize() ...@@ -192,16 +194,29 @@ void TranslationUnit::tokenize()
if (tk.is(T_POUND)) { if (tk.is(T_POUND)) {
unsigned offset = tk.offset; unsigned offset = tk.offset;
lex(&tk); lex(&tk);
if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId)
lex(&tk); if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == genId) {
if (! tk.newline && tk.is(T_INT_LITERAL)) { // it's a gen directive.
unsigned line = (unsigned) strtoul(tk.spell(), 0, 0);
lex(&tk); lex(&tk);
if (! tk.newline && tk.is(T_STRING_LITERAL)) {
StringLiteral *fileName = control()->findOrInsertFileName(tk.string->chars(), if (! tk.newline && tk.is(T_TRUE)) {
tk.string->size()); lex(&tk);
pushPreprocessorLine(offset, line, fileName); generated = true;
} else {
generated = false;
}
} else {
if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId)
lex(&tk);
if (! tk.newline && tk.is(T_INT_LITERAL)) {
unsigned line = (unsigned) strtoul(tk.spell(), 0, 0);
lex(&tk); lex(&tk);
if (! tk.newline && tk.is(T_STRING_LITERAL)) {
StringLiteral *fileName = control()->findOrInsertFileName(tk.string->chars(),
tk.string->size());
pushPreprocessorLine(offset, line, fileName);
lex(&tk);
}
} }
} }
while (tk.isNot(T_EOF_SYMBOL) && ! tk.newline) while (tk.isNot(T_EOF_SYMBOL) && ! tk.newline)
...@@ -214,6 +229,7 @@ void TranslationUnit::tokenize() ...@@ -214,6 +229,7 @@ void TranslationUnit::tokenize()
braces.pop(); braces.pop();
(*_tokens)[open_brace_index].close_brace = _tokens->size(); (*_tokens)[open_brace_index].close_brace = _tokens->size();
} }
tk.generated = generated;
_tokens->push_back(tk); _tokens->push_back(tk);
} while (tk.kind); } while (tk.kind);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment