21 #ifndef templatesimplifierH
22 #define templatesimplifierH
32 #include <unordered_map>
47 friend class TestSimplifyTemplate;
52 const std::string&
dump()
const {
58 void checkComplicatedSyntaxErrorsInTemplates();
66 static unsigned int templateParameters(
const Token *tok);
82 fIsFunction = (1 << 1),
83 fIsVariable = (1 << 2),
85 fIsSpecialization = (1 << 4),
86 fIsPartialSpecialization = (1 << 5),
87 fIsForwardDeclaration = (1 << 6),
88 fIsVariadic = (1 << 7),
90 fFamilyMask = (fIsClass | fIsFunction | fIsVariable)
94 setFlag(fIsClass, state);
97 setFlag(fIsFunction, state);
100 setFlag(fIsVariable, state);
103 setFlag(fIsAlias, state);
106 setFlag(fIsSpecialization, state);
109 setFlag(fIsPartialSpecialization, state);
112 setFlag(fIsForwardDeclaration, state);
115 setFlag(fIsVariadic, state);
118 setFlag(fIsFriend, state);
127 return ((mFlags & flag) != 0);
136 mFlags = state ? mFlags | flag : mFlags & ~flag;
162 std::string dump(
const std::vector<std::string>& fileNames)
const;
174 const std::string &
name()
const {
191 return getFlag(fIsClass);
194 return getFlag(fIsFunction);
197 return getFlag(fIsVariable);
200 return getFlag(fIsAlias);
203 return getFlag(fIsSpecialization);
206 return getFlag(fIsPartialSpecialization);
209 return getFlag(fIsForwardDeclaration);
212 return getFlag(fIsVariadic);
215 return getFlag(fIsFriend);
224 const Token * aliasStartToken()
const;
232 const Token * aliasEndToken()
const;
241 bool isAliasToken(
const Token *tok)
const;
252 return ((mFlags & fFamilyMask) && (decl.
mFlags & fFamilyMask));
261 static Token *findTemplateDeclarationEnd(
Token *tok);
262 static const Token *findTemplateDeclarationEnd(
const Token *tok);
272 static bool instantiateMatch(
const Token *instance,
const std::size_t
numberOfArguments,
bool variadic,
const char patternAfter[]);
280 int getTemplateNamePosition(
const Token *tok);
288 static bool getTemplateNamePositionTemplateClass(
const Token *tok,
int &namepos);
296 static bool getTemplateNamePositionTemplateFunction(
const Token *tok,
int &namepos);
304 static bool getTemplateNamePositionTemplateVariable(
const Token *tok,
int &namepos);
310 void simplifyTemplates(
const std::time_t maxtime);
318 static bool simplifyNumericCalculations(
Token *tok,
bool isTemplate =
true);
326 bool simplifyCalculations(
Token* frontToken =
nullptr,
const Token *backToken =
nullptr,
bool isTemplate =
true);
332 void simplifyTemplateArgs(
Token *start,
const Token *end, std::vector<newInstantiation>* newInst =
nullptr);
339 bool getTemplateDeclarations();
345 void addInstantiation(
Token *token,
const std::string &scope);
350 void getTemplateInstantiations();
356 void fixForwardDeclaredDefaultArgumentValues();
361 void useDefaultArgumentValues();
367 void useDefaultArgumentValues(TokenAndName &declaration);
373 void getSpecializations();
379 void getPartialSpecializations();
384 void simplifyTemplateAliases();
395 bool simplifyTemplateInstantiations(
396 const TokenAndName &templateDeclaration,
397 const std::list<const Token *> &specializations,
398 const std::time_t maxtime,
399 std::set<std::string> &expandedtemplates);
406 void addNamespace(
const TokenAndName &templateDeclaration,
const Token *tok);
414 static bool alreadyHasNamespace(
const TokenAndName &templateDeclaration,
const Token *tok);
425 const TokenAndName &templateDeclaration,
426 const TokenAndName &templateInstantiation,
427 const std::vector<const Token *> &typeParametersInDeclaration,
428 const std::string &newName,
437 void replaceTemplateUsage(
const TokenAndName &instantiation,
438 const std::list<std::string> &typeStringsUsedInTemplateInstantiation,
439 const std::string &newName);
448 static void getTemplateParametersInDeclaration(
450 std::vector<const Token *> & typeParametersInDeclaration);
455 static bool removeTemplate(
Token *tok, std::map<Token*, Token*>* forwardDecls =
nullptr);
460 static bool matchSpecialization(
461 const Token *templateDeclarationNameToken,
462 const Token *templateInstantiationNameToken,
463 const std::list<const Token *> & specializations);
470 static void eraseTokens(
Token *begin,
const Token *end);
477 static void deleteToken(
Token *tok);
485 std::string getNewName(
487 std::list<std::string> &typeStringsUsedInTemplateInstantiation);
490 const TokenAndName &tokenAndName,
491 const std::string &
indent =
" ")
const;
492 void printOut(
const std::string &text =
emptyString)
const;
int numberOfArguments(const Token *ftok)
Determines the number of arguments - if token is a function call or macro.
This is an interface, which the class responsible of error logging should implement.
This is just a container for general settings so that we don't need to pass individual values to func...
Token and its full scopename.
void setFlag(unsigned int flag, bool state)
Set specified flag state.
bool getFlag(unsigned int flag) const
Get specified flag state.
void isFriend(bool state)
const Token * paramEnd() const
bool isForwardDeclaration() const
bool isSameFamily(const TemplateSimplifier::TokenAndName &decl) const
Is declaration the same family (class, function or variable).
void isFunction(bool state)
const std::string & scope() const
void isPartialSpecialization(bool state)
void isSpecialization(bool state)
void paramEnd(const Token *end)
const std::string & name() const
bool isPartialSpecialization() const
void isVariable(bool state)
const std::string & fullName() const
const Token * nameToken() const
void isForwardDeclaration(bool state)
bool isSpecialization() const
void isVariadic(bool state)
Simplify templates from the preprocessed and partially simplified code.
std::list< TokenAndName > mTemplateDeclarations
std::list< TokenAndName > mInstantiatedTemplates
std::vector< TokenAndName > mTypesUsedInTemplateInstantiation
std::vector< TokenAndName > mExplicitInstantiationsToDelete
std::list< TokenAndName > mTemplateForwardDeclarations
ErrorLogger & mErrorLogger
std::unordered_map< const Token *, int > mTemplateNamePos
const Settings & mSettings
const std::string & dump() const
std::list< TokenAndName > mTemplateInstantiations
std::map< Token *, Token * > mTemplateForwardDeclarationsMap
std::list< TokenAndName > mMemberFunctionsToDelete
std::map< Token *, Token * > mTemplatePartialSpecializationMap
std::map< Token *, Token * > mTemplateSpecializationMap
The token list that the TokenList generates is a linked-list of this class.
The main purpose is to tokenize the source code.
static const std::string emptyString
bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2)
static void indent(std::string &str, const nonneg int indent1, const nonneg int indent2)