LEFT | RIGHT |
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 #include "y.tab.h" | 8 #include "y.tab.h" |
9 #include <ar.h> | 9 #include <ar.h> |
10 | 10 |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 if(isbadimport(path)) { | 681 if(isbadimport(path)) { |
682 fakeimport(); | 682 fakeimport(); |
683 return; | 683 return; |
684 } | 684 } |
685 } | 685 } |
686 | 686 |
687 if(!findpkg(path)) { | 687 if(!findpkg(path)) { |
688 yyerror("can't find import: \"%Z\"", f->u.sval); | 688 yyerror("can't find import: \"%Z\"", f->u.sval); |
689 errorexit(); | 689 errorexit(); |
690 } | 690 } |
691 importpkg = mkpkg(path); | 691 importpkg = mkpkg(path); |
692 | 692 |
| 693 // If we already saw that package, feed a dummy statement |
| 694 // to the lexer to avoid parsing export data twice. |
| 695 if(importpkg->imported) { |
| 696 file = strdup(namebuf); |
| 697 p = smprint("package %s\n$$\n", importpkg->name); |
| 698 cannedimports(file, p); |
| 699 return; |
| 700 } |
| 701 importpkg->imported = 1; |
| 702 |
693 imp = Bopen(namebuf, OREAD); | 703 imp = Bopen(namebuf, OREAD); |
694 if(imp == nil) { | 704 if(imp == nil) { |
695 yyerror("can't open import: \"%Z\": %r", f->u.sval); | 705 yyerror("can't open import: \"%Z\": %r", f->u.sval); |
696 errorexit(); | 706 errorexit(); |
697 } | 707 } |
698 file = strdup(namebuf); | 708 file = strdup(namebuf); |
699 | 709 |
700 len = strlen(namebuf); | 710 len = strlen(namebuf); |
701 if(len > 2 && namebuf[len-2] == '.' && namebuf[len-1] == 'a') { | 711 if(len > 2 && namebuf[len-2] == '.' && namebuf[len-1] == 'a') { |
702 if(!skiptopkgdef(imp)) { | 712 if(!skiptopkgdef(imp)) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 continue; | 754 continue; |
745 c = getc(); | 755 c = getc(); |
746 if(c == EOF) | 756 if(c == EOF) |
747 break; | 757 break; |
748 if(c != '$') | 758 if(c != '$') |
749 continue; | 759 continue; |
750 return; | 760 return; |
751 } | 761 } |
752 yyerror("no import in \"%Z\"", f->u.sval); | 762 yyerror("no import in \"%Z\"", f->u.sval); |
753 unimportfile(); | 763 unimportfile(); |
754 } | |
755 | |
756 void | |
757 skipimportfile(void) | |
758 { | |
759 int32 c; | |
760 | |
761 for(;;) { | |
762 c = getc(); | |
763 if(c == EOF) | |
764 break; | |
765 if(c != '$') | |
766 continue; | |
767 c = getc(); | |
768 if(c == EOF) | |
769 break; | |
770 if(c != '$') | |
771 continue; | |
772 ungetc('$'); | |
773 ungetc('$'); | |
774 return; | |
775 } | |
776 } | 764 } |
777 | 765 |
778 void | 766 void |
779 unimportfile(void) | 767 unimportfile(void) |
780 { | 768 { |
781 if(curio.bin != nil) { | 769 if(curio.bin != nil) { |
782 Bterm(curio.bin); | 770 Bterm(curio.bin); |
783 curio.bin = nil; | 771 curio.bin = nil; |
784 } else | 772 } else |
785 lexlineno--; // re correct sys.6 line number | 773 lexlineno--; // re correct sys.6 line number |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 c = getc(); | 1299 c = getc(); |
1312 if(yy_isdigit(c)) | 1300 if(yy_isdigit(c)) |
1313 continue; | 1301 continue; |
1314 if(c >= 'a' && c <= 'f') | 1302 if(c >= 'a' && c <= 'f') |
1315 continue; | 1303 continue; |
1316 if(c >= 'A' && c <= 'F') | 1304 if(c >= 'A' && c <= 'F') |
1317 continue; | 1305 continue; |
1318 if(cp == lexbuf+2) | 1306 if(cp == lexbuf+2) |
1319 yyerror("malformed hex constant"); | 1307 yyerror("malformed hex constant"); |
1320 if(c == 'p') | 1308 if(c == 'p') |
1321 » » » » goto casep; | 1309 » » » » goto caseep; |
1322 goto ncu; | 1310 goto ncu; |
1323 } | 1311 } |
1324 } | 1312 } |
1325 | 1313 |
1326 if(c == 'p') // 0p begins floating point zero | 1314 if(c == 'p') // 0p begins floating point zero |
1327 » » goto casep; | 1315 » » goto caseep; |
1328 | 1316 |
1329 c1 = 0; | 1317 c1 = 0; |
1330 for(;;) { | 1318 for(;;) { |
1331 if(cp+10 >= ep) { | 1319 if(cp+10 >= ep) { |
1332 yyerror("identifier too long"); | 1320 yyerror("identifier too long"); |
1333 errorexit(); | 1321 errorexit(); |
1334 } | 1322 } |
1335 if(!yy_isdigit(c)) | 1323 if(!yy_isdigit(c)) |
1336 break; | 1324 break; |
1337 if(c < '0' || c > '7') | 1325 if(c < '0' || c > '7') |
1338 c1 = 1; // not octal | 1326 c1 = 1; // not octal |
1339 *cp++ = c; | 1327 *cp++ = c; |
1340 c = getc(); | 1328 c = getc(); |
1341 } | 1329 } |
1342 if(c == '.') | 1330 if(c == '.') |
1343 goto casedot; | 1331 goto casedot; |
1344 if(c == 'e' || c == 'E') | 1332 if(c == 'e' || c == 'E') |
1345 » » goto casee; | 1333 » » goto caseep; |
1346 if(c == 'i') | 1334 if(c == 'i') |
1347 goto casei; | 1335 goto casei; |
1348 if(c1) | 1336 if(c1) |
1349 yyerror("malformed octal constant"); | 1337 yyerror("malformed octal constant"); |
1350 goto ncu; | 1338 goto ncu; |
1351 | 1339 |
1352 dc: | 1340 dc: |
1353 if(c == '.') | 1341 if(c == '.') |
1354 goto casedot; | 1342 goto casedot; |
1355 » if(c == 'e' || c == 'E') | 1343 » if(c == 'e' || c == 'E' || c == 'p' || c == 'P') |
1356 » » goto casee; | 1344 » » goto caseep; |
1357 » if(c == 'p' || c == 'P') | |
1358 » » goto casep; | |
1359 if(c == 'i') | 1345 if(c == 'i') |
1360 goto casei; | 1346 goto casei; |
1361 | 1347 |
1362 ncu: | 1348 ncu: |
1363 *cp = 0; | 1349 *cp = 0; |
1364 ungetc(c); | 1350 ungetc(c); |
1365 | 1351 |
1366 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); | 1352 yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); |
1367 mpatofix(yylval.val.u.xval, lexbuf); | 1353 mpatofix(yylval.val.u.xval, lexbuf); |
1368 if(yylval.val.u.xval->ovf) { | 1354 if(yylval.val.u.xval->ovf) { |
(...skipping 15 matching lines...) Expand all Loading... |
1384 *cp++ = c; | 1370 *cp++ = c; |
1385 c = getc(); | 1371 c = getc(); |
1386 if(!yy_isdigit(c)) | 1372 if(!yy_isdigit(c)) |
1387 break; | 1373 break; |
1388 } | 1374 } |
1389 if(c == 'i') | 1375 if(c == 'i') |
1390 goto casei; | 1376 goto casei; |
1391 if(c != 'e' && c != 'E') | 1377 if(c != 'e' && c != 'E') |
1392 goto caseout; | 1378 goto caseout; |
1393 | 1379 |
1394 casee: | 1380 caseep: |
1395 » *cp++ = 'e'; | 1381 » *cp++ = c; |
1396 » c = getc(); | |
1397 » if(c == '+' || c == '-') { | |
1398 » » *cp++ = c; | |
1399 » » c = getc(); | |
1400 » } | |
1401 » if(!yy_isdigit(c)) | |
1402 » » yyerror("malformed fp constant exponent"); | |
1403 » while(yy_isdigit(c)) { | |
1404 » » if(cp+10 >= ep) { | |
1405 » » » yyerror("identifier too long"); | |
1406 » » » errorexit(); | |
1407 » » } | |
1408 » » *cp++ = c; | |
1409 » » c = getc(); | |
1410 » } | |
1411 » if(c == 'i') | |
1412 » » goto casei; | |
1413 » goto caseout; | |
1414 | |
1415 casep: | |
1416 » *cp++ = 'p'; | |
1417 c = getc(); | 1382 c = getc(); |
1418 if(c == '+' || c == '-') { | 1383 if(c == '+' || c == '-') { |
1419 *cp++ = c; | 1384 *cp++ = c; |
1420 c = getc(); | 1385 c = getc(); |
1421 } | 1386 } |
1422 if(!yy_isdigit(c)) | 1387 if(!yy_isdigit(c)) |
1423 yyerror("malformed fp constant exponent"); | 1388 yyerror("malformed fp constant exponent"); |
1424 while(yy_isdigit(c)) { | 1389 while(yy_isdigit(c)) { |
1425 if(cp+10 >= ep) { | 1390 if(cp+10 >= ep) { |
1426 yyerror("identifier too long"); | 1391 yyerror("identifier too long"); |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 p = infile; | 2288 p = infile; |
2324 else | 2289 else |
2325 p = p+1; | 2290 p = p+1; |
2326 snprint(namebuf, sizeof(namebuf), "%s", p); | 2291 snprint(namebuf, sizeof(namebuf), "%s", p); |
2327 p = strrchr(namebuf, '.'); | 2292 p = strrchr(namebuf, '.'); |
2328 if(p != nil) | 2293 if(p != nil) |
2329 *p = 0; | 2294 *p = 0; |
2330 outfile = smprint("%s.%c", namebuf, thechar); | 2295 outfile = smprint("%s.%c", namebuf, thechar); |
2331 } | 2296 } |
2332 } | 2297 } |
LEFT | RIGHT |