| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.body_builder; | 5 library fasta.body_builder; |
| 6 | 6 |
| 7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
| 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 pushNewLocalVariable(null); | 1054 pushNewLocalVariable(null); |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 void pushNewLocalVariable(Expression initializer, | 1057 void pushNewLocalVariable(Expression initializer, |
| 1058 {int equalsCharOffset: TreeNode.noOffset}) { | 1058 {int equalsCharOffset: TreeNode.noOffset}) { |
| 1059 Identifier identifier = pop(); | 1059 Identifier identifier = pop(); |
| 1060 assert(currentLocalVariableModifiers != -1); | 1060 assert(currentLocalVariableModifiers != -1); |
| 1061 bool isConst = (currentLocalVariableModifiers & constMask) != 0; | 1061 bool isConst = (currentLocalVariableModifiers & constMask) != 0; |
| 1062 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; | 1062 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0; |
| 1063 assert(isConst == constantExpressionRequired); | 1063 assert(isConst == constantExpressionRequired); |
| 1064 push(astFactory.variableDeclaration(identifier.name, | 1064 push(astFactory.variableDeclaration(identifier.name, identifier.fileOffset, |
| 1065 initializer: initializer, | 1065 initializer: initializer, |
| 1066 type: currentLocalVariableType, | 1066 type: currentLocalVariableType, |
| 1067 isFinal: isFinal, | 1067 isFinal: isFinal, |
| 1068 isConst: isConst, | 1068 isConst: isConst, |
| 1069 equalsCharOffset: equalsCharOffset)); | 1069 equalsCharOffset: equalsCharOffset)); |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 @override | 1072 @override |
| 1073 void endFieldInitializer(Token assignmentOperator) { | 1073 void endFieldInitializer(Token assignmentOperator) { |
| 1074 debugEvent("FieldInitializer"); | 1074 debugEvent("FieldInitializer"); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 } else if (thisKeyword == null) { | 1518 } else if (thisKeyword == null) { |
| 1519 variable = builder.build(library); | 1519 variable = builder.build(library); |
| 1520 variable.initializer = name.initializer; | 1520 variable.initializer = name.initializer; |
| 1521 } else if (builder.isField && builder.parent == classBuilder) { | 1521 } else if (builder.isField && builder.parent == classBuilder) { |
| 1522 FieldBuilder field = builder; | 1522 FieldBuilder field = builder; |
| 1523 if (type != null) { | 1523 if (type != null) { |
| 1524 nit("Ignoring type on 'this' parameter '${name.name}'.", | 1524 nit("Ignoring type on 'this' parameter '${name.name}'.", |
| 1525 thisKeyword.charOffset); | 1525 thisKeyword.charOffset); |
| 1526 } | 1526 } |
| 1527 type = field.target.type ?? const DynamicType(); | 1527 type = field.target.type ?? const DynamicType(); |
| 1528 variable = astFactory.variableDeclaration(name.name, | 1528 variable = astFactory.variableDeclaration(name.name, name.fileOffset, |
| 1529 type: type, | 1529 type: type, |
| 1530 initializer: name.initializer, | 1530 initializer: name.initializer, |
| 1531 isFinal: isFinal, | 1531 isFinal: isFinal, |
| 1532 isConst: isConst, | 1532 isConst: isConst); |
| 1533 charOffset: name.fileOffset); | |
| 1534 } else { | 1533 } else { |
| 1535 addCompileTimeError( | 1534 addCompileTimeError( |
| 1536 name.fileOffset, "'${name.name}' isn't a field in this class."); | 1535 name.fileOffset, "'${name.name}' isn't a field in this class."); |
| 1537 } | 1536 } |
| 1538 } | 1537 } |
| 1539 variable ??= astFactory.variableDeclaration(name.name, | 1538 variable ??= astFactory.variableDeclaration(name.name, name.fileOffset, |
| 1540 type: type ?? const DynamicType(), | 1539 type: type ?? const DynamicType(), |
| 1541 initializer: name.initializer, | 1540 initializer: name.initializer, |
| 1542 isFinal: isFinal, | 1541 isFinal: isFinal, |
| 1543 isConst: isConst, | 1542 isConst: isConst); |
| 1544 charOffset: name.fileOffset); | |
| 1545 push(variable); | 1543 push(variable); |
| 1546 } | 1544 } |
| 1547 | 1545 |
| 1548 @override | 1546 @override |
| 1549 void endOptionalFormalParameters( | 1547 void endOptionalFormalParameters( |
| 1550 int count, Token beginToken, Token endToken) { | 1548 int count, Token beginToken, Token endToken) { |
| 1551 debugEvent("OptionalFormalParameters"); | 1549 debugEvent("OptionalFormalParameters"); |
| 1552 FormalParameterType kind = optional("{", beginToken) | 1550 FormalParameterType kind = optional("{", beginToken) |
| 1553 ? FormalParameterType.NAMED | 1551 ? FormalParameterType.NAMED |
| 1554 : FormalParameterType.POSITIONAL; | 1552 : FormalParameterType.POSITIONAL; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 debugEvent("NamedArgument"); | 1991 debugEvent("NamedArgument"); |
| 1994 Expression value = popForValue(); | 1992 Expression value = popForValue(); |
| 1995 Identifier identifier = pop(); | 1993 Identifier identifier = pop(); |
| 1996 push(new NamedExpression(identifier.name, value)); | 1994 push(new NamedExpression(identifier.name, value)); |
| 1997 } | 1995 } |
| 1998 | 1996 |
| 1999 @override | 1997 @override |
| 2000 void endFunctionName(Token beginToken, Token token) { | 1998 void endFunctionName(Token beginToken, Token token) { |
| 2001 debugEvent("FunctionName"); | 1999 debugEvent("FunctionName"); |
| 2002 Identifier name = pop(); | 2000 Identifier name = pop(); |
| 2003 VariableDeclaration variable = | 2001 VariableDeclaration variable = astFactory |
| 2004 astFactory.variableDeclaration(name.name, isFinal: true); | 2002 .variableDeclaration(name.name, name.fileOffset, isFinal: true); |
| 2005 push(new FunctionDeclaration( | 2003 push(new FunctionDeclaration( |
| 2006 variable, new FunctionNode(new InvalidStatement())) | 2004 variable, new FunctionNode(new InvalidStatement())) |
| 2007 ..fileOffset = beginToken.charOffset); | 2005 ..fileOffset = beginToken.charOffset); |
| 2008 scope[variable.name] = new KernelVariableBuilder( | 2006 scope[variable.name] = new KernelVariableBuilder( |
| 2009 variable, member ?? classBuilder ?? library, uri); | 2007 variable, member ?? classBuilder ?? library, uri); |
| 2010 enterLocalScope(); | 2008 enterLocalScope(); |
| 2011 } | 2009 } |
| 2012 | 2010 |
| 2013 void enterFunction() { | 2011 void enterFunction() { |
| 2014 debugEvent("enterFunction"); | 2012 debugEvent("enterFunction"); |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3074 } else if (node is PrefixBuilder) { | 3072 } else if (node is PrefixBuilder) { |
| 3075 return node.name; | 3073 return node.name; |
| 3076 } else if (node is ThisAccessor) { | 3074 } else if (node is ThisAccessor) { |
| 3077 return node.isSuper ? "super" : "this"; | 3075 return node.isSuper ? "super" : "this"; |
| 3078 } else if (node is FastaAccessor) { | 3076 } else if (node is FastaAccessor) { |
| 3079 return node.plainNameForRead; | 3077 return node.plainNameForRead; |
| 3080 } else { | 3078 } else { |
| 3081 return internalError("Unhandled: ${node.runtimeType}"); | 3079 return internalError("Unhandled: ${node.runtimeType}"); |
| 3082 } | 3080 } |
| 3083 } | 3081 } |
| OLD | NEW |