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