source: dev/trunk/abdev/BasicCompiler_Common/common.h@ 163

Last change on this file since 163 was 141, checked in by dai_9181, 17 years ago

CClass::vtblNumをリファクタリングした。
インターフェイスを継承したとき、Objectクラスがインターフェイスの後ろに配置されてしまうバグを修正(どんなときも、Objectクラスが一番最初に継承されるべき)

File size: 14.7 KB
Line 
1//#define _CRT_SECURE_NO_DEPRECATE
2#pragma warning(disable : 4996)
3
4#include <windows.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <commctrl.h>
9#include <time.h>
10#include <limits.h>
11#include <shlobj.h>
12#include <vector>
13#include <string>
14#include <fstream>
15
16//boost libraries
17#include <boost/foreach.hpp>
18
19#define foreach BOOST_FOREACH
20
21using namespace std;
22
23#ifdef _AMD64_
24#include "../BasicCompiler64/resource.h"
25#include "../BasicCompiler64/CommandValue.h"
26#include "../BasicCompiler64/FunctionValue.h"
27#define OPCODE_H_PATH "../BasicCompiler64/opcode.h"
28#else
29#include "../BasicCompiler32/resource.h"
30#include "../BasicCompiler32/CommandValue.h"
31#include "../BasicCompiler32/FunctionValue.h"
32#define OPCODE_H_PATH "../BasicCompiler32/opcode.h"
33#endif
34
35#include "../BasicCompiler_Common/BasicFixed.h"
36#include "../BasicCompiler_Common/NonVolatile.h"
37#include "../BasicCompiler_Common/psapi.h"
38#include "../BasicCompiler_Common/BreakPoint.h"
39#include "../BasicCompiler_Common/LexicalScoping.h"
40
41
42
43//バージョン
44#define MAJOR_VER 5
45#define MINOR_VER 00
46#define REVISION_VER 00
47
48#ifdef _AMD64_
49#define VER_INFO "(x64) (rev.280)"
50#else
51#define VER_INFO "(rev.280)"
52#endif
53
54#if defined(JPN)
55//日本語
56#include "common_msg_jpn.h"
57#else
58//英語
59#include "common_msg_eng.h"
60#endif
61
62
63#define PTR_SIZE sizeof(LONG_PTR)
64#define OBJECT_HEAD_SIZE PTR_SIZE*4
65
66#define MAX_LEN 65535
67#define VN_SIZE 512
68#define DIGIT_SIZE 128
69#define MAX_PARMS 64
70#define MAX_ARRAYDIM 16
71#define MAX_HASH 32761
72
73
74#ifdef _AMD64_
75#define PLATFORM 64
76#else
77#define PLATFORM 32
78typedef long LONG_PTR;
79typedef DWORD ULONG_PTR;
80#endif
81
82
83//未定義の定数情報
84#ifndef IMAGE_FILE_MACHINE_AMD64
85 #define IMAGE_FILE_MACHINE_AMD64 0x8664
86#endif
87
88#ifdef _AMD64_
89 #ifndef IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
90 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
91 #endif
92#else
93 #ifndef IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
94 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
95 #endif
96#endif
97
98
99extern HWND hOwnerEditor;
100extern HANDLE hHeap;
101extern char BasicSystemDir[MAX_PATH];
102extern int cp;
103extern bool isUnicode;
104extern int typeOfPtrChar;
105extern int typeOfPtrUChar;
106
107
108
109//////////////////////////////////////////
110// BasicCompiler、ProjectEditor共通の定数
111//////////////////////////////////////////
112
113//サイズ変更枠の太さ
114#define LEVER_THICK 5
115
116#define WM_SHOWERROR WM_USER+70 //エラー表示メッセージ
117
118#define WM_SETCOMPILEVIEW WM_USER+71 //コンパイラウィンドウが表示されたとき
119#define WM_DESTROYCOMPILEVIEW WM_USER+72 //コンパイラウィンドウが破棄されたとき
120
121#define WM_SETDEBUGGERBASE WM_USER+73 //デバッガベースウィンドウが表示されたとき
122#define WM_DESTROYDEBUGGERBASE WM_USER+74 //デバッガベースウィンドウが破棄されたとき
123
124#define WM_SETDEBUGGERVIEW WM_USER+75 //デバッガウィンドウが表示されたとき
125#define WM_DESTROYDEBUGGERVIEW WM_USER+76 //デバッガウィンドウが表示されたとき
126
127///////////////////////////////////////////
128
129
130#define WM_SHOWVARLIST WM_USER+80
131#define WM_VARLIST_CLOSE WM_USER+81 //変数リストの終了メッセージ(破棄のみ、解放なし)
132
133
134
135///////////////////////////////////////////
136// デバッグ コマンド
137
138#define WM_DEBUG_CONTINUE WM_USER+200
139#define WM_STEP_IN WM_USER+201
140#define WM_STEP_OVER WM_USER+202
141#define WM_STEP_CURSOR WM_USER+203
142#define WM_DEBUG_STOP WM_USER+204
143#define WM_DEBUG_PAUSE WM_USER+205
144#define WM_CLOSE_DEBUGGER WM_USER+206
145
146///////////////////////////////////////////
147
148
149
150
151#define FILE_ALIGNMENT 0x1000
152#define MEM_ALIGNMENT 0x1000
153#define EXE_HEADER_SIZE 0x1000
154
155
156// ログ生成を行うためのクラス
157#include <logger.h>
158
159// クラス管理用のクラス
160#include "Class.h"
161
162// 列挙体管理用のクラス
163#include "Enum.h"
164
165// 定数管理用のクラス
166#include "Const.h"
167
168// 変数管理用のクラス
169#include "Variable.h"
170
171// パラメータ管理用のクラス
172#include "Parameter.h"
173
174// プロシージャ管理用のクラス
175#include "Procedure.h"
176
177// コンパイラが必要とするデータハウス
178#include <Smoothie.h>
179
180
181
182struct ERRORINFO{
183 char *FileName;
184 int line;
185};
186struct INCLUDEFILEINFO{
187 char **ppFileNames;
188 int FilesNum;
189 int LineOfFile[MAX_LEN];
190};
191
192//変数の相対情報
193struct RELATIVE_VAR{
194 DWORD dwKind;
195 LONG_PTR offset;
196 BOOL bOffsetOffset;
197};
198
199struct CONSTINFO{
200 char *name;
201 char *StrValue;
202
203 double DblValue;
204 _int64 i64Value;
205 int type;
206 LONG_PTR lpIndex;
207
208 int ParmNum;
209 char **ppParm;
210
211 CONSTINFO *pNextData;
212};
213
214
215#define CODETYPE_SYSTEMPROC 0x0001
216#define CODETYPE_DEBUGPROC 0x0002
217struct LINEINFO{
218 int TopCp;
219 int TopObp;
220 DWORD dwCodeType;
221};
222struct RESOURCEDATAINFO{
223 DWORD dwId;
224 char FileName[MAX_PATH];
225};
226
227
228//////////////////////////////////////////
229// リソース ヘッダ(アイコン、カーソル用)
230typedef struct{
231 WORD idReserved;
232 WORD idType;
233 WORD idCount;
234}ICONDIR,CURSORDIR;
235
236
237/////////////////////////////
238// .curファイルのヘッダ情報
239struct CURSORDIRENTRY{
240 BYTE bWidth;
241 BYTE bHeight;
242 BYTE bColorCount;
243 BYTE bReserved;
244 WORD wXHotspot;
245 WORD wYHotspot;
246 DWORD dwBytesInRes;
247 DWORD dwImageOffset;
248};
249struct CURSORDIRENTRY_RES{
250 WORD wWidth;
251 WORD wHeight;
252 WORD wXHotspot;
253 WORD wYHotspot;
254 DWORD dwBytesInRes;
255 WORD wCursorNum;
256};
257
258
259////////////////////////////
260//.icoファイルのヘッダ情報
261struct ICONDIRENTRY{
262 BYTE bWidth;
263 BYTE bHeight;
264 BYTE bColorCount;
265 BYTE bReserved;
266 WORD wPlanes;
267 WORD wBitCount;
268 DWORD dwBytesInRes;
269 DWORD dwImageOffset;
270};
271struct ICONDIRENTRY_RES{
272 BYTE bWidth;
273 BYTE bHeight;
274 BYTE bColorCount;
275 BYTE bReserved;
276 WORD wPlanes;
277 WORD wBitCount;
278 DWORD dwBytesInRes;
279 WORD wIconNum;
280};
281
282
283
284#include "../BasicCompiler_Common/PESchedule.h"
285#include "../BasicCompiler_Common/DebugSection.h"
286#include "../BasicCompiler_Common/VariableOpe.h"
287#include <Exception.h>
288
289
290
291bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList=0, bool *pIsMemoryAccessError=NULL);
292
293
294//BasicCompiler.cpp
295void HeapDefaultFree(LPVOID lpMem);
296void ts(int i);
297void ts(int i,int i2);
298void ts(char *msg);
299void ts(char *msg,char *title);
300void epi_check();
301void GetRelationalPath(char *path,char *dir);
302void GetFullPath(char *path,char *dir);
303void ShowErrorLine(int LineNum,char *FileName);
304BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,BOOL bOpen);
305void MakeMessageText(char *buffer,char *msg,int flag);
306
307//hash.cpp
308int hash_default(const char *name);
309CONSTINFO *GetConstHash(const char *name);
310DllProc *GetDeclareHash(char *name);
311void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs );
312UserProc *GetSubHash(const char *name,BOOL bError=0);
313UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError=0);
314UserProc *GetClassMethod( const char *className, const char *methodName );
315
316//Object.cpp
317void CallConstructor( const char *ObjectName,const int *SubScripts, const Type &type,const char *Parameter);
318bool Operator_New( const char *expression, const Type &baseType, Type &resultType );
319
320//Overload.sbp
321UserProc *OverloadSolutionWithStrParam(
322 const char *name,
323 std::vector<UserProc *> &subs,
324 const char *Parameter,
325 const char *ObjectName);
326UserProc *OverloadSolution(
327 const char *name,
328 std::vector<UserProc *> &subs,
329 const Parameters &params,
330 const Type &returnType );
331
332//Debug.cpp
333void Debugger_StepIn(void);
334void Debugger_StepOver(void);
335void Debugger_StepCursor(void);
336void Debugger_Stop(void);
337void Debugger_Pause(void);
338ULONG_PTR rva_to_real(DWORD p);
339GlobalProc *GetSubFromObp(ULONG_PTR pos);
340void ReadOpBuffer();
341void DebugProgram(void);
342
343//VarList.cpp
344void InitVarList(DWORD dwThreadId);
345BOOL CALLBACK DlgDebugger(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
346BOOL CALLBACK DlgVarList(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
347
348//WatchList.cpp
349ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar);
350ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip);
351int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss);
352
353//MakeExe.cpp
354void StepCompileProgress(void);
355void DeleteConstInfo(CONSTINFO **ppConstHash);
356void DeleteDeclareInfo(void);
357void AddSourceCode(char *buffer);
358void OutputExe(void);
359int MainThread(DWORD dummy);
360
361//Intermediate_Step1.cpp
362void ChangeReturnCode(char *buffer);
363void DeleteComment(char *buffer);
364void KillReturnCode(char *buffer);
365void CheckParenthesis(char *buffer);
366BOOL CheckParenthesis2(char *buffer);
367void DirectiveCheck(void);
368void NextCommandFormat(char *buffer);
369void SetEscapeSequenceFormat(char *buffer);
370void DefCommandFormat(char *buffer);
371void IfCommandFormat(char *buffer);
372void CheckPareCommand(void);
373
374//Intermediate_Step2.cpp
375bool GetConstInfo(void);
376void ChangeCommandToCode(char *buffer);
377
378//preprocessor.cpp
379char *OpenBasicFile(char *FileName);
380
381//Resource.cpp
382void GetResourceData(char *FileName);
383
384//CommandFormat.cpp
385void ComOpen(char *Parameter,char *buffer,int nowLine);
386void ComClose(char *Parameter,char *buffer);
387void ComField(char *Parameter,char *buffer);
388void ComLine(char *Parameter,char *buffer,int nowLine);
389void ComCircle(char *Parameter,char *buffer,int nowLine);
390void ComPSet(char *Parameter,char *buffer,int nowLine);
391void ComPaint(char *Parameter,char *buffer,int nowLine);
392
393// StrOperation.cpp
394void KillSpaces(char *str1,char *str2);
395void KillStringSpaces(char *str);
396BOOL RemoveStringQuotes(char *str);
397void RemoveStringPare(char *str);
398void RemoveStringBracket(char *str);
399void SetStringQuotes(char *str);
400int FormatString_EscapeSequence(char *buffer);
401void SlideString(char *str,int slide);
402void SlideBuffer(char *buffer,int length,int slide);
403_int8 IsCommandDelimitation(char c);
404BOOL IsBlank(char c);
405int GetOneParameter(const char *Parameter,int pos,char *retAns);
406int JumpOneParameter(char *Parameter,int i);
407int GetStringInQuotation(char *buffer,char *ReadBuffer);
408int GetStringInPare(char *buffer,const char *ReadBuffer);
409int GetStringInPare_RemovePare(char *buffer,char *ReadBuffer);
410int GetStringInBracket(char *buffer,const char *ReadBuffer);
411int JumpStringInPare(const char *buffer,int pos);
412int JumpStringInBracket(const char *buffer,int pos);
413int GetCpFromLine(int LineNum);
414BOOL GetLineNum(int pos,int *pLine,char *FileName);
415char GetEndXXXCommand(char es);
416void GetDefaultNameFromES(char es,char *name);
417void GetCalcName(int idCalc,char *name);
418BOOL IsFile(char *path);
419BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath);
420BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle);
421void ShortPathToLongPath(const char *ShortPath,char *LongPath);
422
423//calculation.cpp
424bool IsNumberTopChar(const char *buffer);
425bool IsNumberChar(const char c);
426BOOL IsNumCalcMark(const char *Command,int p);
427BOOL IsNumCalcMark_Back(const char *Command,int p);
428BOOL IsStrCalcMark(const char c);
429BOOL IsExponent(const char *Command,int p);
430int GetLiteralIndex(_int64 i64data);
431int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2);
432DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType);
433BOOL GetConstCalcBuffer(const char *name,const char *Parameter,char *pCalcBuffer);
434DWORD GetConstValue(char *name,double *dbl,char *buffer,LONG_PTR *plpIndex);
435int IsStrCalculation(char *Command);
436BYTE GetCalcId(const char *Command,int *pi);
437BOOL GetNumOpeElements(const char *Command,int *pnum,
438 char *values[255],long calc[255],long stack[255]);
439
440//NumOpe_GetType.cpp
441int AutoBigCast(int BaseType,int CalcType);
442BOOL CheckCalcType(int idCalc,int *type,int sp);
443bool GetTermType( const char *term, Type &resultType, bool &isLiteral, bool *pIsClassName = NULL );
444bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType );
445
446//Subroutine.cpp
447int GetCallProcName(char *buffer,char *name);
448int GetProc(char *name,void **ppInfo);
449void SplitObjectName(const char *name,char *ObjectName,int *pRefType);
450bool SplitMemberName( const char *desc, char *object, char *member, CClass::RefType &refType );
451bool SplitMemberName( const char *desc, char *object, char *member );
452bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn = true );
453bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType);
454bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType );
455bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType );
456GlobalProc *AddSubData( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic = false );
457void GetSubInfo(void);
458void DeleteSubInfo(GlobalProc **ppSubHash,char **ppMacroNames,int MacroNum);
459void DeleteDeclareInfo(void);
460int AddProcPtrInfo( const string &typeExpression, int nowLine );
461void DeleteProcPtrInfo(void);
462bool IsNeedProcCompile();
463
464//OldStatement.cpp
465void Opcode_Input(const char *Parameter);
466void Opcode_Print(const char *Parameter,BOOL bWrite);
467
468//LoopRefCheck.cpp
469class CLoopRefCheck{
470 char **names;
471 int num;
472 void init();
473public:
474 CLoopRefCheck();
475 ~CLoopRefCheck();
476 void add(const char *lpszInheritsClass);
477 void del(const char *lpszInheritsClass);
478 BOOL check(const CClass &inheritsClass) const;
479};
480extern CLoopRefCheck *pobj_LoopRefCheck;
481
482//DataTable.cpp
483class DataTable{
484 void *pdata;
485 int size;
486
487public:
488 DataTable();
489 ~DataTable();
490 void Init();
491
492 int AddBinary( const void *pdata, int size );
493 int Add( _int64 i64data );
494 int Add( int i32data );
495 int Add( double dbl );
496 int Add( float flt );
497 int AddString( const char *str, int length );
498 int AddString( const char *str );
499
500 const void *GetPtr() const;
501 int GetSize() const;
502};
503extern DataTable dataTable;
504
505//error.cpp
506void SetError(int ErrorNum,const char *KeyWord,int pos);
507void SetError(int ErrorNum,const string &keyWord,int pos);
508void SetError();
509void CompileMessage(char *buffer);
510bool CheckDifferentType(const int VarType,const LONG_PTR lpVarIndex,const int CalcType,const LONG_PTR lpCalcIndex,const char *pszFuncName,const int ParmNum);
511bool CheckDifferentType( const Type &varType,const Type &calcType,const char *pszFuncName,const int ParmNum);
512
513//Compile.cpp
514void ReallocNativeCodeBuffer();
515void GetIdentifierToken( char *token, const char *source, int &pos );
516int JumpStatement(const char *source, int &pos);
517void DebugVariable(void);
518void Compile(void);
519
520//Diagnose.cpp
521void Diagnose();
522
523//gc.cpp
524void InitGCVariables(void);
525void PerformedGcVarSchedule(void);
526
527
528
529#ifdef _DEBUG
530/*Debug*/
531/*
532#define HeapAlloc CheckHeapAlloc
533#define HeapReAlloc CheckHeapReAlloc
534LPVOID CheckHeapAlloc(HANDLE hHeap,DWORD dwFlags,DWORD dwBytes);
535LPVOID CheckHeapReAlloc(HANDLE hHeap,DWORD dwFlags,LPVOID lpMem,DWORD dwBytes);
536*/
537#endif
Note: See TracBrowser for help on using the repository browser.