Changeset 15936a6d in tol
- Timestamp:
- Sep 1, 2009, 8:33:24 AM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 8cf5460
- Parents:
- 992be58
- File:
-
- 1 edited
-
tol/btol/bgrammar/class.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/btol/bgrammar/class.cpp
r992be58 r15936a6d 35 35 #include <tol/tol_blanguag.h> 36 36 #include <tol/tol_bnameblock.h> 37 #include <tol/tol_bcodgra.h> 38 37 39 38 40 //-------------------------------------------------------------------- … … 42 44 BTraceInit("class.cpp"); 43 45 const BClass* BClass::currentClassBuildingInstance_ = NULL; 46 const BClass* BClass::currentStatic_ = NULL; 44 47 45 48 //-------------------------------------------------------------------- … … 95 98 BCore* car; 96 99 parent_ = parent; 97 BToken* tok = (BToken*)branch->car();98 100 isGood_ = true; 99 if((tok->TokenType()==MONARY)&&(tok->Name()=="static")) 101 BToken* tok = NULL; 102 if(parent && branch && branch->car()) 103 { 104 tok = (BToken*)branch->car(); 105 } 106 else 107 { 108 isGood_ = false; 109 } 110 if(isGood_ && (tok->TokenType()==MONARY) && (tok->Name()=="Static")) 100 111 { 101 112 isStatic_ = true; 102 branch_ = branch = branch->cdr(); 103 } 104 if((tok->TokenType()==BINARY)&&(tok->Name()=="=")) 105 { 106 //If is a '=' expression then is not a method and has default value 107 isMethod_ = false; 108 BText expression = BParser::Unparse(branch,"",""); 109 if(expression[0]=='[') 110 { 111 expression = expression.SubString(2,expression.Length()-3); 112 } 113 else if(expression[0]=='{') 114 { 115 expression = expression.SubString(1,expression.Length()-2); 116 } 117 int posEq = expression.Find("="); 118 int posSp = expression.Find(" "); 119 name_ = expression.SubString(posSp+1,posEq-1); 120 declaration_ = expression.SubString(0,posEq-1); 121 definition_ = expression.SubString(posEq+1,expression.Length()); 122 } 123 else if((tok->TokenType()==BINARY)&&(tok->Name()=="#F#")) 124 { 125 //If is a '#F#' expression then is a method and has default value 126 isMethod_ = true; 127 cdr = branch->cdr(); 128 if(cdr) 129 { 130 car = cdr->car(); 131 if(car && car->IsListClass()) 132 { 133 declaration_ = BParser::Unparse((List*)car,"",""); 134 if(((List*)car)->cdr() && 135 ((List*)car)->cdr()->car() && 136 ((List*)car)->cdr()->car()->IsListClass()) 113 if(!(branch = branch->cdr())) 114 { 115 isGood_ = false; 116 } 117 else 118 { 119 if(branch->car()->IsListClass()) 120 { 121 branch = ((List*)branch->car()); 122 } 123 else 124 { 125 isGood_ = false; 126 } 127 } 128 if(isGood_) 129 { 130 tok = (BToken*)branch->car(); 131 } 132 branch_ = branch; 133 } 134 if(isGood_) 135 { 136 if((tok->TokenType()==BINARY)&&(tok->Name()=="=")) 137 { 138 //If is a '=' expression then is not a method and has default value 139 isMethod_ = false; 140 BText expression = BParser::Unparse(branch,"",""); 141 if(expression[0]=='[') 142 { 143 expression = expression.SubString(2,expression.Length()-3); 144 } 145 else if(expression[0]=='{') 146 { 147 expression = expression.SubString(1,expression.Length()-2); 148 } 149 int posEq = expression.Find("="); 150 int posSp = expression.Find(" "); 151 name_ = expression.SubString(posSp+1,posEq-1); 152 declaration_ = expression.SubString(0,posEq-1); 153 definition_ = expression.SubString(posEq+1,expression.Length()); 154 } 155 else if((tok->TokenType()==BINARY)&&(tok->Name()=="#F#")) 156 { 157 //If is a '#F#' expression then is a method and has default value 158 isMethod_ = true; 159 cdr = branch->cdr(); 160 if(cdr) 161 { 162 car = cdr->car(); 163 if(car && car->IsListClass()) 137 164 { 138 car = ((List*)((List*)car)->cdr()->car())->car(); 139 tok = (BToken*)car; 140 name_ = tok->Name(); 141 cdr = cdr->cdr(); 142 if(cdr) 165 declaration_ = BParser::Unparse((List*)car,"",""); 166 if(((List*)car)->cdr() && 167 ((List*)car)->cdr()->car() && 168 ((List*)car)->cdr()->car()->IsListClass()) 143 169 { 144 car = cdr->car(); 145 if(car && car->IsListClass()) 170 car = ((List*)((List*)car)->cdr()->car())->car(); 171 tok = (BToken*)car; 172 name_ = tok->Name(); 173 cdr = cdr->cdr(); 174 if(cdr) 146 175 { 147 definition_ = BParser::Unparse((List*)car,"",""); 148 } 149 else 150 { 151 isGood_ = false; 176 car = cdr->car(); 177 if(car && car->IsListClass()) 178 { 179 definition_ = BParser::Unparse((List*)car,"",""); 180 } 181 else 182 { 183 isGood_ = false; 184 } 152 185 } 153 186 } … … 155 188 } 156 189 } 157 }158 else if(tok->TokenType()==TYPE)159 {160 //If is a 'Type name ...' expression then hasn't default value161 declaration_ = BParser::Unparse(branch,"","");162 car = branch->cdr()->car();163 car = (car->IsListClass())?((List*)car)->car():car;164 tok = (BToken*)car;165 name_ = tok->Name();166 //If main token is FUNCTION then member is a method167 isMethod_ = tok->TokenType()==FUNCTION;168 }169 else if((tok->TokenType()==BINARY)&&(tok->Name()=="::"))170 {171 declaration_ = BParser::Unparse(branch,"","");172 BText simpleDec = declaration_;173 isMethod_ = simpleDec.Find('(')>=0;174 simpleDec.Replace("("," ");175 simpleDec.Compact();176 int p0 = simpleDec.Find(' ');177 if(p0>0)178 {179 int p1 = simpleDec.Find(' ', p0+1);180 if(p1<0) { p1 = simpleDec.Length()+1; }181 if(p0+1<p1-1)182 {183 name_ = simpleDec.SubString(p0+1,p1-1);184 } 185 } 186 }187 //Cleaning open and close parenthesis188 if(declaration_[0]=='{')189 {190 declaration_=declaration_.SubString(1,declaration_.Length()-2);190 else if(tok->TokenType()==TYPE) 191 { 192 //If is a 'Type name ...' expression then hasn't default value 193 declaration_ = BParser::Unparse(branch,"",""); 194 car = branch->cdr()->car(); 195 car = (car->IsListClass())?((List*)car)->car():car; 196 tok = (BToken*)car; 197 name_ = tok->Name(); 198 //If main token is FUNCTION then member is a method 199 isMethod_ = tok->TokenType()==FUNCTION; 200 } 201 else if((tok->TokenType()==BINARY)&&(tok->Name()=="::")) 202 { 203 declaration_ = BParser::Unparse(branch,"",""); 204 BText simpleDec = declaration_; 205 isMethod_ = simpleDec.Find('(')>=0; 206 simpleDec.Replace("("," "); 207 simpleDec.Compact(); 208 int p0 = simpleDec.Find(' '); 209 if(p0>0) 210 { 211 int p1 = simpleDec.Find(' ', p0+1); 212 if(p1<0) { p1 = simpleDec.Length()+1; } 213 if(p0+1<p1-1) 214 { 215 name_ = simpleDec.SubString(p0+1,p1-1); 216 } 217 } 218 } 219 //Cleaning open and close parenthesis 220 if(declaration_[0]=='{') 221 { 222 declaration_=declaration_.SubString(1,declaration_.Length()-2); 223 } 191 224 } 192 225 //Checking mandatory information: name and declaration. 193 226 //Definition is optional 194 if(! name_.HasName() || !declaration_.HasName())227 if(!isGood_ || !name_.HasName() || !declaration_.HasName()) 195 228 { 196 229 isGood_ = false; 197 230 Error(I2("Wrong syntax in member declaration ", 198 231 "Sintaxis incorrecta en declaración de miembro ")+ 199 BParser::Unparse(branch ,"","\n")+232 BParser::Unparse(branch_,"","\n")+ 200 233 I2(" of Class ", "de Class ")+parent->getName()); 201 234 } … … 249 282 //-------------------------------------------------------------------- 250 283 { 251 if(! method_ && isMethod_ && definition_.HasName())284 if(!isStatic_ && !method_ && isMethod_ && definition_.HasName()) 252 285 { 253 286 BGrammar::IncLevel(); … … 293 326 { 294 327 static_ = obj; 328 if(isMethod_) 329 { 330 if(obj->Mode()==BOBJECTMODE) 331 { 332 obj = UCode(obj)->Contens().Operator(); 333 } 334 ((BUserFunction*)obj)->staticOwner_=(const BClass*)parent_; 335 } 295 336 static_->IncNRefs(); 296 337 return(1); … … 950 991 class_->PutName(name); 951 992 BGrammar::AddObject(class_); 952 assert(!class_ || FindClass(name,-1));953 993 } 954 994 } … … 1083 1123 } 1084 1124 1125 //-------------------------------------------------------------------- 1126 static BClass* FindClassInNameBlock( 1127 const BText& name, 1128 BUserNameBlock*& unb ) 1129 //-------------------------------------------------------------------- 1130 { 1131 BClass* cls = NULL; 1132 BSyntaxObject* obj; 1133 int pos = name.Find("::",0); 1134 if(pos>=0) 1135 { 1136 BText prefix; 1137 BText sufix; 1138 prefix = name.SubString(0,pos-1); 1139 sufix = name.SubString(pos+2,name.Length()); 1140 if(!unb) 1141 { 1142 obj = GraNameBlock()->FindVariable(prefix); 1143 if(obj && obj->Grammar()==GraNameBlock()) 1144 { 1145 unb = (BUserNameBlock*)obj; 1146 } 1147 } 1148 else 1149 { 1150 BNameBlock& nb = unb->Contens(); 1151 obj = nb.Member(prefix); 1152 if(obj && obj->Grammar()==GraNameBlock()) 1153 { 1154 unb = (BUserNameBlock*)obj; 1155 } 1156 else 1157 { 1158 unb = NULL; 1159 } 1160 } 1161 if(unb) 1162 { 1163 cls = FindClassInNameBlock(sufix, unb); 1164 } 1165 } 1166 else if(unb) 1167 { 1168 BNameBlock& nb = unb->Contens(); 1169 obj = nb.Member(name); 1170 if(obj && obj->Mode()==BCLASSMODE) 1171 { 1172 cls = (BClass*)obj; 1173 } 1174 } 1175 return(cls); 1176 } 1085 1177 1086 1178 //-------------------------------------------------------------------- … … 1093 1185 { 1094 1186 BSyntaxObject* result = NULL; 1095 BClass* bcls = BStackManager::FindClass(name); 1096 if(!bcls) 1187 BUserNameBlock* unb = NULL; 1188 BClass* cls = FindClassInNameBlock(name, unb); 1189 if(!cls) 1190 { 1191 cls = BStackManager::FindClass(name); 1192 } 1193 if(!cls) 1097 1194 { 1098 1195 const BNameBlock* cns = BNameBlock::Current(); … … 1102 1199 if(result && (result->Mode()==BCLASSMODE)) 1103 1200 { 1104 bcls = (BClass*)result;1201 cls = (BClass*)result; 1105 1202 } 1106 1203 if(!result) … … 1111 1208 } 1112 1209 } 1113 if(! bcls)1210 if(!cls) 1114 1211 { 1115 1212 BObjClassify oc(GraAnything(),BCLASSMODE); 1116 bcls= (BClass*)BGrammar::SymbolTable().Search(oc, name);1117 } 1118 if(! bcls)1213 cls= (BClass*)BGrammar::SymbolTable().Search(oc, name); 1214 } 1215 if(!cls) 1119 1216 { 1120 1217 result = BNameBlock::UsingMember(name); 1121 1218 if(result && (result->Mode()==BCLASSMODE)) 1122 1219 { 1123 bcls = (BClass*)result; 1124 } 1125 } 1126 if(bcls && (defined>=0) && (bcls->isDefined_!=defined)) 1127 { 1128 bcls = NULL; 1129 } 1130 return(bcls); 1131 } 1132 1133 //-------------------------------------------------------------------- 1134 BSyntaxObject* BClass::FindMethod(const BText& memberName) const 1220 cls = (BClass*)result; 1221 } 1222 } 1223 if(cls && (defined>=0) && (cls->isDefined_!=defined)) 1224 { 1225 cls = NULL; 1226 } 1227 return(cls); 1228 } 1229 1230 //-------------------------------------------------------------------- 1231 static bool checkNonPrivate( 1232 const BClass* cls, 1233 const BText& memberName, 1234 bool fullAccess) 1235 //-------------------------------------------------------------------- 1236 { 1237 if(!fullAccess && (memberName[0]=='_')&&(memberName[1]!='.')) 1238 { 1239 Error(I2("Cannot access to private member ", 1240 "No se puede acceder al miembro privado ")+memberName + 1241 I2(" of Class ", 1242 " de Class ")+cls->Name()); 1243 return(false); 1244 } 1245 else 1246 { 1247 return(true); 1248 } 1249 } 1250 //-------------------------------------------------------------------- 1251 BSyntaxObject* BClass::FindMethod(const BText& memberName, bool fullAccess) const 1135 1252 //-------------------------------------------------------------------- 1136 1253 { 1137 1254 BSyntaxObject* result = NULL; 1138 1255 BMember* mbr = FindMember(memberName); 1139 if(mbr && mbr->method_ )1256 if(mbr && mbr->method_ && checkNonPrivate(this, memberName, fullAccess)) 1140 1257 { 1141 1258 result = mbr->method_; … … 1145 1262 1146 1263 //-------------------------------------------------------------------- 1147 BSyntaxObject* BClass::FindStaticMethod(const BText& methodName ) const1264 BSyntaxObject* BClass::FindStaticMethod(const BText& methodName, bool fullAccess) const 1148 1265 //-------------------------------------------------------------------- 1149 1266 { 1150 1267 BSyntaxObject* result = NULL; 1151 1268 BMember* mbr = FindMember(methodName); 1152 if(mbr && mbr->isStatic_ && mbr->isMethod_) 1269 if(mbr && mbr->isStatic_ && mbr->isMethod_ && 1270 checkNonPrivate(this, methodName, fullAccess)) 1153 1271 { 1154 result = mbr->method_; 1272 result = mbr->static_; 1273 result->PutNameBlock(NULL); 1155 1274 } 1156 1275 return(result); … … 1158 1277 1159 1278 //-------------------------------------------------------------------- 1160 BSyntaxObject* BClass::FindStaticMemeber(const BText& memberName ) const1279 BSyntaxObject* BClass::FindStaticMemeber(const BText& memberName, bool fullAccess) const 1161 1280 //-------------------------------------------------------------------- 1162 1281 { 1163 1282 BSyntaxObject* result = NULL; 1164 1283 BMember* mbr = FindMember(memberName); 1165 if(mbr && mbr->static_ && !mbr->isMethod_) 1284 if(mbr && mbr->static_ && !mbr->isMethod_ && 1285 checkNonPrivate(this, memberName, fullAccess)) 1166 1286 { 1167 1287 result = mbr->static_; 1288 result->PutNameBlock(NULL); 1168 1289 } 1169 1290 return(result); 1170 1291 } 1171 1292 1293 //-------------------------------------------------------------------- 1294 BSyntaxObject* BClass::FindStatic(const BText& methodName, bool fullAccess) const 1295 //-------------------------------------------------------------------- 1296 { 1297 BSyntaxObject* result = NULL; 1298 BMember* mbr = FindMember(methodName); 1299 if(mbr && mbr->isStatic_ && checkNonPrivate(this, methodName, fullAccess)) 1300 { 1301 result = mbr->static_; 1302 result->PutNameBlock(NULL); 1303 } 1304 return(result); 1305 } 1306
Note: See TracChangeset
for help on using the changeset viewer.
