source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Const.cpp

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 2.7 KB
Line 
1#include "stdafx.h"
2
3double CConst::GetDoubleData(){
4 double dbl;
5 memcpy(&dbl,&i64data,sizeof(_int64));
6 return dbl;
7}
8
9bool CConst::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
10{
11 type.Resolve( resolver, resolveErrors );
12 return true;
13}
14
15void Consts::Add( const Symbol &symbol, _int64 i64data, const Type &type )
16{
17 CConst *newconst = new CConst( symbol, type, i64data );
18
19 //ハッシュリストに追加
20 Put( newconst );
21}
22void Consts::Add(const Symbol &symbol, int value){
23 CConst *newconst = new CConst( symbol, value);
24
25 //ハッシュリストに追加
26 Put( newconst );
27}
28
29CConst *Consts::GetObjectPtr( const Symbol &symbol )
30{
31 auto c = GetHashArrayElement(symbol.GetName());
32 auto it = std::find_if(c.begin(), c.end(),
33 [&](CConst* t) {return t->IsEqualSymbol(symbol);});
34 return it != c.end()
35 ? *it
36 : nullptr;
37}
38
39
40int Consts::GetBasicType( const Symbol &symbol ){
41 CConst *pConst = GetObjectPtr( symbol );
42
43 if(!pConst) return 0;
44
45 return pConst->GetType().GetBasicType();
46}
47_int64 Consts::GetWholeData( const Symbol &symbol ){
48 CConst *pConst = GetObjectPtr( symbol );
49
50 if(!pConst) return 0;
51
52 return pConst->GetWholeData();
53}
54double Consts::GetDoubleData( const Symbol &symbol ){
55 CConst *pConst = GetObjectPtr( symbol );
56
57 if(!pConst) return 0;
58
59 return pConst->GetDoubleData();
60}
61bool Consts::IsStringPtr( const Symbol &symbol, bool isUnicode ){
62 CConst *pConst = GetObjectPtr( symbol );
63
64 if(!pConst) return false;
65
66 const Type &type = pConst->GetType();
67
68 int charType = isUnicode
69 ? MAKE_PTR_TYPE(DEF_WORD,1)
70 : MAKE_PTR_TYPE(DEF_SBYTE,1);
71
72 return ( type.GetBasicType() == charType && type.GetIndex() == LITERAL_STRING );
73}
74
75bool ConstMacro::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
76{
77 // 依存関係を解決すべきメンバは無い
78 return true;
79}
80
81// マクロ定数を追加するための関数
82bool ConstMacros::Add( const Symbol &symbol, 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 strcpy(temporary,parameterStr+i+1);
121
122 this->Put( new ConstMacro( symbol, parameters, temporary ) );
123
124 return true;
125}
126ConstMacro *ConstMacros::Find( const Symbol &symbol )
127{
128 auto c = GetHashArrayElement(symbol.GetName());
129 auto it = std::find_if(c.begin(), c.end(),
130 [&](ConstMacro* t) {return t->IsEqualSymbol(symbol);});
131 return it != c.end()
132 ? *it
133 : nullptr;
134}
Note: See TracBrowser for help on using the repository browser.