1 /////////////////////////////////////////////////////////////////////////////// 2 // Author: YWX (wxFortranIndent@163.com) 3 // Licence: GNU General Public License, version 3 4 /////////////////////////////////////////////////////////////////////////////// 5 6 #ifndef INDENTESTIMATOR_H 7 #define INDENTESTIMATOR_H 8 9 #include <sdk.h> 10 #ifndef CB_PRECOMP 11 #include <wx/string.h> 12 #include <wx/regex.h> 13 #include <wx/hashmap.h> 14 #include <wx/arrstr.h> 15 #endif 16 #include <vector> 17 18 class FormatIndentCodeTree 19 { 20 public: 21 enum CodeTreeKind 22 { 23 ctcProgramBlock, 24 ctcEndProgramBlockSubFun, 25 ctcModule, 26 ctcEndModule, 27 ctcInterface, 28 ctcEndInterface, 29 ctcSubroutine, 30 ctcFunction, 31 ctcTypeDefine, 32 ctcEndTypeDefine, 33 ctcDoForall, 34 ctcEndDoForall, 35 ctcSeclectCase, 36 ctcSeclectType, 37 ctcEndSeclectCase, 38 ctcIfThen, 39 ctcEndIf, 40 ctcWhere, 41 ctcEndWhere, 42 ctcAssociate, 43 ctcEndAssociate, 44 ctcCritical, 45 ctcEndCritical, 46 ctcSubmodule, 47 ctcEndSubmodule, 48 ctcEnum, 49 ctcEndEnum, 50 ctcEnd, 51 ctcModuleProcedure, 52 ctcEndProcedure, 53 54 ctcNone 55 }; 56 57 public: 58 FormatIndentCodeTree(); 59 ~FormatIndentCodeTree(); 60 void Initialize(int firstLineIndent); 61 void GetCodeTreeIndent(CodeTreeKind iKind, int& myIndent); 62 CodeTreeKind GetParentKind(); 63 64 private: 65 typedef struct { 66 CodeTreeKind kind; 67 int indent; 68 } treeNode; 69 70 std::vector<treeNode> m_Tree; 71 int m_RootIndent; 72 }; 73 74 /// declaration 75 WX_DECLARE_STRING_HASH_MAP( wxRegEx *, FormatIndentRegEx ); 76 77 class IndentEstimator 78 { 79 public: 80 81 /** Constructor. */ IndentEstimator()82 IndentEstimator( ) 83 { 84 CreateFormatIndentRegEx(); 85 } 86 87 /** Destructor. */ ~IndentEstimator()88 ~IndentEstimator( ) 89 { 90 DelFormatIndentRegEx(); 91 } 92 93 void CreateFormatIndentRegEx(); 94 void DelFormatIndentRegEx(); 95 void Initialize(int firstLineIndent); 96 97 bool BuffersDiffer( const wxString &a, const wxString &b ); 98 bool GetIsHasLineContinuation( const wxString & srcLine ); 99 bool GetIsHasPreprocessor( const wxString & srcLine ); 100 void DelLineContinuation( wxString & srcLine ); 101 void DelComment( wxString & srcLine ); 102 void GetFortranIndentLine( const wxString& src, int& indentNum, int& indentNumNext); 103 void CutStringAndComment(wxString& src); 104 void ReadConfig(); 105 106 protected: 107 void CalcFortranIndentLine( const wxString & srcLine, int & deltaIndentCur, int & deltaIndentNext, FormatIndentCodeTree::CodeTreeKind & iKind ); 108 void PrepareLine(const wxString & srcIn, wxArrayString & srcLines); 109 110 FormatIndentRegEx m_RegEx; 111 FormatIndentCodeTree m_CodeTree; 112 113 bool m_IndentProgFunSub; 114 bool m_IndentModule; 115 bool m_IndentContainsModule; 116 bool m_IndentContainsModuleAfter; 117 bool m_IndentContainsProcedure; 118 bool m_IndentContainsProcedureAfter; 119 bool m_IndentContainsTypedef; 120 bool m_IndentContainsTypedefAfter; 121 bool m_IndentSelectCaseAfter; 122 bool m_IndentSelectTypeAfter; 123 }; 124 125 126 #endif // INDENTESTIMATOR_H 127 128