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

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

依存関係を整理中

File size: 2.8 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, _int64 i64data, const Type &type )
10{
11 CConst *newconst = new CConst(namespaceScopes, name, type, i64data);
12
13 //ハッシュリストに追加
14 Put( newconst );
15}
16void Consts::Add(const NamespaceScopes &namespaceScopes, const std::string &name, int value){
17 CConst *newconst = new CConst( namespaceScopes, name, value);
18
19 //ハッシュリストに追加
20 Put( newconst );
21}
22
23CConst *Consts::GetObjectPtr( const Symbol &symbol )
24{
25 CConst *pConst = GetHashArrayElement( symbol.GetName().c_str() );
26 while( pConst )
27 {
28 if( pConst->IsEqualSymbol( symbol ) )
29 {
30 break;
31 }
32 pConst = pConst->GetChainNext();
33 }
34
35 return pConst;
36}
37
38
39int Consts::GetBasicType( const Symbol &symbol ){
40 CConst *pConst = GetObjectPtr( symbol );
41
42 if(!pConst) return 0;
43
44 return pConst->GetType().GetBasicType();
45}
46_int64 Consts::GetWholeData( const Symbol &symbol ){
47 CConst *pConst = GetObjectPtr( symbol );
48
49 if(!pConst) return 0;
50
51 return pConst->GetWholeData();
52}
53double Consts::GetDoubleData( const Symbol &symbol ){
54 CConst *pConst = GetObjectPtr( symbol );
55
56 if(!pConst) return 0;
57
58 return pConst->GetDoubleData();
59}
60bool Consts::IsStringPtr( const Symbol &symbol, bool isUnicode ){
61 CConst *pConst = GetObjectPtr( symbol );
62
63 if(!pConst) return false;
64
65 const Type &type = pConst->GetType();
66
67 int charType = isUnicode
68 ? MAKE_PTR_TYPE(DEF_WORD,1)
69 : MAKE_PTR_TYPE(DEF_SBYTE,1);
70
71 return ( type.GetBasicType() == charType && type.GetIndex() == LITERAL_STRING );
72}
73
74// マクロ定数を追加するための関数
75bool ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
76{
77 std::vector<std::string> parameters;
78
79 int i = 0;
80 if(parameterStr[i]!='(')
81 {
82 return false;
83 }
84
85 char temporary[VN_SIZE];
86 int i2;
87 for(i++,i2=0;;i++,i2++){
88 if(parameterStr[i]=='\0')
89 {
90 return false;
91 }
92 if(parameterStr[i]==','||parameterStr[i]==')'){
93 temporary[i2]=0;
94
95 parameters.push_back( temporary );
96
97 if(parameterStr[i]==')'){
98 i++;
99 if(parameterStr[i]!='=')
100 {
101 return false;
102 }
103 break;
104 }
105
106 i2=-1;
107 continue;
108 }
109 temporary[i2]=parameterStr[i];
110 }
111
112 //データ
113 lstrcpy(temporary,parameterStr+i+1);
114
115 this->Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
116
117 return true;
118}
119ConstMacro *ConstMacros::Find( const Symbol &symbol )
120{
121 ConstMacro *pConstMacro = GetHashArrayElement( symbol.GetName().c_str() );
122 while( pConstMacro )
123 {
124 if( pConstMacro->IsEqualSymbol( symbol ) )
125 {
126 break;
127 }
128 pConstMacro = pConstMacro->GetChainNext();
129 }
130
131 return pConstMacro;
132}
Note: See TracBrowser for help on using the repository browser.