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