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

Last change on this file since 581 was 579, checked in by dai_9181, 17 years ago

Consts/ConstMacrosクラスのLexicalAnalyzerクラスへの依存性をなくした。

File size: 3.0 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 Symbol &symbol )
39{
40 CConst *pConst = GetHashArrayElement( symbol.GetName().c_str() );
41 while( pConst )
42 {
43 if( pConst->IsEqualSymbol( symbol ) )
44 {
45 break;
46 }
47 pConst = pConst->GetChainNext();
48 }
49
50 return pConst;
51}
52
53
54int Consts::GetBasicType( const Symbol &symbol ){
55 CConst *pConst = GetObjectPtr( symbol );
56
57 if(!pConst) return 0;
58
59 return pConst->GetType().GetBasicType();
60}
61_int64 Consts::GetWholeData( const Symbol &symbol ){
62 CConst *pConst = GetObjectPtr( symbol );
63
64 if(!pConst) return 0;
65
66 return pConst->GetWholeData();
67}
68double Consts::GetDoubleData( const Symbol &symbol ){
69 CConst *pConst = GetObjectPtr( symbol );
70
71 if(!pConst) return 0;
72
73 return pConst->GetDoubleData();
74}
75bool Consts::IsStringPtr( const Symbol &symbol ){
76 CConst *pConst = GetObjectPtr( symbol );
77
78 if(!pConst) return false;
79
80 const Type &type = pConst->GetType();
81
82 return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
83}
84
85// マクロ定数を追加するための関数
86bool ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
87{
88 std::vector<std::string> parameters;
89
90 int i = 0;
91 if(parameterStr[i]!='(')
92 {
93 return false;
94 }
95
96 char temporary[VN_SIZE];
97 int i2;
98 for(i++,i2=0;;i++,i2++){
99 if(parameterStr[i]=='\0')
100 {
101 return false;
102 }
103 if(parameterStr[i]==','||parameterStr[i]==')'){
104 temporary[i2]=0;
105
106 parameters.push_back( temporary );
107
108 if(parameterStr[i]==')'){
109 i++;
110 if(parameterStr[i]!='=')
111 {
112 return false;
113 }
114 break;
115 }
116
117 i2=-1;
118 continue;
119 }
120 temporary[i2]=parameterStr[i];
121 }
122
123 //データ
124 lstrcpy(temporary,parameterStr+i+1);
125
126 this->Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
127
128 return true;
129}
130ConstMacro *ConstMacros::Find( const Symbol &symbol )
131{
132 ConstMacro *pConstMacro = GetHashArrayElement( symbol.GetName().c_str() );
133 while( pConstMacro )
134 {
135 if( pConstMacro->IsEqualSymbol( symbol ) )
136 {
137 break;
138 }
139 pConstMacro = pConstMacro->GetChainNext();
140 }
141
142 return pConstMacro;
143}
Note: See TracBrowser for help on using the repository browser.