Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(166)

Delta Between Two Patch Sets: src/cmd/gc/walk.c

Issue 5966075: code review 5966075: cmd/gc: inline slice[arr,str] in the frontend (mostly). (Closed)
Left Patch Set: diff -r 99292bad0d6d https://go.googlecode.com/hg/ Created 12 years, 11 months ago
Right Patch Set: diff -r 316890203045 https://go.googlecode.com/hg/ Created 12 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 #include <u.h> 5 #include <u.h>
6 #include <libc.h> 6 #include <libc.h>
7 #include "go.h" 7 #include "go.h"
8 8
9 static Node* walkprint(Node*, NodeList**, int); 9 static Node* walkprint(Node*, NodeList**, int);
10 static Node* mapfn(char*, Type*); 10 static Node* mapfn(char*, Type*);
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 if (n->right != N && n->right->left == N && n->right->right == N ) { // noop 897 if (n->right != N && n->right->left == N && n->right->right == N ) { // noop
898 walkexpr(&n->left, init); 898 walkexpr(&n->left, init);
899 n = n->left; 899 n = n->left;
900 goto ret; 900 goto ret;
901 } 901 }
902 // fallthrough 902 // fallthrough
903 case OSLICEARR: 903 case OSLICEARR:
904 case OSLICESTR: 904 case OSLICESTR:
905 if(n->right) { 905 if(n->right) {
906 walkexpr(&n->left, init); 906 walkexpr(&n->left, init);
907 » » » n->left = copyexpr(n->left, n->left->type, init); 907 » » » // cgen_slice can't handle string literals as source
908 » » » // TODO the OINDEX case is a bug elsewhere that needs to be traced. it causes a crash on ([2][]int{ ... })[1][lo:hi]
909 » » » if((n->op == OSLICESTR && n->left->op == OLITERAL) || (n ->left->op == OINDEX))
910 » » » » n->left = copyexpr(n->left, n->left->type, init) ;
911 » » » else
912 » » » » n->left = safeexpr(n->left, init);
908 walkexpr(&n->right->left, init); 913 walkexpr(&n->right->left, init);
909 n->right->left = safeexpr(n->right->left, init); 914 n->right->left = safeexpr(n->right->left, init);
910 walkexpr(&n->right->right, init); 915 walkexpr(&n->right->right, init);
911 n->right->right = safeexpr(n->right->right, init); 916 n->right->right = safeexpr(n->right->right, init);
912 917
913 n = sliceany(n, init); // chops n->right, sets n->list 918 n = sliceany(n, init); // chops n->right, sets n->list
914 } 919 }
915 goto ret; 920 goto ret;
916 921
917 case OADDR: 922 case OADDR:
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 Node *src, *lb, *hb, *bound, *chk, *chk1, *chk2; 2337 Node *src, *lb, *hb, *bound, *chk, *chk1, *chk2;
2333 int64 lbv, hbv, bv, w; 2338 int64 lbv, hbv, bv, w;
2334 Type *bt; 2339 Type *bt;
2335 2340
2336 // print("before sliceany: %+N\n", n); 2341 // print("before sliceany: %+N\n", n);
2337 2342
2338 src = n->left; 2343 src = n->left;
2339 lb = n->right->left; 2344 lb = n->right->left;
2340 hb = n->right->right; 2345 hb = n->right->right;
2341 2346
2342 nochk = n->etype; 2347 nochk = n->etype;
rsc 2012/06/02 22:47:58 This is now n->bounded.
2343 ········ 2348 ········
2344 if(n->op == OSLICESTR) 2349 if(n->op == OSLICESTR)
2345 bound = nod(OLEN, src, N); 2350 bound = nod(OLEN, src, N);
2346 else 2351 else
2347 bound = nod(OCAP, src, N); 2352 bound = nod(OCAP, src, N);
2348 2353
2349 typecheck(&bound, Erv); 2354 typecheck(&bound, Erv);
2350 walkexpr(&bound, init); // if src is an array, bound will be a const no w. 2355 walkexpr(&bound, init); // if src is an array, bound will be a const no w.
2351 2356
2352 // static checks if possible 2357 // static checks if possible
2353 bv = (1LL << 31) - 1; // TODO this is to satisfy the unittest, which te sts with 1<<31 as smallest invalid 2358 bv = (1LL << 31) - 1; // TODO this is to satisfy the unittest, which te sts with 1<<31 as smallest invalid
2354 if (isconst(bound, CTINT)) 2359 if (isconst(bound, CTINT))
rsc 2012/06/02 22:47:58 All these isconst need to check the range of the v
2355 bv = mpgetfix(bound->val.u.xval); 2360 bv = mpgetfix(bound->val.u.xval);
2356 lbv = -1; 2361 lbv = -1;
2357 hbv = -1; 2362 hbv = -1;
2358 2363
2359 if(isconst(hb, CTINT)) { 2364 if(isconst(hb, CTINT)) {
2360 hbv = mpgetfix(hb->val.u.xval); 2365 hbv = mpgetfix(hb->val.u.xval);
2361 if(hbv < 0 || hbv > bv) { 2366 if(hbv < 0 || hbv > bv) {
2362 yyerror("slice index out of bounds"); 2367 yyerror("slice index out of bounds");
2363 hbv = -1; 2368 hbv = -1;
2364 } 2369 }
(...skipping 23 matching lines...) Expand all
2388 if(lb != N && lb->type->width > 4) 2393 if(lb != N && lb->type->width > 4)
2389 bt = types[TUINT64]; 2394 bt = types[TUINT64];
2390 2395
2391 bound = cheapexpr(conv(bound, bt), init); 2396 bound = cheapexpr(conv(bound, bt), init);
2392 2397
2393 if(hb != N) { 2398 if(hb != N) {
2394 hb = cheapexpr(conv(hb, bt), init); 2399 hb = cheapexpr(conv(hb, bt), init);
2395 if(!nochk) 2400 if(!nochk)
2396 chk1 = nod(OLT, bound, hb);·· 2401 chk1 = nod(OLT, bound, hb);··
2397 } else { 2402 } else {
2398 if(n->op == OSLICE) { 2403 if(n->op == OSLICE) {
rsc 2012/06/02 22:47:58 I think OSLICESTR should be here too.
2399 hb = nod(OLEN, src, N); 2404 hb = nod(OLEN, src, N);
2400 typecheck(&hb, Erv); 2405 typecheck(&hb, Erv);
2401 walkexpr(&hb, init); 2406 walkexpr(&hb, init);
2402 hb = cheapexpr(conv(hb, bt), init); 2407 hb = cheapexpr(conv(hb, bt), init);
2403 } else 2408 } else
2404 hb = bound; 2409 hb = bound;
2405 } 2410 }
2406 2411
2407 2412
2408 if(lb != N) { 2413 if(lb != N) {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 argtype(fn, n->left->type); 2651 argtype(fn, n->left->type);
2647 argtype(fn, n->left->type); 2652 argtype(fn, n->left->type);
2648 r = mkcall1(fn, n->type, init, typename(n->left->type), l, r); 2653 r = mkcall1(fn, n->type, init, typename(n->left->type), l, r);
2649 if(n->op == ONE) { 2654 if(n->op == ONE) {
2650 r = nod(ONOT, r, N); 2655 r = nod(ONOT, r, N);
2651 typecheck(&r, Erv); 2656 typecheck(&r, Erv);
2652 } 2657 }
2653 *np = r; 2658 *np = r;
2654 return; 2659 return;
2655 } 2660 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b