source: dev/BasicCompiler_Common/Const.cpp@ 4

Last change on this file since 4 was 4, checked in by dai_9181, 17 years ago
File size: 1.5 KB
Line 
1#include "common.h"
2
3
4
5CConstBase::CConstBase(char *Name){
6 this->Name = (char *)malloc(lstrlen(Name)+1);
7 lstrcpy(this->Name, Name);
8}
9CConstBase::~CConstBase(){
10 free(Name);
11 Name=0;
12}
13
14
15
16CConst::CConst(char *Name, char *Expression):CConstBase(Name)
17{
18 LONG_PTR lpIndex;
19 Type = StaticCalculation(false, Expression, 0, &i64data, &lpIndex);
20}
21CConst::~CConst(){
22}
23
24
25
26CDBConst::CDBConst(){
27 //定数管理領域を初期化
28 ppobj_Const = (CConst **)malloc(1);
29 NumOfConst = 0;
30
31 //定数マクロ管理領域を初期化
32 ppobj_Macro = (CConstMacro **)malloc(1);
33 NumOfMacro = 0;
34}
35CDBConst::~CDBConst(){
36 int i;
37 for(i=0; i<NumOfConst; i++){
38 delete ppobj_Const[i];
39 }
40 free(ppobj_Const);
41 ppobj_Const = 0;
42
43 for(i=0; i<NumOfMacro; i++){
44 delete ppobj_Macro[i];
45 }
46 free(ppobj_Macro);
47 ppobj_Macro = 0;
48}
49
50void CDBConst::Add(char *buffer){
51 int i;
52
53 //名前を取得
54 char Name[VN_SIZE];
55 for(i=0;;i++){
56 if(buffer[i]=='\0'){
57 SetError(10,"Const",cp);
58 return;
59 }
60 if(buffer[i]=='='||buffer[i]=='('){
61 Name[i]=0;
62 break;
63 }
64 Name[i]=buffer[i];
65 }
66
67 if(buffer[i] == '('){
68 //定数マクロ
69
70 //未完成
71 }
72 else{
73 //一般の定数
74 char *Expression = buffer + i + 1;
75
76 AddConst(Name,Expression);
77 }
78}
79
80void CDBConst::AddConst(char *Name, char *Expression){
81 CConst *newconst = new CConst(Name, Expression);
82
83 //管理クラスへ追加
84 ppobj_Const = (CConst **)realloc( ppobj_Const, (NumOfConst + 1) * sizeof(CConst) );
85 ppobj_Const[NumOfConst] = newconst;
86 NumOfConst++;
87}
Note: See TracBrowser for help on using the repository browser.