[193] | 1 | #include <Compiler.h>
|
---|
[195] | 2 | #include <NamespaceSupporter.h>
|
---|
[193] | 3 |
|
---|
[4] | 4 | #include "common.h"
|
---|
[7] | 5 | #include OPCODE_H_PATH //opcode.h
|
---|
[4] | 6 |
|
---|
| 7 |
|
---|
[7] | 8 | //シングルトンオブジェクト
|
---|
| 9 | CDBConst CDBConst::obj;
|
---|
[4] | 10 |
|
---|
[7] | 11 |
|
---|
[103] | 12 | bool ConstBase::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
|
---|
| 13 | {
|
---|
| 14 | if( GetName() != name ){
|
---|
| 15 | return false;
|
---|
| 16 | }
|
---|
[199] | 17 | return compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->namespaceScopes, namespaceScopes );
|
---|
[4] | 18 | }
|
---|
[103] | 19 | bool ConstBase::IsEqualSymbol( const string &fullName ) const
|
---|
| 20 | {
|
---|
| 21 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
| 22 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
[182] | 23 | bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
|
---|
[4] | 24 |
|
---|
[103] | 25 | return IsEqualSymbol( NamespaceScopes( AreaName ), NestName );
|
---|
[7] | 26 | }
|
---|
[4] | 27 |
|
---|
| 28 |
|
---|
[7] | 29 |
|
---|
[103] | 30 |
|
---|
[188] | 31 | CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, const Type &newType, _int64 i64data)
|
---|
[103] | 32 | : ConstBase( namespaceScopes, name )
|
---|
[188] | 33 | , type( newType )
|
---|
[103] | 34 | , i64data( i64data )
|
---|
| 35 | , pNext( NULL )
|
---|
[4] | 36 | {
|
---|
| 37 | }
|
---|
[103] | 38 | CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, int value)
|
---|
| 39 | : ConstBase( namespaceScopes, name )
|
---|
| 40 | , type( Type(DEF_LONG) )
|
---|
| 41 | , i64data( value )
|
---|
| 42 | , pNext( NULL )
|
---|
[7] | 43 | {
|
---|
| 44 | }
|
---|
[4] | 45 | CConst::~CConst(){
|
---|
[7] | 46 | //連結先のオブジェクトを破棄
|
---|
| 47 | if(pNext){
|
---|
| 48 | delete pNext;
|
---|
| 49 | pNext = 0;
|
---|
| 50 | }
|
---|
[4] | 51 | }
|
---|
| 52 |
|
---|
[103] | 53 | Type CConst::GetType(){
|
---|
| 54 | return type;
|
---|
[7] | 55 | }
|
---|
| 56 | _int64 CConst::GetWholeData(){
|
---|
| 57 | return i64data;
|
---|
| 58 | }
|
---|
| 59 | double CConst::GetDoubleData(){
|
---|
| 60 | double dbl;
|
---|
| 61 | memcpy(&dbl,&i64data,sizeof(_int64));
|
---|
| 62 | return dbl;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
[103] | 67 | CConstMacro::CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression)
|
---|
| 68 | : ConstBase( namespaceScopes, name )
|
---|
[5] | 69 | {
|
---|
| 70 | }
|
---|
| 71 | CConstMacro::~CConstMacro(){
|
---|
| 72 | }
|
---|
[4] | 73 |
|
---|
| 74 |
|
---|
[5] | 75 |
|
---|
[7] | 76 |
|
---|
| 77 |
|
---|
[4] | 78 | CDBConst::CDBConst(){
|
---|
[7] | 79 | memset(this,0,sizeof(CDBConst));
|
---|
[4] | 80 |
|
---|
[7] | 81 | ppHash = (CConst **)calloc(MAX_HASH*sizeof(CConst *),1);
|
---|
| 82 | Init();
|
---|
[4] | 83 | }
|
---|
| 84 | CDBConst::~CDBConst(){
|
---|
[7] | 85 | Free();
|
---|
| 86 |
|
---|
| 87 | free(ppHash);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | //解放
|
---|
| 91 | void CDBConst::Free(){
|
---|
[4] | 92 | int i;
|
---|
[7] | 93 | for(i=0; i<MAX_HASH; i++){
|
---|
| 94 | if(ppHash[i]){
|
---|
| 95 | delete ppHash[i];
|
---|
| 96 | ppHash[i] = 0;
|
---|
| 97 | }
|
---|
[4] | 98 | }
|
---|
[7] | 99 | }
|
---|
[4] | 100 |
|
---|
[7] | 101 | //初期化
|
---|
| 102 | void CDBConst::Init(){
|
---|
| 103 | Free();
|
---|
[4] | 104 | }
|
---|
| 105 |
|
---|
[7] | 106 | void AddConstData(char *Command);
|
---|
[103] | 107 | void CDBConst::Add( const NamespaceScopes &namespaceScopes, char *buffer ){
|
---|
[4] | 108 | int i;
|
---|
| 109 |
|
---|
| 110 | //名前を取得
|
---|
| 111 | char Name[VN_SIZE];
|
---|
| 112 | for(i=0;;i++){
|
---|
| 113 | if(buffer[i]=='\0'){
|
---|
| 114 | SetError(10,"Const",cp);
|
---|
| 115 | return;
|
---|
| 116 | }
|
---|
| 117 | if(buffer[i]=='='||buffer[i]=='('){
|
---|
| 118 | Name[i]=0;
|
---|
| 119 | break;
|
---|
| 120 | }
|
---|
| 121 | Name[i]=buffer[i];
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[7] | 124 | //重複チェック
|
---|
[103] | 125 | if(GetBasicType(Name)){
|
---|
[7] | 126 | SetError(15,Name,cp);
|
---|
| 127 | return;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[4] | 130 | if(buffer[i] == '('){
|
---|
| 131 | //定数マクロ
|
---|
| 132 |
|
---|
| 133 | //未完成
|
---|
[7] | 134 | AddConstData(buffer);
|
---|
[4] | 135 | }
|
---|
| 136 | else{
|
---|
| 137 | //一般の定数
|
---|
| 138 | char *Expression = buffer + i + 1;
|
---|
| 139 |
|
---|
[103] | 140 | AddConst( namespaceScopes, Name,Expression);
|
---|
[4] | 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[103] | 144 | void CDBConst::AddConst( const string &name, CConst *newconst){
|
---|
| 145 | int key = hash_default(name.c_str());
|
---|
[7] | 146 |
|
---|
| 147 | //ハッシュリストに追加
|
---|
| 148 | if(ppHash[key]){
|
---|
| 149 | CConst *pConst = ppHash[key];
|
---|
| 150 | while(pConst->pNext){
|
---|
| 151 | pConst = pConst->pNext;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | pConst->pNext = newconst;
|
---|
| 155 | }
|
---|
| 156 | else{
|
---|
| 157 | ppHash[key] = newconst;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
[103] | 160 | void CDBConst::AddConst( const NamespaceScopes &namespaceScopes, const string &name , char *Expression){
|
---|
[7] | 161 | _int64 i64data;
|
---|
[75] | 162 | Type resultType;
|
---|
| 163 | if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){
|
---|
| 164 | //変数の場合
|
---|
| 165 | //何もしない(実行領域コンパイル時にdim宣言として扱う)
|
---|
| 166 | return;
|
---|
| 167 | }
|
---|
[4] | 168 |
|
---|
[75] | 169 | //リテラル値の場合
|
---|
| 170 | //登録を行う
|
---|
[7] | 171 |
|
---|
[103] | 172 | CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data);
|
---|
[7] | 173 |
|
---|
[103] | 174 | AddConst( name, newconst);
|
---|
[4] | 175 | }
|
---|
[103] | 176 | void CDBConst::AddConst(const NamespaceScopes &namespaceScopes, const string &name, int value){
|
---|
| 177 | CConst *newconst = new CConst( namespaceScopes, name, value);
|
---|
[7] | 178 |
|
---|
[103] | 179 | AddConst(name, newconst);
|
---|
[7] | 180 | }
|
---|
| 181 |
|
---|
[103] | 182 | CConst *CDBConst::GetObjectPtr( const string &name ){
|
---|
| 183 | char ObjName[VN_SIZE]; //オブジェクト変数
|
---|
| 184 | char NestMember[VN_SIZE]; //入れ子メンバ
|
---|
[182] | 185 | bool isObjectMember = CClass::SplitName( name.c_str(), ObjName, NestMember );
|
---|
[103] | 186 |
|
---|
[7] | 187 | //ハッシュ値を取得
|
---|
| 188 | int key;
|
---|
[103] | 189 | key=hash_default( NestMember );
|
---|
[7] | 190 |
|
---|
| 191 | //格納位置を取得
|
---|
| 192 | CConst *pConst;
|
---|
| 193 | pConst=ppHash[key];
|
---|
| 194 | while(pConst){
|
---|
[103] | 195 | if( pConst->IsEqualSymbol( name ) ) break;
|
---|
[7] | 196 |
|
---|
| 197 | pConst=pConst->pNext;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | return pConst;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
[103] | 204 | int CDBConst::GetBasicType(char *Name){
|
---|
[7] | 205 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 206 |
|
---|
| 207 | if(!pConst) return 0;
|
---|
| 208 |
|
---|
[103] | 209 | return pConst->GetType().GetBasicType();
|
---|
[7] | 210 | }
|
---|
| 211 | _int64 CDBConst::GetWholeData(char *Name){
|
---|
| 212 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 213 |
|
---|
| 214 | if(!pConst) return 0;
|
---|
| 215 |
|
---|
| 216 | return pConst->GetWholeData();
|
---|
| 217 | }
|
---|
| 218 | double CDBConst::GetDoubleData(char *Name){
|
---|
| 219 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 220 |
|
---|
| 221 | if(!pConst) return 0;
|
---|
| 222 |
|
---|
| 223 | return pConst->GetDoubleData();
|
---|
| 224 | }
|
---|
[103] | 225 | bool CDBConst::IsStringPtr( char *Name ){
|
---|
| 226 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 227 |
|
---|
| 228 | if(!pConst) return false;
|
---|
| 229 |
|
---|
| 230 | const Type &type = pConst->GetType();
|
---|
| 231 |
|
---|
| 232 | return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
|
---|
| 233 | }
|
---|