Lines Matching refs:token
48 static DirectiveType getDirective(const pp::Token* token) in getDirective() argument
64 if (token->type != pp::Token::IDENTIFIER) in getDirective()
67 if (token->text == kDirectiveDefine) in getDirective()
69 else if (token->text == kDirectiveUndef) in getDirective()
71 else if (token->text == kDirectiveIf) in getDirective()
73 else if (token->text == kDirectiveIfdef) in getDirective()
75 else if (token->text == kDirectiveIfndef) in getDirective()
77 else if (token->text == kDirectiveElse) in getDirective()
79 else if (token->text == kDirectiveElif) in getDirective()
81 else if (token->text == kDirectiveEndif) in getDirective()
83 else if (token->text == kDirectiveError) in getDirective()
85 else if (token->text == kDirectivePragma) in getDirective()
87 else if (token->text == kDirectiveExtension) in getDirective()
89 else if (token->text == kDirectiveVersion) in getDirective()
91 else if (token->text == kDirectiveLine) in getDirective()
114 static bool isEOD(const pp::Token* token) in isEOD() argument
116 return (token->type == '\n') || (token->type == pp::Token::LAST); in isEOD()
119 static void skipUntilEOD(pp::Lexer* lexer, pp::Token* token) in skipUntilEOD() argument
121 while(!isEOD(token)) in skipUntilEOD()
123 lexer->lex(token); in skipUntilEOD()
162 void DirectiveParser::lex(Token* token) in lex() argument
166 mTokenizer->lex(token); in lex()
168 if (token->type == Token::PP_HASH) in lex()
170 parseDirective(token); in lex()
174 if (token->type == Token::LAST) in lex()
185 } while (skipping() || (token->type == '\n')); in lex()
190 void DirectiveParser::parseDirective(Token* token) in parseDirective() argument
192 assert(token->type == Token::PP_HASH); in parseDirective()
194 mTokenizer->lex(token); in parseDirective()
195 if (isEOD(token)) in parseDirective()
201 DirectiveType directive = getDirective(token); in parseDirective()
207 skipUntilEOD(mTokenizer, token); in parseDirective()
215 token->location, token->text); in parseDirective()
216 skipUntilEOD(mTokenizer, token); in parseDirective()
219 parseDefine(token); in parseDirective()
222 parseUndef(token); in parseDirective()
225 parseIf(token); in parseDirective()
228 parseIfdef(token); in parseDirective()
231 parseIfndef(token); in parseDirective()
234 parseElse(token); in parseDirective()
237 parseElif(token); in parseDirective()
240 parseEndif(token); in parseDirective()
243 parseError(token); in parseDirective()
246 parsePragma(token); in parseDirective()
249 parseExtension(token); in parseDirective()
252 parseVersion(token); in parseDirective()
255 parseLine(token); in parseDirective()
262 skipUntilEOD(mTokenizer, token); in parseDirective()
263 if (token->type == Token::LAST) in parseDirective()
266 token->location, token->text); in parseDirective()
270 void DirectiveParser::parseDefine(Token* token) in parseDefine() argument
272 assert(getDirective(token) == DIRECTIVE_DEFINE); in parseDefine()
274 mTokenizer->lex(token); in parseDefine()
275 if (token->type != Token::IDENTIFIER) in parseDefine()
278 token->location, token->text); in parseDefine()
281 if (isMacroPredefined(token->text, *mMacroSet)) in parseDefine()
284 token->location, token->text); in parseDefine()
287 if (isMacroNameReserved(token->text)) in parseDefine()
290 token->location, token->text); in parseDefine()
296 macro.name = token->text; in parseDefine()
298 mTokenizer->lex(token); in parseDefine()
299 if (token->type == '(' && !token->hasLeadingSpace()) in parseDefine()
304 mTokenizer->lex(token); in parseDefine()
305 if (token->type != Token::IDENTIFIER) in parseDefine()
308 …if (std::find(macro.parameters.begin(), macro.parameters.end(), token->text) != macro.parameters.e… in parseDefine()
311 token->location, token->text); in parseDefine()
315 macro.parameters.push_back(token->text); in parseDefine()
317 mTokenizer->lex(token); // Get ','. in parseDefine()
318 } while (token->type == ','); in parseDefine()
320 if (token->type != ')') in parseDefine()
323 token->location, in parseDefine()
324 token->text); in parseDefine()
327 mTokenizer->lex(token); // Get ')'. in parseDefine()
330 while ((token->type != '\n') && (token->type != Token::LAST)) in parseDefine()
335 token->location = SourceLocation(); in parseDefine()
336 macro.replacements.push_back(*token); in parseDefine()
337 mTokenizer->lex(token); in parseDefine()
351 token->location, in parseDefine()
358 void DirectiveParser::parseUndef(Token* token) in parseUndef() argument
360 assert(getDirective(token) == DIRECTIVE_UNDEF); in parseUndef()
362 mTokenizer->lex(token); in parseUndef()
363 if (token->type != Token::IDENTIFIER) in parseUndef()
366 token->location, token->text); in parseUndef()
370 MacroSet::iterator iter = mMacroSet->find(token->text); in parseUndef()
376 token->location, token->text); in parseUndef()
384 mTokenizer->lex(token); in parseUndef()
387 void DirectiveParser::parseIf(Token* token) in parseIf() argument
389 assert(getDirective(token) == DIRECTIVE_IF); in parseIf()
390 parseConditionalIf(token); in parseIf()
393 void DirectiveParser::parseIfdef(Token* token) in parseIfdef() argument
395 assert(getDirective(token) == DIRECTIVE_IFDEF); in parseIfdef()
396 parseConditionalIf(token); in parseIfdef()
399 void DirectiveParser::parseIfndef(Token* token) in parseIfndef() argument
401 assert(getDirective(token) == DIRECTIVE_IFNDEF); in parseIfndef()
402 parseConditionalIf(token); in parseIfndef()
405 void DirectiveParser::parseElse(Token* token) in parseElse() argument
407 assert(getDirective(token) == DIRECTIVE_ELSE); in parseElse()
412 token->location, token->text); in parseElse()
413 skipUntilEOD(mTokenizer, token); in parseElse()
421 skipUntilEOD(mTokenizer, token); in parseElse()
427 token->location, token->text); in parseElse()
428 skipUntilEOD(mTokenizer, token); in parseElse()
437 mTokenizer->lex(token); in parseElse()
438 if (!isEOD(token)) in parseElse()
441 token->location, token->text); in parseElse()
442 skipUntilEOD(mTokenizer, token); in parseElse()
446 void DirectiveParser::parseElif(Token* token) in parseElif() argument
448 assert(getDirective(token) == DIRECTIVE_ELIF); in parseElif()
453 token->location, token->text); in parseElif()
454 skipUntilEOD(mTokenizer, token); in parseElif()
462 skipUntilEOD(mTokenizer, token); in parseElif()
468 token->location, token->text); in parseElif()
469 skipUntilEOD(mTokenizer, token); in parseElif()
477 skipUntilEOD(mTokenizer, token); in parseElif()
481 int expression = parseExpressionIf(token); in parseElif()
486 void DirectiveParser::parseEndif(Token* token) in parseEndif() argument
488 assert(getDirective(token) == DIRECTIVE_ENDIF); in parseEndif()
493 token->location, token->text); in parseEndif()
494 skipUntilEOD(mTokenizer, token); in parseEndif()
501 mTokenizer->lex(token); in parseEndif()
502 if (!isEOD(token)) in parseEndif()
505 token->location, token->text); in parseEndif()
506 skipUntilEOD(mTokenizer, token); in parseEndif()
510 void DirectiveParser::parseError(Token* token) in parseError() argument
512 assert(getDirective(token) == DIRECTIVE_ERROR); in parseError()
515 mTokenizer->lex(token); in parseError()
516 while ((token->type != '\n') && (token->type != Token::LAST)) in parseError()
518 stream << *token; in parseError()
519 mTokenizer->lex(token); in parseError()
521 mDirectiveHandler->handleError(token->location, stream.str()); in parseError()
525 void DirectiveParser::parsePragma(Token* token) in parsePragma() argument
527 assert(getDirective(token) == DIRECTIVE_PRAGMA); in parsePragma()
541 mTokenizer->lex(token); in parsePragma()
542 while ((token->type != '\n') && (token->type != Token::LAST)) in parsePragma()
547 name = token->text; in parsePragma()
548 valid = valid && (token->type == Token::IDENTIFIER); in parsePragma()
551 valid = valid && (token->type == '('); in parsePragma()
554 value = token->text; in parsePragma()
555 valid = valid && (token->type == Token::IDENTIFIER); in parsePragma()
558 valid = valid && (token->type == ')'); in parsePragma()
564 mTokenizer->lex(token); in parsePragma()
573 token->location, name); in parsePragma()
577 mDirectiveHandler->handlePragma(token->location, name, value); in parsePragma()
581 void DirectiveParser::parseExtension(Token* token) in parseExtension() argument
583 assert(getDirective(token) == DIRECTIVE_EXTENSION); in parseExtension()
596 mTokenizer->lex(token); in parseExtension()
597 while ((token->type != '\n') && (token->type != Token::LAST)) in parseExtension()
602 if (valid && (token->type != Token::IDENTIFIER)) in parseExtension()
605 token->location, token->text); in parseExtension()
608 if (valid) name = token->text; in parseExtension()
611 if (valid && (token->type != ':')) in parseExtension()
614 token->location, token->text); in parseExtension()
619 if (valid && (token->type != Token::IDENTIFIER)) in parseExtension()
622 token->location, token->text); in parseExtension()
625 if (valid) behavior = token->text; in parseExtension()
631 token->location, token->text); in parseExtension()
636 mTokenizer->lex(token); in parseExtension()
641 token->location, token->text); in parseExtension()
645 mDirectiveHandler->handleExtension(token->location, name, behavior); in parseExtension()
648 void DirectiveParser::parseVersion(Token* token) in parseVersion() argument
650 assert(getDirective(token) == DIRECTIVE_VERSION); in parseVersion()
655 token->location, token->text); in parseVersion()
656 skipUntilEOD(mTokenizer, token); in parseVersion()
671 mTokenizer->lex(token); in parseVersion()
672 while (valid && (token->type != '\n') && (token->type != Token::LAST)) in parseVersion()
677 if (token->type != Token::CONST_INT) in parseVersion()
680 token->location, token->text); in parseVersion()
683 if (valid && !token->iValue(&version)) in parseVersion()
686 token->location, token->text); in parseVersion()
695 if (token->type != Token::IDENTIFIER || token->text != "es") in parseVersion()
698 token->location, token->text); in parseVersion()
705 token->location, token->text); in parseVersion()
710 mTokenizer->lex(token); in parseVersion()
716 token->location, token->text); in parseVersion()
722 mDirectiveHandler->handleVersion(token->location, version); in parseVersion()
726 void DirectiveParser::parseLine(Token* token) in parseLine() argument
728 assert(getDirective(token) == DIRECTIVE_LINE); in parseLine()
741 macroExpander.lex(token); in parseLine()
742 while ((token->type != '\n') && (token->type != Token::LAST)) in parseLine()
747 if (valid && (token->type != Token::CONST_INT)) in parseLine()
750 token->location, token->text); in parseLine()
753 if (valid && !token->iValue(&line)) in parseLine()
756 token->location, token->text); in parseLine()
761 if (valid && (token->type != Token::CONST_INT)) in parseLine()
764 token->location, token->text); in parseLine()
767 if (valid && !token->iValue(&file)) in parseLine()
770 token->location, token->text); in parseLine()
778 token->location, token->text); in parseLine()
783 macroExpander.lex(token); in parseLine()
789 token->location, token->text); in parseLine()
807 void DirectiveParser::parseConditionalIf(Token* token) in parseConditionalIf() argument
810 block.type = token->text; in parseConditionalIf()
811 block.location = token->location; in parseConditionalIf()
819 skipUntilEOD(mTokenizer, token); in parseConditionalIf()
824 DirectiveType directive = getDirective(token); in parseConditionalIf()
830 expression = parseExpressionIf(token); in parseConditionalIf()
833 expression = parseExpressionIfdef(token); in parseConditionalIf()
836 expression = parseExpressionIfdef(token) == 0 ? 1 : 0; in parseConditionalIf()
848 int DirectiveParser::parseExpressionIf(Token* token) in parseExpressionIf() argument
850 assert((getDirective(token) == DIRECTIVE_IF) || in parseExpressionIf()
851 (getDirective(token) == DIRECTIVE_ELIF)); in parseExpressionIf()
857 macroExpander.lex(token); in parseExpressionIf()
858 expressionParser.parse(token, &expression); in parseExpressionIf()
861 if (!isEOD(token)) in parseExpressionIf()
864 token->location, token->text); in parseExpressionIf()
865 skipUntilEOD(mTokenizer, token); in parseExpressionIf()
871 int DirectiveParser::parseExpressionIfdef(Token* token) in parseExpressionIfdef() argument
873 assert((getDirective(token) == DIRECTIVE_IFDEF) || in parseExpressionIfdef()
874 (getDirective(token) == DIRECTIVE_IFNDEF)); in parseExpressionIfdef()
876 mTokenizer->lex(token); in parseExpressionIfdef()
877 if (token->type != Token::IDENTIFIER) in parseExpressionIfdef()
880 token->location, token->text); in parseExpressionIfdef()
881 skipUntilEOD(mTokenizer, token); in parseExpressionIfdef()
885 MacroSet::const_iterator iter = mMacroSet->find(token->text); in parseExpressionIfdef()
889 mTokenizer->lex(token); in parseExpressionIfdef()
890 if (!isEOD(token)) in parseExpressionIfdef()
893 token->location, token->text); in parseExpressionIfdef()
894 skipUntilEOD(mTokenizer, token); in parseExpressionIfdef()