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

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

インクルード順序を整理

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