Changeset 778
- Timestamp:
- 12/05/10 06:56:52 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/parse.c (modified) (1 diff)
- branches/dmd-1.x/src/statement.c (modified) (1 diff)
- trunk/src/parse.c (modified) (1 diff)
- trunk/src/statement.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/parse.c
r717 r778 3159 3159 if (t->value == TOKcomma || t->value == TOKsemicolon) 3160 3160 { 3161 3161 arg = new Parameter(STCin, NULL, token.ident, NULL); 3162 3162 nextToken(); 3163 3163 nextToken(); 3164 3164 if (1 || !global.params.useDeprecated) 3165 3165 error("if (v; e) is deprecated, use if (auto v = e)"); 3166 3166 } 3167 3167 } 3168 3168 3169 3169 condition = parseExpression(); 3170 3170 check(TOKrparen); 3171 3171 ifbody = parseStatement(PSscope); 3172 3172 if (token.value == TOKelse) 3173 3173 { 3174 3174 nextToken(); 3175 3175 elsebody = parseStatement(PSscope); 3176 3176 } 3177 3177 else 3178 3178 elsebody = NULL; 3179 s = new IfStatement(loc, arg, condition, ifbody, elsebody); 3179 if (condition && ifbody) 3180 s = new IfStatement(loc, arg, condition, ifbody, elsebody); 3181 else 3182 s = NULL; // don't propagate parsing errors 3180 3183 break; 3181 3184 } 3182 3185 3183 3186 case TOKscope: 3184 3187 if (peek(&token)->value != TOKlparen) 3185 3188 goto Ldeclaration; // scope used as storage class 3186 3189 nextToken(); 3187 3190 check(TOKlparen, "scope"); 3188 3191 if (token.value != TOKidentifier) 3189 3192 { error("scope (identifier) expected"); 3190 3193 goto Lerror; 3191 3194 } 3192 3195 else 3193 3196 { TOK t = TOKon_scope_exit; 3194 3197 Identifier *id = token.ident; 3195 3198 3196 3199 if (id == Id::exit) 3197 3200 t = TOKon_scope_exit; 3198 3201 else if (id == Id::failure) 3199 3202 t = TOKon_scope_failure; branches/dmd-1.x/src/statement.c
r731 r778 301 301 Statements *CompileStatement::flatten(Scope *sc) 302 302 { 303 303 //printf("CompileStatement::flatten() %s\n", exp->toChars()); 304 304 exp = exp->semantic(sc); 305 305 exp = resolveProperties(sc, exp); 306 306 exp = exp->optimize(WANTvalue | WANTinterpret); 307 307 if (exp->op != TOKstring) 308 308 { error("argument to mixin must be a string, not (%s)", exp->toChars()); 309 309 return NULL; 310 310 } 311 311 StringExp *se = (StringExp *)exp; 312 312 se = se->toUTF8(sc); 313 313 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 314 314 p.loc = loc; 315 315 p.nextToken(); 316 316 317 317 Statements *a = new Statements(); 318 318 while (p.token.value != TOKeof) 319 319 { 320 320 Statement *s = p.parseStatement(PSsemi | PScurlyscope); 321 a->push(s); 321 if (s) // if no parsing errors 322 a->push(s); 322 323 } 323 324 return a; 324 325 } 325 326 326 327 Statement *CompileStatement::semantic(Scope *sc) 327 328 { 328 329 //printf("CompileStatement::semantic() %s\n", exp->toChars()); 329 330 Statements *a = flatten(sc); 330 331 if (!a) 331 332 return NULL; 332 333 Statement *s = new CompoundStatement(loc, a); 333 334 return s->semantic(sc); 334 335 } 335 336 336 337 337 338 /******************************** DeclarationStatement ***************************/ 338 339 339 340 DeclarationStatement::DeclarationStatement(Loc loc, Dsymbol *declaration) 340 341 : ExpStatement(loc, new DeclarationExp(loc, declaration)) 341 342 { trunk/src/parse.c
r769 r778 3765 3765 if (t->value == TOKcomma || t->value == TOKsemicolon) 3766 3766 { 3767 3767 arg = new Parameter(0, NULL, token.ident, NULL); 3768 3768 nextToken(); 3769 3769 nextToken(); 3770 3770 if (1 || !global.params.useDeprecated) 3771 3771 error("if (v; e) is deprecated, use if (auto v = e)"); 3772 3772 } 3773 3773 } 3774 3774 3775 3775 condition = parseExpression(); 3776 3776 check(TOKrparen); 3777 3777 ifbody = parseStatement(PSscope); 3778 3778 if (token.value == TOKelse) 3779 3779 { 3780 3780 nextToken(); 3781 3781 elsebody = parseStatement(PSscope); 3782 3782 } 3783 3783 else 3784 3784 elsebody = NULL; 3785 s = new IfStatement(loc, arg, condition, ifbody, elsebody); 3785 if (condition && ifbody) 3786 s = new IfStatement(loc, arg, condition, ifbody, elsebody); 3787 else 3788 s = NULL; // don't propagate parsing errors 3786 3789 break; 3787 3790 } 3788 3791 3789 3792 case TOKscope: 3790 3793 if (peek(&token)->value != TOKlparen) 3791 3794 goto Ldeclaration; // scope used as storage class 3792 3795 nextToken(); 3793 3796 check(TOKlparen); 3794 3797 if (token.value != TOKidentifier) 3795 3798 { error("scope identifier expected"); 3796 3799 goto Lerror; 3797 3800 } 3798 3801 else 3799 3802 { TOK t = TOKon_scope_exit; 3800 3803 Identifier *id = token.ident; 3801 3804 3802 3805 if (id == Id::exit) 3803 3806 t = TOKon_scope_exit; 3804 3807 else if (id == Id::failure) 3805 3808 t = TOKon_scope_failure; trunk/src/statement.c
r737 r778 318 318 Statements *CompileStatement::flatten(Scope *sc) 319 319 { 320 320 //printf("CompileStatement::flatten() %s\n", exp->toChars()); 321 321 exp = exp->semantic(sc); 322 322 exp = resolveProperties(sc, exp); 323 323 exp = exp->optimize(WANTvalue | WANTinterpret); 324 324 if (exp->op != TOKstring) 325 325 { error("argument to mixin must be a string, not (%s)", exp->toChars()); 326 326 return NULL; 327 327 } 328 328 StringExp *se = (StringExp *)exp; 329 329 se = se->toUTF8(sc); 330 330 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 331 331 p.loc = loc; 332 332 p.nextToken(); 333 333 334 334 Statements *a = new Statements(); 335 335 while (p.token.value != TOKeof) 336 336 { 337 337 Statement *s = p.parseStatement(PSsemi | PScurlyscope); 338 a->push(s); 338 if (s) // if no parsing errors 339 a->push(s); 339 340 } 340 341 return a; 341 342 } 342 343 343 344 Statement *CompileStatement::semantic(Scope *sc) 344 345 { 345 346 //printf("CompileStatement::semantic() %s\n", exp->toChars()); 346 347 Statements *a = flatten(sc); 347 348 if (!a) 348 349 return NULL; 349 350 Statement *s = new CompoundStatement(loc, a); 350 351 return s->semantic(sc); 351 352 } 352 353 353 354 354 355 /******************************** DeclarationStatement ***************************/ 355 356 356 357 DeclarationStatement::DeclarationStatement(Loc loc, Dsymbol *declaration) 357 358 : ExpStatement(loc, new DeclarationExp(loc, declaration)) 358 359 {
