| [78] | 1 | #pragma once
 | 
|---|
| [74] | 2 | 
 | 
|---|
| [75] | 3 | class Procedure{
 | 
|---|
| [74] | 4 | public:
 | 
|---|
| [75] | 5 |     // 種類
 | 
|---|
 | 6 |     enum Kind{
 | 
|---|
 | 7 |         Sub,
 | 
|---|
 | 8 |         Function,
 | 
|---|
 | 9 |     };
 | 
|---|
| [74] | 10 | 
 | 
|---|
| [75] | 11 | private:
 | 
|---|
 | 12 |     const string name;
 | 
|---|
| [74] | 13 | 
 | 
|---|
| [75] | 14 |     Kind kind;
 | 
|---|
| [74] | 15 | 
 | 
|---|
| [75] | 16 |     bool isCdecl;
 | 
|---|
 | 17 |     bool isUsing;
 | 
|---|
| [74] | 18 | 
 | 
|---|
| [75] | 19 | protected:
 | 
|---|
| [74] | 20 | 
 | 
|---|
| [75] | 21 |     // パラメータ
 | 
|---|
| [74] | 22 |     Parameters params;
 | 
|---|
| [75] | 23 | 
 | 
|---|
 | 24 |     // 戻り値の型
 | 
|---|
 | 25 |     Type returnType;
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 |     // ソースコードの位置
 | 
|---|
 | 28 |     int codePos;
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | public:
 | 
|---|
 | 31 |     Procedure( const string &name, Kind kind, bool isCdecl ):
 | 
|---|
 | 32 |       name( name ),
 | 
|---|
 | 33 |       kind( kind ),
 | 
|---|
 | 34 |       isCdecl( isCdecl ),
 | 
|---|
 | 35 |       isUsing( false ),
 | 
|---|
 | 36 |       codePos( -1 )
 | 
|---|
 | 37 |     {}
 | 
|---|
 | 38 |     ~Procedure(){
 | 
|---|
 | 39 |         foreach( Parameter *pParam, params ){
 | 
|---|
 | 40 |             delete pParam;
 | 
|---|
 | 41 |         }
 | 
|---|
 | 42 |     }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |     const string &GetName() const
 | 
|---|
 | 45 |     {
 | 
|---|
 | 46 |         return name;
 | 
|---|
 | 47 |     }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |     bool IsSub() const
 | 
|---|
 | 50 |     {
 | 
|---|
 | 51 |         return ( kind == Sub );
 | 
|---|
 | 52 |     }
 | 
|---|
 | 53 |     bool IsFunction() const
 | 
|---|
 | 54 |     {
 | 
|---|
 | 55 |         return ( kind == Function );
 | 
|---|
 | 56 |     }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |     bool IsCdecl() const
 | 
|---|
 | 59 |     {
 | 
|---|
 | 60 |         return isCdecl;
 | 
|---|
 | 61 |     }
 | 
|---|
 | 62 |     void Using(){
 | 
|---|
 | 63 |         isUsing = true;
 | 
|---|
 | 64 |     }
 | 
|---|
 | 65 |     bool IsUsing() const
 | 
|---|
 | 66 |     {
 | 
|---|
 | 67 |         return isUsing;
 | 
|---|
 | 68 |     }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 |     int GetCodePos() const
 | 
|---|
 | 71 |     {
 | 
|---|
 | 72 |         return codePos;
 | 
|---|
 | 73 |     }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |     const Parameters &Params() const
 | 
|---|
 | 76 |     {
 | 
|---|
 | 77 |         return params;
 | 
|---|
 | 78 |     }
 | 
|---|
 | 79 |     const Type &ReturnType() const
 | 
|---|
 | 80 |     {
 | 
|---|
 | 81 |         return returnType;
 | 
|---|
 | 82 |     }
 | 
|---|
 | 83 | };
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | class UserProc : public Procedure
 | 
