MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / compileTerm

Function compileTerm

lib/tokenlist.cpp:771–922  ·  view source on GitHub ↗

* @throws InternalError thrown if unexpected tokens are encountered */

Source from the content-addressed store, hash-verified

769 * @throws InternalError thrown if unexpected tokens are encountered
770 */
771static void compileTerm(Token *&tok, AST_state& state)
772{
773 if (!tok)
774 return;
775 if (Token::Match(tok, "L %str%|%char%"))
776 tok = tok->next();
777 if (state.inArrayAssignment && Token::Match(tok->previous(), "[{,] . %name%")) { // Jump over . in C style struct initialization
778 state.op.push(tok);
779 tok->astOperand1(tok->next());
780 tok = tok->tokAt(2);
781 }
782 if (state.inArrayAssignment && Token::Match(tok->previous(), "[{,] [ %num%|%name% ]")) {
783 state.op.push(tok);
784 tok->astOperand1(tok->next());
785 tok = tok->tokAt(3);
786 }
787 if (tok->isLiteral()) {
788 state.op.push(tok);
789 do {
790 tok = tok->next();
791 } while (Token::Match(tok, "%name%|%str%"));
792 } else if (tok->isName()) {
793 if (Token::Match(tok, "return|case") || (state.cpp && (tok->str() == "throw"))) {
794 if (tok->str() == "case")
795 state.inCase = true;
796 const bool tokIsReturn = tok->str() == "return";
797 const bool stopAtColon = state.stopAtColon;
798 state.stopAtColon=true;
799 compileUnaryOp(tok, state, compileExpression);
800 state.stopAtColon=stopAtColon;
801 if (tokIsReturn)
802 state.op.pop();
803 if (state.inCase && Token::simpleMatch(tok, ": ;")) {
804 state.inCase = false;
805 tok = tok->next();
806 }
807 } else if (Token::Match(tok, "sizeof !!(")) {
808 compileUnaryOp(tok, state, compileExpression);
809 state.op.pop();
810 } else if (state.cpp && findCppTypeInitPar(tok)) { // int(0), int*(123), ..
811 tok = findCppTypeInitPar(tok);
812 state.op.push(tok);
813 tok = tok->tokAt(2);
814 } else if (state.cpp && iscpp11init(tok)) { // X{} X<Y>{} etc
815 state.op.push(tok);
816 tok = tok->next();
817 if (tok->str() == "<")
818 tok = tok->link()->next();
819
820 if (Token::Match(tok, "{ . %name% =|{")) {
821 const Token* end = tok->link();
822 const int inArrayAssignment = state.inArrayAssignment;
823 state.inArrayAssignment = 1;
824 compileBinOp(tok, state, compileExpression);
825 state.inArrayAssignment = inArrayAssignment;
826 if (tok == end)
827 tok = tok->next();
828 else

Callers 1

compileScopeFunction · 0.85

Calls 15

compileUnaryOpFunction · 0.85
findCppTypeInitParFunction · 0.85
iscpp11initFunction · 0.85
compileBinOpFunction · 0.85
skipDeclFunction · 0.85
compileExpressionFunction · 0.85
iscastFunction · 0.85
precedesFunction · 0.85
findsimplematchFunction · 0.85
nextMethod · 0.80
astOperand1Method · 0.80
linkAtMethod · 0.80

Tested by

no test coverage detected