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

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

LexicalAnalyzer::ConstMacroToExpressionメソッドを実装。

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