|---|
 | 86 | {
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | private:
 | 
|---|
 | 89 |     bool isMacro;
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |     // パラメータの追加情報
 | 
|---|
 | 92 |     int secondParmNum;
 | 
|---|
| [74] | 93 |     Parameters realParams;
 | 
|---|
| [75] | 94 |     int realSecondParmNum;
 | 
|---|
| [74] | 95 | 
 | 
|---|
| [75] | 96 |     // 親クラスと対応するメソッド
 | 
|---|
 | 97 |     CClass *pParentClass;
 | 
|---|
 | 98 |     CMethod *pMethod;
 | 
|---|
| [74] | 99 | 
 | 
|---|
| [75] | 100 |     // 各種フラグ
 | 
|---|
 | 101 |     bool isExport;
 | 
|---|
 | 102 |     bool isSystem;
 | 
|---|
| [90] | 103 |     bool isAutoGeneration;
 | 
|---|
| [75] | 104 |     bool isCompiled;
 | 
|---|
| [74] | 105 | 
 | 
|---|
| [75] | 106 | public:
 | 
|---|
 | 107 |     // ハッシュリスト用
 | 
|---|
 | 108 |     UserProc *pNextData;
 | 
|---|
| [74] | 109 | 
 | 
|---|
| [75] | 110 |     UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
 | 
|---|
 | 111 |       Procedure( name, kind, isCdecl ),
 | 
|---|
 | 112 |       isMacro( isMacro ),
 | 
|---|
 | 113 |       pParentClass( NULL ),
 | 
|---|
 | 114 |       pMethod( NULL ),
 | 
|---|
 | 115 |       isExport( isExport ),
 | 
|---|
 | 116 |       isSystem( false ),
 | 
|---|
| [90] | 117 |       isAutoGeneration( false ),
 | 
|---|
| [75] | 118 |       isCompiled( false ),
 | 
|---|
 | 119 |       pNextData( NULL )
 | 
|---|
 | 120 |     {
 | 
|---|
 | 121 |     }
 | 
|---|
 | 122 |     ~UserProc(){
 | 
|---|
 | 123 |         foreach( Parameter *pParam, realParams ){
 | 
|---|
 | 124 |             delete pParam;
 | 
|---|
 | 125 |         }
 | 
|---|
 | 126 |     }
 | 
|---|
 | 127 | 
 | 
|---|
| [91] | 128 |     string GetFullName() const
 | 
|---|
 | 129 |     {
 | 
|---|
 | 130 |         if( HasParentClass() ){
 | 
|---|
 | 131 |             return (string)GetParentClass().name + "." + GetName();
 | 
|---|
 | 132 |         }
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 |         return GetName();
 | 
|---|
 | 135 |     }
 | 
|---|
 | 136 | 
 | 
|---|
| [75] | 137 |     bool IsMacro() const
 | 
|---|
 | 138 |     {
 | 
|---|
 | 139 |         return isMacro;
 | 
|---|
 | 140 |     }
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 |     virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 |     int GetSecondParmNum() const
 | 
|---|
 | 145 |     {
 | 
|---|
 | 146 |         return secondParmNum;
 | 
|---|
 | 147 |     }
 | 
|---|
 | 148 |     const Parameters &RealParams() const
 | 
|---|
 | 149 |     {
 | 
|---|
 | 150 |         return realParams;
 | 
|---|
 | 151 |     }
 | 
|---|
 | 152 |     int GetRealSecondParmNum() const
 | 
|---|
 | 153 |     {
 | 
|---|
 | 154 |         return realSecondParmNum;
 | 
|---|
 | 155 |     }
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 |     void SetParentClass( CClass *pParentClass ){
 | 
|---|
 | 158 |         this->pParentClass = pParentClass;
 | 
|---|
 | 159 |     }
 | 
|---|
 | 160 |     CClass *GetParentClassPtr()
 | 
|---|
 | 161 |     {
 | 
|---|
 | 162 |         return pParentClass;
 | 
|---|
 | 163 |     }
 | 
|---|
 | 164 |     const CClass &GetParentClass() const
 | 
|---|
 | 165 |     {
 | 
|---|
 | 166 |         return *pParentClass;
 | 
|---|
 | 167 |     }
 | 
|---|
| [89] | 168 |     bool HasParentClass() const
 | 
|---|
 | 169 |     {
 | 
|---|
 | 170 |         return ( pParentClass != NULL );
 | 
|---|
 | 171 |     }
 | 
|---|
| [75] | 172 |     void SetMethod( CMethod *pMethod ){
 | 
|---|
 | 173 |         this->pMethod = pMethod;
 | 
|---|
 | 174 |     }
 | 
|---|
 | 175 | 
 | 
|---|
 | 176 |     void ExportOff(){
 | 
|---|
 | 177 |         isExport = false;
 | 
|---|
 | 178 |     }
 | 
|---|
 | 179 |     bool IsExport() const
 | 
|---|
 | 180 |     {
 | 
|---|
 | 181 |         return isExport;
 | 
|---|
 | 182 |     }
 | 
|---|
 | 183 |     void ThisIsSystemProc(){
 | 
|---|
 | 184 |         isSystem = true;
 | 
|---|
 | 185 |     }
 | 
|---|
 | 186 |     bool IsSystem() const
 | 
|---|
 | 187 |     {
 | 
|---|
 | 188 |         return isSystem;
 | 
|---|
 | 189 |     }
 | 
|---|
| [90] | 190 |     void ThisIsAutoGenerationProc(){
 | 
|---|
 | 191 |         isAutoGeneration = true;
 | 
|---|
 | 192 |     }
 | 
|---|
 | 193 |     bool IsAutoGeneration(){
 | 
|---|
 | 194 |         return isAutoGeneration;
 | 
|---|
 | 195 |     }
 | 
|---|
| [75] | 196 |     void CompleteCompile(){
 | 
|---|
 | 197 |         isCompiled = true;
 | 
|---|
 | 198 |     }
 | 
|---|
 | 199 |     void KillCompileStatus(){
 | 
|---|
 | 200 |         isCompiled = false;
 | 
|---|
 | 201 |     }
 | 
|---|
 | 202 |     bool IsCompiled() const
 | 
|---|
 | 203 |     {
 | 
|---|
 | 204 |         return isCompiled;
 | 
|---|
 | 205 |     }
 | 
|---|
 | 206 |     bool IsDestructor() const
 | 
|---|
 | 207 |     {
 | 
|---|
 | 208 |         return ( GetName()[0] == '~' );
 | 
|---|
 | 209 |     }
 | 
|---|
 | 210 |     bool IsVirtual() const
 | 
|---|
 | 211 |     {
 | 
|---|
 | 212 |         if( pMethod == NULL ){
 | 
|---|
 | 213 |             return false;
 | 
|---|
 | 214 |         }
 | 
|---|
 | 215 |         return ( pMethod->bVirtual != 0 );
 | 
|---|
 | 216 |     }
 | 
|---|
 | 217 | 
 | 
|---|
 | 218 | 
 | 
|---|
 | 219 |     // バイナリコードの位置
 | 
|---|
 | 220 |     DWORD beginOpAddress;
 | 
|---|
 | 221 |     DWORD endOpAddress;
 | 
|---|
| [91] | 222 |     int GetCodeSize() const
 | 
|---|
 | 223 |     {
 | 
|---|
 | 224 |         return endOpAddress - beginOpAddress;
 | 
|---|
 | 225 |     }
 | 
|---|
| [75] | 226 | 
 | 
|---|
 | 227 |     // ローカル変数
 | 
|---|
 | 228 |     Variables localVars;
 | 
|---|
 | 229 | 
 | 
|---|
 | 230 |     // TODO: 適切なコードへ直す
 | 
|---|
 | 231 |     long id;
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 | 
 | 
|---|
 | 234 |     /////////////////////////////////////////////////////////////////
 | 
|---|
 | 235 |     // コンパイル中の関数を管理
 | 
|---|
 | 236 |     /////////////////////////////////////////////////////////////////
 | 
|---|
 | 237 | private:
 | 
|---|
 | 238 |     static UserProc *pCompilingUserProc;
 | 
|---|
 | 239 | public:
 | 
|---|
 | 240 |     static void CompileStartForGlobalArea(){
 | 
|---|
 | 241 |         pCompilingUserProc = NULL;
 | 
|---|
 | 242 |     }
 | 
|---|
 | 243 |     static void CompileStartForUserProc( UserProc *pUserProc ){
 | 
|---|
 | 244 |         pCompilingUserProc = pUserProc;
 | 
|---|
 | 245 |     }
 | 
|---|
 | 246 |     static bool IsGlobalAreaCompiling(){
 | 
|---|
 | 247 |         return ( pCompilingUserProc == NULL );
 | 
|---|
 | 248 |     }
 | 
|---|
 | 249 |     static bool IsLocalAreaCompiling(){
 | 
|---|
 | 250 |         return ( pCompilingUserProc != NULL );
 | 
|---|
 | 251 |     }
 | 
|---|
 | 252 |     static UserProc &CompilingUserProc(){
 | 
|---|
 | 253 |         return *pCompilingUserProc;
 | 
|---|
 | 254 |     }
 | 
|---|
| [74] | 255 | };
 | 
