comparison dmd/statement.c @ 1103:b30fe7e1dbb9

- Updated to DMD frontend 1.041. - Removed dmd/inifile.c , it's not under a free license, replaced with libconfig based config file.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Thu, 12 Mar 2009 20:37:27 +0100
parents 03d7c4aac654
children e7f0c2b48047
comparison
equal deleted inserted replaced
1102:ae950bd712d3 1103:b30fe7e1dbb9
1 1
2 // Compiler implementation of the D programming language 2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars 3 // Copyright (c) 1999-2009 by Digital Mars
4 // All Rights Reserved 4 // All Rights Reserved
5 // written by Walter Bright 5 // written by Walter Bright
6 // http://www.digitalmars.com 6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License 7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt. 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "mem.h" 15 #include "rmem.h"
16 16
17 #include "statement.h" 17 #include "statement.h"
18 #include "expression.h" 18 #include "expression.h"
19 #include "cond.h" 19 #include "cond.h"
20 #include "init.h" 20 #include "init.h"
92 { 92 {
93 va_list ap; 93 va_list ap;
94 va_start(ap, format); 94 va_start(ap, format);
95 ::verror(loc, format, ap); 95 ::verror(loc, format, ap);
96 va_end( ap ); 96 va_end( ap );
97 }
98
99 void Statement::warning(const char *format, ...)
100 {
101 if (global.params.warnings && !global.gag)
102 {
103 fprintf(stdmsg, "warning - ");
104 va_list ap;
105 va_start(ap, format);
106 ::verror(loc, format, ap);
107 va_end( ap );
108 }
97 } 109 }
98 110
99 int Statement::hasBreak() 111 int Statement::hasBreak()
100 { 112 {
101 //printf("Statement::hasBreak()\n"); 113 //printf("Statement::hasBreak()\n");
537 { 549 {
538 //printf("result = x%x\n", result); 550 //printf("result = x%x\n", result);
539 //printf("%s\n", s->toChars()); 551 //printf("%s\n", s->toChars());
540 if (!(result & BEfallthru) && !s->comeFrom()) 552 if (!(result & BEfallthru) && !s->comeFrom())
541 { 553 {
542 if (global.params.warnings) 554 s->warning("statement is not reachable");
543 { fprintf(stdmsg, "warning - ");
544 s->error("statement is not reachable");
545 }
546 } 555 }
547 556
548 result &= ~BEfallthru; 557 result &= ~BEfallthru;
549 result |= s->blockExit(); 558 result |= s->blockExit();
550 } 559 }
1027 ScopeDsymbol *sym = new ScopeDsymbol(); 1036 ScopeDsymbol *sym = new ScopeDsymbol();
1028 sym->parent = sc->scopesym; 1037 sym->parent = sc->scopesym;
1029 sc = sc->push(sym); 1038 sc = sc->push(sym);
1030 if (init) 1039 if (init)
1031 init = init->semantic(sc); 1040 init = init->semantic(sc);
1041 #if 0
1032 if (!condition) 1042 if (!condition)
1033 // Use a default value 1043 // Use a default value
1034 condition = new IntegerExp(loc, 1, Type::tboolean); 1044 condition = new IntegerExp(loc, 1, Type::tboolean);
1045 #endif
1035 sc->noctor++; 1046 sc->noctor++;
1036 if (condition) 1047 if (condition)
1037 { 1048 {
1038 condition = condition->semantic(sc); 1049 condition = condition->semantic(sc);
1039 condition = resolveProperties(sc, condition); 1050 condition = resolveProperties(sc, condition);
1094 } 1105 }
1095 else 1106 else
1096 result &= ~BEfallthru; // the body must do the exiting 1107 result &= ~BEfallthru; // the body must do the exiting
1097 if (body) 1108 if (body)
1098 { int r = body->blockExit(); 1109 { int r = body->blockExit();
1099 if (r & BEbreak) 1110 if (r & (BEbreak | BEgoto))
1100 result |= BEfallthru; 1111 result |= BEfallthru;
1101 result |= r & ~(BEbreak | BEcontinue); 1112 result |= r & ~(BEfallthru | BEbreak | BEcontinue);
1102 } 1113 }
1103 if (increment && increment->canThrow()) 1114 if (increment && increment->canThrow())
1104 result |= BEthrow; 1115 result |= BEthrow;
1105 return result; 1116 return result;
1106 } 1117 }
1667 case Twchar: flag += 1; break; 1678 case Twchar: flag += 1; break;
1668 case Tdchar: flag += 2; break; 1679 case Tdchar: flag += 2; break;
1669 default: assert(0); 1680 default: assert(0);
1670 } 1681 }
1671 const char *r = (op == TOKforeach_reverse) ? "R" : ""; 1682 const char *r = (op == TOKforeach_reverse) ? "R" : "";
1672 int j = sprintf(fdname, "_aApply%s%.*s%" PRIuSIZE, r, 2, fntab[flag], dim); 1683 int j = sprintf(fdname, "_aApply%s%.*s%zu", r, 2, fntab[flag], dim);
1673 assert(j < sizeof(fdname)); 1684 assert(j < sizeof(fdname));
1674 //LDC: Build arguments. 1685 //LDC: Build arguments.
1675 Arguments* args = new Arguments; 1686 Arguments* args = new Arguments;
1676 args->push(new Argument(STCin, tn->arrayOf(), NULL, NULL)); 1687 args->push(new Argument(STCin, tn->arrayOf(), NULL, NULL));
1677 if (dim == 2) { 1688 if (dim == 2) {
2321 } 2332 }
2322 2333
2323 if (!sc->sw->sdefault) 2334 if (!sc->sw->sdefault)
2324 { hasNoDefault = 1; 2335 { hasNoDefault = 1;
2325 2336
2326 if (global.params.warnings) 2337 warning("switch statement has no default");
2327 { warning("%s: switch statement has no default", loc.toChars());
2328 }
2329 2338
2330 // Generate runtime error if the default is hit 2339 // Generate runtime error if the default is hit
2331 Statements *a = new Statements(); 2340 Statements *a = new Statements();
2332 CompoundStatement *cs; 2341 CompoundStatement *cs;
2333 Statement *s; 2342 Statement *s;
3928 3937
3929 LabelDsymbol *LabelDsymbol::isLabel() // is this a LabelDsymbol()? 3938 LabelDsymbol *LabelDsymbol::isLabel() // is this a LabelDsymbol()?
3930 { 3939 {
3931 return this; 3940 return this;
3932 } 3941 }
3933
3934