| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dev_compiler.src.codegen.ast_builder; | 5 library dev_compiler.src.codegen.ast_builder; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/scanner.dart'; | 8 import 'package:analyzer/src/generated/scanner.dart'; |
| 9 import 'package:analyzer/src/generated/utilities_dart.dart'; | 9 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 10 import 'package:logging/logging.dart' as logger; | 10 import 'package:logging/logging.dart' as logger; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 static ArgumentList argumentList(List<Expression> args) { | 42 static ArgumentList argumentList(List<Expression> args) { |
| 43 return RawAstBuilder.argumentList(args); | 43 return RawAstBuilder.argumentList(args); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static TypeName typeName(Identifier id, List<TypeName> args) { | 46 static TypeName typeName(Identifier id, List<TypeName> args) { |
| 47 TypeArgumentList argList = null; | 47 TypeArgumentList argList = null; |
| 48 if (args != null && args.length > 0) argList = typeArgumentList(args); | 48 if (args != null && args.length > 0) argList = typeArgumentList(args); |
| 49 return RawAstBuilder.typeName(id, argList); | 49 return RawAstBuilder.typeName(id, argList); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static FunctionTypeAlias functionTypeAlias(TypeName ret, | 52 static FunctionTypeAlias functionTypeAlias( |
| 53 SimpleIdentifier name, List<TypeParameter> tParams, | 53 TypeName ret, |
| 54 SimpleIdentifier name, |
| 55 List<TypeParameter> tParams, |
| 54 List<FormalParameter> params) { | 56 List<FormalParameter> params) { |
| 55 TypeParameterList tps = | 57 TypeParameterList tps = |
| 56 (tParams.length == 0) ? null : typeParameterList(tParams); | 58 (tParams.length == 0) ? null : typeParameterList(tParams); |
| 57 FormalParameterList fps = formalParameterList(params); | 59 FormalParameterList fps = formalParameterList(params); |
| 58 return RawAstBuilder.functionTypeAlias(ret, name, tps, fps); | 60 return RawAstBuilder.functionTypeAlias(ret, name, tps, fps); |
| 59 } | 61 } |
| 60 | 62 |
| 61 static BooleanLiteral booleanLiteral(bool b) { | 63 static BooleanLiteral booleanLiteral(bool b) { |
| 62 return RawAstBuilder.booleanLiteral(b); | 64 return RawAstBuilder.booleanLiteral(b); |
| 63 } | 65 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 246 } |
| 245 | 247 |
| 246 static FormalParameterList formalParameterList(List<FormalParameter> params) { | 248 static FormalParameterList formalParameterList(List<FormalParameter> params) { |
| 247 return RawAstBuilder.formalParameterList(params); | 249 return RawAstBuilder.formalParameterList(params); |
| 248 } | 250 } |
| 249 | 251 |
| 250 static Block block(List<Statement> statements) { | 252 static Block block(List<Statement> statements) { |
| 251 return RawAstBuilder.block(statements); | 253 return RawAstBuilder.block(statements); |
| 252 } | 254 } |
| 253 | 255 |
| 254 static MethodDeclaration blockMethodDeclaration(TypeName rt, | 256 static MethodDeclaration blockMethodDeclaration( |
| 255 SimpleIdentifier m, List<FormalParameter> params, | 257 TypeName rt, |
| 256 List<Statement> statements, {bool isStatic: false}) { | 258 SimpleIdentifier m, |
| 259 List<FormalParameter> params, |
| 260 List<Statement> statements, |
| 261 {bool isStatic: false}) { |
| 257 FormalParameterList fl = formalParameterList(params); | 262 FormalParameterList fl = formalParameterList(params); |
| 258 Block b = block(statements); | 263 Block b = block(statements); |
| 259 BlockFunctionBody body = RawAstBuilder.blockFunctionBody(b); | 264 BlockFunctionBody body = RawAstBuilder.blockFunctionBody(b); |
| 260 return RawAstBuilder.methodDeclaration(rt, m, fl, body, isStatic: isStatic); | 265 return RawAstBuilder.methodDeclaration(rt, m, fl, body, isStatic: isStatic); |
| 261 } | 266 } |
| 262 | 267 |
| 263 static FunctionDeclaration blockFunctionDeclaration(TypeName rt, | 268 static FunctionDeclaration blockFunctionDeclaration( |
| 264 SimpleIdentifier f, List<FormalParameter> params, | 269 TypeName rt, |
| 270 SimpleIdentifier f, |
| 271 List<FormalParameter> params, |
| 265 List<Statement> statements) { | 272 List<Statement> statements) { |
| 266 FunctionExpression fexp = blockFunction(params, statements); | 273 FunctionExpression fexp = blockFunction(params, statements); |
| 267 return RawAstBuilder.functionDeclaration(rt, f, fexp); | 274 return RawAstBuilder.functionDeclaration(rt, f, fexp); |
| 268 } | 275 } |
| 269 | 276 |
| 270 static FunctionExpression blockFunction( | 277 static FunctionExpression blockFunction( |
| 271 List<FormalParameter> params, List<Statement> statements) { | 278 List<FormalParameter> params, List<Statement> statements) { |
| 272 FormalParameterList fl = formalParameterList(params); | 279 FormalParameterList fl = formalParameterList(params); |
| 273 Block b = block(statements); | 280 Block b = block(statements); |
| 274 BlockFunctionBody body = RawAstBuilder.blockFunctionBody(b); | 281 BlockFunctionBody body = RawAstBuilder.blockFunctionBody(b); |
| 275 return RawAstBuilder.functionExpression(fl, body); | 282 return RawAstBuilder.functionExpression(fl, body); |
| 276 } | 283 } |
| 277 | 284 |
| 278 static FunctionExpression expressionFunction( | 285 static FunctionExpression expressionFunction( |
| 279 List<FormalParameter> params, Expression body, [bool decl = false]) { | 286 List<FormalParameter> params, Expression body, |
| 287 [bool decl = false]) { |
| 280 FormalParameterList fl = formalParameterList(params); | 288 FormalParameterList fl = formalParameterList(params); |
| 281 ExpressionFunctionBody b = RawAstBuilder.expressionFunctionBody(body, decl); | 289 ExpressionFunctionBody b = RawAstBuilder.expressionFunctionBody(body, decl); |
| 282 return RawAstBuilder.functionExpression(fl, b); | 290 return RawAstBuilder.functionExpression(fl, b); |
| 283 } | 291 } |
| 284 | 292 |
| 285 static FunctionDeclarationStatement functionDeclarationStatement( | 293 static FunctionDeclarationStatement functionDeclarationStatement( |
| 286 TypeName rType, SimpleIdentifier name, FunctionExpression fe) { | 294 TypeName rType, SimpleIdentifier name, FunctionExpression fe) { |
| 287 var fd = RawAstBuilder.functionDeclaration(rType, name, fe); | 295 var fd = RawAstBuilder.functionDeclaration(rType, name, fe); |
| 288 return RawAstBuilder.functionDeclarationStatement(fd); | 296 return RawAstBuilder.functionDeclarationStatement(fd); |
| 289 } | 297 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 Token semi = (decl) ? new Token(TokenType.SEMICOLON, 0) : null; | 509 Token semi = (decl) ? new Token(TokenType.SEMICOLON, 0) : null; |
| 502 return new ExpressionFunctionBody(null, null, body, semi); | 510 return new ExpressionFunctionBody(null, null, body, semi); |
| 503 } | 511 } |
| 504 | 512 |
| 505 static FunctionDeclaration functionDeclaration( | 513 static FunctionDeclaration functionDeclaration( |
| 506 TypeName rt, SimpleIdentifier f, FunctionExpression fexp) { | 514 TypeName rt, SimpleIdentifier f, FunctionExpression fexp) { |
| 507 return new FunctionDeclaration(null, null, null, rt, null, f, fexp); | 515 return new FunctionDeclaration(null, null, null, rt, null, f, fexp); |
| 508 } | 516 } |
| 509 | 517 |
| 510 static MethodDeclaration methodDeclaration(TypeName rt, SimpleIdentifier m, | 518 static MethodDeclaration methodDeclaration(TypeName rt, SimpleIdentifier m, |
| 511 FormalParameterList fl, FunctionBody body, {bool isStatic: false}) { | 519 FormalParameterList fl, FunctionBody body, |
| 520 {bool isStatic: false}) { |
| 512 Token st = isStatic ? new KeywordToken(Keyword.STATIC, 0) : null; | 521 Token st = isStatic ? new KeywordToken(Keyword.STATIC, 0) : null; |
| 513 return new MethodDeclaration( | 522 return new MethodDeclaration( |
| 514 null, null, null, st, rt, null, null, m, null, fl, body); | 523 null, null, null, st, rt, null, null, m, null, fl, body); |
| 515 } | 524 } |
| 516 | 525 |
| 517 static FunctionExpression functionExpression( | 526 static FunctionExpression functionExpression( |
| 518 FormalParameterList fl, FunctionBody body) { | 527 FormalParameterList fl, FunctionBody body) { |
| 519 return new FunctionExpression(null, fl, body); | 528 return new FunctionExpression(null, fl, body); |
| 520 } | 529 } |
| 521 | 530 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 Label l = new Label(s, new Token(TokenType.COLON, 0)); | 570 Label l = new Label(s, new Token(TokenType.COLON, 0)); |
| 562 return new NamedExpression(l, e); | 571 return new NamedExpression(l, e); |
| 563 } | 572 } |
| 564 | 573 |
| 565 static VariableDeclarationStatement variableDeclarationStatement( | 574 static VariableDeclarationStatement variableDeclarationStatement( |
| 566 VariableDeclarationList varDecl) { | 575 VariableDeclarationList varDecl) { |
| 567 var semi = new Token(TokenType.SEMICOLON, 0); | 576 var semi = new Token(TokenType.SEMICOLON, 0); |
| 568 return new VariableDeclarationStatement(varDecl, semi); | 577 return new VariableDeclarationStatement(varDecl, semi); |
| 569 } | 578 } |
| 570 } | 579 } |
| OLD | NEW |