Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tokenize.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2016 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 //---------------------------------------------------------------------------
20 #ifndef tokenizeH
21 #define tokenizeH
22 //---------------------------------------------------------------------------
23 
24 #include "config.h"
25 #include "errorlogger.h"
26 #include "tokenlist.h"
27 
28 #include <ctime>
29 #include <list>
30 #include <map>
31 #include <string>
32 
33 class Settings;
34 class SymbolDatabase;
35 class TimerResults;
36 class Token;
37 
38 namespace simplecpp {
39  class TokenList;
40 }
41 
42 /// @addtogroup Core
43 /// @{
44 
45 /** @brief The main purpose is to tokenize the source code. It also has functions that simplify the token list */
47 
48  friend class TestSimplifyTokens;
49  friend class TestSimplifyTypedef;
50  friend class TestTokenizer;
51  friend class SymbolDatabase;
52 public:
53  Tokenizer();
54  Tokenizer(const Settings * settings, ErrorLogger *errorLogger);
55  ~Tokenizer();
56 
58  m_timerResults = tr;
59  }
60 
61  /** Is the code C. Used for bailouts */
62  bool isC() const {
63  return list.isC();
64  }
65 
66  /** Is the code CPP. Used for bailouts */
67  bool isCPP() const {
68  return list.isCPP();
69  }
70 
71  /**
72  * Check if inner scope ends with a call to a noreturn function
73  * \param endScopeToken The '}' token
74  * \param unknown set to true if it's unknown if the scope is noreturn
75  * \return true if scope ends with a function call that might be 'noreturn'
76  */
77  bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = nullptr) const;
78 
79  bool createTokens(std::istream &code, const std::string& FileName);
80  void createTokens(const simplecpp::TokenList *tokenList);
81 
82  bool simplifyTokens1(const std::string &configuration);
83  /**
84  * Tokenize code
85  * @param code input stream for code, e.g.
86  * \code
87  * #file "p.h"
88  * class Foo
89  * {
90  * private:
91  * void Bar();
92  * };
93  *
94  * #endfile
95  * void Foo::Bar()
96  * {
97  * }
98  * \endcode
99  *
100  * @param FileName The filename
101  * @param configuration E.g. "A" for code where "#ifdef A" is true
102  * @return false if source code contains syntax errors
103  */
104  bool tokenize(std::istream &code,
105  const char FileName[],
106  const std::string &configuration = emptyString);
107 
108  /** Set variable id */
109  void setVarId();
110  void setVarIdPass1();
111  void setVarIdPass2();
112 
113  /**
114  * Basic simplification of tokenlist
115  *
116  * @param FileName The filename to run; used to do
117  * markup checks.
118  *
119  * @return false if there is an error that requires aborting
120  * the checking of this file.
121  */
122  bool simplifyTokenList1(const char FileName[]);
123 
124  void SimplifyNamelessRValueReferences();
125 
126  /**
127  * Most aggressive simplification of tokenlist
128  *
129  * @return false if there is an error that requires aborting
130  * the checking of this file.
131  */
132  bool simplifyTokenList2();
133 
134  /**
135  * Deletes dead code between 'begin' and 'end'.
136  * In general not everything can be erased, such as:
137  * - code after labels;
138  * - code outside the scope where the function is called;
139  * - code after a change of scope caused by 'switch(...);'
140  * instructions, like 'case %any%;' or 'default;'
141  * Also, if the dead code contains a 'switch' block
142  * and inside it there's a label, the function removes all
143  * the 'switch(..)' tokens and every occurrence of 'case %any%; | default;'
144  * expression, such as the 'switch' block is reduced to a simple block.
145  *
146  * @param begin Tokens after this have a possibility to be erased.
147  * @param end Tokens before this have a possibility to be erased.
148  */
149  static void eraseDeadCode(Token *begin, const Token *end);
150 
151  /**
152  * Simplify '* & ( %name% ) =' or any combination of '* &' and '()'
153  * parentheses around '%name%' to '%name% ='
154  */
155  void simplifyMulAndParens();
156 
157  /**
158  * Calculates sizeof value for given type.
159  * @param type Token which will contain e.g. "int", "*", or string.
160  * @return sizeof for given type, or 0 if it can't be calculated.
161  */
162  unsigned int sizeOfType(const Token *type) const;
163 
164  /**
165  * Try to determine if function parameter is passed by value by looking
166  * at the function declaration.
167  * @param fpar token for function parameter in the function call
168  * @return true if the parameter is passed by value. if unsure, false is returned
169  */
170  bool isFunctionParameterPassedByValue(const Token *fpar) const;
171 
172  /** Simplify assignment in function call "f(x=g());" => "x=g();f(x);"
173  */
174  void simplifyAssignmentInFunctionCall();
175 
176  /** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */
177  void simplifyAssignmentBlock();
178 
179  /**
180  * Simplify constant calculations such as "1+2" => "3"
181  * @return true if modifications to token-list are done.
182  * false if no modifications are done.
183  */
184  bool simplifyCalculations();
185 
186  /**
187  * Simplify dereferencing a pointer offset by a number:
188  * "*(ptr + num)" => "ptr[num]"
189  * "*(ptr - num)" => "ptr[-num]"
190  */
191  void simplifyOffsetPointerDereference();
192 
193  /**
194  * Simplify referencing a pointer offset:
195  * "Replace "&str[num]" => "(str + num)"
196  */
197  void simplifyOffsetPointerReference();
198 
199  /** Insert array size where it isn't given */
200  void arraySize();
201 
202  /** Simplify labels and 'case|default' syntaxes.
203  */
204  void simplifyLabelsCaseDefault();
205 
206  /** simplify case ranges (gcc extension)
207  */
208  void simplifyCaseRange();
209 
210  /** Remove macros in global scope */
211  void removeMacrosInGlobalScope();
212 
213  /** Remove undefined macro in class definition:
214  * class DLLEXPORT Fred { };
215  * class Fred FINAL : Base { };
216  */
217  void removeMacroInClassDef();
218 
219  /** Remove unknown macro in variable declarations: PROGMEM char x; */
220  void removeMacroInVarDecl();
221 
222  /** Remove redundant assignment */
223  void removeRedundantAssignment();
224 
225  /** Simplifies some realloc usage like
226  * 'x = realloc (0, n);' => 'x = malloc(n);'
227  * 'x = realloc (y, 0);' => 'x = 0; free(y);'
228  */
229  void simplifyRealloc();
230 
231  /** Add parentheses for sizeof: sizeof x => sizeof(x) */
232  void sizeofAddParentheses();
233 
234  /**
235  * Replace sizeof() to appropriate size.
236  * @return true if modifications to token-list are done.
237  * false if no modifications are done.
238  */
239  bool simplifySizeof();
240 
241  /**
242  * Simplify variable declarations (split up)
243  * \param only_k_r_fpar Only simplify K&R function parameters
244  */
245  void simplifyVarDecl(const bool only_k_r_fpar);
246  void simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, const bool only_k_r_fpar);
247 
248  /**
249  * Simplify variable initialization
250  * '; int *p(0);' => '; int *p = 0;'
251  */
252  void simplifyInitVar();
253  Token * initVar(Token * tok);
254 
255  /**
256  * Convert platform dependent types to standard types.
257  * 32 bits: size_t -> unsigned long
258  * 64 bits: size_t -> unsigned long long
259  */
260  void simplifyPlatformTypes();
261 
262  /**
263  * Simplify easy constant '?:' operation
264  * Example: 0 ? (2/0) : 0 => 0
265  * @return true if something is modified
266  * false if nothing is done.
267  */
268  bool simplifyConstTernaryOp();
269 
270  /**
271  * Simplify compound assignments
272  * Example: ";a+=b;" => ";a=a+b;"
273  */
274  void simplifyCompoundAssignment();
275 
276  /**
277  * Simplify the location of "static" and "const" qualifiers in
278  * a variable declaration or definition.
279  * Example: "int static const a;" => "static const a;"
280  * Example: "long long const static b;" => "static const long long b;"
281  */
282  void simplifyStaticConst();
283 
284  /**
285  * Simplify assignments in "if" and "while" conditions
286  * Example: "if(a=b);" => "a=b;if(a);"
287  * Example: "while(a=b) { f(a); }" => "a = b; while(a){ f(a); a = b; }"
288  * Example: "do { f(a); } while(a=b);" => "do { f(a); a = b; } while(a);"
289  */
290  void simplifyIfAndWhileAssign();
291 
292  /**
293  * Simplify multiple assignments.
294  * Example: "a = b = c = 0;" => "a = 0; b = 0; c = 0;"
295  */
296  void simplifyVariableMultipleAssign();
297 
298  /**
299  * Simplify the 'C Alternative Tokens'
300  * Examples:
301  * "if(s and t)" => "if(s && t)"
302  * "while((r bitand s) and not t)" => while((r & s) && !t)"
303  * "a and_eq b;" => "a &= b;"
304  */
305  bool simplifyCAlternativeTokens();
306 
307  /**
308  * Simplify comma into a semicolon when possible:
309  * - "delete a, delete b" => "delete a; delete b;"
310  * - "a = 0, b = 0;" => "a = 0; b = 0;"
311  * - "return a(), b;" => "a(); return b;"
312  */
313  void simplifyComma();
314 
315  /** Add braces to an if-block, for-block, etc.
316  * @return true if no syntax errors
317  */
318  bool simplifyAddBraces();
319 
320  /** Add braces to an if-block, for-block, etc.
321  * for command starting at token including else-block
322  * @return last token of command
323  * or input token in case of an error where no braces are added
324  * or NULL when syntaxError is called
325  */
326  Token * simplifyAddBracesToCommand(Token * tok);
327 
328  /** Add pair of braces to an single if-block, else-block, for-block, etc.
329  * for command starting at token
330  * @return last token of command
331  * or input token in case of an error where no braces are added
332  * or NULL when syntaxError is called
333  */
334  Token * simplifyAddBracesPair(Token *tok, bool commandWithCondition);
335 
336  /**
337  * typedef A mytype;
338  * mytype c;
339  *
340  * Becomes:
341  * typedef A mytype;
342  * A c;
343  */
344  void simplifyTypedef();
345 
346  /**
347  * Simplify casts
348  */
349  void simplifyCasts();
350 
351  /**
352  * Change (multiple) arrays to (multiple) pointers.
353  */
354  void simplifyUndefinedSizeArray();
355 
356  /**
357  * A simplify function that replaces a variable with its value in cases
358  * when the value is known. e.g. "x=10; if(x)" => "x=10;if(10)"
359  *
360  * @return true if modifications to token-list are done.
361  * false if no modifications are done.
362  */
363  bool simplifyKnownVariables();
364 
365  /**
366  * Utility function for simplifyKnownVariables. Get data about an
367  * assigned variable.
368  */
369  static bool simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar);
370 
371  /**
372  * utility function for simplifyKnownVariables. Perform simplification
373  * of a given variable
374  */
375  bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const;
376 
377  /** Simplify useless C++ empty namespaces, like: 'namespace %name% { }'*/
378  void simplifyEmptyNamespaces();
379 
380  /** Simplify redundant code placed after control flow statements :
381  * 'return', 'throw', 'goto', 'break' and 'continue'
382  */
383  void simplifyFlowControl();
384 
385  /** Expand nested strcat() calls. */
386  void simplifyNestedStrcat();
387 
388  /** Simplify "if else" */
389  void elseif();
390 
391  /** Simplify conditions
392  * @return true if something is modified
393  * false if nothing is done.
394  */
395  bool simplifyConditions();
396 
397  /** Remove redundant code, e.g. if( false ) { int a; } should be
398  * removed, because it is never executed.
399  * @return true if something is modified
400  * false if nothing is done.
401  */
402  bool removeRedundantConditions();
403 
404  /**
405  * Remove redundant for:
406  * "for (x=0;x<1;x++) { }" => "{ x = 1; }"
407  */
408  void removeRedundantFor();
409 
410 
411  /**
412  * Reduces "; ;" to ";", except in "( ; ; )"
413  */
414  void removeRedundantSemicolons();
415 
416  /** Simplify function calls - constant return value
417  * @return true if something is modified
418  * false if nothing is done.
419  */
420  bool simplifyFunctionReturn();
421 
422  /** Struct simplification
423  * "struct S { } s;" => "struct S { }; S s;"
424  */
425 
426  void simplifyStructDecl();
427 
428  /**
429  * Remove redundant parentheses:
430  * - "((x))" => "(x)"
431  * - "(function())" => "function()"
432  * - "(delete x)" => "delete x"
433  * - "(delete [] x)" => "delete [] x"
434  * @return true if modifications to token-list are done.
435  * false if no modifications are done.
436  */
437  bool simplifyRedundantParentheses();
438 
439  void simplifyCharAt();
440 
441  /** Simplify references */
442  void simplifyReference();
443 
444  /**
445  * Simplify functions like "void f(x) int x; {"
446  * into "void f(int x) {"
447  */
448  void simplifyFunctionParameters();
449 
450  /**
451  * Simplify templates
452  */
453  void simplifyTemplates();
454 
455  void simplifyDoublePlusAndDoubleMinus();
456 
457  void simplifyRedundantConsecutiveBraces();
458 
459  void simplifyArrayAccessSyntax();
460 
461  void simplifyParameterVoid();
462 
463  void fillTypeSizes();
464 
465  void combineOperators();
466 
467  void combineStringAndCharLiterals();
468 
469  void concatenateNegativeNumberAndAnyPositive();
470 
471  void simplifyExternC();
472 
473  void simplifyRoundCurlyParentheses();
474 
475  void simplifySQL();
476 
477  void checkForEnumsWithTypedef();
478 
479  void findComplicatedSyntaxErrorsInTemplates();
480 
481  /**
482  * Simplify e.g. 'atol("0")' into '0'
483  */
484  void simplifyMathFunctions();
485 
486  /**
487  * Simplify e.g. 'sin(0)' into '0'
488  */
489  void simplifyMathExpressions();
490 
491  /**
492  * Modify strings in the token list by replacing hex and oct
493  * values. E.g. "\x61" -> "a" and "\000" -> "\0"
494  * @param source The string to be modified, e.g. "\x61"
495  * @return Modified string, e.g. "a"
496  */
497  static std::string simplifyString(const std::string &source);
498 
499  /**
500  * is token pointing at function head?
501  * @param tok A '(' or ')' token in a possible function head
502  * @param endsWith string after function head
503  * @return token matching with endsWith if syntax seems to be a function head else nullptr
504  */
505  const Token * isFunctionHead(const Token *tok, const std::string &endsWith) const;
506 
507 private:
508 
509  /**
510  * is token pointing at function head?
511  * @param tok A '(' or ')' token in a possible function head
512  * @param endsWith string after function head
513  * @param cpp c++ code
514  * @return token matching with endsWith if syntax seems to be a function head else nullptr
515  */
516  static const Token * isFunctionHead(const Token *tok, const std::string &endsWith, bool cpp);
517 
518  /**
519  * simplify "while (0)"
520  */
521  void simplifyWhile0();
522 
523  /**
524  * Simplify while(func() && errno==EINTR)
525  */
526  void simplifyErrNoInWhile();
527 
528  /**
529  * Simplify while(func(f))
530  */
531  void simplifyFuncInWhile();
532 
533  /**
534  * Remove "std::" before some function names
535  */
536  void simplifyStd();
537 
538  /** Simplify pointer to standard type (C only) */
539  void simplifyPointerToStandardType();
540 
541  /** Simplify function pointers */
542  void simplifyFunctionPointers();
543 
544  /**
545  * Send error message to error logger about internal bug.
546  * @param tok the token that this bug concerns.
547  */
548  void cppcheckError(const Token *tok) const;
549 
550  /**
551  * Setup links for tokens so that one can call Token::link().
552  */
553  void createLinks();
554 
555  /**
556  * Setup links between < and >.
557  */
558  void createLinks2();
559 
560 public:
561 
562  /** Syntax error */
563  void syntaxError(const Token *tok) const;
564 
565  /** Syntax error. Example: invalid number of ')' */
566  void syntaxError(const Token *tok, char c) const;
567 
568  /** Syntax error. C++ code in C file. */
569  void syntaxErrorC(const Token *tok, const std::string &what) const;
570 
571 private:
572 
573  /** Report that there is an unhandled "class x y {" code */
574  void unhandled_macro_class_x_y(const Token *tok) const;
575 
576  /** Check configuration (unknown macros etc) */
577  void checkConfiguration() const;
578  void macroWithSemicolonError(const Token *tok, const std::string &macroName) const;
579 
580  /**
581  * Is there C++ code in C file?
582  */
583  void validateC() const;
584 
585  /**
586  * assert that tokens are ok - used during debugging for example
587  * to catch problems in simplifyTokenList1/2.
588  */
589  void validate() const;
590 
591  /** Detect garbage code */
592  const Token * findGarbageCode() const;
593 
594  /** Detect garbage expression */
595  static bool isGarbageExpr(const Token *start, const Token *end);
596 
597  /**
598  * Remove __declspec()
599  */
600  void simplifyDeclspec();
601 
602  /**
603  * Remove calling convention
604  */
605  void simplifyCallingConvention();
606 
607  /**
608  * Remove __attribute__ ((?))
609  */
610  void simplifyAttribute();
611 
612  /**
613  * Remove keywords "volatile", "inline", "register", and "restrict"
614  */
615  void simplifyKeyword();
616 
617  /**
618  * Remove __asm
619  */
620  void simplifyAsm();
621 
622  /**
623  * asm heuristics, Put ^{} statements in asm()
624  */
625  void simplifyAsm2();
626 
627  /**
628  * Simplify bitfields - the field width is removed as we don't use it.
629  */
630  void simplifyBitfields();
631 
632  /**
633  * Remove unnecessary member qualification
634  */
635  void removeUnnecessaryQualification();
636 
637  /**
638  * Add std:: in front of std classes, when using namespace std; was given
639  */
640  void simplifyNamespaceStd();
641 
642  /**
643  * Convert Microsoft memory functions
644  * CopyMemory(dst, src, len) -> memcpy(dst, src, len)
645  * FillMemory(dst, len, val) -> memset(dst, val, len)
646  * MoveMemory(dst, src, len) -> memmove(dst, src, len)
647  * ZeroMemory(dst, len) -> memset(dst, 0, len)
648  */
649  void simplifyMicrosoftMemoryFunctions();
650 
651  /**
652  * Convert Microsoft string functions
653  * _tcscpy -> strcpy
654  */
655  void simplifyMicrosoftStringFunctions();
656 
657  /**
658  * Remove Borland code
659  */
660  void simplifyBorland();
661 
662  /**
663  * Remove Qt signals and slots
664  */
665  void simplifyQtSignalsSlots();
666 
667  /**
668  * Collapse operator name tokens into single token
669  * operator = => operator=
670  */
671  void simplifyOperatorName();
672 
673  /**
674  * Remove [[deprecated]] (C++14) from TokenList
675  */
676  void simplifyDeprecated();
677 
678  /**
679  * Replace strlen(str)
680  * @return true if any replacement took place, false else
681  * */
682  bool simplifyStrlen();
683 
684  /**
685  * Prepare ternary operators with parentheses so that the AST can be created
686  * */
687  void prepareTernaryOpForAST();
688 
689  /**
690  * check for duplicate enum definition
691  */
692  static bool duplicateDefinition(Token **tokPtr);
693 
694  /**
695  * report error message
696  */
697  void reportError(const Token* tok, const Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const;
698  void reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const;
699 
700  bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const;
701 
702  void unsupportedTypedef(const Token *tok) const;
703 
704  void setVarIdClassDeclaration(const Token * const startToken,
705  const std::map<std::string, unsigned int> &variableId,
706  const unsigned int scopeStartVarId,
707  std::map<unsigned int, std::map<std::string,unsigned int> >& structMembers);
708 
709 
710  /**
711  * Simplify e.g. 'return(strncat(temp,"a",1));' into
712  * strncat(temp,"a",1); return temp;
713  */
714  void simplifyReturnStrncat();
715 
716  /**
717  * Output list of unknown types.
718  */
719  void printUnknownTypes() const;
720 
721  /** Find end of SQL (or PL/SQL) block */
722  const Token *findSQLBlockEnd(const Token *tokSQLStart) const;
723 
724 public:
725 
726  /** Was there templates in the code? */
727  bool codeWithTemplates() const {
728  return _codeWithTemplates;
729  }
730 
731 
732  void setSettings(const Settings *settings) {
733  _settings = settings;
734  list.setSettings(settings);
735  }
736 
738  return _symbolDatabase;
739  }
740  void createSymbolDatabase();
741  void deleteSymbolDatabase();
742 
743  /** print --debug output if debug flags match the simplification:
744  * 0=unknown/both simplifications
745  * 1=1st simplifications
746  * 2=2nd simplifications
747  */
748  void printDebugOutput(unsigned int simplification) const;
749 
750  void dump(std::ostream &out) const;
751 
752  Token *deleteInvalidTypedef(Token *typeDef);
753 
754  /**
755  * Get variable count.
756  * @return number of variables
757  */
758  unsigned int varIdCount() const {
759  return _varId;
760  }
761 
762  /**
763  * Token list: stores all tokens.
764  */
766  // Implement tokens() as a wrapper for convenience when using the TokenList
767  const Token* tokens() const {
768  return list.front();
769  }
770 
771  /**
772  * Copy tokens.
773  * @param dest destination token where copied tokens will be inserted after
774  * @param first first token to copy
775  * @param last last token to copy
776  * @param one_line true=>copy all tokens to the same line as dest. false=>copy all tokens to dest while keeping the 'line breaks'
777  * @return new location of last token copied
778  */
779  static Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true);
780 
781  /**
782  * Helper function to check whether number is zero (0 or 0.0 or 0E+0) or not?
783  * @param s the string to check
784  * @return true in case is is zero and false otherwise.
785  */
786  static bool isZeroNumber(const std::string &s);
787 
788  /**
789  * Helper function to check whether number is one (1 or 0.1E+1 or 1E+0) or not?
790  * @param s the string to check
791  * @return true in case is is one and false otherwise.
792  */
793  static bool isOneNumber(const std::string &s);
794 
795  /**
796  * Helper function to check whether number is two (2 or 0.2E+1 or 2E+0) or not?
797  * @param s the string to check
798  * @return true in case is is two and false otherwise.
799  */
800  static bool isTwoNumber(const std::string &s);
801 
802  /**
803  * Helper function to check for start of function execution scope.
804  * Do not use this in checks. Use the symbol database.
805  * @param tok pointer to end parentheses of parameter list
806  * @return pointer to start brace of function scope or nullptr if not start.
807  */
808  static const Token * startOfExecutableScope(const Token * tok);
809 
810 #ifdef MAXTIME
811  bool isMaxTime() const {
812  return (std::time(0) > maxtime);
813 #else
814  static bool isMaxTime() {
815  return false;
816 #endif
817  }
818 
819 private:
820  /** Disable copy constructor, no implementation */
821  Tokenizer(const Tokenizer &);
822 
823  /** Disable assignment operator, no implementation */
824  Tokenizer &operator=(const Tokenizer &);
825 
826  Token *processFunc(Token *tok2, bool inOperator) const;
827 
828  /**
829  * Get new variable id.
830  * @return new variable id
831  */
832  unsigned int newVarId() {
833  return ++_varId;
834  }
835 
836  /** Set pod types */
837  void setPodTypes();
838 
839  /** settings */
841 
842  /** errorlogger */
844 
845  /** Symbol database that all checks etc can use */
847 
848  /** E.g. "A" for code where "#ifdef A" is true. This is used to
849  print additional information in error situations. */
850  std::string _configuration;
851 
852  /** sizeof information for known types */
853  std::map<std::string, unsigned int> _typeSize;
854 
855  /** variable count */
856  unsigned int _varId;
857 
858  /**
859  * was there any templates? templates that are "unused" are
860  * removed from the token list
861  */
863 
864  /**
865  * TimerResults
866  */
868 
869 #ifdef MAXTIME
870  /** Tokenizer maxtime */
871  std::time_t maxtime;
872 #endif
873 };
874 
875 /// @}
876 
877 //---------------------------------------------------------------------------
878 #endif // tokenizeH
bool isCPP() const
Is the code CPP.
Definition: tokenize.h:67
TimerResults * m_timerResults
TimerResults.
Definition: tokenize.h:867
std::string _configuration
E.g.
Definition: tokenize.h:850
ErrorLogger *const _errorLogger
errorlogger
Definition: tokenize.h:843
The main purpose is to tokenize the source code.
Definition: tokenize.h:46
SymbolDatabase * _symbolDatabase
Symbol database that all checks etc can use.
Definition: tokenize.h:846
#define CPPCHECKLIB
Definition: config.h:13
bool _codeWithTemplates
was there any templates? templates that are "unused" are removed from the token list ...
Definition: tokenize.h:862
unsigned int newVarId()
Get new variable id.
Definition: tokenize.h:832
void setTimerResults(TimerResults *tr)
Definition: tokenize.h:57
bool isC() const
Is the code C.
Definition: tokenize.h:62
const Settings * _settings
settings
Definition: tokenize.h:840
std::map< std::string, unsigned int > _typeSize
sizeof information for known types
Definition: tokenize.h:853
static const std::string emptyString
Definition: config.h:23
unsigned int sizeOfType(const Token *type) const
Calculates sizeof value for given type.
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:174
const Settings * _settings
bool endsWith(const std::string &str, char c)
Definition: utils.h:61
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:50
SeverityType
Message severities.
Definition: errorlogger.h:70
const Token * tokens() const
Definition: tokenize.h:767
const Token * front() const
get first token of list
Definition: tokenlist.h:96
void validate() const
static bool isMaxTime()
Definition: tokenize.h:814
bool codeWithTemplates() const
Was there templates in the code?
Definition: tokenize.h:727
const SymbolDatabase * getSymbolDatabase() const
Definition: tokenize.h:737
void setSettings(const Settings *settings)
Definition: tokenize.h:732
The token list that the TokenList generates is a linked-list of this class.
Definition: token.h:55
TokenList list
Token list: stores all tokens.
Definition: tokenize.h:765
unsigned int varIdCount() const
Get variable count.
Definition: tokenize.h:758
unsigned int _varId
variable count
Definition: tokenize.h:856