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 PARSERTHREADF_H
8 #define PARSERTHREADF_H
9 
10 #include <sdk.h>
11 #ifndef CB_PRECOMP
12     #include <wx/arrstr.h>
13 #endif
14 #include <set>
15 
16 #include "tokenf.h"
17 #include "tokenizerf.h"
18 #include "usetokenf.h"
19 #include "moduletokenf.h"
20 #include "submoduletokenf.h"
21 #include "includedb.h"
22 #include "docblock.h"
23 
24 
25 class ParserThreadF
26 {
27     public:
28         ParserThreadF(const wxString& projectFilename,
29                              const wxString& bufferOrFilename,
30                              TokensArrayF* tokens,
31                              FortranSourceForm fsForm,
32                              bool isBuffer=false,
33                              IncludeDB* includeDB=NULL);
34         ParserThreadF(const wxString& projectFilename,
35                              const wxString& filename,
36                              TokensArrayF* tokens,
37                              FortranSourceForm fsForm,
38                              IncludeDB* includeDB,
39                              const wxString& buffer);
40         virtual ~ParserThreadF();
41         bool Parse();
42         void ParseDeclarations(bool breakAtEnd=false, bool breakAtContains=false);
43         static void SplitAssociateConstruct(const wxString& argLine, std::map<wxString,wxString>& assocMap);
44     protected:
45     private:
46         TokenF* DoAddToken(TokenKindF kind, const wxString& name, const wxString& args=wxEmptyString, const wxString& typeDefinition=wxEmptyString);
47         TokenF* DoAddToken(TokenKindF kind, const wxString& name, const wxString& args, const unsigned int defStartLine);
48         FileTokenF* DoAddFileToken(const wxString& filename, const wxString& projectFilename);
49         UseTokenF* DoAddUseToken(const wxString& modName);
50         ModuleTokenF* DoAddModuleToken(const wxString& modName);
51         SubmoduleTokenF* DoAddSubmoduleToken(const wxString& submName, const wxString& ancestorModule, const wxString& parentSubmodule, unsigned int defStartLine);
52 
53         Tokenizerf m_Tokens;
54         TokensArrayF* m_pTokens;
55         TokenF* m_pLastParent;
56         wxString m_Filename;
57         wxArrayString m_IncludeList;
58         IncludeDB* m_pIncludeDB;
59 
60         int m_NumberOfBlockConstruct;
61 
62         wxString m_LastTokenName;
63         DocBlock m_ParentDocs;
64 
65         unsigned int m_InterfaceOperator;
66         unsigned int m_InterfaceAssignment;
67         unsigned int m_InterfaceRead;
68         unsigned int m_InterfaceWrite;
69 
70         const wxString m_Briefend;
71 
72         TokensArrayF* m_pPPDefineTokens;
73         int m_inIfdef;
74 
75         void InitSecondEndPart();
76         void HandleModule();
77         void HandleSubmodule();
78         void HandleFunction(TokenKindF, TokenAccessKind taKind=taPublic);
79         void HandleType(bool& needDefault, TokenF* &newToken);
80         void HandleType();
81         void HandleUse();
82         void HandleBlockConstruct();
83         void HandleAssociateConstruct();
84         void HandleSelectTypeConstruct();
85         void HandleSelectCaseConstruct();
86         void HandleInterface(TokenAccessKind taKind=taPublic);
87         void HandleInterface(TokenAccessKind taKind, TokenF* &tokNew, bool &isGeneric);
88         void HandleBlockData();
89         void HandleInclude();
90         void HandlePPDirective(wxString& token);
91         void HandlePPDefine();
92         void HandlePPUndefine();
93         void HandlePPIfdef(wxString& ifToken);
94         bool HasDefine(const wxString& token, unsigned int lnum);
95         void SkipPPIfdef(wxString& tokenAtEnd);
96         void HandleAccessList(TokenAccessKind taKind, bool& changeDefault, int& countAccess, wxArrayString& nameList);
97         void HandleProcedureList();
98         void HandlePrivatePublic();
99         void GoThroughBody();
100         bool IsEnd(wxString tok_low, wxString nex_low);
101         bool ParseDeclarationsFirstPart(wxString& token, wxString& next);
102         void ParseDeclarationsSecondPart(wxString& token, bool& needDefault, TokensArrayF& newTokenArr);
103         void HandleSubmoduleProcedure();
104         void CheckParseOneDeclaration(wxString& token, wxString& tok_low, wxString& next, wxString& next_low,
105                                 bool& needDefault, TokensArrayF& newTokenArr, bool& hasFunctionInLine);
106         void ParseTypeBoundProcedures(const wxString& firstWord, bool breakAtEOL, bool passIn=true);
107         void MakeArrayStringLower(wxArrayString &arr, wxArrayString &arrLw);
108         void SetTokenAccess(ModuleTokenF* modToken, TokenF* token, TokenAccessKind defAKind);
109         void GetDocBlock(DocBlock &docs, bool lookDown, unsigned int ln, bool takeSimpleDoc);
110         wxString TrimRepetitives(wxString& inStr);
111         wxString GetDocLine(unsigned int ln);
112         void AddParamDocs(TokenF* pParToken, DocBlock &docs);
113         void HandleBindTo();
114         void CheckParseCallProcedure(wxString& token, wxString& tok_low, wxString& next);
115         void TakeFunctionsCallsFromString(const wxString& strIn);
116         void GetWordBefore(const wxString& str, int idxEnd, wxString& funName, int& idxStart);
117 
118         std::set<wxString> m_KnownEndSecPart;
119 };
120 
121 #endif // PARSERTHREADF_H
122