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