diff --git a/CodeCompletionsTests/CCTest/cctest.cpp b/CodeCompletionsTests/CCTest/cctest.cpp index 007337b361..a170e90c64 100644 --- a/CodeCompletionsTests/CCTest/cctest.cpp +++ b/CodeCompletionsTests/CCTest/cctest.cpp @@ -438,8 +438,8 @@ TEST_FUNC(testBoostSharedPtr) std::vector tags; TagsManagerST::Get()->AutoCompleteCandidates(wxFileName(wxT("../tests/boost_shared_ptr.h")), 2, - wxT("autoPtr->second->"), - LoadFile(wxT("../tests/test_auto_simple.h")), + wxT("s->"), + LoadFile(wxT("../tests/boost_shared_ptr.h")), tags); CHECK_SIZE(tags.size(), CLASS_WITH_MEMBERS_COUNT); return true; diff --git a/CodeCompletionsTests/SampleWorkspace/SampleWorksapce.project b/CodeCompletionsTests/SampleWorkspace/SampleWorksapce.project index 7c92b3de2c..b54bc5bca5 100644 --- a/CodeCompletionsTests/SampleWorkspace/SampleWorksapce.project +++ b/CodeCompletionsTests/SampleWorkspace/SampleWorksapce.project @@ -1,6 +1,9 @@ + + + - - - @@ -70,12 +70,12 @@ - + - D:\src\wxWidgets\include -C:\src\codelite + C:\src\codelite +$BOOST_HOME diff --git a/CodeCompletionsTests/SampleWorkspace/header.h b/CodeCompletionsTests/SampleWorkspace/header.h index 79e26eb942..3b9421b758 100644 --- a/CodeCompletionsTests/SampleWorkspace/header.h +++ b/CodeCompletionsTests/SampleWorkspace/header.h @@ -28,6 +28,7 @@ #include #include #include +#include struct ST { std::string name; @@ -131,7 +132,7 @@ typedef std::vector VectorTypedef_t; // Template class with static member template -class Foo +class FooTemplate { T* t; @@ -139,4 +140,5 @@ class Foo static T* Get() { return t; } }; -typedef Foo Foo_t; +//ContextManager::Get()-> +typedef FooTemplate Foo_t; diff --git a/CodeLite/language.cpp b/CodeLite/language.cpp index 300deaaa28..cf3ce37d40 100644 --- a/CodeLite/language.cpp +++ b/CodeLite/language.cpp @@ -143,8 +143,8 @@ ParsedToken* Language::ParseTokens(const wxString& scopeName) } if(result.m_isaType) { - pt->SetTypeScope(result.m_scope.empty() ? wxString(wxT("")) : - wxString::From8BitData(result.m_scope.c_str())); + pt->SetTypeScope( + result.m_scope.empty() ? wxString(wxT("")) : wxString::From8BitData(result.m_scope.c_str())); pt->SetTypeName(wxString::From8BitData(result.m_name.c_str())); } else if(result.m_isGlobalScope) { @@ -156,8 +156,8 @@ ParsedToken* Language::ParseTokens(const wxString& scopeName) // special handle for 'this' keyword //----------------------------------------- - pt->SetTypeScope(result.m_scope.empty() ? wxString(wxT("")) : - wxString::From8BitData(result.m_scope.c_str())); + pt->SetTypeScope( + result.m_scope.empty() ? wxString(wxT("")) : wxString::From8BitData(result.m_scope.c_str())); if(scopeName == wxT("")) { ParsedToken::DeleteTokens(header); return NULL; @@ -202,11 +202,11 @@ ParsedToken* Language::ParseTokens(const wxString& scopeName) delim.Clear(); subscript = false; } - + if(header && header->GetNext() && header->GetName().IsEmpty() && header->GetOperator() == "::") { // a chain with more than one token and the first token is simple "::" // Delete the first token from the list - ParsedToken *newHeader = header->GetNext(); + ParsedToken* newHeader = header->GetNext(); newHeader->SetPrev(NULL); wxDELETE(header); header = newHeader; @@ -318,18 +318,16 @@ bool Language::NextToken(wxString& token, wxString& delim, bool& subscriptOperat void Language::SetAutoCompDeliemters(const std::vector& delimArr) { m_delimArr = delimArr; } -bool Language::ProcessExpression(const wxString& stmt, - const wxString& text, - const wxFileName& fn, - int lineno, - wxString& typeName, // output - wxString& typeScope, // output - wxString& oper, // output - wxString& scopeTemplateInitList) // output +bool Language::ProcessExpression(const wxString& stmt, const wxString& text, const wxFileName& fn, int lineno, + wxString& typeName, // output + wxString& typeScope, // output + wxString& oper, // output + wxString& scopeTemplateInitList) // output { CL_DEBUG(wxT(" >>> Language::ProcessExpression started ...")); bool evaluationSucceeded = true; + m_templateArgs.clear(); wxString statement(stmt); @@ -420,7 +418,7 @@ bool Language::ProcessExpression(const wxString& stmt, if(container.current->GetIsTemplate() && container.current->GetTemplateArgList().IsEmpty()) { // We got no template declaration... - container.current->SetTemplateArgList(DoExtractTemplateDeclarationArgs(container.current)); + container.current->SetTemplateArgList(DoExtractTemplateDeclarationArgs(container.current), m_templateArgs); } int retryCount(0); @@ -802,7 +800,7 @@ wxString Language::GetScopeName(const wxString& in, std::vector* addit wxArrayString moreScopes = GetTagsManager()->BreakToOuterScopes(scope); for(size_t i = 0; i < moreScopes.GetCount(); i++) { if(moreScopes.Item(i) != scope && - std::find(additionlNS->begin(), additionlNS->end(), moreScopes.Item(i)) == additionlNS->end()) { + std::find(additionlNS->begin(), additionlNS->end(), moreScopes.Item(i)) == additionlNS->end()) { additionlNS->push_back(moreScopes.Item(i)); } } @@ -855,7 +853,7 @@ bool Language::ProcessToken(TokenContainer* tokeContainer) CL_DEBUG(wxT("Parsing for local variables...")); CL_DEBUG1("Current scrope:\n%s\n", GetVisibleScope()); - + const wxCharBuffer buf = _C(GetVisibleScope()); const wxCharBuffer buf2 = _C(GetLastFunctionSignature() + wxT(";")); get_variables(buf.data(), li, ignoreTokens, false); @@ -953,7 +951,7 @@ bool Language::ProcessToken(TokenContainer* tokeContainer) // if we are a "member" or " variable" // try to locate the template initialization list bool isTyperef = !tags.at(0)->GetTyperef().IsEmpty(); - + TagEntryPtr tag = tags.at(0); if(!isTyperef && (tags.at(0)->GetKind() == wxT("member") || tags.at(0)->GetKind() == wxT("variable"))) { const wxCharBuffer buf = _C(tags.at(0)->GetPattern()); @@ -978,10 +976,10 @@ bool Language::ProcessToken(TokenContainer* tokeContainer) // Parse the definition list CxxTemplateFunction ctf(tag); ctf.ParseDefinitionList(); - + if(!ctf.GetList().IsEmpty()) { token->SetIsTemplate(true); - token->SetTemplateArgList(ctf.GetList()); + token->SetTemplateArgList(ctf.GetList(), m_templateArgs); } } // fall through... @@ -996,10 +994,8 @@ bool Language::ProcessToken(TokenContainer* tokeContainer) return false; } -bool Language::CorrectUsingNamespace(wxString& type, - wxString& typeScope, - const wxString& parentScope, - std::vector& tags) +bool Language::CorrectUsingNamespace( + wxString& type, wxString& typeScope, const wxString& parentScope, std::vector& tags) { wxString strippedScope(typeScope); wxArrayString tmplInitList; @@ -1047,12 +1043,8 @@ bool Language::CorrectUsingNamespace(wxString& type, return true; } -bool Language::DoSearchByNameAndScope(const wxString& name, - const wxString& scopeName, - std::vector& tags, - wxString& type, - wxString& typeScope, - bool testGlobalScope) +bool Language::DoSearchByNameAndScope(const wxString& name, const wxString& scopeName, std::vector& tags, + wxString& type, wxString& typeScope, bool testGlobalScope) { PERF_BLOCK("DoSearchByNameAndScope") { @@ -1343,7 +1335,7 @@ void Language::GetLocalVariables(const wxString& in, std::vector& t // Don't suggest what we have typed so far if(flags & PartialMatch && tmpTagName == tmpName) continue; if(flags & ExactMatch && tmpTagName != tmpName) continue; - + } // else no name is specified, collect all tags TagEntryPtr tag(new TagEntry()); @@ -1533,7 +1525,7 @@ void Language::CheckForTemplateAndTypedef(ParsedToken* token) if(tags.size() == 1 && !tags.at(0)->IsTypedef()) { // Not a typedef - token->SetTemplateArgList(DoExtractTemplateDeclarationArgs(tags.at(0))); + token->SetTemplateArgList(DoExtractTemplateDeclarationArgs(tags.at(0)), m_templateArgs); token->SetIsTemplate(token->GetTemplateArgList().IsEmpty() == false); } else if(tags.size() == 1) { @@ -1743,7 +1735,7 @@ wxString TemplateHelper::Substitute(const wxString& name) if(where != wxNOT_FOUND) { // it exists, return the name in the templateInstantiation list if(templateInstantiationVector.at(i).GetCount() > (size_t)where && - templateInstantiationVector.at(i).Item(where) != name) + templateInstantiationVector.at(i).Item(where) != name) return templateInstantiationVector.at(i).Item(where); } } @@ -1785,7 +1777,7 @@ void Language::SetAdditionalScopes(const std::vector& additionalScopes // "using namespace" may not contains current namespace, so make sure we add it for(size_t i = 0; i < additionalScopes.size(); i++) { if(!(std::find(this->m_additionalScopes.begin(), this->m_additionalScopes.end(), additionalScopes.at(i)) != - this->m_additionalScopes.end())) { + this->m_additionalScopes.end())) { this->m_additionalScopes.push_back(additionalScopes.at(i)); } } @@ -1873,6 +1865,11 @@ bool Language::DoIsTypeAndScopeExist(ParsedToken* token) return true; } + // Does the typename is happen to be a template argument? + if(m_templateArgs.count(token->GetTypeName())) { + return true; + } + wxString type(token->GetTypeName()); wxString scope(token->GetTypeScope()); bool res = GetTagsManager()->IsTypeAndScopeExists(type, scope); @@ -1943,7 +1940,7 @@ void Language::DoExtractTemplateInitListFromInheritance(TagEntryPtr tag, ParsedT if(tags.size() == 1) { wxArrayString newArgList = DoExtractTemplateDeclarationArgs(tags.at(0)); if(newArgList.IsEmpty() == false) { - token->SetTemplateArgList(newArgList); + token->SetTemplateArgList(newArgList, m_templateArgs); } } } @@ -2011,7 +2008,7 @@ void Language::DoExtractTemplateArgsFromSelf(ParsedToken* token) GetTagsManager()->FindByPath(token->GetPath(), tags); if(tags.size() == 1 && !tags.at(0)->IsTypedef()) { // Not a typedef - token->SetTemplateArgList(DoExtractTemplateDeclarationArgs(tags.at(0))); + token->SetTemplateArgList(DoExtractTemplateDeclarationArgs(tags.at(0)), m_templateArgs); token->SetIsTemplate(token->GetTemplateArgList().IsEmpty() == false); } } @@ -2094,10 +2091,8 @@ int Language::DoReadClassName(CppScanner& scanner, wxString& clsname) const return 0; } -bool Language::InsertFunctionDecl(const wxString& clsname, - const wxString& functionDecl, - wxString& sourceContent, - int visibility) +bool Language::InsertFunctionDecl( + const wxString& clsname, const wxString& functionDecl, wxString& sourceContent, int visibility) { // detemine the visibility requested int typeVisibility = lexPUBLIC; @@ -2228,11 +2223,8 @@ bool Language::InsertFunctionDecl(const wxString& clsname, return true; } -void Language::InsertFunctionImpl(const wxString& clsname, - const wxString& functionImpl, - const wxString& filename, - wxString& sourceContent, - int& insertedLine) +void Language::InsertFunctionImpl(const wxString& clsname, const wxString& functionImpl, const wxString& filename, + wxString& sourceContent, int& insertedLine) { insertedLine = wxNOT_FOUND; if(sourceContent.EndsWith(wxT("\n")) == false) sourceContent << wxT("\n"); diff --git a/CodeLite/language.h b/CodeLite/language.h index c2333d9216..42acadb235 100644 --- a/CodeLite/language.h +++ b/CodeLite/language.h @@ -38,6 +38,7 @@ #include "comment.h" #include #include "codelite_exports.h" +#include enum SearchFlags { PartialMatch = 0x00000001, @@ -101,6 +102,7 @@ class WXDLLIMPEXP_CL Language std::vector m_additionalScopes; // collected by parsing 'using namespace XXX' std::map > m_additionalScopesCache; // collected by parsing 'using namespace XXX' TemplateHelper m_templateHelper; + std::set m_templateArgs; protected: void SetVisibleScope(const wxString& visibleScope) { this->m_visibleScope = visibleScope; } diff --git a/CodeLite/parsedtoken.h b/CodeLite/parsedtoken.h index 44fe2680ce..4a9611b08f 100644 --- a/CodeLite/parsedtoken.h +++ b/CodeLite/parsedtoken.h @@ -29,93 +29,72 @@ #include #include #include +#include class TagsManager; class ParsedToken { - wxString m_type; - wxString m_typeScope; - wxString m_oper; - bool m_isTemplate; + wxString m_type; + wxString m_typeScope; + wxString m_oper; + bool m_isTemplate; wxArrayString m_templateInitialization; wxArrayString m_templateArgList; - wxString m_name; - bool m_subscriptOperator; - wxString m_currentScopeName; - wxString m_argumentList; - ParsedToken* m_next; - ParsedToken* m_prev; - bool m_isAutoVariable; - wxString m_autoExpression; + wxString m_name; + bool m_subscriptOperator; + wxString m_currentScopeName; + wxString m_argumentList; + ParsedToken* m_next; + ParsedToken* m_prev; + bool m_isAutoVariable; + wxString m_autoExpression; public: - static void DeleteTokens( ParsedToken *head ); + static void DeleteTokens(ParsedToken* head); public: ParsedToken(); ~ParsedToken(); - void SetAutoExpression(const wxString& autoExpression) { - this->m_autoExpression = autoExpression; - } - void SetIsAutoVariable(bool isAutoVariable) { - this->m_isAutoVariable = isAutoVariable; - } - const wxString& GetAutoExpression() const { - return m_autoExpression; - } - bool IsAutoVariable() const { - return m_isAutoVariable; - } + void SetAutoExpression(const wxString& autoExpression) { this->m_autoExpression = autoExpression; } + void SetIsAutoVariable(bool isAutoVariable) { this->m_isAutoVariable = isAutoVariable; } + const wxString& GetAutoExpression() const { return m_autoExpression; } + bool IsAutoVariable() const { return m_isAutoVariable; } bool IsThis() const; - void SetCurrentScopeName(const wxString& currentScopeName) { + void SetCurrentScopeName(const wxString& currentScopeName) + { this->m_currentScopeName = currentScopeName; this->m_currentScopeName.Trim().Trim(false); } - const wxString& GetCurrentScopeName() const { - return m_currentScopeName; - } - void SetName(const wxString& name) { + const wxString& GetCurrentScopeName() const { return m_currentScopeName; } + void SetName(const wxString& name) + { this->m_name = name; - this->m_name.Trim().Trim(false);; - } - const wxString& GetName() const { - return m_name; - } - void SetNext(ParsedToken* next) { - this->m_next = next; - } - void SetPrev(ParsedToken* prev) { - this->m_prev = prev; - } - ParsedToken* GetNext() const { - return m_next; - } - ParsedToken* GetPrev() const { - return m_prev; - } - void SetSubscriptOperator(bool subscriptOperator) { - this->m_subscriptOperator = subscriptOperator; - } - bool GetSubscriptOperator() const { - return m_subscriptOperator; - } - - void SetIsTemplate(bool isTemplate) { - this->m_isTemplate = isTemplate; - } - bool GetIsTemplate() const { - return m_isTemplate; - } - void SetOperator(const wxString& oper) { + this->m_name.Trim().Trim(false); + ; + } + const wxString& GetName() const { return m_name; } + void SetNext(ParsedToken* next) { this->m_next = next; } + void SetPrev(ParsedToken* prev) { this->m_prev = prev; } + ParsedToken* GetNext() const { return m_next; } + ParsedToken* GetPrev() const { return m_prev; } + void SetSubscriptOperator(bool subscriptOperator) { this->m_subscriptOperator = subscriptOperator; } + bool GetSubscriptOperator() const { return m_subscriptOperator; } + + void SetIsTemplate(bool isTemplate) { this->m_isTemplate = isTemplate; } + bool GetIsTemplate() const { return m_isTemplate; } + void SetOperator(const wxString& oper) + { this->m_oper = oper; this->m_oper.Trim().Trim(false); } - void SetTypeName(const wxString& type) { + void SetTypeName(const wxString& type) + { this->m_type = type; this->m_type.Trim().Trim(false); } - void SetTypeScope(const wxString& typeScope) { + void SetTypeScope(const wxString& typeScope) + { this->m_typeScope = typeScope; this->m_typeScope.Trim().Trim(false); @@ -124,42 +103,33 @@ class ParsedToken } } - const wxString& GetOperator() const { - return m_oper; - } - const wxString& GetTypeName() const { - return m_type; - } - const wxString& GetTypeScope() const { - return m_typeScope; - } - void SetTemplateArgList(const wxArrayString& templateArgList) { + const wxString& GetOperator() const { return m_oper; } + const wxString& GetTypeName() const { return m_type; } + const wxString& GetTypeScope() const { return m_typeScope; } + void SetTemplateArgList(const wxArrayString& templateArgList, std::set& argsSet) + { this->m_templateArgList = templateArgList; + // Keep track of the template arguments + argsSet.insert(m_templateArgList.begin(), m_templateArgList.end()); } - void SetTemplateInitialization(const wxArrayString& templateInitialization) { + + void SetTemplateInitialization(const wxArrayString& templateInitialization) + { this->m_templateInitialization = templateInitialization; } - const wxArrayString& GetTemplateArgList() const { - return m_templateArgList; - } - const wxArrayString& GetTemplateInitialization() const { - return m_templateInitialization; - } + const wxArrayString& GetTemplateArgList() const { return m_templateArgList; } + const wxArrayString& GetTemplateInitialization() const { return m_templateInitialization; } - void SetArgumentList(const wxString& argumentList) { - this->m_argumentList = argumentList; - } - const wxString& GetArgumentList() const { - return m_argumentList; - } + void SetArgumentList(const wxString& argumentList) { this->m_argumentList = argumentList; } + const wxString& GetArgumentList() const { return m_argumentList; } wxString GetContextScope() const; wxString GetPath() const; - void RemoveScopeFromType(); + void RemoveScopeFromType(); /** * @brief replace the current type which is template with an actual type */ - bool ResovleTemplate(TagsManager *lookup); + bool ResovleTemplate(TagsManager* lookup); /** * @brief fix the template type with actual type @@ -180,34 +150,40 @@ class ParsedToken * * @param lookup */ - void ResolveTemplateType(TagsManager *lookup); + void ResolveTemplateType(TagsManager* lookup); /** * @brief replace template argument with the actual type (std::vector: _Tp --> wxString) * @param templateArg the template argument to replace */ - wxString TemplateToType( const wxString &templateArg ); + wxString TemplateToType(const wxString& templateArg); }; class TokenContainer { public: - ParsedToken *head; - ParsedToken *current; - bool rew; - int retries; + ParsedToken* head; + ParsedToken* current; + bool rew; + int retries; public: - TokenContainer() : head(NULL), current(NULL), retries(0) {} + TokenContainer() + : head(NULL) + , current(NULL) + , retries(0) + { + } - bool Rewind() { - if(retries > 3) - return false; + bool Rewind() + { + if(retries > 3) return false; return rew; } - void SetRewind(bool r) { + void SetRewind(bool r) + { if(r) { retries++; } else {