source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Const.cpp@ 578

Last change on this file since 578 was 578, checked in by dai_9181, 16 years ago

LexicalAnalyzer::ConstMacroToExpressionメソッドを実装。

File size: 3.4 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5using namespace ActiveBasic::Compiler;
6
7double CConst::GetDoubleData(){
8 double dbl;
9 memcpy(&dbl,&i64data,sizeof(_int64));
10 return dbl;
11}
12
13void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name , const char *Expression)
14{
15 _int64 i64data;
16 Type resultType;
17 if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){
18 //変数の場合
19 //何もしない(実行領域コンパイル時にdim宣言として扱う)
20 return;
21 }
22
23 //リテラル値の場合
24 //登録を行う
25
26 CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data);
27
28 //ハッシュリストに追加
29 Put( newconst );
30}
31void Consts::Add(const NamespaceScopes &namespaceScopes, const std::string &name, int value){
32 CConst *newconst = new CConst( namespaceScopes, name, value);
33
34 //ハッシュリストに追加
35 Put( newconst );
36}
37
38CConst *Consts::GetObjectPtr( const std::string &name ){
39 char ObjName[VN_SIZE]; //オブジェクト変数
40 char NestMember[VN_SIZE]; //入れ子メンバ
41 bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember );
42
43 CConst *pConst = GetHashArrayElement( NestMember );
44 while( pConst )
45 {
46 if( pConst->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) )
47 {
48 break;
49 }
50 pConst = pConst->GetChainNext();
51 }
52
53 return pConst;
54}
55
56
57int Consts::GetBasicType(const char *Name){
58 CConst *pConst = GetObjectPtr(Name);
59
60 if(!pConst) return 0;
61
62 return pConst->GetType().GetBasicType();
63}
64_int64 Consts::GetWholeData(const char *Name){
65 CConst *pConst = GetObjectPtr(Name);
66
67 if(!pConst) return 0;
68
69 return pConst->GetWholeData();
70}
71double Consts::GetDoubleData(const char *Name){
72 CConst *pConst = GetObjectPtr(Name);
73
74 if(!pConst) return 0;
75
76 return pConst->GetDoubleData();
77}
78bool Consts::IsStringPtr( const char *Name ){
79 CConst *pConst = GetObjectPtr(Name);
80
81 if(!pConst) return false;
82
83 const Type &type = pConst->GetType();
84
85 return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
86}
87
88// マクロ定数を追加するための関数
89void ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
90{
91 std::vector<std::string> parameters;
92
93 int i = 0;
94 if(parameterStr[i]!='(')
95 {
96 compiler.errorMessenger.OutputFatalError();
97 return;
98 }
99
100 char temporary[VN_SIZE];
101 int i2;
102 for(i++,i2=0;;i++,i2++){
103 if(parameterStr[i]=='\0'){
104 compiler.errorMessenger.Output(1,NULL,cp);
105 return;
106 }
107 if(parameterStr[i]==','||parameterStr[i]==')'){
108 temporary[i2]=0;
109
110 parameters.push_back( temporary );
111
112 if(parameterStr[i]==')'){
113 i++;
114 if(parameterStr[i]!='='){
115 extern int cp;
116 compiler.errorMessenger.Output(1,NULL,cp);
117 return;
118 }
119 break;
120 }
121
122 i2=-1;
123 continue;
124 }
125 temporary[i2]=parameterStr[i];
126 }
127
128 //データ
129 lstrcpy(temporary,parameterStr+i+1);
130
131 Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
132}
133ConstMacro *ConstMacros::Find( const std::string &name ){
134 char ObjName[VN_SIZE]; //オブジェクト変数
135 char NestMember[VN_SIZE]; //入れ子メンバ
136 bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember );
137
138 ConstMacro *pConstMacro = GetHashArrayElement( NestMember );
139 while( pConstMacro )
140 {
141 if( pConstMacro->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) )
142 {
143 break;
144 }
145 pConstMacro = pConstMacro->GetChainNext();
146 }
147
148 return pConstMacro;
149}
Note: See TracBrowser for help on using the repository browser.