|---|
| [75] | 256 | 
 | 
|---|
 | 257 | class DllProc : public Procedure
 | 
|---|
 | 258 | {
 | 
|---|
 | 259 |     const string dllFileName;
 | 
|---|
 | 260 |     const string alias;
 | 
|---|
 | 261 |     int lookupAddress;
 | 
|---|
 | 262 | 
 | 
|---|
 | 263 | public:
 | 
|---|
 | 264 |     // ハッシュリスト用
 | 
|---|
 | 265 |     DllProc *pNextData;
 | 
|---|
 | 266 | 
 | 
|---|
 | 267 |     DllProc( const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
 | 
|---|
 | 268 |       Procedure( name, kind, isCdecl ),
 | 
|---|
 | 269 |       dllFileName( dllFileName ),
 | 
|---|
 | 270 |       alias( alias ),
 | 
|---|
 | 271 |       lookupAddress( 0 ),
 | 
|---|
 | 272 |       pNextData( NULL )
 | 
|---|
 | 273 |     {
 | 
|---|
 | 274 |     }
 | 
|---|
 | 275 |     ~DllProc(){}
 | 
|---|
 | 276 | 
 | 
|---|
 | 277 |     virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
 | 
|---|
 | 278 | 
 | 
|---|
 | 279 |     const string &GetDllFileName() const
 | 
|---|
 | 280 |     {
 | 
|---|
 | 281 |         return dllFileName;
 | 
|---|
 | 282 |     }
 | 
|---|
 | 283 |     const string &GetAlias() const
 | 
|---|
 | 284 |     {
 | 
|---|
 | 285 |         return alias;
 | 
|---|
 | 286 |     }
 | 
|---|
 | 287 | 
 | 
|---|
 | 288 |     void SetLookupAddress( int lookupAddress ){
 | 
|---|
 | 289 |         this->lookupAddress = lookupAddress;
 | 
|---|
 | 290 |     }
 | 
|---|
 | 291 |     int GetLookupAddress() const
 | 
|---|
 | 292 |     {
 | 
|---|
 | 293 |         return lookupAddress;
 | 
|---|
 | 294 |     }
 | 
|---|
 | 295 | 
 | 
|---|
 | 296 | };
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 | class ProcPointer : public Procedure
 | 
|---|
 | 299 | {
 | 
|---|
 | 300 | public:
 | 
|---|
 | 301 |     ProcPointer( Kind kind ):
 | 
|---|
 | 302 |       Procedure( "", kind, false )
 | 
|---|
 | 303 |     {
 | 
|---|
 | 304 |     }
 | 
|---|
 | 305 |     ~ProcPointer(){}
 | 
|---|
 | 306 | 
 | 
|---|
 | 307 |     virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
 | 
|---|
 | 308 | };
 | 
|---|