Changeset 814 in dev for branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp
- Timestamp:
- Mar 19, 2011, 1:29:12 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp
r812 r814 4 4 #include "Compiler.h" 5 5 #include "StrOperation.h" 6 #include <boost/algorithm/string/predicate.hpp> 6 7 7 8 using namespace ActiveBasic::Compiler; 8 9 9 void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string&expression, int nowLine )10 void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const boost::iterator_range<char const*> &expression, int nowLine ) 10 11 { 11 int i; 12 char temporary[VN_SIZE]; 12 auto name = boost::find<boost::return_begin_found>(expression, '='); 13 13 14 for(i=0;;i++){ 15 if(expression[i]=='='||expression[i]=='\0'){ 16 temporary[i]=0; 17 break; 18 } 19 temporary[i]=expression[i]; 20 } 21 22 if(expression[i]!='='){ 23 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 14 if (boost::end(name) == boost::end(expression)) 15 { 16 compiler.errorMessenger.Output(10, "TypeDef", nowLine); 24 17 return; 25 18 } 26 19 27 const char *pTemp =expression.c_str()+i+1;20 const char *pTemp = expression.begin() + boost::size(name) + 1; 28 21 29 22 //識別文字のエラーチェック(新しい型) 30 i=0; 31 for(;;i++){ 32 if(temporary[i]=='\0') break; 33 if( !( IsVariableChar( temporary[i], true) ) ){ 34 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 35 return; 36 } 23 if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);})) 24 { 25 compiler.errorMessenger.Output(10, "TypeDef", nowLine); 26 return; 37 27 } 38 28 … … 45 35 } 46 36 } 47 else{ 48 i=0; 37 else 38 { 39 int i=0; 49 40 while(pTemp[i]=='*') i++; 50 for(;;i++){ 51 if(pTemp[i]=='\0') break; 52 if( !( IsVariableChar( pTemp[i], true) ) ) 53 { 54 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 55 return; 56 } 41 if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);})) 42 { 43 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 44 return; 57 45 } 58 46 } 59 47 48 std::string baseName(pTemp, expression.end()); 49 60 50 //識別子が重複している場合はエラーにする 61 if(lstrcmp(temporary,pTemp)==0){ 51 if (boost::algorithm::equals(name, baseName)) 52 { 62 53 compiler.errorMessenger.Output(1,NULL,nowLine); 63 54 return; … … 71 62 72 63 Type baseType; 73 if( !compiler.StringToType( pTemp, baseType ) )64 if( !compiler.StringToType( baseName, baseType ) ) 74 65 { 75 compiler.errorMessenger.Output(3, pTemp, nowLine );66 compiler.errorMessenger.Output(3, baseName, nowLine ); 76 67 return; 77 68 } … … 79 70 typeDefs.push_back( 80 71 TypeDef( 81 Symbol( namespaceScopes, temporary),82 pTemp,72 Symbol(namespaceScopes, boost::copy_range<std::string>(name)), 73 baseName, 83 74 baseType 84 75 ) … … 94 85 compiler.GetNamespaceSupporter().ClearImportedNamespaces(); 95 86 96 int i=-1, i2; 97 char temporary[VN_SIZE]; 98 while(1){ 99 100 i++; 101 87 for (int i = 0; ; ++i) 88 { 102 89 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 103 for(i+=2,i2=0;;i2++,i++){ 104 if( IsCommandDelimitation( source[i] ) ){ 105 temporary[i2]=0; 106 break; 107 } 108 temporary[i2]=source[i]; 90 i+=2; 91 char const* p = &source[i]; 92 while (!IsCommandDelimitation(source[i])) 93 { 94 ++i; 109 95 } 110 namespaceScopes.push_back( temporary);96 namespaceScopes.push_back(std::string(p, &source[i])); 111 97 112 98 continue; … … 124 110 } 125 111 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ 126 for(i+=2,i2=0;;i2++,i++){ 127 if( IsCommandDelimitation( source[i] ) ){ 128 temporary[i2]=0; 129 break; 130 } 131 temporary[i2]=source[i]; 112 i+=2; 113 char const* p = &source[i]; 114 while (!IsCommandDelimitation(source[i])) 115 { 116 ++i; 132 117 } 133 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) 118 std::string s(p, &source[i]); 119 if (!compiler.GetNamespaceSupporter().ImportsNamespace(s)) 134 120 { 135 compiler.errorMessenger.Output(64, temporary,i);121 compiler.errorMessenger.Output(64, s.c_str(), i); 136 122 } 137 123 … … 148 134 char temporary[VN_SIZE]; 149 135 if(source[i+1]==ESC_TYPEDEF){ 150 int i2 = 0; 151 for(i+=2;;i2++,i++){ 152 if(source[i]=='\n'){ 153 temporary[i2]=0; 154 break; 155 } 156 temporary[i2]=source[i]; 157 if(source[i]=='\0') break; 136 i+=2; 137 char const* p = &source[i]; 138 while (!IsCommandDelimitation(source[i])) 139 { 140 ++i; 158 141 } 159 AddTypeDef( typeDefs, namespaceScopes, temporary, i ); 160 142 AddTypeDef(typeDefs, namespaceScopes, boost::make_iterator_range(p, &source[i]), i); 161 143 continue; 162 144 } … … 172 154 } 173 155 174 Type baseType;175 if( !compiler.StringToType( "Long", baseType ) )176 {177 throw;178 }179 180 156 typeDefs.push_back( 181 157 TypeDef( 182 158 Symbol( namespaceScopes, temporary ), 183 159 "Long", 184 baseType160 Type(DEF_LONG) 185 161 ) 186 162 );
Note:
See TracChangeset
for help on using the changeset viewer.