1 #ifndef BINDTO_H
2 #define BINDTO_H
3 
4 //(*Headers(Bindto)
5 #include <wx/button.h>
6 #include <wx/checkbox.h>
7 #include <wx/dialog.h>
8 #include <wx/listctrl.h>
9 #include <wx/notebook.h>
10 #include <wx/panel.h>
11 #include <wx/radiobut.h>
12 #include <wx/sizer.h>
13 #include <wx/stattext.h>
14 #include <wx/textctrl.h>
15 //*)
16 
17 #include "parserf.h"
18 #include "bindtonewtype.h"
19 #include <map>
20 
21 enum BindToIn
22 {
23     bindToProject,
24     bindToFile,
25 };
26 
27 typedef std::map<wxString,wxArrayString> TypeMap;
28 typedef std::map<wxString,wxString> StrMap;
29 typedef std::set<wxString> StrSet;
30 
31 
32 class Bindto: public wxDialog
33 {
34 	public:
35 
36 		Bindto(wxWindow* parent, ParserF* pParser);
37 		virtual ~Bindto();
38 
39 		//(*Declarations(Bindto)
40 		wxButton* bt_Add;
41 		wxButton* bt_Defaults;
42 		wxButton* bt_Edit;
43 		wxButton* bt_OutputDir;
44 		wxButton* bt_Remove;
45 		wxButton* bt_copy;
46 		wxCheckBox* cb_ctorEnd;
47 		wxCheckBox* cb_ctorStart;
48 		wxCheckBox* cb_dtorEnd;
49 		wxCheckBox* cb_dtorStart;
50 		wxCheckBox* cb_genCython;
51 		wxCheckBox* cb_globalToOne;
52 		wxCheckBox* cb_incompleteWrapperProc;
53 		wxCheckBox* cb_pyFirstSelf;
54 		wxCheckBox* cb_pyGenClass;
55 		wxListView* lv_Types;
56 		wxPanel* Panel1;
57 		wxPanel* Panel2;
58 		wxPanel* Panel4;
59 		wxPanel* Panel5;
60 		wxPanel* pn_pyOpts;
61 		wxRadioButton* rb_ActiveProject;
62 		wxRadioButton* rb_CurrentFile;
63 		wxStaticText* StaticText16;
64 		wxStaticText* StaticText7;
65 		wxStaticText* st_globalFilename;
66 		wxTextCtrl* tc_OutputDir;
67 		wxTextCtrl* tc_bindCName;
68 		wxTextCtrl* tc_ctorEnd;
69 		wxTextCtrl* tc_ctorStart;
70 		wxTextCtrl* tc_dtorEnd;
71 		wxTextCtrl* tc_dtorStart;
72 		wxTextCtrl* tc_globalFilename;
73 		wxTextCtrl* tc_pyFunName;
74 		//*)
75 
76 	protected:
77 
78 		//(*Identifiers(Bindto)
79 		static const long ID_BTOACTIVEPROJECT;
80 		static const long ID_BTOCURRENTFILE;
81 		static const long ID_TEXTCTRL1;
82 		static const long ID_STATICTEXT5;
83 		static const long ID_CHECKBOX9;
84 		static const long ID_CHECKBOX3;
85 		static const long ID_TEXTCTRL6;
86 		static const long ID_STATICTEXT1;
87 		static const long ID_TEXTCTRL7;
88 		static const long ID_BUTTON1;
89 		static const long ID_PANEL2;
90 		static const long ID_LV_TYPES;
91 		static const long ID_BUTTON_ADD;
92 		static const long ID_BUTTON_COPY;
93 		static const long ID_BUTTON_EDIT;
94 		static const long ID_BUTTON_REMOVE;
95 		static const long ID_BUTTON_DEFAULTS;
96 		static const long ID_PANEL1;
97 		static const long ID_CHECKBOX4;
98 		static const long ID_TEXTCTRL4;
99 		static const long ID_CHECKBOX5;
100 		static const long ID_TEXTCTRL5;
101 		static const long ID_PANEL3;
102 		static const long ID_CHECKBOX1;
103 		static const long ID_TEXTCTRL2;
104 		static const long ID_CHECKBOX2;
105 		static const long ID_TEXTCTRL3;
106 		static const long ID_PANEL4;
107 		static const long ID_CHECKBOX6;
108 		static const long ID_TEXTCTRL8;
109 		static const long ID_CHECKBOX7;
110 		static const long ID_CHECKBOX8;
111 		static const long ID_PANEL6;
112 		static const long ID_PANEL5;
113 		static const long ID_NOTEBOOK1;
114 		//*)
115 
116 	private:
117 
118 		//(*Handlers(Bindto)
119 		void OnAdd(wxCommandEvent& event);
120 		void OnEdit(wxCommandEvent& event);
121 		void OnRemove(wxCommandEvent& event);
122 		void OnDefaults(wxCommandEvent& event);
123 		void OnClick_cbCtorStart(wxCommandEvent& event);
124 		void OnClick_cbCtorEnd(wxCommandEvent& event);
125 		void OnClick_cbDtorStart(wxCommandEvent& event);
126 		void OnClick_cbDtorEnd(wxCommandEvent& event);
127 		void Onrb_ActiveProjectSelect(wxCommandEvent& event);
128 		void Onbt_OutputDirClick(wxCommandEvent& event);
129 		void Oncb_genCythonClick(wxCommandEvent& event);
130 		void OnCopy(wxCommandEvent& event);
131 		void Oncb_globalToOneClick(wxCommandEvent& event);
132 		//*)
133 
134 		enum Language
135 		{
136 		    Fortran,
137 		    C,
138 		    Python,
139 		};
140 
141 		struct TypeBind
142 		{
143 		    wxString fType;
144 		    wxString fTypeOnly;
145 		    wxString fDrvTypeName;
146 		    wxString bType;
147 		    wxString bDim;
148 		    wxString cType;
149 		    wxString cDim;
150 		    wxString info;
151 		    wxString errMsg;
152 		    bool wasFound;
153 		};
154 
155 		struct TypePyx
156 		{
157 		    wxString declarPyxFirst;
158 		    wxString callCSecond;
159 		    wxString intent;
160 		    wxString fDrvTypeName;
161 		    wxString initStr;
162 		    bool hide;
163 		    bool copy;
164 		    int ndim;
165 		    wxArrayString addIntArg;
166 		};
167 
168 		struct BintoDirective
169 		{
170 		    wxString      varName;
171 		    wxArrayString dim;
172 		    StrSet        intent;
173 		    wxString      initStr;
174 		};
175 		typedef std::map<wxString,BintoDirective> BTDirMap;
176 
177 		ParserF* m_pParser;
178         TokenF*  m_pTokenCurrent;
179         int m_Indent;
180         int m_TabSize;
181         TypeMap m_TypeMap;
182         TypeMap m_TypeDefinedInMap;
183         TypeMap m_TypeDefinedInGlobMap;
184         bool m_IsTypeMapDefault;
185         bool m_WriteIncompleteWrapper;
186         bool m_OneGProcFile;
187         wxString m_OneGProcFileName;
188         wxString m_BindCName;
189         wxString m_CtorStartsWith;
190         wxString m_CtorEndsWith;
191         wxString m_DtorStartsWith;
192         wxString m_DtorEndsWith;
193         wxString m_InitialOutputDirFile;
194         wxString m_InitialOutputDirProj;
195         wxString m_OutputDir;
196         bool m_LogToInt;
197         TypeMap m_GlobLogFunMap;
198         StrSet  m_LogTypeSet;
199         wxString m_ProjectBinDir;
200         wxString m_TargetLibraryName;
201         bool m_IsTargetStaticLib;
202         wxString m_TargetCompilerName;
203 
204         bool m_UseOneGlobalFile;
205         wxString m_GlobProceduresFile;
206         wxString m_GlobProceduresFileH;
207         wxString m_GlobProcWarnMessages;
208         StrSet m_GlobProceduresCInclude;
209         bool m_GlobWriteStrFtoC;
210         bool m_GlobWriteStrCtoF;
211         bool m_GlobWriteStrLen;
212         wxString m_WarnMessage;
213         StrSet m_NotFoundTypes;
214         wxString m_CStructs;
215         wxArrayString m_CreatedMsg;
216         StrSet m_CInclude;
217         bool m_WriteStrFtoC;
218         bool m_WriteStrCtoF;
219         bool m_WriteStrLen;
220         StrSet m_DefinedTypes;
221         StrSet m_DefinedTypesBindC;
222         StrSet m_NoArgConstructors;
223         StrMap m_Deallocators;
224         StrSet m_ModuleChildNames;
225         wxString m_CurProcedure;
226         wxString m_CurModule;
227         wxString m_CurFile;
228         bool m_InFortranModule;
229         BTDirMap m_BTDirMap;
230         bool m_FileWasCreated;
231         wxArrayString m_PyxFileArr;
232 
233         bool m_PyGenCython;
234         StrSet m_PyInclude;
235         int m_PyIndent;
236         wxString m_PyFuncName;
237         bool m_PyCreateClass;
238         bool m_PyFirstArgAsSelf;
239         bool m_HasPyClassConstructor;
240         StrMap m_C2NumpyTypes;
241 
242         StrSet m_PyIncludeGlob;
243         wxString m_TxtCythonFirstGlob;
244         wxString m_TxtCythonGlob;
245 
246         void FillC2NumpyTypesMap();
247         void FillTypeList();
248         void LoadInitialValues();
249         void FillTypeMapDefault();
250         void LoadBindToConfig();
251         void SaveBindToConfig();
252         void OnOK(wxCommandEvent& event);
253         void MakeBindTo(BindToIn btin);
254         void FileBindTo(const wxString& filename);
255         wxString GetIS(int nint = -1);
256         wxString CreateBindFilename(const wxString& filename, bool header);
257         wxString CheckOverwriteFilename(wxFileName &fname);
258         void BindProcedure(wxString& txtBind, wxString& txtHeaders, wxString& txtCythonFirst, wxString& txtCythonSecond,
259                            TokenF* token, const wxString& moduleName, bool isGlobal, wxString callName=wxEmptyString);
260         TypeBind GetBindType(TokenF* token, int& nDimVarAdd);
261         TypeBind GetBindType(const wxString& declar, int& nDimVarAdd);
262         wxString GetToken(const wxString& txt, int iPos);
263         wxArrayString GetTypeAndKind(wxString decl);
264         wxString GetFunctionDeclaration(TokenF* token);
265         wxString GetCDims(wxString vdim);
266         wxString SplitLines(const wxString& txt, Language lang);
267         void GetSubStrFtoC(wxArrayString& strFtoC);
268         void GetSubStrCtoF(wxArrayString& strCtoF);
269         void GetFunStrLen(wxArrayString& strLen);
270         void GetFunLogical(const wxString& logType, const wxString& nameLtoI, const wxString& nameItoL, wxArrayString& funLtoI, wxArrayString& funItoL);
271         void GetHelperModule(bool useGlobal, bool getAll, std::map<wxString,wxString> &procMap, wxString& modHead);
272         void PrepareAssumedShapeVariables(const wxArrayString& argArr, const wxArrayString& dimVarNames,
273                                           wxArrayString& additionalDeclar, wxArrayString& addVarNames, wxArrayString& addVarNamesC,
274                                           const wxArrayString& varNamesOfDim, const StrSet& argHideSetPy, wxArrayString& additionalDeclarPy,
275                                           wxArrayString& addVarNamesPy, wxArrayString& addArgNamesPy);
276         void AddDimVariables(const wxArrayString& argArr, wxArrayString& dimVarNames, int nDimVarAdd, wxString varFirstPart, const wxString& argName,
277                              wxArrayString& varNamesOfDim, TypeBind& tys);
278         void HideAssumedShape(const wxString& vdim, wxString& vdimHid, int& nAssumedDim);
279         void AddDimVariablesFromDoc(wxArrayString& dimVarNames, int& nDimVarAdd, const wxString& argName,
280                                     wxArrayString& varNamesOfDim, TypeBind& tys);
281         wxString GetCName(const wxString& procName, const wxString& moduleName);
282         wxString GetProcName(const wxString& procName, const wxString& moduleName, const wxString& nameFrame);
283         void AddConstructors(wxString& txtBind, wxString& txtHeadersMod, wxString& txtCythonCtor, wxString& txtCythonFirst, const wxString& moduleName);
284         void AddDestructors(wxString& txtBind, wxString& txtHeadersMod, wxString& txtCythonDtor, wxString& txtCythonFirst, const wxString& moduleName);
285         wxString GetConstructorName(const wxString& type);
286         bool IsConstructor(TokenF* token);
287         bool IsDestructor(TokenF* token);
288         wxString GetPyName(const wxString& procName, const wxString& moduleName);
289         TypePyx GetBindTypePy(const TypeBind& tya, const wxString& varName);
290         wxString CreateCythonFilename(const wxString& filename);
291         void GetInitialOutputDir(wxString& initialOutputDirFile, wxString& initialOutputDirProj);
292         bool MakeOutputDir();
293         bool ValidatePyFuncName();
294         void ShowNewTypeDlg(BindtoNewType& addNewType);
295         void PrepateTypes(wxString& ft, wxString& bt, wxString& ct);
296         wxArrayString GetLogFunNames(const wxString& fType);
297         void ParseBindtoDirectives(const TokenF* parentToken);
298         wxArrayString GetDimArr(const wxString& dimStr);
299         void AddPyArgs(const wxArrayString& argArr, wxArrayString& morePyIntArgs, const wxArrayString& addIntArg);
300         void WriteSetupPy(const wxArrayString& pyxFArr, const wxString& setupPyFn, const wxString& binDir);
301         void AddToCStruct(TokenF* typeTok);
302         void GetHeaderStartEnd(const wxString& hfname, wxString& hStart, wxString& hEnd);
303         void WriteHelperModFile();
304         void AddToLogFile(const wxString& msg);
305 
306 		DECLARE_EVENT_TABLE()
307 };
308 
309 #endif
310