Changeset 389
- Timestamp:
- 02/19/10 04:13:07 (2 years ago)
- Files:
-
- branches/dmd-1.x/src/e2ir.c (modified) (1 diff)
- branches/dmd-1.x/src/expression.c (modified) (1 diff)
- trunk/src/e2ir.c (modified) (2 diffs)
- trunk/src/expression.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/e2ir.c
r266 r389 2010 2010 Type *telement = t1->nextOf()->toBasetype(); 2011 2011 int rtlfunc; 2012 2012 2013 2013 ea1 = e1->toElem(irs); 2014 2014 ea1 = array_toDarray(t1, ea1); 2015 2015 ea2 = e2->toElem(irs); 2016 2016 ea2 = array_toDarray(t2, ea2); 2017 2017 2018 2018 #if DMDV2 2019 2019 ep = el_params(telement->arrayOf()->getInternalTypeInfo(NULL)->toElem(irs), 2020 2020 ea2, ea1, NULL); 2021 2021 rtlfunc = RTLSYM_ARRAYEQ2; 2022 2022 #else 2023 2023 ep = el_params(telement->getInternalTypeInfo(NULL)->toElem(irs), ea2, ea1, NULL); 2024 2024 rtlfunc = RTLSYM_ARRAYEQ; 2025 2025 #endif 2026 2026 e = el_bin(OPcall, TYint, el_var(rtlsym[rtlfunc]), ep); 2027 2027 if (op == TOKnotequal) 2028 2028 e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 2029 2029 el_setLoc(e,loc); 2030 } 2031 else if (t1->ty == Taarray && t2->ty == Taarray) 2032 { TypeAArray *taa = (TypeAArray *)t1; 2033 Symbol *s = taa->aaGetSymbol("Equal", 0); 2034 elem *ti = taa->getTypeInfo(NULL)->toElem(irs); 2035 elem *ea1 = e1->toElem(irs); 2036 elem *ea2 = e2->toElem(irs); 2037 // aaEqual(ti, e1, e2) 2038 elem *ep = el_params(ea2, ea1, ti, NULL); 2039 e = el_bin(OPcall, TYnptr, el_var(s), ep); 2040 if (op == TOKnotequal) 2041 e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 2042 el_setLoc(e,loc); 2043 return e; 2030 2044 } 2031 2045 else 2032 2046 e = toElemBin(irs, eop); 2033 2047 return e; 2034 2048 } 2035 2049 2036 2050 elem *IdentityExp::toElem(IRState *irs) 2037 2051 { 2038 2052 elem *e; 2039 2053 enum OPER eop; 2040 2054 Type *t1 = e1->type->toBasetype(); 2041 2055 Type *t2 = e2->type->toBasetype(); 2042 2056 2043 2057 switch (op) 2044 2058 { 2045 2059 case TOKidentity: eop = OPeqeq; break; 2046 2060 case TOKnotidentity: eop = OPne; break; 2047 2061 default: 2048 2062 dump(0); 2049 2063 assert(0); branches/dmd-1.x/src/expression.c
r382 r389 5240 5240 { char *name; 5241 5241 StringExp *se; 5242 5242 5243 5243 #if LOGSEMANTIC 5244 5244 printf("FileExp::semantic('%s')\n", toChars()); 5245 5245 #endif 5246 5246 UnaExp::semantic(sc); 5247 5247 e1 = resolveProperties(sc, e1); 5248 5248 e1 = e1->optimize(WANTvalue); 5249 5249 if (e1->op != TOKstring) 5250 5250 { error("file name argument must be a string, not (%s)", e1->toChars()); 5251 5251 goto Lerror; 5252 5252 } 5253 5253 se = (StringExp *)e1; 5254 5254 se = se->toUTF8(sc); 5255 5255 name = (char *)se->string; 5256 5256 5257 5257 if (!global.params.fileImppath) 5258 5258 { error("need -Jpath switch to import text file %s", name); 5259 5259 goto Lerror; 5260 } 5261 5262 /* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory 5263 * ('Path Traversal') attacks. 5264 * http://cwe.mitre.org/data/definitions/22.html 5265 */ 5266 5267 /* Do harsh sanitizing by limiting the name's character set. 5268 */ 5269 for (const char *p = name; *p; p++) 5270 { 5271 if (!(isalnum(*p) || *p == '.' || *p == '_')) 5272 { 5273 error("file name characters are restricted to [a-zA-Z0-9._] not '%c'", *p); 5274 goto Lerror; 5275 } 5260 5276 } 5261 5277 5262 5278 if (name != FileName::name(name)) 5263 5279 { error("use -Jpath switch to provide path for filename %s", name); 5264 5280 goto Lerror; 5265 5281 } 5266 5282 5267 5283 name = FileName::searchPath(global.filePath, name, 0); 5268 5284 if (!name) 5269 5285 { error("file %s cannot be found, check -Jpath", se->toChars()); 5270 5286 goto Lerror; 5271 5287 } 5272 5288 5273 5289 if (global.params.verbose) 5274 5290 printf("file %s\t(%s)\n", (char *)se->string, name); 5275 5291 5276 5292 { File f(name); 5277 5293 if (f.read()) 5278 5294 { error("cannot read file %s", f.toChars()); 5279 5295 goto Lerror; trunk/src/e2ir.c
r368 r389 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-20 09by Digital Mars3 // Copyright (c) 1999-2010 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 // License for redistribution is by either the Artistic License 8 8 // in artistic.txt, or the GNU General Public License in gnu.txt. 9 9 // See the included readme.txt for details. 10 10 11 11 #include <stdio.h> 12 12 #include <string.h> 13 13 #include <time.h> 14 14 #include <complex.h> 15 15 16 16 #include "port.h" 17 17 18 18 #include "lexer.h" 19 19 #include "expression.h" 20 20 #include "mtype.h" 21 21 #include "dsymbol.h" 22 22 #include "declaration.h" 23 23 #include "enum.h" … … 2295 2295 { 2296 2296 Type *telement = t1->nextOf()->toBasetype(); 2297 2297 2298 2298 elem *ea1 = e1->toElem(irs); 2299 2299 ea1 = array_toDarray(t1, ea1); 2300 2300 elem *ea2 = e2->toElem(irs); 2301 2301 ea2 = array_toDarray(t2, ea2); 2302 2302 2303 2303 #if DMDV2 2304 2304 elem *ep = el_params(telement->arrayOf()->getInternalTypeInfo(NULL)->toElem(irs), 2305 2305 ea2, ea1, NULL); 2306 2306 int rtlfunc = RTLSYM_ARRAYEQ2; 2307 2307 #else 2308 2308 elem *ep = el_params(telement->getInternalTypeInfo(NULL)->toElem(irs), ea2, ea1, NULL); 2309 2309 int rtlfunc = RTLSYM_ARRAYEQ; 2310 2310 #endif 2311 2311 e = el_bin(OPcall, TYint, el_var(rtlsym[rtlfunc]), ep); 2312 2312 if (op == TOKnotequal) 2313 2313 e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 2314 2314 el_setLoc(e,loc); 2315 } 2316 else if (t1->ty == Taarray && t2->ty == Taarray) 2317 { TypeAArray *taa = (TypeAArray *)t1; 2318 Symbol *s = taa->aaGetSymbol("Equal", 0); 2319 elem *ti = taa->getTypeInfo(NULL)->toElem(irs); 2320 elem *ea1 = e1->toElem(irs); 2321 elem *ea2 = e2->toElem(irs); 2322 // aaEqual(ti, e1, e2) 2323 elem *ep = el_params(ea2, ea1, ti, NULL); 2324 e = el_bin(OPcall, TYnptr, el_var(s), ep); 2325 if (op == TOKnotequal) 2326 e = el_bin(OPxor, TYint, e, el_long(TYint, 1)); 2327 el_setLoc(e,loc); 2328 return e; 2315 2329 } 2316 2330 else 2317 2331 e = toElemBin(irs, eop); 2318 2332 return e; 2319 2333 } 2320 2334 2321 2335 elem *IdentityExp::toElem(IRState *irs) 2322 2336 { 2323 2337 elem *e; 2324 2338 enum OPER eop; 2325 2339 Type *t1 = e1->type->toBasetype(); 2326 2340 Type *t2 = e2->type->toBasetype(); 2327 2341 2328 2342 switch (op) 2329 2343 { 2330 2344 case TOKidentity: eop = OPeqeq; break; 2331 2345 case TOKnotidentity: eop = OPne; break; 2332 2346 default: 2333 2347 dump(0); 2334 2348 assert(0); trunk/src/expression.c
r382 r389 5584 5584 5585 5585 #if LOGSEMANTIC 5586 5586 printf("FileExp::semantic('%s')\n", toChars()); 5587 5587 #endif 5588 5588 UnaExp::semantic(sc); 5589 5589 e1 = resolveProperties(sc, e1); 5590 5590 e1 = e1->optimize(WANTvalue); 5591 5591 if (e1->op != TOKstring) 5592 5592 { error("file name argument must be a string, not (%s)", e1->toChars()); 5593 5593 goto Lerror; 5594 5594 } 5595 5595 se = (StringExp *)e1; 5596 5596 se = se->toUTF8(sc); 5597 5597 name = (char *)se->string; 5598 5598 5599 5599 if (!global.params.fileImppath) 5600 5600 { error("need -Jpath switch to import text file %s", name); 5601 5601 goto Lerror; 5602 5602 } 5603 5603 5604 /* Be wary of CWE-22: Improper Limitation of a Pathname to a Restricted Directory 5605 * ('Path Traversal') attacks. 5606 * http://cwe.mitre.org/data/definitions/22.html 5607 */ 5608 5609 /* Do harsh sanitizing by limiting the name's character set. 5610 */ 5611 for (const char *p = name; *p; p++) 5612 { 5613 if (!(isalnum(*p) || *p == '.' || *p == '_')) 5614 { 5615 error("file name characters are restricted to [a-zA-Z0-9._] not '%c'", *p); 5616 goto Lerror; 5617 } 5618 } 5619 5604 5620 if (name != FileName::name(name)) 5605 5621 { error("use -Jpath switch to provide path for filename %s", name); 5606 5622 goto Lerror; 5607 5623 } 5608 5624 5609 5625 name = FileName::searchPath(global.filePath, name, 0); 5610 5626 if (!name) 5611 5627 { error("file %s cannot be found, check -Jpath", se->toChars()); 5612 5628 goto Lerror; 5613 5629 } 5614 5630 5615 5631 if (global.params.verbose) 5616 5632 printf("file %s\t(%s)\n", (char *)se->string, name); 5617 5633 5618 5634 { File f(name); 5619 5635 if (f.read()) 5620 5636 { error("cannot read file %s", f.toChars()); 5621 5637 goto Lerror; 5622 5638 } 5623 5639 else
