1 /* 2 * This file is part of the FortranProject plugin for Code::Blocks IDE 3 * and licensed under the GNU General Public License, version 3 4 * http://www.gnu.org/licenses/gpl-3.0.html 5 */ 6 7 #ifndef PARSERF_H 8 #define PARSERF_H 9 10 #include <sdk.h> 11 #ifndef CB_PRECOMP 12 #include <wx/string.h> 13 #include <wx/event.h> 14 #include <wx/file.h> 15 16 #include <cbeditor.h> 17 #endif 18 #include <set> 19 #include <vector> 20 21 #include "tokenf.h" 22 #include "tokenizerf.h" 23 #include "includedb.h" 24 #include "farrays.h" 25 #include "fortranfileext.h" 26 #include "calledbydict.h" 27 28 typedef std::vector<FortranSourceForm> ArrayOfFortranSourceForm; 29 30 extern FortranFileExt g_FortranFileExt; 31 32 class ParserF 33 { 34 public: 35 ParserF(bool withIntrinsicModules=true); 36 ~ParserF(); 37 bool Parse(const wxString& projectFilename, const wxString& filename, FortranSourceForm fsForm); 38 bool Reparse(const wxString& projectFilename, const wxString& filename, FortranSourceForm fsForm); 39 bool BatchParse(const wxArrayString& projectFilenames, const wxArrayString& filenames, ArrayOfFortranSourceForm& fileForms); 40 bool RemoveFile(const wxString& filename); 41 void RemoveBuffer(const wxString& filename); GetTokens()42 TokensArrayF* GetTokens(){return m_pTokens;}; 43 bool FindTypeBoundProcedures(const TokenFlat& interToken, const wxArrayString& searchArr, TokensArrayFlat& resTokenArr); 44 bool FindMatchTokenInSameModule(const TokenFlat& procedureToken, const wxString& search, TokensArrayFlat& result, int tokenKindMask, int noChildrenOf); 45 size_t FindMatchTokensDeclared(const wxString& search, TokensArrayFlat& result, int tokenKindMask, bool partialMatch=false, int noChildrenOf=0, 46 bool onlyPublicNames=false, bool noIncludeFiles=false); 47 size_t FindMatchTokens(wxString filename, wxString search, TokensArrayF& result); 48 void Clear(); 49 void ObtainUsedDeclaredModules(const wxString& fileName, StringSet* fileUseModules, StringSet* fileDeclaredModules, 50 StringSet* fileExtendsSModules, StringSet* fileDeclaredSubmodules, StringSet* fileIncludes); 51 bool IsFileFortran(const wxString& filename, FortranSourceForm& fsForm); 52 void FindMatchDeclarationsInCurrentScope(const wxString& search, cbEditor* ed, TokensArrayFlat& result, bool partialMatch, int endPos=-1, int* nLineStart=NULL); 53 void FindMatchVariablesInModules(const wxString& search, TokensArrayFlat& result, bool partialMatch); 54 bool FindMatchTypeComponents(TokenFlat& parentTok, const wxString& lineStr, TokensArrayFlat& result); 55 bool FindMatchTypeComponents(cbEditor* ed, const wxString& line, TokensArrayFlat& result, bool partialMatch, bool onlyPublicNames, 56 bool& isAfterPercent, bool getAsProcedure); 57 bool FindMatchTypeComponents2(TokensArrayFlat* foundVariables, unsigned int myScopeLine, wxString& myFilename, wxArrayString& parts, 58 TokensArrayFlat& result, bool partialMatch, bool onlyPublicNames, bool getAsProcedure); 59 bool CutLineIntoParts(const wxString& lineCur, bool& isAfterPercent, wxArrayString& parts); 60 void FindMatchTokensForToolTip(const wxString& nameUnder, int posEndOfWord, cbEditor* ed, bool onlyUseAssoc, bool onlyPublicNames, TokensArrayFlat& result, bool& isAfterPercent); 61 void FindGenericTypeBoudComponents(TokenFlat* token, TokensArrayFlat& result); 62 void FindMatchOperatorTokensForJump(wxString& nameOperator, TokensArrayFlat& result); 63 void FindMatchTokensForJump(cbEditor* ed, bool onlyUseAssoc, bool onlyPublicNames, TokensArrayFlat& result); 64 bool FindMatchTokensForCodeCompletion(bool useSmartCC, bool onlyUseAssoc, bool onlyPublicNames, const wxString& nameUnderCursor, 65 cbEditor* ed, TokensArrayFlat& result, bool& isAfterPercent, int& tokKind, wxArrayString& firstWords); 66 bool FindWordsBefore(cbEditor* ed, int numberOfWordsMax, wxString &curLine, wxArrayString &firstWords); 67 void RereadOptions(); 68 bool FindTokenDeclaration(TokenFlat& token, const wxString& argName, wxString& argDecl, wxString& argDescription); 69 bool FindTokenRange(TokenFlat& token, wxString& txtRange, wxString& buff, std::vector<int> &lineStarts, bool withDefinition=false, bool readFile=true); 70 bool FindTokenRange(TokenFlat& token, wxString& txtRange); 71 bool FindInfoLog(TokenFlat& token, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg); 72 bool FindInfoLog(TokenFlat& token, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg, bool readFile); 73 bool FindInfoLog(TokenFlat& token, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg, wxString& argsNew); 74 bool FindInfoLog(TokenFlat& token, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg, const wxString& argsNew, bool readFile); 75 bool FindTooltipForTypeBoundProc(wxString& msg, TokenFlat* token1, TokenFlat* token2); 76 bool FindInfoLogForTypeBoundProc(TokensArrayFlat& tokenPair, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg, 77 wxString* buff=NULL, std::vector<int>* lineStarts=NULL); 78 bool FindInfoLogForGenericTBProc(TokensArrayFlat& tokens, bool logComAbove, bool logComBelow, bool logDeclar, bool logComVariab, wxString& msg); 79 bool GetTokenStr(TokenFlat& token, wxString& msg); 80 void FindChildrenOfInterface(TokenFlat* token, TokensArrayFlat& result); 81 void GetPossitionOfDummyArgument(const wxString& args, const wxString& arg, int& start, int& end); 82 void GetCallTipHighlight(const wxString& calltip, int commasWas, int& start, int& end); 83 void FindUseAssociatedTokens(bool onlyPublicNames, TokenFlat* tok, const wxString& search, bool partialMatch, TokensArrayFlat& result, int tokenKindMask, bool changeDisplayName, TokensArrayFlat* useWithRenameTok=NULL); 84 void FindUseAssociatedTokens(bool onlyPublicNames, cbEditor* ed, const wxString& search, bool partialMatch, TokensArrayFlat& result, int tokenKindMask, bool changeDisplayName, TokensArrayFlat* useWithRenameTok=NULL); 85 void FindUseAssociatedTokens(bool onlyPublicNames, wxArrayString& address, const wxString& search, bool partialMatch, TokensArrayFlat& result, int tokenKindMask, bool changeDisplayName, TokensArrayFlat* useWithRenameTok=NULL); 86 void GetTypeComponentsInFile(const wxString& fileName, const unsigned int line, const wxString& nameType, TokensArrayFlat* result); 87 bool IsIncludeFile(wxString fileName); 88 bool HasIncludeFiles(); 89 TokenF* FindFile(const wxString& filename); 90 void FindFile(const wxString& filename, TokensArrayFlat& result); 91 void SetNewTokens(TokensArrayF* pTokens); 92 void SetNewIncludeDB(IncludeDB* pIncludeDB); 93 void SetNewADirTokens(TokensArrayF* pTokens); 94 void SetNewADirIncludeDB(IncludeDB* pIncludeDB); 95 void ConnectToNewTokens(); 96 void ConnectToNewADirTokens(); 97 void SetNewCurrentTokens(TokensArrayF* pTokens); 98 void ConnectToNewCurrentTokens(); 99 void ChangeLineIfRequired(cbEditor* ed, wxString& curLine); 100 TokenF* FindTokenBetweenChildren(TokenF* pToken, const wxString& name); 101 //void GetAddress(TokenF* token, wxArrayString& address); 102 void GetAddressOfToken(TokenF* token, wxArrayString& address); 103 TokenF* FindToken(const TokenFlat &token, TokensArrayF* children=NULL); 104 void ChangeArgumentsTypeBoundProc(TokenFlat& tbProcTok, const TokenFlat& procTok); 105 void GetChildren(TokenFlat* token, int tokenKindMask, TokensArrayFlat& result, int levelMax=1); 106 void GetChildren(TokenF* pToken, int tokenKindMask, TokensArrayFlat& result, int level, int levelMax); 107 void FindImplementedProcInMySubmodules(TokenFlat* tok, const wxString& search, TokensArrayFlat& result); 108 void BuildCalledByDict(CalledByDict& cByDict); 109 110 protected: 111 private: 112 void FindMatchChildren(TokensArrayF &m_Children, wxString search, TokensArrayF& result, bool exact=false); 113 size_t GetFileIndex(const wxString& filename); 114 TokensArrayF* FindFileTokens(const wxString& filename); 115 TokenF* FindFileTokenWithName(const wxString& filename); 116 TokenF* FindModuleSubmoduleToken(const wxString& moduleName); 117 void ObtainUDModulesToken(TokenF* token, StringSet* fileUseModules, StringSet* fileDeclaredModules, 118 StringSet* fileExtendsSModules, StringSet* fileDeclaredSubmodules, StringSet* fileIncludes); 119 void FindMatchChildrenDeclared(TokensArrayF &m_Children, const wxString search, TokensArrayFlat& result, int tokenKindMask, bool partialMatch=false, int noChildrenOf=0, bool onlyPublicNames=false); 120 bool FindLineScope(unsigned int line, int& lineStart, int tokenKindMask, TokensArrayF& children, TokenF* &pToken); 121 void FindLineScopeLN(cbEditor* ed, int& lineStart, TokenFlat* &token, int endPos); 122 bool CutBlocks(const wxChar& ch, wxString& line); 123 bool GetTypeOfComponent(const wxString& nameType, const wxString& nameComponent, wxString& nameTypeComponent); 124 bool GetTypeOfComponent(TokenF** pT, const wxString& nameComponent, wxString& nameTypeComponent); 125 bool GetTypeOfChild(TokenF* pT, const wxString& nameComponent, wxString& nameTypeComponent); 126 TokenF* GetType(const wxString& nameType); 127 TokenF* GetTypeInFile(const wxString& fileName, const unsigned int line, const wxString& nameType); 128 //void FindUseAssociatedTokens(TokenF* useToken, const wxString& searchLw, TokensArrayFlat& result, int tokenKindMask, bool partialMatch, bool changeDisplayName, bool onlyPublicNames, TokensArrayFlat* useWithRenameTok=NULL); 129 //void FindMatchTokensInModuleAndUse(const wxString &modName, const wxString& searchLw, TokensArrayFlat& result, int tokenKindMask, int noChildrenOf, bool partialMatch, bool onlyPublicNames, bool changeDisplayName, TokensArrayFlat* useWithRenameTok); 130 void FindUseAssociatedTokens2(TokenF* useToken, const wxString &searchLw, ArrOfSizeT &resChildrenIdx, BoolArray2D &resCanBeSeen2D, int tokenKindMask, bool partialMatch, bool changeDisplayName, 131 bool onlyPublicNames, TokensArrayFlat& renamedTokens, TokensArrayFlat* useWithRenameTok); 132 void FindMatchTokensInModuleAndUse2(const wxString& modName, const wxString& searchLw, ArrOfSizeT* &childrenIdx, BoolArray2D* &canBeSeen2D, int tokenKindMask, 133 int noChildrenOf, bool partialMatch, bool onlyPublicNames, bool changeDisplayName, TokensArrayFlat* useWithRenameTok); 134 void ChangeAssociatedName(wxString& line, TokenFlat* token); 135 void FindAddress(cbEditor* ed, wxArrayString& address); 136 void FindAddress(TokenFlat* tokFl, wxArrayString& address); 137 void FindTokensForUse(const wxString& search, wxArrayString& firstWords, TokensArrayFlat& result, bool onlyPublicNames); 138 void AddUniqueResult(TokensArrayFlat& result, const TokenF* token, bool isHostAssociated); 139 void AddUniqueResult(TokensArrayFlat& result, const TokenFlat* token); 140 void AddIncludeFileChildren(const TokenF* include, TokensArrayF& tokens); 141 void GetSubmoduleHostTokens(TokenF* subModToken, std::vector<TokensArrayF*> &vpChildren); 142 void ClearTokens(TokensArrayF* pTokens); 143 void ParseIntrinsicModules(); 144 void ChangeCaseChildren(TokensArrayF &children, int dispCase); 145 void FindImplementedProcInMySubmodules(cbEditor* ed, const wxString& search, TokensArrayFlat& result); 146 void FindImplementedProcInMySubmodules(wxArrayString& address, const wxString& search, TokensArrayFlat& result); 147 void FindSubmodulesWhichExtends(const wxString& moduleName, TokensArrayF* result); 148 void FindMatchTokensAtInclude(cbEditor* ed, const wxString& findName, bool onlyPublicNames, bool partialMach, TokensArrayFlat& result); 149 void GetChildrenAssociateConstruct(TokenF* token, int tokenKindMask, TokensArrayFlat& result); 150 151 TokensArrayF* m_pTokens; 152 TokensArrayF* m_pIntrinsicModuleTokens; 153 IncludeDB* m_pIncludeDB; 154 TokensArrayF* m_pAdditionalDirTokens; 155 IncludeDB* m_pIncludeDBADir; 156 bool m_Done; 157 158 wxString m_Buff; 159 std::vector<int> m_LineStarts; 160 161 int m_RecursiveDeep; 162 //size_t maxResultCount; 163 //bool reachedResultCountLimit; 164 165 wxArrayString m_VisitedModules; 166 PassedTokensArray2D m_PassedTokensVisited; 167 ArrOfSizeT2D m_ChildrenIdxVisited; 168 BoolArray3D m_CanBeSeenVisited; 169 170 bool m_UseRenameArrays; 171 int m_RenameDeep; 172 173 int m_IncludeDeep; 174 int m_SubmodDeep; 175 176 wxArrayString m_VisitedModulesRen; 177 PassedTokensArray2D m_PassedTokensVisitedRen; 178 ArrOfSizeT2D m_ChildrenIdxVisitedRen; 179 BoolArray3D m_CanBeSeenVisitedRen; 180 181 TokensArrayF* m_pTokensNew; 182 IncludeDB* m_pIncludeDBNew; 183 TokensArrayF* m_pTokensADirNew; 184 IncludeDB* m_pIncludeDBADirNew; 185 TokensArrayF* m_pBufferTokens; 186 TokensArrayF* m_pCurrentBufferTokensNew; 187 }; 188 189 #endif // PARSERF_H 190