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

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