1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | double CConst::GetDoubleData(){
|
---|
4 | double dbl;
|
---|
5 | memcpy(&dbl,&i64data,sizeof(_int64));
|
---|
6 | return dbl;
|
---|
7 | }
|
---|
8 |
|
---|
9 | bool CConst::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
10 | {
|
---|
11 | type.Resolve( resolver, resolveErrors );
|
---|
12 | return true;
|
---|
13 | }
|
---|
14 |
|
---|
15 | void 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 | }
|
---|
22 | void Consts::Add(const Symbol &symbol, int value){
|
---|
23 | CConst *newconst = new CConst( symbol, value);
|
---|
24 |
|
---|
25 | //ハッシュリストに追加
|
---|
26 | Put( newconst );
|
---|
27 | }
|
---|
28 |
|
---|
29 | CConst *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 |
|
---|
40 | int 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 | }
|
---|
54 | double Consts::GetDoubleData( const Symbol &symbol ){
|
---|
55 | CConst *pConst = GetObjectPtr( symbol );
|
---|
56 |
|
---|
57 | if(!pConst) return 0;
|
---|
58 |
|
---|
59 | return pConst->GetDoubleData();
|
---|
60 | }
|
---|
61 | bool 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 |
|
---|
75 | bool ConstMacro::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
76 | {
|
---|
77 | // 依存関係を解決すべきメンバは無い
|
---|
78 | return true;
|
---|
79 | }
|
---|
80 |
|
---|
81 | // マクロ定数を追加するための関数
|
---|
82 | bool 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 | }
|
---|
126 | ConstMacro *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 | }
|
---|