Changeset 78 in dev for BasicCompiler_Common/TypeDef.cpp
- Timestamp:
- Mar 25, 2007, 2:47:49 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/TypeDef.cpp
r46 r78 1 #include " ../BasicCompiler_Common/common.h"1 #include "common.h" 2 2 3 3 4 CDBTypeDef *pobj_DBTypeDef; 5 6 7 CTypeDef::CTypeDef(const char *name,char *base){8 lpszName=(char *)malloc(lstrlen(name)+1);9 lstrcpy(lpszName,name);10 lpszBaseName=(char *)malloc(lstrlen(base)+1);11 lstrcpy(lpszBaseName,base);4 TypeDef::TypeDef( const string &newName, const string &baseName ): 5 newName( newName ), 6 baseName( baseName ) 7 { 8 if( !Type::StringToType( baseName, baseType ) ){ 9 SetError(3, baseName, cp ); 10 return; 11 } 12 12 } 13 CTypeDef::~CTypeDef(){ 14 free(lpszName); 15 free(lpszBaseName); 13 TypeDef::~TypeDef(){ 16 14 } 17 15 18 16 19 CDBTypeDef::CDBTypeDef(){ 20 ppobj_TypeDef=(CTypeDef **)malloc(1); 21 iNum=0; 17 TypeDefCollection::TypeDefCollection(){ 22 18 } 23 CDBTypeDef::~CDBTypeDef(){ 24 init(); 25 free(ppobj_TypeDef); 19 TypeDefCollection::~TypeDefCollection(){ 26 20 } 27 void CDBTypeDef::init(){ 28 int i; 29 for(i=0;i<iNum;i++){ 30 delete ppobj_TypeDef[i]; 31 } 32 iNum=0; 33 } 34 void CDBTypeDef::add(const char *name,char *base){ 35 ppobj_TypeDef=(CTypeDef **)realloc(ppobj_TypeDef,(iNum+1)*sizeof(CTypeDef *)); 36 ppobj_TypeDef[iNum]=new CTypeDef(name,base); 37 iNum++; 21 void TypeDefCollection::Add( const string &newName, const string &baseName ){ 22 TypeDef typeDef( newName, baseName ); 23 this->push_back( typeDef ); 38 24 39 25 26 /* 27 TODO: 消す1 40 28 //////////////////////// 41 29 // 循環参照をチェック … … 43 31 44 32 int i; 45 char temporary[1024]; 46 lstrcpy(temporary,base); 33 string tempName = newName; 47 34 48 35 while(1){ 49 i= check(temporary);36 i=GetIndex( tempName ); 50 37 if(i==-1) break; 51 38 52 if( lstrcmp(base,ppobj_TypeDef[i]->lpszBaseName)==0){39 if( (*this)[i].baseName == newName ){ 53 40 //循環エラー 54 41 extern int cp; … … 56 43 57 44 //不明な型として、Long型を指定しておく 58 ppobj_TypeDef[i]->lpszBaseName=(char *)realloc(ppobj_TypeDef[i]->lpszBaseName,5); 59 lstrcpy(ppobj_TypeDef[i]->lpszBaseName,"Long"); 45 (*this)[i].baseName = "Long"; 60 46 61 47 break; 62 48 } 63 49 64 lstrcpy(temporary,ppobj_TypeDef[i]->lpszBaseName);65 } 50 tempName = (*this)[i].baseName; 51 }*/ 66 52 } 67 int CDBTypeDef::check(const char *name){68 int i;69 for( i=0;i<iNum;i++){70 if( lstrcmp(ppobj_TypeDef[i]->lpszName,name)==0){53 int TypeDefCollection::GetIndex( const string &typeName ) const{ 54 int max = (*this).size(); 55 for( int i=0; i<max; i++ ){ 56 if( (*this)[i].newName == typeName ){ 71 57 return i; 72 58 } … … 75 61 } 76 62 77 78 79 void AddTypeDefData(char *Command){ 80 extern int cp; 63 void TypeDefCollection::Add( const string &expression, int nowLine ){ 81 64 int i; 82 char temporary[VN_SIZE] ,*pTemp;65 char temporary[VN_SIZE]; 83 66 84 67 for(i=0;;i++){ 85 if( Command[i]=='='||Command[i]=='\0'){68 if(expression[i]=='='||expression[i]=='\0'){ 86 69 temporary[i]=0; 87 70 break; 88 71 } 89 temporary[i]= Command[i];72 temporary[i]=expression[i]; 90 73 } 91 74 92 if( Command[i]!='='){93 SetError(10,"TypeDef", cp);75 if(expression[i]!='='){ 76 SetError(10,"TypeDef",nowLine); 94 77 return; 95 78 } 96 79 97 pTemp=Command+i+1;80 const char *pTemp=expression.c_str()+i+1; 98 81 99 82 //識別文字のエラーチェック(新しい型) … … 102 85 if(temporary[i]=='\0') break; 103 86 if(!IsVariableChar(temporary[i])){ 104 SetError(10,"TypeDef", cp);87 SetError(10,"TypeDef",nowLine); 105 88 return; 106 89 } … … 111 94 //関数ポインタ 112 95 if(pTemp[3]!='('){ 113 SetError(10,"TypeDef", cp);96 SetError(10,"TypeDef",nowLine); 114 97 return; 115 98 } … … 121 104 if(pTemp[i]=='\0') break; 122 105 if(!IsVariableChar(pTemp[i])){ 123 SetError(10,"TypeDef", cp);106 SetError(10,"TypeDef",nowLine); 124 107 return; 125 108 } … … 129 112 //識別子が重複している場合はエラーにする 130 113 if(lstrcmp(temporary,pTemp)==0){ 131 SetError(1,NULL, cp);114 SetError(1,NULL,nowLine); 132 115 return; 133 116 } … … 138 121 // TypeDef情報を追加 139 122 ////////////////////////// 140 pobj_DBTypeDef->add(temporary,pTemp); 123 124 //エラー用 125 extern int cp; 126 cp = nowLine; 127 128 House::typeDefs.Add(temporary,pTemp); 141 129 } 130 131 void TypeDefCollection::Init(){ 132 // 初期化 133 clear(); 134 135 int i=-1; 136 while(1){ 137 i++; 138 139 extern char *basbuf; 140 if( basbuf[i]==1 ){ 141 char temporary[VN_SIZE]; 142 if(basbuf[i+1]==ESC_TYPEDEF){ 143 int i2 = 0; 144 for(i+=2;;i2++,i++){ 145 if(basbuf[i]=='\n'){ 146 temporary[i2]=0; 147 break; 148 } 149 temporary[i2]=basbuf[i]; 150 if(basbuf[i]=='\0') break; 151 } 152 Add(temporary,i); 153 154 continue; 155 } 156 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){ 157 int i2 = 0; 158 for(i+=4;;i2++,i++){ 159 if(!IsVariableChar(basbuf[i])){ 160 temporary[i2]=0; 161 break; 162 } 163 temporary[i2]=basbuf[i]; 164 if(basbuf[i]=='\0') break; 165 } 166 House::typeDefs.Add(temporary,"Long"); 167 } 168 } 169 170 //次の行 171 for(;;i++){ 172 if(IsCommandDelimitation(basbuf[i])) break; 173 } 174 if(basbuf[i]=='\0') break; 175 } 176 }
Note:
See TracChangeset
for help on using the changeset viewer.