| 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 library kernel.analyzer.ast_from_analyzer; | 4 library kernel.analyzer.ast_from_analyzer; |
| 5 | 5 |
| 6 import '../ast.dart' as ast; | 6 import '../ast.dart' as ast; |
| 7 import '../frontend/accessors.dart'; | 7 import '../frontend/accessors.dart'; |
| 8 import '../frontend/super_initializers.dart'; | 8 import '../frontend/super_initializers.dart'; |
| 9 import '../log.dart'; | 9 import '../log.dart'; |
| 10 import '../type_algebra.dart'; | 10 import '../type_algebra.dart'; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 var returnType = element is ConstructorElement | 467 var returnType = element is ConstructorElement |
| 468 ? const ast.VoidType() | 468 ? const ast.VoidType() |
| 469 : buildType(element.returnType); | 469 : buildType(element.returnType); |
| 470 return new ast.FunctionNode(null, | 470 return new ast.FunctionNode(null, |
| 471 typeParameters: typeParameters, | 471 typeParameters: typeParameters, |
| 472 positionalParameters: positional, | 472 positionalParameters: positional, |
| 473 namedParameters: named, | 473 namedParameters: named, |
| 474 requiredParameterCount: requiredParameterCount, | 474 requiredParameterCount: requiredParameterCount, |
| 475 returnType: returnType); | 475 returnType: returnType)..fileOffset = element.nameOffset; |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 | 478 |
| 479 class ExpressionScope extends TypeScope { | 479 class ExpressionScope extends TypeScope { |
| 480 ast.Library currentLibrary; | 480 ast.Library currentLibrary; |
| 481 final Map<LocalElement, ast.VariableDeclaration> localVariables = | 481 final Map<LocalElement, ast.VariableDeclaration> localVariables = |
| 482 <LocalElement, ast.VariableDeclaration>{}; | 482 <LocalElement, ast.VariableDeclaration>{}; |
| 483 | 483 |
| 484 ExpressionBuilder _expressionBuilder; | 484 ExpressionBuilder _expressionBuilder; |
| 485 StatementBuilder _statementBuilder; | 485 StatementBuilder _statementBuilder; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 559 |
| 560 case ParameterKind.POSITIONAL: | 560 case ParameterKind.POSITIONAL: |
| 561 positional.add(declaration); | 561 positional.add(declaration); |
| 562 break; | 562 break; |
| 563 | 563 |
| 564 case ParameterKind.NAMED: | 564 case ParameterKind.NAMED: |
| 565 named.add(declaration); | 565 named.add(declaration); |
| 566 break; | 566 break; |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 int offset = formalParameters?.offset ?? body.offset; |
| 570 int endOffset = body.endToken.offset; |
| 569 return new ast.FunctionNode(buildOptionalFunctionBody(body), | 571 return new ast.FunctionNode(buildOptionalFunctionBody(body), |
| 570 typeParameters: typeParameters, | 572 typeParameters: typeParameters, |
| 571 positionalParameters: positional, | 573 positionalParameters: positional, |
| 572 namedParameters: named, | 574 namedParameters: named, |
| 573 requiredParameterCount: requiredParameterCount, | 575 requiredParameterCount: requiredParameterCount, |
| 574 returnType: buildOptionalTypeAnnotation(returnType) ?? | 576 returnType: buildOptionalTypeAnnotation(returnType) ?? |
| 575 inferredReturnType ?? | 577 inferredReturnType ?? |
| 576 const ast.DynamicType(), | 578 const ast.DynamicType(), |
| 577 asyncMarker: getAsyncMarker( | 579 asyncMarker: getAsyncMarker( |
| 578 isAsync: body.isAsynchronous, isStar: body.isGenerator)); | 580 isAsync: body.isAsynchronous, isStar: body.isGenerator)) |
| 581 ..fileOffset = offset |
| 582 ..fileEndOffset = endOffset; |
| 579 } | 583 } |
| 580 | 584 |
| 581 ast.Expression buildOptionalTopLevelExpression(Expression node) { | 585 ast.Expression buildOptionalTopLevelExpression(Expression node) { |
| 582 return node == null ? null : buildTopLevelExpression(node); | 586 return node == null ? null : buildTopLevelExpression(node); |
| 583 } | 587 } |
| 584 | 588 |
| 585 ast.Expression buildTopLevelExpression(Expression node) { | 589 ast.Expression buildTopLevelExpression(Expression node) { |
| 586 try { | 590 try { |
| 587 return _expressionBuilder.build(node); | 591 return _expressionBuilder.build(node); |
| 588 } on _CompilationError catch (e) { | 592 } on _CompilationError catch (e) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 element is FunctionElement; | 633 element is FunctionElement; |
| 630 } | 634 } |
| 631 | 635 |
| 632 bool isConst(Element element) { | 636 bool isConst(Element element) { |
| 633 return element is VariableElement && element.isConst; | 637 return element is VariableElement && element.isConst; |
| 634 } | 638 } |
| 635 | 639 |
| 636 ast.VariableDeclaration getVariableReference(LocalElement element) { | 640 ast.VariableDeclaration getVariableReference(LocalElement element) { |
| 637 return localVariables.putIfAbsent(element, () { | 641 return localVariables.putIfAbsent(element, () { |
| 638 return new ast.VariableDeclaration(element.name, | 642 return new ast.VariableDeclaration(element.name, |
| 639 isFinal: isFinal(element), isConst: isConst(element)); | 643 isFinal: isFinal(element), |
| 644 isConst: isConst(element))..fileOffset = element.nameOffset; |
| 640 }); | 645 }); |
| 641 } | 646 } |
| 642 | 647 |
| 643 ast.DartType getInferredVariableType(Element element) { | 648 ast.DartType getInferredVariableType(Element element) { |
| 644 if (!strongMode) return const ast.DynamicType(); | 649 if (!strongMode) return const ast.DynamicType(); |
| 645 if (element is FunctionTypedElement) { | 650 if (element is FunctionTypedElement) { |
| 646 return buildType(element.type); | 651 return buildType(element.type); |
| 647 } else if (element is VariableElement) { | 652 } else if (element is VariableElement) { |
| 648 return buildType(element.type); | 653 return buildType(element.type); |
| 649 } else { | 654 } else { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 LabelStack.many(this.labels, this.next); | 898 LabelStack.many(this.labels, this.next); |
| 894 } | 899 } |
| 895 | 900 |
| 896 class StatementBuilder extends GeneralizingAstVisitor<ast.Statement> { | 901 class StatementBuilder extends GeneralizingAstVisitor<ast.Statement> { |
| 897 final ExpressionScope scope; | 902 final ExpressionScope scope; |
| 898 LabelStack breakStack, continueStack; | 903 LabelStack breakStack, continueStack; |
| 899 | 904 |
| 900 StatementBuilder(this.scope, [this.breakStack, this.continueStack]); | 905 StatementBuilder(this.scope, [this.breakStack, this.continueStack]); |
| 901 | 906 |
| 902 ast.Statement build(Statement node) { | 907 ast.Statement build(Statement node) { |
| 903 return node.accept(this); | 908 ast.Statement result = node.accept(this); |
| 909 result.fileOffset = _getOffset(node); |
| 910 return result; |
| 904 } | 911 } |
| 905 | 912 |
| 906 ast.Statement buildOptional(Statement node) { | 913 ast.Statement buildOptional(Statement node) { |
| 907 return node?.accept(this); | 914 ast.Statement result = node?.accept(this); |
| 915 result?.fileOffset = _getOffset(node); |
| 916 return result; |
| 917 } |
| 918 |
| 919 int _getOffset(AstNode node) { |
| 920 return node.offset; |
| 908 } | 921 } |
| 909 | 922 |
| 910 ast.Statement buildInScope( | 923 ast.Statement buildInScope( |
| 911 Statement node, LabelStack breakNode, LabelStack continueNode) { | 924 Statement node, LabelStack breakNode, LabelStack continueNode) { |
| 912 var oldBreak = this.breakStack; | 925 var oldBreak = this.breakStack; |
| 913 var oldContinue = this.continueStack; | 926 var oldContinue = this.continueStack; |
| 914 breakStack = breakNode; | 927 breakStack = breakNode; |
| 915 continueStack = continueNode; | 928 continueStack = continueNode; |
| 916 var result = build(node); | 929 var result = build(node); |
| 917 this.breakStack = oldBreak; | 930 this.breakStack = oldBreak; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 var declaration = node.functionDeclaration; | 1292 var declaration = node.functionDeclaration; |
| 1280 var expression = declaration.functionExpression; | 1293 var expression = declaration.functionExpression; |
| 1281 LocalElement element = declaration.element as dynamic; // Cross cast. | 1294 LocalElement element = declaration.element as dynamic; // Cross cast. |
| 1282 // TODO: Set a function type on the variable. | 1295 // TODO: Set a function type on the variable. |
| 1283 return new ast.FunctionDeclaration( | 1296 return new ast.FunctionDeclaration( |
| 1284 scope.makeVariableDeclaration(element), | 1297 scope.makeVariableDeclaration(element), |
| 1285 scope.buildFunctionNode(expression.parameters, expression.body, | 1298 scope.buildFunctionNode(expression.parameters, expression.body, |
| 1286 typeParameters: scope.buildOptionalTypeParameterList( | 1299 typeParameters: scope.buildOptionalTypeParameterList( |
| 1287 expression.typeParameters, | 1300 expression.typeParameters, |
| 1288 strongModeOnly: true), | 1301 strongModeOnly: true), |
| 1289 returnType: declaration.returnType)); | 1302 returnType: declaration.returnType))..fileOffset = node.offset; |
| 1290 } | 1303 } |
| 1291 | 1304 |
| 1292 @override | 1305 @override |
| 1293 visitStatement(Statement node) { | 1306 visitStatement(Statement node) { |
| 1294 return scope.internalError('Unhandled statement ${node.runtimeType}'); | 1307 return scope.internalError('Unhandled statement ${node.runtimeType}'); |
| 1295 } | 1308 } |
| 1296 } | 1309 } |
| 1297 | 1310 |
| 1298 class ExpressionBuilder | 1311 class ExpressionBuilder |
| 1299 extends GeneralizingAstVisitor /* <ast.Expression | Accessor> */ { | 1312 extends GeneralizingAstVisitor /* <ast.Expression | Accessor> */ { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1313 if (node is MethodInvocation) { | 1326 if (node is MethodInvocation) { |
| 1314 return node.methodName.offset; | 1327 return node.methodName.offset; |
| 1315 } else if (node is InstanceCreationExpression) { | 1328 } else if (node is InstanceCreationExpression) { |
| 1316 return node.constructorName.offset; | 1329 return node.constructorName.offset; |
| 1317 } else if (node is BinaryExpression) { | 1330 } else if (node is BinaryExpression) { |
| 1318 return node.operator.offset; | 1331 return node.operator.offset; |
| 1319 } else if (node is PrefixedIdentifier) { | 1332 } else if (node is PrefixedIdentifier) { |
| 1320 return node.identifier.offset; | 1333 return node.identifier.offset; |
| 1321 } else if (node is AssignmentExpression) { | 1334 } else if (node is AssignmentExpression) { |
| 1322 return _getOffset(node.leftHandSide); | 1335 return _getOffset(node.leftHandSide); |
| 1336 } else if (node is PropertyAccess) { |
| 1337 return node.propertyName.offset; |
| 1338 } else if (node is IsExpression) { |
| 1339 return node.isOperator.offset; |
| 1340 } else if (node is StringLiteral) { |
| 1341 // Use a catch-all for StringInterpolation and AdjacentStrings: |
| 1342 // the debugger stops at the end. |
| 1343 return node.end; |
| 1323 } | 1344 } |
| 1324 return node.offset; | 1345 return node.offset; |
| 1325 } | 1346 } |
| 1326 | 1347 |
| 1327 Accessor buildLeftHandValue(Expression node) { | 1348 Accessor buildLeftHandValue(Expression node) { |
| 1328 var result = node.accept(this); | 1349 var result = node.accept(this); |
| 1329 if (result is Accessor) { | 1350 if (result is Accessor) { |
| 1330 return result; | 1351 return result; |
| 1331 } else { | 1352 } else { |
| 1332 return new ReadOnlyAccessor(result); | 1353 return new ReadOnlyAccessor(result); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1346 if (operator == '=') { | 1367 if (operator == '=') { |
| 1347 return leftHand.buildAssignment(rightHand, voidContext: voidContext); | 1368 return leftHand.buildAssignment(rightHand, voidContext: voidContext); |
| 1348 } else if (operator == '??=') { | 1369 } else if (operator == '??=') { |
| 1349 return leftHand.buildNullAwareAssignment( | 1370 return leftHand.buildNullAwareAssignment( |
| 1350 rightHand, scope.buildType(node.staticType), | 1371 rightHand, scope.buildType(node.staticType), |
| 1351 voidContext: voidContext); | 1372 voidContext: voidContext); |
| 1352 } else { | 1373 } else { |
| 1353 // Cut off the trailing '='. | 1374 // Cut off the trailing '='. |
| 1354 var name = new ast.Name(operator.substring(0, operator.length - 1)); | 1375 var name = new ast.Name(operator.substring(0, operator.length - 1)); |
| 1355 return leftHand.buildCompoundAssignment(name, rightHand, | 1376 return leftHand.buildCompoundAssignment(name, rightHand, |
| 1377 offset: node.offset, |
| 1356 voidContext: voidContext, | 1378 voidContext: voidContext, |
| 1357 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); | 1379 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); |
| 1358 } | 1380 } |
| 1359 } | 1381 } |
| 1360 | 1382 |
| 1361 ast.Expression visitAwaitExpression(AwaitExpression node) { | 1383 ast.Expression visitAwaitExpression(AwaitExpression node) { |
| 1362 return new ast.AwaitExpression(build(node.expression)); | 1384 return new ast.AwaitExpression(build(node.expression)); |
| 1363 } | 1385 } |
| 1364 | 1386 |
| 1365 ast.Arguments buildSingleArgument(Expression node) { | 1387 ast.Arguments buildSingleArgument(Expression node) { |
| 1366 return new ast.Arguments(<ast.Expression>[build(node)]); | 1388 return new ast.Arguments(<ast.Expression>[build(node)]); |
| 1367 } | 1389 } |
| 1368 | 1390 |
| 1369 ast.Expression visitBinaryExpression(BinaryExpression node) { | 1391 ast.Expression visitBinaryExpression(BinaryExpression node) { |
| 1370 String operator = node.operator.value(); | 1392 String operator = node.operator.value(); |
| 1371 if (operator == '&&' || operator == '||') { | 1393 if (operator == '&&' || operator == '||') { |
| 1372 return new ast.LogicalExpression( | 1394 return new ast.LogicalExpression( |
| 1373 build(node.leftOperand), operator, build(node.rightOperand)); | 1395 build(node.leftOperand), operator, build(node.rightOperand)); |
| 1374 } | 1396 } |
| 1375 if (operator == '??') { | 1397 if (operator == '??') { |
| 1376 ast.Expression leftOperand = build(node.leftOperand); | 1398 ast.Expression leftOperand = build(node.leftOperand); |
| 1377 if (leftOperand is ast.VariableGet) { | 1399 if (leftOperand is ast.VariableGet) { |
| 1378 return new ast.ConditionalExpression( | 1400 return new ast.ConditionalExpression( |
| 1379 buildIsNull(leftOperand), | 1401 buildIsNull(leftOperand, offset: node.leftOperand.offset), |
| 1380 build(node.rightOperand), | 1402 build(node.rightOperand), |
| 1381 new ast.VariableGet(leftOperand.variable), | 1403 new ast.VariableGet(leftOperand.variable), |
| 1382 scope.getInferredType(node)); | 1404 scope.getInferredType(node)); |
| 1383 } else { | 1405 } else { |
| 1384 var variable = new ast.VariableDeclaration.forValue(leftOperand); | 1406 var variable = new ast.VariableDeclaration.forValue(leftOperand); |
| 1385 return new ast.Let( | 1407 return new ast.Let( |
| 1386 variable, | 1408 variable, |
| 1387 new ast.ConditionalExpression( | 1409 new ast.ConditionalExpression( |
| 1388 buildIsNull(new ast.VariableGet(variable)), | 1410 buildIsNull(new ast.VariableGet(variable), |
| 1411 offset: leftOperand.fileOffset), |
| 1389 build(node.rightOperand), | 1412 build(node.rightOperand), |
| 1390 new ast.VariableGet(variable), | 1413 new ast.VariableGet(variable), |
| 1391 scope.getInferredType(node))); | 1414 scope.getInferredType(node))); |
| 1392 } | 1415 } |
| 1393 } | 1416 } |
| 1394 bool isNegated = false; | 1417 bool isNegated = false; |
| 1395 if (operator == '!=') { | 1418 if (operator == '!=') { |
| 1396 isNegated = true; | 1419 isNegated = true; |
| 1397 operator = '=='; | 1420 operator = '=='; |
| 1398 } | 1421 } |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 var receiver = makeOrReuseVariable(build(target)); | 1910 var receiver = makeOrReuseVariable(build(target)); |
| 1888 return makeLet( | 1911 return makeLet( |
| 1889 receiver, | 1912 receiver, |
| 1890 new ast.ConditionalExpression( | 1913 new ast.ConditionalExpression( |
| 1891 buildIsNull(new ast.VariableGet(receiver)), | 1914 buildIsNull(new ast.VariableGet(receiver)), |
| 1892 new ast.NullLiteral(), | 1915 new ast.NullLiteral(), |
| 1893 buildDecomposableMethodInvocation( | 1916 buildDecomposableMethodInvocation( |
| 1894 new ast.VariableGet(receiver), | 1917 new ast.VariableGet(receiver), |
| 1895 scope.buildName(node.methodName), | 1918 scope.buildName(node.methodName), |
| 1896 buildArgumentsForInvocation(node), | 1919 buildArgumentsForInvocation(node), |
| 1897 element), | 1920 element)..fileOffset = node.methodName.offset, |
| 1898 scope.buildType(node.staticType))); | 1921 scope.buildType(node.staticType))); |
| 1899 } else { | 1922 } else { |
| 1900 return buildDecomposableMethodInvocation( | 1923 return buildDecomposableMethodInvocation( |
| 1901 build(node.target), | 1924 build(node.target), |
| 1902 scope.buildName(node.methodName), | 1925 scope.buildName(node.methodName), |
| 1903 buildArgumentsForInvocation(node), | 1926 buildArgumentsForInvocation(node), |
| 1904 element); | 1927 element); |
| 1905 } | 1928 } |
| 1906 } | 1929 } |
| 1907 | 1930 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1922 } | 1945 } |
| 1923 | 1946 |
| 1924 ast.Expression visitPostfixExpression(PostfixExpression node) { | 1947 ast.Expression visitPostfixExpression(PostfixExpression node) { |
| 1925 String operator = node.operator.value(); | 1948 String operator = node.operator.value(); |
| 1926 switch (operator) { | 1949 switch (operator) { |
| 1927 case '++': | 1950 case '++': |
| 1928 case '--': | 1951 case '--': |
| 1929 var leftHand = buildLeftHandValue(node.operand); | 1952 var leftHand = buildLeftHandValue(node.operand); |
| 1930 var binaryOperator = new ast.Name(operator[0]); | 1953 var binaryOperator = new ast.Name(operator[0]); |
| 1931 return leftHand.buildPostfixIncrement(binaryOperator, | 1954 return leftHand.buildPostfixIncrement(binaryOperator, |
| 1955 offset: node.offset, |
| 1932 voidContext: isInVoidContext(node), | 1956 voidContext: isInVoidContext(node), |
| 1933 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); | 1957 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); |
| 1934 | 1958 |
| 1935 default: | 1959 default: |
| 1936 return scope.internalError('Invalid postfix operator $operator'); | 1960 return scope.internalError('Invalid postfix operator $operator'); |
| 1937 } | 1961 } |
| 1938 } | 1962 } |
| 1939 | 1963 |
| 1940 ast.Expression visitPrefixExpression(PrefixExpression node) { | 1964 ast.Expression visitPrefixExpression(PrefixExpression node) { |
| 1941 String operator = node.operator.value(); | 1965 String operator = node.operator.value(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1955 scope.resolveInterfaceMethod(node.staticElement)); | 1979 scope.resolveInterfaceMethod(node.staticElement)); |
| 1956 | 1980 |
| 1957 case '!': | 1981 case '!': |
| 1958 return new ast.Not(build(node.operand)); | 1982 return new ast.Not(build(node.operand)); |
| 1959 | 1983 |
| 1960 case '++': | 1984 case '++': |
| 1961 case '--': | 1985 case '--': |
| 1962 var leftHand = buildLeftHandValue(node.operand); | 1986 var leftHand = buildLeftHandValue(node.operand); |
| 1963 var binaryOperator = new ast.Name(operator[0]); | 1987 var binaryOperator = new ast.Name(operator[0]); |
| 1964 return leftHand.buildPrefixIncrement(binaryOperator, | 1988 return leftHand.buildPrefixIncrement(binaryOperator, |
| 1989 offset: node.offset, |
| 1965 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); | 1990 interfaceTarget: scope.resolveInterfaceMethod(node.staticElement)); |
| 1966 | 1991 |
| 1967 default: | 1992 default: |
| 1968 return scope.internalError('Invalid prefix operator $operator'); | 1993 return scope.internalError('Invalid prefix operator $operator'); |
| 1969 } | 1994 } |
| 1970 } | 1995 } |
| 1971 | 1996 |
| 1972 visitPropertyAccess(PropertyAccess node) { | 1997 visitPropertyAccess(PropertyAccess node) { |
| 1973 Element element = node.propertyName.staticElement; | 1998 Element element = node.propertyName.staticElement; |
| 1974 Element auxiliary = node.propertyName.auxiliaryElements?.staticElement; | 1999 Element auxiliary = node.propertyName.auxiliaryElements?.staticElement; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 node.accept(this); | 2371 node.accept(this); |
| 2347 } | 2372 } |
| 2348 | 2373 |
| 2349 /// Builds an empty class for broken classes that have no AST. | 2374 /// Builds an empty class for broken classes that have no AST. |
| 2350 /// | 2375 /// |
| 2351 /// This should only be used to recover from a compile-time error. | 2376 /// This should only be used to recover from a compile-time error. |
| 2352 void buildBrokenClass() { | 2377 void buildBrokenClass() { |
| 2353 currentClass.name = element.name; | 2378 currentClass.name = element.name; |
| 2354 currentClass.supertype = scope.getRootClassReference().asRawSupertype; | 2379 currentClass.supertype = scope.getRootClassReference().asRawSupertype; |
| 2355 currentClass.constructors.add( | 2380 currentClass.constructors.add( |
| 2356 new ast.Constructor(new ast.FunctionNode(new ast.InvalidStatement()))); | 2381 new ast.Constructor(new ast.FunctionNode(new ast.InvalidStatement())) |
| 2382 ..fileOffset = element.nameOffset); |
| 2357 } | 2383 } |
| 2358 | 2384 |
| 2359 void addAnnotations(List<Annotation> annotations) { | 2385 void addAnnotations(List<Annotation> annotations) { |
| 2360 // Class type parameters are not in scope in the annotation list. | 2386 // Class type parameters are not in scope in the annotation list. |
| 2361 for (var annotation in annotations) { | 2387 for (var annotation in annotations) { |
| 2362 currentClass.addAnnotation(annotationScope.buildAnnotation(annotation)); | 2388 currentClass.addAnnotation(annotationScope.buildAnnotation(annotation)); |
| 2363 } | 2389 } |
| 2364 } | 2390 } |
| 2365 | 2391 |
| 2366 void _buildMemberBody(ast.Member member, Element element, AstNode node) { | 2392 void _buildMemberBody(ast.Member member, Element element, AstNode node) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2495 var parameter = new ast.VariableDeclaration('index', type: intType); | 2521 var parameter = new ast.VariableDeclaration('index', type: intType); |
| 2496 var function = new ast.FunctionNode(new ast.EmptyStatement(), | 2522 var function = new ast.FunctionNode(new ast.EmptyStatement(), |
| 2497 positionalParameters: [parameter]); | 2523 positionalParameters: [parameter]); |
| 2498 var superConstructor = scope.loader.getRootClassConstructorReference(); | 2524 var superConstructor = scope.loader.getRootClassConstructorReference(); |
| 2499 var constructor = new ast.Constructor(function, | 2525 var constructor = new ast.Constructor(function, |
| 2500 name: new ast.Name(''), | 2526 name: new ast.Name(''), |
| 2501 isConst: true, | 2527 isConst: true, |
| 2502 initializers: [ | 2528 initializers: [ |
| 2503 new ast.FieldInitializer(indexField, new ast.VariableGet(parameter)), | 2529 new ast.FieldInitializer(indexField, new ast.VariableGet(parameter)), |
| 2504 new ast.SuperInitializer(superConstructor, new ast.Arguments.empty()) | 2530 new ast.SuperInitializer(superConstructor, new ast.Arguments.empty()) |
| 2505 ]); | 2531 ])..fileOffset = element.nameOffset; |
| 2506 classNode.addMember(constructor); | 2532 classNode.addMember(constructor); |
| 2507 int index = 0; | 2533 int index = 0; |
| 2508 var enumConstantFields = <ast.Field>[]; | 2534 var enumConstantFields = <ast.Field>[]; |
| 2509 for (var constant in node.constants) { | 2535 for (var constant in node.constants) { |
| 2510 ast.Field field = scope.getMemberReference(constant.element); | 2536 ast.Field field = scope.getMemberReference(constant.element); |
| 2511 field.initializer = new ast.ConstructorInvocation( | 2537 field.initializer = new ast.ConstructorInvocation( |
| 2512 constructor, new ast.Arguments([new ast.IntLiteral(index)]), | 2538 constructor, new ast.Arguments([new ast.IntLiteral(index)]), |
| 2513 isConst: true)..parent = field; | 2539 isConst: true)..parent = field; |
| 2514 field.type = classNode.rawType; | 2540 field.type = classNode.rawType; |
| 2515 classNode.addMember(field); | 2541 classNode.addMember(field); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2571 final MemberScope scope; | 2597 final MemberScope scope; |
| 2572 final Element element; | 2598 final Element element; |
| 2573 ast.Member get currentMember => scope.currentMember; | 2599 ast.Member get currentMember => scope.currentMember; |
| 2574 | 2600 |
| 2575 MemberBodyBuilder( | 2601 MemberBodyBuilder( |
| 2576 ReferenceLevelLoader loader, ast.Member member, this.element) | 2602 ReferenceLevelLoader loader, ast.Member member, this.element) |
| 2577 : scope = new MemberScope(loader, member); | 2603 : scope = new MemberScope(loader, member); |
| 2578 | 2604 |
| 2579 void build(AstNode node) { | 2605 void build(AstNode node) { |
| 2580 if (node != null) { | 2606 if (node != null) { |
| 2607 currentMember.fileEndOffset = node.endToken.offset; |
| 2581 node.accept(this); | 2608 node.accept(this); |
| 2582 } else { | 2609 } else { |
| 2583 buildBrokenMember(); | 2610 buildBrokenMember(); |
| 2584 } | 2611 } |
| 2585 } | 2612 } |
| 2586 | 2613 |
| 2587 /// Builds an empty member. | 2614 /// Builds an empty member. |
| 2588 /// | 2615 /// |
| 2589 /// This should only be used to recover from a compile-time error. | 2616 /// This should only be used to recover from a compile-time error. |
| 2590 void buildBrokenMember() { | 2617 void buildBrokenMember() { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2865 if (list[i - 1].compareTo(item) == 0) { | 2892 if (list[i - 1].compareTo(item) == 0) { |
| 2866 ++deleted; | 2893 ++deleted; |
| 2867 } else if (deleted > 0) { | 2894 } else if (deleted > 0) { |
| 2868 list[i - deleted] = item; | 2895 list[i - deleted] = item; |
| 2869 } | 2896 } |
| 2870 } | 2897 } |
| 2871 if (deleted > 0) { | 2898 if (deleted > 0) { |
| 2872 list.length -= deleted; | 2899 list.length -= deleted; |
| 2873 } | 2900 } |
| 2874 } | 2901 } |
| OLD | NEW |