| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.resolver; | 4 library engine.resolver; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 8 import 'java_engine.dart'; |
| 9 import 'source.dart'; | 9 import 'source.dart'; |
| 10 import 'error.dart'; | 10 import 'error.dart'; |
| 11 import 'scanner.dart' show Keyword, TokenType, Token, KeywordToken, StringToken; | 11 import 'scanner.dart' as sc; |
| 12 import 'utilities_dart.dart'; | 12 import 'utilities_dart.dart'; |
| 13 import 'ast.dart'; | 13 import 'ast.dart'; |
| 14 import 'parser.dart' show Parser; |
| 14 import 'element.dart' hide HideCombinator, ShowCombinator; | 15 import 'element.dart' hide HideCombinator, ShowCombinator; |
| 16 import 'html.dart' as ht; |
| 15 import 'engine.dart'; | 17 import 'engine.dart'; |
| 16 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; | 18 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single | 21 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single |
| 20 * compilation unit. | 22 * compilation unit. |
| 23 * @coverage dart.engine.resolver |
| 21 */ | 24 */ |
| 22 class CompilationUnitBuilder { | 25 class CompilationUnitBuilder { |
| 23 /** | 26 /** |
| 24 * The analysis context in which the element model will be built. | 27 * The analysis context in which the element model will be built. |
| 25 */ | 28 */ |
| 26 AnalysisContextImpl _analysisContext; | 29 AnalysisContextImpl _analysisContext; |
| 27 /** | 30 /** |
| 28 * The listener to which errors will be reported. | 31 * The listener to which errors will be reported. |
| 29 */ | 32 */ |
| 30 AnalysisErrorListener _errorListener; | 33 AnalysisErrorListener _errorListener; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 element.typeAliases = holder.typeAliases; | 65 element.typeAliases = holder.typeAliases; |
| 63 element.types = holder.types; | 66 element.types = holder.types; |
| 64 element.topLevelVariables = holder.topLevelVariables; | 67 element.topLevelVariables = holder.topLevelVariables; |
| 65 unit.element = element; | 68 unit.element = element; |
| 66 return element; | 69 return element; |
| 67 } | 70 } |
| 68 } | 71 } |
| 69 /** | 72 /** |
| 70 * Instances of the class {@code ElementBuilder} traverse an AST structure and b
uild the element | 73 * Instances of the class {@code ElementBuilder} traverse an AST structure and b
uild the element |
| 71 * model representing the AST structure. | 74 * model representing the AST structure. |
| 75 * @coverage dart.engine.resolver |
| 72 */ | 76 */ |
| 73 class ElementBuilder extends RecursiveASTVisitor<Object> { | 77 class ElementBuilder extends RecursiveASTVisitor<Object> { |
| 74 /** | 78 /** |
| 75 * The element holder associated with the element that is currently being buil
t. | 79 * The element holder associated with the element that is currently being buil
t. |
| 76 */ | 80 */ |
| 77 ElementHolder _currentHolder; | 81 ElementHolder _currentHolder; |
| 78 /** | 82 /** |
| 79 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. | 83 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. |
| 80 */ | 84 */ |
| 81 bool _inFieldContext = false; | 85 bool _inFieldContext = false; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 element.labels = holder.labels; | 172 element.labels = holder.labels; |
| 169 element.localVariables = holder.localVariables; | 173 element.localVariables = holder.localVariables; |
| 170 element.parameters = holder.parameters; | 174 element.parameters = holder.parameters; |
| 171 _currentHolder.addConstructor(element); | 175 _currentHolder.addConstructor(element); |
| 172 node.element = element; | 176 node.element = element; |
| 173 if (constructorName != null) { | 177 if (constructorName != null) { |
| 174 constructorName.element = element; | 178 constructorName.element = element; |
| 175 } | 179 } |
| 176 return null; | 180 return null; |
| 177 } | 181 } |
| 182 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 183 SimpleIdentifier variableName = node.identifier; |
| 184 sc.Token keyword27 = node.keyword; |
| 185 LocalVariableElementImpl element = new LocalVariableElementImpl(variableName
); |
| 186 ForEachStatement statement = node.parent as ForEachStatement; |
| 187 int declarationEnd = node.offset + node.length; |
| 188 int statementEnd = statement.offset + statement.length; |
| 189 element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1); |
| 190 element.const2 = matches(keyword27, sc.Keyword.CONST); |
| 191 element.final2 = matches(keyword27, sc.Keyword.FINAL); |
| 192 _currentHolder.addLocalVariable(element); |
| 193 variableName.element = element; |
| 194 return super.visitDeclaredIdentifier(node); |
| 195 } |
| 178 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 196 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 179 ElementHolder holder = new ElementHolder(); | 197 ElementHolder holder = new ElementHolder(); |
| 180 visit(holder, node.defaultValue); | 198 visit(holder, node.defaultValue); |
| 181 FunctionElementImpl initializer = new FunctionElementImpl(); | 199 FunctionElementImpl initializer = new FunctionElementImpl(); |
| 182 initializer.functions = holder.functions; | 200 initializer.functions = holder.functions; |
| 183 initializer.labels = holder.labels; | 201 initializer.labels = holder.labels; |
| 184 initializer.localVariables = holder.localVariables; | 202 initializer.localVariables = holder.localVariables; |
| 185 initializer.parameters = holder.parameters; | 203 initializer.parameters = holder.parameters; |
| 186 SimpleIdentifier parameterName = node.parameter.identifier; | 204 SimpleIdentifier parameterName = node.parameter.identifier; |
| 187 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); | 205 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 FunctionExpression expression = node.functionExpression; | 243 FunctionExpression expression = node.functionExpression; |
| 226 if (expression != null) { | 244 if (expression != null) { |
| 227 ElementHolder holder = new ElementHolder(); | 245 ElementHolder holder = new ElementHolder(); |
| 228 bool wasInFunction = _inFunction; | 246 bool wasInFunction = _inFunction; |
| 229 _inFunction = true; | 247 _inFunction = true; |
| 230 try { | 248 try { |
| 231 visitChildren(holder, expression); | 249 visitChildren(holder, expression); |
| 232 } finally { | 250 } finally { |
| 233 _inFunction = wasInFunction; | 251 _inFunction = wasInFunction; |
| 234 } | 252 } |
| 235 Token property = node.propertyKeyword; | 253 sc.Token property = node.propertyKeyword; |
| 236 if (property == null) { | 254 if (property == null) { |
| 237 SimpleIdentifier functionName = node.name; | 255 SimpleIdentifier functionName = node.name; |
| 238 FunctionElementImpl element = new FunctionElementImpl.con1(functionName)
; | 256 FunctionElementImpl element = new FunctionElementImpl.con1(functionName)
; |
| 239 element.functions = holder.functions; | 257 element.functions = holder.functions; |
| 240 element.labels = holder.labels; | 258 element.labels = holder.labels; |
| 241 element.localVariables = holder.localVariables; | 259 element.localVariables = holder.localVariables; |
| 242 element.parameters = holder.parameters; | 260 element.parameters = holder.parameters; |
| 243 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); | 261 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); |
| 244 element.type = type; | 262 element.type = type; |
| 245 _currentHolder.addFunction(element); | 263 _currentHolder.addFunction(element); |
| 246 expression.element = element; | 264 expression.element = element; |
| 247 functionName.element = element; | 265 functionName.element = element; |
| 248 } else { | 266 } else { |
| 249 SimpleIdentifier propertyNameNode = node.name; | 267 SimpleIdentifier propertyNameNode = node.name; |
| 250 if (propertyNameNode == null) { | 268 if (propertyNameNode == null) { |
| 251 return null; | 269 return null; |
| 252 } | 270 } |
| 253 String propertyName = propertyNameNode.name; | 271 String propertyName = propertyNameNode.name; |
| 254 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE
lementImpl; | 272 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE
lementImpl; |
| 255 if (field == null) { | 273 if (field == null) { |
| 256 field = new FieldElementImpl.con2(node.name.name); | 274 field = new FieldElementImpl.con2(node.name.name); |
| 257 field.final2 = true; | 275 field.final2 = true; |
| 258 _currentHolder.addField(field); | 276 _currentHolder.addField(field); |
| 259 } | 277 } |
| 260 if (matches(property, Keyword.GET)) { | 278 if (matches(property, sc.Keyword.GET)) { |
| 261 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); | 279 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.c
on1(propertyNameNode); |
| 262 getter.functions = holder.functions; | 280 getter.functions = holder.functions; |
| 263 getter.labels = holder.labels; | 281 getter.labels = holder.labels; |
| 264 getter.localVariables = holder.localVariables; | 282 getter.localVariables = holder.localVariables; |
| 265 getter.variable = field; | 283 getter.variable = field; |
| 266 getter.getter = true; | 284 getter.getter = true; |
| 267 field.getter = getter; | 285 field.getter = getter; |
| 268 _currentHolder.addAccessor(getter); | 286 _currentHolder.addAccessor(getter); |
| 269 propertyNameNode.element = getter; | 287 propertyNameNode.element = getter; |
| 270 } else { | 288 } else { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 370 } |
| 353 Object visitMethodDeclaration(MethodDeclaration node) { | 371 Object visitMethodDeclaration(MethodDeclaration node) { |
| 354 ElementHolder holder = new ElementHolder(); | 372 ElementHolder holder = new ElementHolder(); |
| 355 bool wasInFunction = _inFunction; | 373 bool wasInFunction = _inFunction; |
| 356 _inFunction = true; | 374 _inFunction = true; |
| 357 try { | 375 try { |
| 358 visitChildren(holder, node); | 376 visitChildren(holder, node); |
| 359 } finally { | 377 } finally { |
| 360 _inFunction = wasInFunction; | 378 _inFunction = wasInFunction; |
| 361 } | 379 } |
| 362 Token property = node.propertyKeyword; | 380 sc.Token property = node.propertyKeyword; |
| 363 if (property == null) { | 381 if (property == null) { |
| 364 SimpleIdentifier methodName = node.name; | 382 SimpleIdentifier methodName = node.name; |
| 365 String nameOfMethod = methodName.name; | 383 String nameOfMethod = methodName.name; |
| 366 if (nameOfMethod == TokenType.MINUS.lexeme && node.parameters.parameters.l
ength == 0) { | 384 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter
s.length == 0) { |
| 367 nameOfMethod = "unary-"; | 385 nameOfMethod = "unary-"; |
| 368 } | 386 } |
| 369 MethodElementImpl element = new MethodElementImpl.con2(nameOfMethod, metho
dName.offset); | 387 MethodElementImpl element = new MethodElementImpl.con2(nameOfMethod, metho
dName.offset); |
| 370 Token keyword = node.modifierKeyword; | 388 sc.Token keyword = node.modifierKeyword; |
| 371 element.abstract = matches(keyword, Keyword.ABSTRACT); | 389 element.abstract = matches(keyword, sc.Keyword.ABSTRACT); |
| 372 element.functions = holder.functions; | 390 element.functions = holder.functions; |
| 373 element.labels = holder.labels; | 391 element.labels = holder.labels; |
| 374 element.localVariables = holder.localVariables; | 392 element.localVariables = holder.localVariables; |
| 375 element.parameters = holder.parameters; | 393 element.parameters = holder.parameters; |
| 376 element.static = matches(keyword, Keyword.STATIC); | 394 element.static = matches(keyword, sc.Keyword.STATIC); |
| 377 _currentHolder.addMethod(element); | 395 _currentHolder.addMethod(element); |
| 378 methodName.element = element; | 396 methodName.element = element; |
| 379 } else { | 397 } else { |
| 380 SimpleIdentifier propertyNameNode = node.name; | 398 SimpleIdentifier propertyNameNode = node.name; |
| 381 String propertyName = propertyNameNode.name; | 399 String propertyName = propertyNameNode.name; |
| 382 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldEle
mentImpl; | 400 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldEle
mentImpl; |
| 383 if (field == null) { | 401 if (field == null) { |
| 384 field = new FieldElementImpl.con2(node.name.name); | 402 field = new FieldElementImpl.con2(node.name.name); |
| 385 field.final2 = true; | 403 field.final2 = true; |
| 386 field.static = matches(node.modifierKeyword, Keyword.STATIC); | 404 field.static = matches(node.modifierKeyword, sc.Keyword.STATIC); |
| 387 _currentHolder.addField(field); | 405 _currentHolder.addField(field); |
| 388 } | 406 } |
| 389 if (matches(property, Keyword.GET)) { | 407 if (matches(property, sc.Keyword.GET)) { |
| 390 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con
1(propertyNameNode); | 408 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con
1(propertyNameNode); |
| 391 getter.functions = holder.functions; | 409 getter.functions = holder.functions; |
| 392 getter.labels = holder.labels; | 410 getter.labels = holder.labels; |
| 393 getter.localVariables = holder.localVariables; | 411 getter.localVariables = holder.localVariables; |
| 394 getter.variable = field; | 412 getter.variable = field; |
| 395 getter.getter = true; | 413 getter.getter = true; |
| 396 field.getter = getter; | 414 field.getter = getter; |
| 397 _currentHolder.addAccessor(getter); | 415 _currentHolder.addAccessor(getter); |
| 398 propertyNameNode.element = getter; | 416 propertyNameNode.element = getter; |
| 399 } else { | 417 } else { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 int blockEnd = enclosingBlock.offset + enclosingBlock.length; | 489 int blockEnd = enclosingBlock.offset + enclosingBlock.length; |
| 472 ((element as LocalVariableElementImpl)).setVisibleRange(functionEnd, block
End - functionEnd - 1); | 490 ((element as LocalVariableElementImpl)).setVisibleRange(functionEnd, block
End - functionEnd - 1); |
| 473 _currentHolder.addLocalVariable((element as LocalVariableElementImpl)); | 491 _currentHolder.addLocalVariable((element as LocalVariableElementImpl)); |
| 474 variableName.element = element; | 492 variableName.element = element; |
| 475 } else { | 493 } else { |
| 476 SimpleIdentifier variableName = node.name; | 494 SimpleIdentifier variableName = node.name; |
| 477 element = new TopLevelVariableElementImpl.con1(variableName); | 495 element = new TopLevelVariableElementImpl.con1(variableName); |
| 478 _currentHolder.addTopLevelVariable((element as TopLevelVariableElementImpl
)); | 496 _currentHolder.addTopLevelVariable((element as TopLevelVariableElementImpl
)); |
| 479 variableName.element = element; | 497 variableName.element = element; |
| 480 } | 498 } |
| 481 Token keyword26 = ((node.parent as VariableDeclarationList)).keyword; | 499 sc.Token keyword28 = ((node.parent as VariableDeclarationList)).keyword; |
| 482 bool isFinal = matches(keyword26, Keyword.FINAL); | 500 bool isFinal = matches(keyword28, sc.Keyword.FINAL); |
| 483 element.const2 = matches(keyword26, Keyword.CONST); | 501 element.const2 = matches(keyword28, sc.Keyword.CONST); |
| 484 element.final2 = isFinal; | 502 element.final2 = isFinal; |
| 485 if (node.initializer != null) { | 503 if (node.initializer != null) { |
| 486 ElementHolder holder = new ElementHolder(); | 504 ElementHolder holder = new ElementHolder(); |
| 487 bool wasInFieldContext = _inFieldContext; | 505 bool wasInFieldContext = _inFieldContext; |
| 488 _inFieldContext = false; | 506 _inFieldContext = false; |
| 489 try { | 507 try { |
| 490 visit(holder, node.initializer); | 508 visit(holder, node.initializer); |
| 491 } finally { | 509 } finally { |
| 492 _inFieldContext = wasInFieldContext; | 510 _inFieldContext = wasInFieldContext; |
| 493 } | 511 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 504 getter.getter = true; | 522 getter.getter = true; |
| 505 _currentHolder.addAccessor(getter); | 523 _currentHolder.addAccessor(getter); |
| 506 variable.getter = getter; | 524 variable.getter = getter; |
| 507 if (!isFinal) { | 525 if (!isFinal) { |
| 508 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); | 526 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); |
| 509 setter.setter = true; | 527 setter.setter = true; |
| 510 _currentHolder.addAccessor(setter); | 528 _currentHolder.addAccessor(setter); |
| 511 variable.setter = setter; | 529 variable.setter = setter; |
| 512 } | 530 } |
| 513 if (_inFieldContext) { | 531 if (_inFieldContext) { |
| 514 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a
s FieldDeclaration)).keyword, Keyword.STATIC); | 532 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a
s FieldDeclaration)).keyword, sc.Keyword.STATIC); |
| 515 } | 533 } |
| 516 } | 534 } |
| 517 return super.visitVariableDeclaration(node); | 535 return super.visitVariableDeclaration(node); |
| 518 } | 536 } |
| 519 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { | 537 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { |
| 520 int typeVariableCount = typeVariables.length; | 538 int typeVariableCount = typeVariables.length; |
| 521 List<Type2> typeArguments = new List<Type2>(typeVariableCount); | 539 List<Type2> typeArguments = new List<Type2>(typeVariableCount); |
| 522 for (int i = 0; i < typeVariableCount; i++) { | 540 for (int i = 0; i < typeVariableCount; i++) { |
| 523 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; | 541 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; |
| 524 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; | 542 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 544 parent13 = parent13.parent; | 562 parent13 = parent13.parent; |
| 545 } | 563 } |
| 546 return null; | 564 return null; |
| 547 } | 565 } |
| 548 /** | 566 /** |
| 549 * Return {@code true} if the given token is a token for the given keyword. | 567 * Return {@code true} if the given token is a token for the given keyword. |
| 550 * @param token the token being tested | 568 * @param token the token being tested |
| 551 * @param keyword the keyword being tested for | 569 * @param keyword the keyword being tested for |
| 552 * @return {@code true} if the given token is a token for the given keyword | 570 * @return {@code true} if the given token is a token for the given keyword |
| 553 */ | 571 */ |
| 554 bool matches(Token token, Keyword keyword34) => token != null && identical(tok
en.type, TokenType.KEYWORD) && identical(((token as KeywordToken)).keyword, keyw
ord34); | 572 bool matches(sc.Token token, sc.Keyword keyword36) => token != null && identic
al(token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).k
eyword, keyword36); |
| 555 /** | 573 /** |
| 556 * Make the given holder be the current holder while visiting the given node. | 574 * Make the given holder be the current holder while visiting the given node. |
| 557 * @param holder the holder that will gather elements that are built while vis
iting the children | 575 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 558 * @param node the node to be visited | 576 * @param node the node to be visited |
| 559 */ | 577 */ |
| 560 void visit(ElementHolder holder, ASTNode node) { | 578 void visit(ElementHolder holder, ASTNode node) { |
| 561 if (node != null) { | 579 if (node != null) { |
| 562 ElementHolder previousHolder = _currentHolder; | 580 ElementHolder previousHolder = _currentHolder; |
| 563 _currentHolder = holder; | 581 _currentHolder = holder; |
| 564 try { | 582 try { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 581 node.visitChildren(this); | 599 node.visitChildren(this); |
| 582 } finally { | 600 } finally { |
| 583 _currentHolder = previousHolder; | 601 _currentHolder = previousHolder; |
| 584 } | 602 } |
| 585 } | 603 } |
| 586 } | 604 } |
| 587 } | 605 } |
| 588 /** | 606 /** |
| 589 * Instances of the class {@code ElementHolder} hold on to elements created whil
e traversing an AST | 607 * Instances of the class {@code ElementHolder} hold on to elements created whil
e traversing an AST |
| 590 * structure so that they can be accessed when creating their enclosing element. | 608 * structure so that they can be accessed when creating their enclosing element. |
| 609 * @coverage dart.engine.resolver |
| 591 */ | 610 */ |
| 592 class ElementHolder { | 611 class ElementHolder { |
| 593 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>()
; | 612 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>()
; |
| 594 List<ConstructorElement> _constructors = new List<ConstructorElement>(); | 613 List<ConstructorElement> _constructors = new List<ConstructorElement>(); |
| 595 List<FieldElement> _fields = new List<FieldElement>(); | 614 List<FieldElement> _fields = new List<FieldElement>(); |
| 596 List<FunctionElement> _functions = new List<FunctionElement>(); | 615 List<FunctionElement> _functions = new List<FunctionElement>(); |
| 597 List<LabelElement> _labels = new List<LabelElement>(); | 616 List<LabelElement> _labels = new List<LabelElement>(); |
| 598 List<VariableElement> _localVariables = new List<VariableElement>(); | 617 List<VariableElement> _localVariables = new List<VariableElement>(); |
| 599 List<MethodElement> _methods = new List<MethodElement>(); | 618 List<MethodElement> _methods = new List<MethodElement>(); |
| 600 List<TypeAliasElement> _typeAliases = new List<TypeAliasElement>(); | 619 List<TypeAliasElement> _typeAliases = new List<TypeAliasElement>(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 List<LabelElement> get labels => new List.from(_labels); | 677 List<LabelElement> get labels => new List.from(_labels); |
| 659 List<LocalVariableElement> get localVariables => new List.from(_localVariables
); | 678 List<LocalVariableElement> get localVariables => new List.from(_localVariables
); |
| 660 List<MethodElement> get methods => new List.from(_methods); | 679 List<MethodElement> get methods => new List.from(_methods); |
| 661 List<ParameterElement> get parameters => new List.from(_parameters); | 680 List<ParameterElement> get parameters => new List.from(_parameters); |
| 662 List<TopLevelVariableElement> get topLevelVariables => new List.from(_topLevel
Variables); | 681 List<TopLevelVariableElement> get topLevelVariables => new List.from(_topLevel
Variables); |
| 663 List<TypeAliasElement> get typeAliases => new List.from(_typeAliases); | 682 List<TypeAliasElement> get typeAliases => new List.from(_typeAliases); |
| 664 List<ClassElement> get types => new List.from(_types); | 683 List<ClassElement> get types => new List.from(_types); |
| 665 List<TypeVariableElement> get typeVariables => new List.from(_typeVariables); | 684 List<TypeVariableElement> get typeVariables => new List.from(_typeVariables); |
| 666 } | 685 } |
| 667 /** | 686 /** |
| 687 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s
ingle HTML unit. |
| 688 */ |
| 689 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { |
| 690 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; |
| 691 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; |
| 692 static String _SCRIPT = "script"; |
| 693 static String _SRC = "src"; |
| 694 static String _TYPE = "type"; |
| 695 /** |
| 696 * The analysis context in which the element model will be built. |
| 697 */ |
| 698 AnalysisContextImpl _context; |
| 699 /** |
| 700 * The HTML element being built. |
| 701 */ |
| 702 HtmlElementImpl _htmlElement; |
| 703 /** |
| 704 * The script elements being built. |
| 705 */ |
| 706 List<HtmlScriptElement> _scripts; |
| 707 /** |
| 708 * Initialize a newly created HTML unit builder. |
| 709 * @param context the analysis context in which the element model will be buil
t |
| 710 */ |
| 711 HtmlUnitBuilder(AnalysisContextImpl context) { |
| 712 this._context = context; |
| 713 } |
| 714 /** |
| 715 * Build the HTML element for the given source. |
| 716 * @param source the source describing the compilation unit |
| 717 * @return the HTML element that was built |
| 718 * @throws AnalysisException if the analysis could not be performed |
| 719 */ |
| 720 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _
context.parseHtml(source).htmlUnit); |
| 721 /** |
| 722 * Build the HTML element for the given source. |
| 723 * @param source the source describing the compilation unit |
| 724 * @param unit the AST structure representing the HTML |
| 725 * @throws AnalysisException if the analysis could not be performed |
| 726 */ |
| 727 HtmlElementImpl buildHtmlElement2(Source source14, ht.HtmlUnit unit) { |
| 728 HtmlElementImpl result = new HtmlElementImpl(_context, source14.shortName); |
| 729 result.source = source14; |
| 730 _htmlElement = result; |
| 731 unit.accept(this); |
| 732 _htmlElement = null; |
| 733 unit.element = result; |
| 734 return result; |
| 735 } |
| 736 Object visitHtmlUnit(ht.HtmlUnit node) { |
| 737 _scripts = new List<HtmlScriptElement>(); |
| 738 node.visitChildren(this); |
| 739 _htmlElement.scripts = new List.from(_scripts); |
| 740 _scripts = null; |
| 741 return null; |
| 742 } |
| 743 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null; |
| 744 Object visitXmlTagNode(ht.XmlTagNode node) { |
| 745 if (isScriptNode(node)) { |
| 746 Source htmlSource = _htmlElement.source; |
| 747 String scriptSourcePath = getScriptSourcePath(node); |
| 748 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath
== null) { |
| 749 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl
(node); |
| 750 String contents = node.content; |
| 751 AnalysisErrorListener errorListener = new AnalysisErrorListener_2(); |
| 752 sc.StringScanner scanner = new sc.StringScanner(null, contents, errorLis
tener); |
| 753 sc.Token firstToken = scanner.tokenize(); |
| 754 List<int> lineStarts2 = scanner.lineStarts; |
| 755 Parser parser = new Parser(null, errorListener); |
| 756 CompilationUnit unit = parser.parseCompilationUnit(firstToken); |
| 757 try { |
| 758 CompilationUnitBuilder builder = new CompilationUnitBuilder(_context,
errorListener); |
| 759 CompilationUnitElementImpl elem = builder.buildCompilationUnit2(htmlSo
urce, unit); |
| 760 LibraryElementImpl library = new LibraryElementImpl(_context, null); |
| 761 library.definingCompilationUnit = elem; |
| 762 script.scriptLibrary = library; |
| 763 } on AnalysisException catch (e) { |
| 764 print(e); |
| 765 } |
| 766 _scripts.add(script); |
| 767 } else { |
| 768 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl
(node); |
| 769 if (scriptSourcePath != null) { |
| 770 script.scriptSource = htmlSource.resolve(scriptSourcePath); |
| 771 } |
| 772 _scripts.add(script); |
| 773 } |
| 774 } else { |
| 775 node.visitChildren(this); |
| 776 } |
| 777 return null; |
| 778 } |
| 779 /** |
| 780 * Return the value of the source attribute if it exists. |
| 781 * @param node the node containing attributes |
| 782 * @return the source path or {@code null} if not defined |
| 783 */ |
| 784 String getScriptSourcePath(ht.XmlTagNode node) { |
| 785 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 786 if (attribute.name.lexeme == _SRC) { |
| 787 String text2 = attribute.text; |
| 788 return text2 != null && text2.length > 0 ? text2 : null; |
| 789 } |
| 790 } |
| 791 return null; |
| 792 } |
| 793 /** |
| 794 * Determine if the specified node is a Dart script. |
| 795 * @param node the node to be tested (not {@code null}) |
| 796 * @return {@code true} if the node is a Dart script |
| 797 */ |
| 798 bool isScriptNode(ht.XmlTagNode node) { |
| 799 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { |
| 800 return false; |
| 801 } |
| 802 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 803 if (attribute.name.lexeme == _TYPE) { |
| 804 ht.Token valueToken = attribute.value; |
| 805 if (valueToken != null) { |
| 806 String value = valueToken.lexeme; |
| 807 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { |
| 808 return true; |
| 809 } |
| 810 } |
| 811 } |
| 812 } |
| 813 return false; |
| 814 } |
| 815 } |
| 816 class AnalysisErrorListener_2 implements AnalysisErrorListener { |
| 817 void onError(AnalysisError error) { |
| 818 } |
| 819 } |
| 820 /** |
| 668 * Instances of the class {@code ElementResolver} are used by instances of {@lin
k ResolverVisitor}to resolve references within the AST structure to the elements
being referenced. The requirements | 821 * Instances of the class {@code ElementResolver} are used by instances of {@lin
k ResolverVisitor}to resolve references within the AST structure to the elements
being referenced. The requirements |
| 669 * for the element resolver are: | 822 * for the element resolver are: |
| 670 * <ol> | 823 * <ol> |
| 671 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which
it refers. | 824 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which
it refers. |
| 672 * Specifically: | 825 * Specifically: |
| 673 * <ul> | 826 * <ul> |
| 674 * <li>An identifier within the declaration of that name should resolve to the e
lement being | 827 * <li>An identifier within the declaration of that name should resolve to the e
lement being |
| 675 * declared.</li> | 828 * declared.</li> |
| 676 * <li>An identifier denoting a prefix should resolve to the element representin
g the import that | 829 * <li>An identifier denoting a prefix should resolve to the element representin
g the import that |
| 677 * defines the prefix (an {@link ImportElement}).</li> | 830 * defines the prefix (an {@link ImportElement}).</li> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 702 * <li>The identifiers in the hide and show combinators in {@link ImportDirectiv
e}s and{@link ExportDirective}s should resolve to the elements that are being hi
dden or shown, | 855 * <li>The identifiers in the hide and show combinators in {@link ImportDirectiv
e}s and{@link ExportDirective}s should resolve to the elements that are being hi
dden or shown, |
| 703 * respectively, unless those names are not defined in the specified library (or
the specified | 856 * respectively, unless those names are not defined in the specified library (or
the specified |
| 704 * library does not exist).</li> | 857 * library does not exist).</li> |
| 705 * <li>Every {@link PartDirective} should resolve to the element representing th
e compilation unit | 858 * <li>Every {@link PartDirective} should resolve to the element representing th
e compilation unit |
| 706 * being specified by the string unless the specified compilation unit does not
exist (a{@link CompilationUnitElement}).</li> | 859 * being specified by the string unless the specified compilation unit does not
exist (a{@link CompilationUnitElement}).</li> |
| 707 * </ol> | 860 * </ol> |
| 708 * Note that AST nodes that would represent elements that are not defined are no
t resolved to | 861 * Note that AST nodes that would represent elements that are not defined are no
t resolved to |
| 709 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and | 862 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and |
| 710 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an | 863 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an |
| 711 * error). | 864 * error). |
| 865 * @coverage dart.engine.resolver |
| 712 */ | 866 */ |
| 713 class ElementResolver extends SimpleASTVisitor<Object> { | 867 class ElementResolver extends SimpleASTVisitor<Object> { |
| 714 /** | 868 /** |
| 715 * The resolver driving this participant. | 869 * The resolver driving this participant. |
| 716 */ | 870 */ |
| 717 ResolverVisitor _resolver; | 871 ResolverVisitor _resolver; |
| 718 /** | 872 /** |
| 719 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 873 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 720 * @param resolver the resolver driving this participant | 874 * @param resolver the resolver driving this participant |
| 721 */ | 875 */ |
| 722 ElementResolver(ResolverVisitor resolver) { | 876 ElementResolver(ResolverVisitor resolver) { |
| 723 this._resolver = resolver; | 877 this._resolver = resolver; |
| 724 } | 878 } |
| 725 Object visitAssignmentExpression(AssignmentExpression node) { | 879 Object visitAssignmentExpression(AssignmentExpression node) { |
| 726 TokenType operator7 = node.operator.type; | 880 sc.TokenType operator7 = node.operator.type; |
| 727 if (operator7 != TokenType.EQ) { | 881 if (operator7 != sc.TokenType.EQ) { |
| 728 operator7 = operatorFromCompoundAssignment(operator7); | 882 operator7 = operatorFromCompoundAssignment(operator7); |
| 729 Expression leftNode = node.leftHandSide; | 883 Expression leftNode = node.leftHandSide; |
| 730 if (leftNode != null) { | 884 if (leftNode != null) { |
| 731 Type2 leftType = leftNode.staticType; | 885 Type2 leftType = leftNode.staticType; |
| 732 if (leftType != null) { | 886 if (leftType != null) { |
| 733 Element leftElement = leftType.element; | 887 Element leftElement = leftType.element; |
| 734 if (leftElement != null) { | 888 if (leftElement != null) { |
| 735 MethodElement method = lookUpMethod(leftElement, operator7.lexeme); | 889 MethodElement method = lookUpMethod(leftElement, operator7.lexeme); |
| 736 if (method != null) { | 890 if (method != null) { |
| 737 node.element = method; | 891 node.element = method; |
| 738 } else { | 892 } else { |
| 739 } | 893 } |
| 740 } | 894 } |
| 741 } | 895 } |
| 742 } | 896 } |
| 743 } | 897 } |
| 744 return null; | 898 return null; |
| 745 } | 899 } |
| 746 Object visitBinaryExpression(BinaryExpression node) { | 900 Object visitBinaryExpression(BinaryExpression node) { |
| 747 Token operator8 = node.operator; | 901 sc.Token operator8 = node.operator; |
| 748 if (operator8.isUserDefinableOperator()) { | 902 if (operator8.isUserDefinableOperator()) { |
| 749 Type2 leftType = getType(node.leftOperand); | 903 Type2 leftType = getType(node.leftOperand); |
| 750 Element leftTypeElement; | 904 Element leftTypeElement; |
| 751 if (leftType == null || leftType.isDynamic()) { | 905 if (leftType == null || leftType.isDynamic()) { |
| 752 return null; | 906 return null; |
| 753 } else if (leftType is FunctionType) { | 907 } else if (leftType is FunctionType) { |
| 754 leftTypeElement = _resolver.typeProvider.functionType.element; | 908 leftTypeElement = _resolver.typeProvider.functionType.element; |
| 755 } else { | 909 } else { |
| 756 leftTypeElement = leftType.element; | 910 leftTypeElement = leftType.element; |
| 757 } | 911 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 } | 955 } |
| 802 Object visitContinueStatement(ContinueStatement node) { | 956 Object visitContinueStatement(ContinueStatement node) { |
| 803 SimpleIdentifier labelNode = node.label; | 957 SimpleIdentifier labelNode = node.label; |
| 804 LabelElementImpl labelElement = lookupLabel(node, labelNode); | 958 LabelElementImpl labelElement = lookupLabel(node, labelNode); |
| 805 if (labelElement != null && labelElement.isOnSwitchStatement()) { | 959 if (labelElement != null && labelElement.isOnSwitchStatement()) { |
| 806 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod
e, []); | 960 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod
e, []); |
| 807 } | 961 } |
| 808 return null; | 962 return null; |
| 809 } | 963 } |
| 810 Object visitExportDirective(ExportDirective node) { | 964 Object visitExportDirective(ExportDirective node) { |
| 811 Element element20 = node.element; | 965 Element element21 = node.element; |
| 812 if (element20 is ExportElement) { | 966 if (element21 is ExportElement) { |
| 813 resolveCombinators(((element20 as ExportElement)).exportedLibrary, node.co
mbinators); | 967 resolveCombinators(((element21 as ExportElement)).exportedLibrary, node.co
mbinators); |
| 814 } | 968 } |
| 815 return null; | 969 return null; |
| 816 } | 970 } |
| 817 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
null; | 971 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) =>
null; |
| 818 Object visitImportDirective(ImportDirective node) { | 972 Object visitImportDirective(ImportDirective node) { |
| 819 SimpleIdentifier prefixNode = node.prefix; | 973 SimpleIdentifier prefixNode = node.prefix; |
| 820 if (prefixNode != null) { | 974 if (prefixNode != null) { |
| 821 String prefixName = prefixNode.name; | 975 String prefixName = prefixNode.name; |
| 822 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) { | 976 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) { |
| 823 if (prefixElement.name == prefixName) { | 977 if (prefixElement.name == prefixName) { |
| 824 recordResolution(prefixNode, prefixElement); | 978 recordResolution(prefixNode, prefixElement); |
| 825 break; | 979 break; |
| 826 } | 980 } |
| 827 } | 981 } |
| 828 } | 982 } |
| 829 Element element21 = node.element; | 983 Element element22 = node.element; |
| 830 if (element21 is ImportElement) { | 984 if (element22 is ImportElement) { |
| 831 resolveCombinators(((element21 as ImportElement)).importedLibrary, node.co
mbinators); | 985 resolveCombinators(((element22 as ImportElement)).importedLibrary, node.co
mbinators); |
| 832 } | 986 } |
| 833 return null; | 987 return null; |
| 834 } | 988 } |
| 835 Object visitIndexExpression(IndexExpression node) { | 989 Object visitIndexExpression(IndexExpression node) { |
| 836 Type2 arrayType = getType(node.realTarget); | 990 Type2 arrayType = getType(node.realTarget); |
| 837 if (arrayType == null || arrayType.isDynamic()) { | 991 if (arrayType == null || arrayType.isDynamic()) { |
| 838 return null; | 992 return null; |
| 839 } | 993 } |
| 840 Element arrayTypeElement = arrayType.element; | 994 Element arrayTypeElement = arrayType.element; |
| 841 String operator; | 995 String operator; |
| 842 if (node.inSetterContext()) { | 996 if (node.inSetterContext()) { |
| 843 operator = TokenType.INDEX_EQ.lexeme; | 997 operator = sc.TokenType.INDEX_EQ.lexeme; |
| 844 } else { | 998 } else { |
| 845 operator = TokenType.INDEX.lexeme; | 999 operator = sc.TokenType.INDEX.lexeme; |
| 846 } | 1000 } |
| 847 MethodElement member = lookUpMethod(arrayTypeElement, operator); | 1001 MethodElement member = lookUpMethod(arrayTypeElement, operator); |
| 848 if (member == null) { | 1002 if (member == null) { |
| 849 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, node, [operato
r]); | 1003 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, node, [operato
r]); |
| 850 } else { | 1004 } else { |
| 851 node.element = member; | 1005 node.element = member; |
| 852 } | 1006 } |
| 853 return null; | 1007 return null; |
| 854 } | 1008 } |
| 855 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 1009 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 } | 1051 } |
| 898 } | 1052 } |
| 899 if (element == null && target is SuperExpression) { | 1053 if (element == null && target is SuperExpression) { |
| 900 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me
thodName2, [methodName2.name, targetType.element.name]); | 1054 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me
thodName2, [methodName2.name, targetType.element.name]); |
| 901 return null; | 1055 return null; |
| 902 } | 1056 } |
| 903 } else if (target is SimpleIdentifier) { | 1057 } else if (target is SimpleIdentifier) { |
| 904 Element targetElement = ((target as SimpleIdentifier)).element; | 1058 Element targetElement = ((target as SimpleIdentifier)).element; |
| 905 if (targetElement is PrefixElement) { | 1059 if (targetElement is PrefixElement) { |
| 906 String name9 = "${((target as SimpleIdentifier)).name}.${methodName2}"
; | 1060 String name9 = "${((target as SimpleIdentifier)).name}.${methodName2}"
; |
| 907 Identifier functionName = new Identifier_3(name9); | 1061 Identifier functionName = new Identifier_4(name9); |
| 908 element = _resolver.nameScope.lookup(functionName, _resolver.definingL
ibrary); | 1062 element = _resolver.nameScope.lookup(functionName, _resolver.definingL
ibrary); |
| 909 } else { | 1063 } else { |
| 910 return null; | 1064 return null; |
| 911 } | 1065 } |
| 912 } else { | 1066 } else { |
| 913 return null; | 1067 return null; |
| 914 } | 1068 } |
| 915 } | 1069 } |
| 916 ExecutableElement invokedMethod = null; | 1070 ExecutableElement invokedMethod = null; |
| 917 if (element is ExecutableElement) { | 1071 if (element is ExecutableElement) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 938 } else { | 1092 } else { |
| 939 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION,
methodName2, [methodName2.name]); | 1093 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION,
methodName2, [methodName2.name]); |
| 940 return null; | 1094 return null; |
| 941 } | 1095 } |
| 942 } | 1096 } |
| 943 recordResolution(methodName2, invokedMethod); | 1097 recordResolution(methodName2, invokedMethod); |
| 944 resolveNamedArguments(node.argumentList, invokedMethod); | 1098 resolveNamedArguments(node.argumentList, invokedMethod); |
| 945 return null; | 1099 return null; |
| 946 } | 1100 } |
| 947 Object visitPostfixExpression(PostfixExpression node) { | 1101 Object visitPostfixExpression(PostfixExpression node) { |
| 948 Token operator9 = node.operator; | 1102 sc.Token operator9 = node.operator; |
| 949 Type2 operandType = getType(node.operand); | 1103 Type2 operandType = getType(node.operand); |
| 950 if (operandType == null || operandType.isDynamic()) { | 1104 if (operandType == null || operandType.isDynamic()) { |
| 951 return null; | 1105 return null; |
| 952 } | 1106 } |
| 953 Element operandTypeElement = operandType.element; | 1107 Element operandTypeElement = operandType.element; |
| 954 String methodName; | 1108 String methodName; |
| 955 if (identical(operator9.type, TokenType.PLUS_PLUS)) { | 1109 if (identical(operator9.type, sc.TokenType.PLUS_PLUS)) { |
| 956 methodName = TokenType.PLUS.lexeme; | 1110 methodName = sc.TokenType.PLUS.lexeme; |
| 957 } else { | 1111 } else { |
| 958 methodName = TokenType.MINUS.lexeme; | 1112 methodName = sc.TokenType.MINUS.lexeme; |
| 959 } | 1113 } |
| 960 MethodElement member = lookUpMethod(operandTypeElement, methodName); | 1114 MethodElement member = lookUpMethod(operandTypeElement, methodName); |
| 961 if (member == null) { | 1115 if (member == null) { |
| 962 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator9, [m
ethodName]); | 1116 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator9, [m
ethodName]); |
| 963 } else { | 1117 } else { |
| 964 node.element = member; | 1118 node.element = member; |
| 965 } | 1119 } |
| 966 return null; | 1120 return null; |
| 967 } | 1121 } |
| 968 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 1122 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 969 SimpleIdentifier prefix6 = node.prefix; | 1123 SimpleIdentifier prefix6 = node.prefix; |
| 970 SimpleIdentifier identifier12 = node.identifier; | 1124 SimpleIdentifier identifier13 = node.identifier; |
| 971 Element prefixElement = prefix6.element; | 1125 Element prefixElement = prefix6.element; |
| 972 if (prefixElement is PrefixElement) { | 1126 if (prefixElement is PrefixElement) { |
| 973 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); | 1127 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); |
| 974 if (element == null) { | 1128 if (element == null) { |
| 975 return null; | 1129 return null; |
| 976 } | 1130 } |
| 977 recordResolution(identifier12, element); | 1131 recordResolution(identifier13, element); |
| 978 return null; | 1132 return null; |
| 979 } | 1133 } |
| 980 if (prefixElement is ClassElement) { | 1134 if (prefixElement is ClassElement) { |
| 981 Element memberElement; | 1135 Element memberElement; |
| 982 if (node.identifier.inSetterContext()) { | 1136 if (node.identifier.inSetterContext()) { |
| 983 memberElement = lookUpSetterInType((prefixElement as ClassElement), iden
tifier12.name); | 1137 memberElement = lookUpSetterInType((prefixElement as ClassElement), iden
tifier13.name); |
| 984 } else { | 1138 } else { |
| 985 memberElement = lookUpGetterInType((prefixElement as ClassElement), iden
tifier12.name); | 1139 memberElement = lookUpGetterInType((prefixElement as ClassElement), iden
tifier13.name); |
| 986 } | 1140 } |
| 987 if (memberElement == null) { | 1141 if (memberElement == null) { |
| 988 MethodElement methodElement = lookUpMethod(prefixElement, identifier12.n
ame); | 1142 MethodElement methodElement = lookUpMethod(prefixElement, identifier13.n
ame); |
| 989 if (methodElement != null) { | 1143 if (methodElement != null) { |
| 990 recordResolution(identifier12, methodElement); | 1144 recordResolution(identifier13, methodElement); |
| 991 return null; | 1145 return null; |
| 992 } | 1146 } |
| 993 } | 1147 } |
| 994 if (memberElement == null) { | 1148 if (memberElement == null) { |
| 995 reportGetterOrSetterNotFound(node, identifier12, prefixElement.name); | 1149 reportGetterOrSetterNotFound(node, identifier13, prefixElement.name); |
| 996 } else { | 1150 } else { |
| 997 recordResolution(identifier12, memberElement); | 1151 recordResolution(identifier13, memberElement); |
| 998 } | 1152 } |
| 999 return null; | 1153 return null; |
| 1000 } | 1154 } |
| 1001 Element variableTypeElement; | 1155 Element variableTypeElement; |
| 1002 if (prefixElement is PropertyAccessorElement) { | 1156 if (prefixElement is PropertyAccessorElement) { |
| 1003 PropertyAccessorElement accessor = prefixElement as PropertyAccessorElemen
t; | 1157 PropertyAccessorElement accessor = prefixElement as PropertyAccessorElemen
t; |
| 1004 FunctionType type14 = accessor.type; | 1158 FunctionType type14 = accessor.type; |
| 1005 if (type14 == null) { | 1159 if (type14 == null) { |
| 1006 return null; | 1160 return null; |
| 1007 } | 1161 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1019 Type2 prefixType = ((prefixElement as VariableElement)).type; | 1173 Type2 prefixType = ((prefixElement as VariableElement)).type; |
| 1020 if (prefixType == null || prefixType.isDynamic()) { | 1174 if (prefixType == null || prefixType.isDynamic()) { |
| 1021 return null; | 1175 return null; |
| 1022 } | 1176 } |
| 1023 variableTypeElement = prefixType.element; | 1177 variableTypeElement = prefixType.element; |
| 1024 } else { | 1178 } else { |
| 1025 return null; | 1179 return null; |
| 1026 } | 1180 } |
| 1027 PropertyAccessorElement memberElement = null; | 1181 PropertyAccessorElement memberElement = null; |
| 1028 if (node.identifier.inSetterContext()) { | 1182 if (node.identifier.inSetterContext()) { |
| 1029 memberElement = lookUpSetter(variableTypeElement, identifier12.name); | 1183 memberElement = lookUpSetter(variableTypeElement, identifier13.name); |
| 1030 } | 1184 } |
| 1031 if (memberElement == null && node.identifier.inGetterContext()) { | 1185 if (memberElement == null && node.identifier.inGetterContext()) { |
| 1032 memberElement = lookUpGetter(variableTypeElement, identifier12.name); | 1186 memberElement = lookUpGetter(variableTypeElement, identifier13.name); |
| 1033 } | 1187 } |
| 1034 if (memberElement == null) { | 1188 if (memberElement == null) { |
| 1035 MethodElement methodElement = lookUpMethod(variableTypeElement, identifier
12.name); | 1189 MethodElement methodElement = lookUpMethod(variableTypeElement, identifier
13.name); |
| 1036 if (methodElement != null) { | 1190 if (methodElement != null) { |
| 1037 recordResolution(identifier12, methodElement); | 1191 recordResolution(identifier13, methodElement); |
| 1038 return null; | 1192 return null; |
| 1039 } | 1193 } |
| 1040 } | 1194 } |
| 1041 if (memberElement == null) { | 1195 if (memberElement == null) { |
| 1042 reportGetterOrSetterNotFound(node, identifier12, variableTypeElement.name)
; | 1196 reportGetterOrSetterNotFound(node, identifier13, variableTypeElement.name)
; |
| 1043 } else { | 1197 } else { |
| 1044 recordResolution(identifier12, memberElement); | 1198 recordResolution(identifier13, memberElement); |
| 1045 } | 1199 } |
| 1046 return null; | 1200 return null; |
| 1047 } | 1201 } |
| 1048 Object visitPrefixExpression(PrefixExpression node) { | 1202 Object visitPrefixExpression(PrefixExpression node) { |
| 1049 Token operator10 = node.operator; | 1203 sc.Token operator10 = node.operator; |
| 1050 TokenType operatorType = operator10.type; | 1204 sc.TokenType operatorType = operator10.type; |
| 1051 if (operatorType.isUserDefinableOperator() || identical(operatorType, TokenT
ype.PLUS_PLUS) || identical(operatorType, TokenType.MINUS_MINUS)) { | 1205 if (operatorType.isUserDefinableOperator() || identical(operatorType, sc.Tok
enType.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
| 1052 Type2 operandType = getType(node.operand); | 1206 Type2 operandType = getType(node.operand); |
| 1053 if (operandType == null || operandType.isDynamic()) { | 1207 if (operandType == null || operandType.isDynamic()) { |
| 1054 return null; | 1208 return null; |
| 1055 } | 1209 } |
| 1056 Element operandTypeElement = operandType.element; | 1210 Element operandTypeElement = operandType.element; |
| 1057 String methodName; | 1211 String methodName; |
| 1058 if (identical(operatorType, TokenType.PLUS_PLUS)) { | 1212 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { |
| 1059 methodName = TokenType.PLUS.lexeme; | 1213 methodName = sc.TokenType.PLUS.lexeme; |
| 1060 } else if (identical(operatorType, TokenType.MINUS_MINUS)) { | 1214 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
| 1061 methodName = TokenType.MINUS.lexeme; | 1215 methodName = sc.TokenType.MINUS.lexeme; |
| 1062 } else if (identical(operatorType, TokenType.MINUS)) { | 1216 } else if (identical(operatorType, sc.TokenType.MINUS)) { |
| 1063 methodName = "unary-"; | 1217 methodName = "unary-"; |
| 1064 } else { | 1218 } else { |
| 1065 methodName = operator10.lexeme; | 1219 methodName = operator10.lexeme; |
| 1066 } | 1220 } |
| 1067 MethodElement member = lookUpMethod(operandTypeElement, methodName); | 1221 MethodElement member = lookUpMethod(operandTypeElement, methodName); |
| 1068 if (member == null) { | 1222 if (member == null) { |
| 1069 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator10,
[methodName]); | 1223 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator10,
[methodName]); |
| 1070 } else { | 1224 } else { |
| 1071 node.element = member; | 1225 node.element = member; |
| 1072 } | 1226 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } | 1341 } |
| 1188 return null; | 1342 return null; |
| 1189 } | 1343 } |
| 1190 /** | 1344 /** |
| 1191 * Search through the array of parameters for a parameter whose name matches t
he given name. | 1345 * Search through the array of parameters for a parameter whose name matches t
he given name. |
| 1192 * Return the parameter with the given name, or {@code null} if there is no su
ch parameter. | 1346 * Return the parameter with the given name, or {@code null} if there is no su
ch parameter. |
| 1193 * @param parameters the parameters being searched | 1347 * @param parameters the parameters being searched |
| 1194 * @param name the name being searched for | 1348 * @param name the name being searched for |
| 1195 * @return the parameter with the given name | 1349 * @return the parameter with the given name |
| 1196 */ | 1350 */ |
| 1197 ParameterElement findNamedParameter(List<ParameterElement> parameters, String
name24) { | 1351 ParameterElement findNamedParameter(List<ParameterElement> parameters, String
name25) { |
| 1198 for (ParameterElement parameter in parameters) { | 1352 for (ParameterElement parameter in parameters) { |
| 1199 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { | 1353 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { |
| 1200 String parameteName = parameter.name; | 1354 String parameteName = parameter.name; |
| 1201 if (parameteName != null && parameteName == name24) { | 1355 if (parameteName != null && parameteName == name25) { |
| 1202 return parameter; | 1356 return parameter; |
| 1203 } | 1357 } |
| 1204 } | 1358 } |
| 1205 } | 1359 } |
| 1206 return null; | 1360 return null; |
| 1207 } | 1361 } |
| 1208 /** | 1362 /** |
| 1209 * Return the element representing the superclass of the given class. | 1363 * Return the element representing the superclass of the given class. |
| 1210 * @param targetClass the class whose superclass is to be returned | 1364 * @param targetClass the class whose superclass is to be returned |
| 1211 * @return the element representing the superclass of the given class | 1365 * @return the element representing the superclass of the given class |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 return accessor; | 1622 return accessor; |
| 1469 } | 1623 } |
| 1470 } | 1624 } |
| 1471 return null; | 1625 return null; |
| 1472 } | 1626 } |
| 1473 /** | 1627 /** |
| 1474 * Return the binary operator that is invoked by the given compound assignment
operator. | 1628 * Return the binary operator that is invoked by the given compound assignment
operator. |
| 1475 * @param operator the assignment operator being mapped | 1629 * @param operator the assignment operator being mapped |
| 1476 * @return the binary operator that invoked by the given assignment operator | 1630 * @return the binary operator that invoked by the given assignment operator |
| 1477 */ | 1631 */ |
| 1478 TokenType operatorFromCompoundAssignment(TokenType operator) { | 1632 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { |
| 1479 while (true) { | 1633 while (true) { |
| 1480 if (operator == TokenType.AMPERSAND_EQ) { | 1634 if (operator == sc.TokenType.AMPERSAND_EQ) { |
| 1481 return TokenType.AMPERSAND; | 1635 return sc.TokenType.AMPERSAND; |
| 1482 } else if (operator == TokenType.BAR_EQ) { | 1636 } else if (operator == sc.TokenType.BAR_EQ) { |
| 1483 return TokenType.BAR; | 1637 return sc.TokenType.BAR; |
| 1484 } else if (operator == TokenType.CARET_EQ) { | 1638 } else if (operator == sc.TokenType.CARET_EQ) { |
| 1485 return TokenType.CARET; | 1639 return sc.TokenType.CARET; |
| 1486 } else if (operator == TokenType.GT_GT_EQ) { | 1640 } else if (operator == sc.TokenType.GT_GT_EQ) { |
| 1487 return TokenType.GT_GT; | 1641 return sc.TokenType.GT_GT; |
| 1488 } else if (operator == TokenType.LT_LT_EQ) { | 1642 } else if (operator == sc.TokenType.LT_LT_EQ) { |
| 1489 return TokenType.LT_LT; | 1643 return sc.TokenType.LT_LT; |
| 1490 } else if (operator == TokenType.MINUS_EQ) { | 1644 } else if (operator == sc.TokenType.MINUS_EQ) { |
| 1491 return TokenType.MINUS; | 1645 return sc.TokenType.MINUS; |
| 1492 } else if (operator == TokenType.PERCENT_EQ) { | 1646 } else if (operator == sc.TokenType.PERCENT_EQ) { |
| 1493 return TokenType.PERCENT; | 1647 return sc.TokenType.PERCENT; |
| 1494 } else if (operator == TokenType.PLUS_EQ) { | 1648 } else if (operator == sc.TokenType.PLUS_EQ) { |
| 1495 return TokenType.PLUS; | 1649 return sc.TokenType.PLUS; |
| 1496 } else if (operator == TokenType.SLASH_EQ) { | 1650 } else if (operator == sc.TokenType.SLASH_EQ) { |
| 1497 return TokenType.SLASH; | 1651 return sc.TokenType.SLASH; |
| 1498 } else if (operator == TokenType.STAR_EQ) { | 1652 } else if (operator == sc.TokenType.STAR_EQ) { |
| 1499 return TokenType.STAR; | 1653 return sc.TokenType.STAR; |
| 1500 } else if (operator == TokenType.TILDE_SLASH_EQ) { | 1654 } else if (operator == sc.TokenType.TILDE_SLASH_EQ) { |
| 1501 return TokenType.TILDE_SLASH; | 1655 return sc.TokenType.TILDE_SLASH; |
| 1502 } | 1656 } |
| 1503 break; | 1657 break; |
| 1504 } | 1658 } |
| 1505 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); | 1659 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); |
| 1506 return operator; | 1660 return operator; |
| 1507 } | 1661 } |
| 1508 /** | 1662 /** |
| 1509 * Record the fact that the given AST node was resolved to the given element. | 1663 * Record the fact that the given AST node was resolved to the given element. |
| 1510 * @param node the AST node that was resolved | 1664 * @param node the AST node that was resolved |
| 1511 * @param element the element to which the AST node was resolved | 1665 * @param element the element to which the AST node was resolved |
| 1512 */ | 1666 */ |
| 1513 void recordResolution(SimpleIdentifier node, Element element47) { | 1667 void recordResolution(SimpleIdentifier node, Element element49) { |
| 1514 if (element47 != null) { | 1668 if (element49 != null) { |
| 1515 node.element = element47; | 1669 node.element = element49; |
| 1516 } | 1670 } |
| 1517 } | 1671 } |
| 1518 /** | 1672 /** |
| 1519 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and | 1673 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and |
| 1520 * <code>UNDEFINED_GETTER</code>. | 1674 * <code>UNDEFINED_GETTER</code>. |
| 1521 * @param node the prefixed identifier that gives the context to determine if
the error on the | 1675 * @param node the prefixed identifier that gives the context to determine if
the error on the |
| 1522 * undefined identifier is a getter or a setter | 1676 * undefined identifier is a getter or a setter |
| 1523 * @param identifier the identifier in the passed prefix identifier | 1677 * @param identifier the identifier in the passed prefix identifier |
| 1524 * @param typeName the name of the type of the left hand side of the passed pr
efixed identifier | 1678 * @param typeName the name of the type of the left hand side of the passed pr
efixed identifier |
| 1525 */ | 1679 */ |
| 1526 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id
entifier29, String typeName) { | 1680 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id
entifier30, String typeName) { |
| 1527 bool isSetterContext = node.identifier.inSetterContext(); | 1681 bool isSetterContext = node.identifier.inSetterContext(); |
| 1528 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT
ER : StaticTypeWarningCode.UNDEFINED_GETTER; | 1682 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT
ER : StaticTypeWarningCode.UNDEFINED_GETTER; |
| 1529 _resolver.reportError(errorCode, identifier29, [identifier29.name, typeName]
); | 1683 _resolver.reportError(errorCode, identifier30, [identifier30.name, typeName]
); |
| 1530 } | 1684 } |
| 1531 /** | 1685 /** |
| 1532 * Resolve the names in the given combinators in the scope of the given librar
y. | 1686 * Resolve the names in the given combinators in the scope of the given librar
y. |
| 1533 * @param library the library that defines the names | 1687 * @param library the library that defines the names |
| 1534 * @param combinators the combinators containing the names to be resolved | 1688 * @param combinators the combinators containing the names to be resolved |
| 1535 */ | 1689 */ |
| 1536 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { | 1690 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { |
| 1537 if (library == null) { | 1691 if (library == null) { |
| 1538 return; | 1692 return; |
| 1539 } | 1693 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 } | 1729 } |
| 1576 } | 1730 } |
| 1577 } | 1731 } |
| 1578 /** | 1732 /** |
| 1579 * If the given element is a type variable, resolve it to the class that shoul
d be used when | 1733 * If the given element is a type variable, resolve it to the class that shoul
d be used when |
| 1580 * looking up members. Otherwise, return the original element. | 1734 * looking up members. Otherwise, return the original element. |
| 1581 * @param element the element that is to be resolved if it is a type variable | 1735 * @param element the element that is to be resolved if it is a type variable |
| 1582 * @return the class that should be used in place of the argument if it is a t
ype variable, or the | 1736 * @return the class that should be used in place of the argument if it is a t
ype variable, or the |
| 1583 * original argument if it isn't a type variable | 1737 * original argument if it isn't a type variable |
| 1584 */ | 1738 */ |
| 1585 Element resolveTypeVariable(Element element48) { | 1739 Element resolveTypeVariable(Element element50) { |
| 1586 if (element48 is TypeVariableElement) { | 1740 if (element50 is TypeVariableElement) { |
| 1587 Type2 bound4 = ((element48 as TypeVariableElement)).bound; | 1741 Type2 bound4 = ((element50 as TypeVariableElement)).bound; |
| 1588 if (bound4 == null) { | 1742 if (bound4 == null) { |
| 1589 return _resolver.typeProvider.objectType.element; | 1743 return _resolver.typeProvider.objectType.element; |
| 1590 } | 1744 } |
| 1591 return bound4.element; | 1745 return bound4.element; |
| 1592 } | 1746 } |
| 1593 return element48; | 1747 return element50; |
| 1594 } | 1748 } |
| 1595 } | 1749 } |
| 1596 class Identifier_3 extends Identifier { | 1750 class Identifier_4 extends Identifier { |
| 1597 String name9; | 1751 String name9; |
| 1598 Identifier_3(this.name9) : super(); | 1752 Identifier_4(this.name9) : super(); |
| 1599 accept(ASTVisitor visitor) => null; | 1753 accept(ASTVisitor visitor) => null; |
| 1600 Token get beginToken => null; | 1754 sc.Token get beginToken => null; |
| 1601 Element get element => null; | 1755 Element get element => null; |
| 1602 Token get endToken => null; | 1756 sc.Token get endToken => null; |
| 1603 String get name => name9; | 1757 String get name => name9; |
| 1604 void visitChildren(ASTVisitor<Object> visitor) { | 1758 void visitChildren(ASTVisitor<Object> visitor) { |
| 1605 } | 1759 } |
| 1606 } | 1760 } |
| 1607 /** | 1761 /** |
| 1608 * Instances of the class {@code Library} represent the data about a single libr
ary during the | 1762 * Instances of the class {@code Library} represent the data about a single libr
ary during the |
| 1609 * resolution of some (possibly different) library. They are not intended to be
used except during | 1763 * resolution of some (possibly different) library. They are not intended to be
used except during |
| 1610 * the resolution process. | 1764 * the resolution process. |
| 1765 * @coverage dart.engine.resolver |
| 1611 */ | 1766 */ |
| 1612 class Library { | 1767 class Library { |
| 1613 /** | 1768 /** |
| 1614 * The analysis context in which this library is being analyzed. | 1769 * The analysis context in which this library is being analyzed. |
| 1615 */ | 1770 */ |
| 1616 AnalysisContextImpl _analysisContext; | 1771 AnalysisContextImpl _analysisContext; |
| 1617 /** | 1772 /** |
| 1618 * The listener to which analysis errors will be reported. | 1773 * The listener to which analysis errors will be reported. |
| 1619 */ | 1774 */ |
| 1620 AnalysisErrorListener _errorListener; | 1775 AnalysisErrorListener _errorListener; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 try { | 1994 try { |
| 1840 appendStringValue(builder, literal); | 1995 appendStringValue(builder, literal); |
| 1841 } on IllegalArgumentException catch (exception) { | 1996 } on IllegalArgumentException catch (exception) { |
| 1842 return null; | 1997 return null; |
| 1843 } | 1998 } |
| 1844 return builder.toString().trim(); | 1999 return builder.toString().trim(); |
| 1845 } | 2000 } |
| 1846 } | 2001 } |
| 1847 /** | 2002 /** |
| 1848 * Instances of the class {@code LibraryElementBuilder} build an element model f
or a single library. | 2003 * Instances of the class {@code LibraryElementBuilder} build an element model f
or a single library. |
| 2004 * @coverage dart.engine.resolver |
| 1849 */ | 2005 */ |
| 1850 class LibraryElementBuilder { | 2006 class LibraryElementBuilder { |
| 1851 /** | 2007 /** |
| 1852 * The analysis context in which the element model will be built. | 2008 * The analysis context in which the element model will be built. |
| 1853 */ | 2009 */ |
| 1854 AnalysisContextImpl _analysisContext; | 2010 AnalysisContextImpl _analysisContext; |
| 1855 /** | 2011 /** |
| 1856 * The listener to which errors will be reported. | 2012 * The listener to which errors will be reported. |
| 1857 */ | 2013 */ |
| 1858 AnalysisErrorListener _errorListener; | 2014 AnalysisErrorListener _errorListener; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 } | 2122 } |
| 1967 } | 2123 } |
| 1968 } on AnalysisException catch (exception) { | 2124 } on AnalysisException catch (exception) { |
| 1969 } | 2125 } |
| 1970 return null; | 2126 return null; |
| 1971 } | 2127 } |
| 1972 } | 2128 } |
| 1973 /** | 2129 /** |
| 1974 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent | 2130 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent |
| 1975 * libraries within a single context. | 2131 * libraries within a single context. |
| 2132 * @coverage dart.engine.resolver |
| 1976 */ | 2133 */ |
| 1977 class LibraryResolver { | 2134 class LibraryResolver { |
| 1978 /** | 2135 /** |
| 1979 * The analysis context in which the libraries are being analyzed. | 2136 * The analysis context in which the libraries are being analyzed. |
| 1980 */ | 2137 */ |
| 1981 AnalysisContextImpl _analysisContext; | 2138 AnalysisContextImpl _analysisContext; |
| 1982 /** | 2139 /** |
| 1983 * The listener to which analysis errors will be reported, this error listener
is either | 2140 * The listener to which analysis errors will be reported, this error listener
is either |
| 1984 * references {@link #recordingErrorListener}, or it unions the passed{@link A
nalysisErrorListener} with the {@link #recordingErrorListener}. | 2141 * references {@link #recordingErrorListener}, or it unions the passed{@link A
nalysisErrorListener} with the {@link #recordingErrorListener}. |
| 1985 */ | 2142 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2008 Map<Source, Library> _libraryMap = new Map<Source, Library>(); | 2165 Map<Source, Library> _libraryMap = new Map<Source, Library>(); |
| 2009 /** | 2166 /** |
| 2010 * A collection containing the libraries that are being resolved together. | 2167 * A collection containing the libraries that are being resolved together. |
| 2011 */ | 2168 */ |
| 2012 Set<Library> _librariesInCycles; | 2169 Set<Library> _librariesInCycles; |
| 2013 /** | 2170 /** |
| 2014 * Initialize a newly created library resolver to resolve libraries within the
given context. | 2171 * Initialize a newly created library resolver to resolve libraries within the
given context. |
| 2015 * @param analysisContext the analysis context in which the library is being a
nalyzed | 2172 * @param analysisContext the analysis context in which the library is being a
nalyzed |
| 2016 */ | 2173 */ |
| 2017 LibraryResolver.con1(AnalysisContextImpl analysisContext) { | 2174 LibraryResolver.con1(AnalysisContextImpl analysisContext) { |
| 2018 _jtd_constructor_220_impl(analysisContext); | 2175 _jtd_constructor_226_impl(analysisContext); |
| 2019 } | 2176 } |
| 2020 _jtd_constructor_220_impl(AnalysisContextImpl analysisContext) { | 2177 _jtd_constructor_226_impl(AnalysisContextImpl analysisContext) { |
| 2021 _jtd_constructor_221_impl(analysisContext, null); | 2178 _jtd_constructor_227_impl(analysisContext, null); |
| 2022 } | 2179 } |
| 2023 /** | 2180 /** |
| 2024 * Initialize a newly created library resolver to resolve libraries within the
given context. | 2181 * Initialize a newly created library resolver to resolve libraries within the
given context. |
| 2025 * @param analysisContext the analysis context in which the library is being a
nalyzed | 2182 * @param analysisContext the analysis context in which the library is being a
nalyzed |
| 2026 * @param errorListener the listener to which analysis errors will be reported | 2183 * @param errorListener the listener to which analysis errors will be reported |
| 2027 */ | 2184 */ |
| 2028 LibraryResolver.con2(AnalysisContextImpl analysisContext2, AnalysisErrorListen
er additionalAnalysisErrorListener) { | 2185 LibraryResolver.con2(AnalysisContextImpl analysisContext2, AnalysisErrorListen
er additionalAnalysisErrorListener) { |
| 2029 _jtd_constructor_221_impl(analysisContext2, additionalAnalysisErrorListener)
; | 2186 _jtd_constructor_227_impl(analysisContext2, additionalAnalysisErrorListener)
; |
| 2030 } | 2187 } |
| 2031 _jtd_constructor_221_impl(AnalysisContextImpl analysisContext2, AnalysisErrorL
istener additionalAnalysisErrorListener) { | 2188 _jtd_constructor_227_impl(AnalysisContextImpl analysisContext2, AnalysisErrorL
istener additionalAnalysisErrorListener) { |
| 2032 this._analysisContext = analysisContext2; | 2189 this._analysisContext = analysisContext2; |
| 2033 this._recordingErrorListener = new RecordingErrorListener(); | 2190 this._recordingErrorListener = new RecordingErrorListener(); |
| 2034 if (additionalAnalysisErrorListener == null) { | 2191 if (additionalAnalysisErrorListener == null) { |
| 2035 this._errorListener = _recordingErrorListener; | 2192 this._errorListener = _recordingErrorListener; |
| 2036 } else { | 2193 } else { |
| 2037 this._errorListener = new AnalysisErrorListener_4(this, additionalAnalysis
ErrorListener); | 2194 this._errorListener = new AnalysisErrorListener_5(this, additionalAnalysis
ErrorListener); |
| 2038 } | 2195 } |
| 2039 _coreLibrarySource = analysisContext2.sourceFactory.forUri(LibraryElementBui
lder.CORE_LIBRARY_URI); | 2196 _coreLibrarySource = analysisContext2.sourceFactory.forUri(LibraryElementBui
lder.CORE_LIBRARY_URI); |
| 2040 } | 2197 } |
| 2041 /** | 2198 /** |
| 2042 * Return the analysis context in which the libraries are being analyzed. | 2199 * Return the analysis context in which the libraries are being analyzed. |
| 2043 * @return the analysis context in which the libraries are being analyzed | 2200 * @return the analysis context in which the libraries are being analyzed |
| 2044 */ | 2201 */ |
| 2045 AnalysisContextImpl get analysisContext => _analysisContext; | 2202 AnalysisContextImpl get analysisContext => _analysisContext; |
| 2046 /** | 2203 /** |
| 2047 * Return the listener to which analysis errors will be reported. | 2204 * Return the listener to which analysis errors will be reported. |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 for (Source source in library.compilationUnitSources) { | 2597 for (Source source in library.compilationUnitSources) { |
| 2441 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 2598 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 2442 CompilationUnit unit = library.getAST(source); | 2599 CompilationUnit unit = library.getAST(source); |
| 2443 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider); | 2600 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider); |
| 2444 unit.accept(errorVerifier); | 2601 unit.accept(errorVerifier); |
| 2445 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter); | 2602 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter); |
| 2446 unit.accept(constantVerifier); | 2603 unit.accept(constantVerifier); |
| 2447 } | 2604 } |
| 2448 } | 2605 } |
| 2449 } | 2606 } |
| 2450 class AnalysisErrorListener_4 implements AnalysisErrorListener { | 2607 class AnalysisErrorListener_5 implements AnalysisErrorListener { |
| 2451 final LibraryResolver LibraryResolver_this; | 2608 final LibraryResolver LibraryResolver_this; |
| 2452 AnalysisErrorListener additionalAnalysisErrorListener; | 2609 AnalysisErrorListener additionalAnalysisErrorListener; |
| 2453 AnalysisErrorListener_4(this.LibraryResolver_this, this.additionalAnalysisErro
rListener); | 2610 AnalysisErrorListener_5(this.LibraryResolver_this, this.additionalAnalysisErro
rListener); |
| 2454 void onError(AnalysisError error) { | 2611 void onError(AnalysisError error) { |
| 2455 additionalAnalysisErrorListener.onError(error); | 2612 additionalAnalysisErrorListener.onError(error); |
| 2456 LibraryResolver_this._recordingErrorListener.onError(error); | 2613 LibraryResolver_this._recordingErrorListener.onError(error); |
| 2457 } | 2614 } |
| 2458 } | 2615 } |
| 2459 /** | 2616 /** |
| 2460 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single | 2617 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single |
| 2461 * compilation unit. | 2618 * compilation unit. |
| 2619 * @coverage dart.engine.resolver |
| 2462 */ | 2620 */ |
| 2463 class ResolverVisitor extends ScopedVisitor { | 2621 class ResolverVisitor extends ScopedVisitor { |
| 2464 /** | 2622 /** |
| 2465 * The object used to resolve the element associated with the current node. | 2623 * The object used to resolve the element associated with the current node. |
| 2466 */ | 2624 */ |
| 2467 ElementResolver _elementResolver; | 2625 ElementResolver _elementResolver; |
| 2468 /** | 2626 /** |
| 2469 * The object used to compute the type associated with the current node. | 2627 * The object used to compute the type associated with the current node. |
| 2470 */ | 2628 */ |
| 2471 StaticTypeAnalyzer _typeAnalyzer; | 2629 StaticTypeAnalyzer _typeAnalyzer; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 * the current node is not contained in a class. | 2740 * the current node is not contained in a class. |
| 2583 * @return the class element representing the class containing the current nod
e | 2741 * @return the class element representing the class containing the current nod
e |
| 2584 */ | 2742 */ |
| 2585 ClassElement get enclosingClass => _enclosingClass; | 2743 ClassElement get enclosingClass => _enclosingClass; |
| 2586 /** | 2744 /** |
| 2587 * Return the element representing the function containing the current node, o
r {@code null} if | 2745 * Return the element representing the function containing the current node, o
r {@code null} if |
| 2588 * the current node is not contained in a function. | 2746 * the current node is not contained in a function. |
| 2589 * @return the element representing the function containing the current node | 2747 * @return the element representing the function containing the current node |
| 2590 */ | 2748 */ |
| 2591 ExecutableElement get enclosingFunction => _enclosingFunction; | 2749 ExecutableElement get enclosingFunction => _enclosingFunction; |
| 2750 get elementResolver_J2DAccessor => _elementResolver; |
| 2751 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; |
| 2752 get labelScope_J2DAccessor => _labelScope; |
| 2753 set labelScope_J2DAccessor(__v) => _labelScope = __v; |
| 2754 get nameScope_J2DAccessor => _nameScope; |
| 2755 set nameScope_J2DAccessor(__v) => _nameScope = __v; |
| 2756 get typeAnalyzer_J2DAccessor => _typeAnalyzer; |
| 2757 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; |
| 2758 get enclosingClass_J2DAccessor => _enclosingClass; |
| 2759 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; |
| 2592 } | 2760 } |
| 2593 /** | 2761 /** |
| 2594 * The abstract class {@code ScopedVisitor} maintains name and label scopes as a
n AST structure is | 2762 * The abstract class {@code ScopedVisitor} maintains name and label scopes as a
n AST structure is |
| 2595 * being visited. | 2763 * being visited. |
| 2764 * @coverage dart.engine.resolver |
| 2596 */ | 2765 */ |
| 2597 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { | 2766 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { |
| 2598 /** | 2767 /** |
| 2599 * The element for the library containing the compilation unit being visited. | 2768 * The element for the library containing the compilation unit being visited. |
| 2600 */ | 2769 */ |
| 2601 LibraryElement _definingLibrary; | 2770 LibraryElement _definingLibrary; |
| 2602 /** | 2771 /** |
| 2603 * The source representing the compilation unit being visited. | 2772 * The source representing the compilation unit being visited. |
| 2604 */ | 2773 */ |
| 2605 Source _source; | 2774 Source _source; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2813 } | 2982 } |
| 2814 try { | 2983 try { |
| 2815 super.visitSwitchStatement(node); | 2984 super.visitSwitchStatement(node); |
| 2816 } finally { | 2985 } finally { |
| 2817 _labelScope = outerScope; | 2986 _labelScope = outerScope; |
| 2818 } | 2987 } |
| 2819 return null; | 2988 return null; |
| 2820 } | 2989 } |
| 2821 Object visitVariableDeclaration(VariableDeclaration node) { | 2990 Object visitVariableDeclaration(VariableDeclaration node) { |
| 2822 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent
is! FieldDeclaration) { | 2991 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent
is! FieldDeclaration) { |
| 2823 VariableElement element22 = node.element; | 2992 VariableElement element23 = node.element; |
| 2824 if (element22 != null) { | 2993 if (element23 != null) { |
| 2825 _nameScope.define(element22); | 2994 _nameScope.define(element23); |
| 2826 } | 2995 } |
| 2827 } | 2996 } |
| 2828 super.visitVariableDeclaration(node); | 2997 super.visitVariableDeclaration(node); |
| 2829 return null; | 2998 return null; |
| 2830 } | 2999 } |
| 2831 Object visitWhileStatement(WhileStatement node) { | 3000 Object visitWhileStatement(WhileStatement node) { |
| 2832 LabelScope outerScope = _labelScope; | 3001 LabelScope outerScope = _labelScope; |
| 2833 _labelScope = new LabelScope.con1(outerScope, false, false); | 3002 _labelScope = new LabelScope.con1(outerScope, false, false); |
| 2834 try { | 3003 try { |
| 2835 super.visitWhileStatement(node); | 3004 super.visitWhileStatement(node); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2856 */ | 3025 */ |
| 2857 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { | 3026 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { |
| 2858 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, [arguments])); | 3027 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, [arguments])); |
| 2859 } | 3028 } |
| 2860 /** | 3029 /** |
| 2861 * Report an error with the given error code and arguments. | 3030 * Report an error with the given error code and arguments. |
| 2862 * @param errorCode the error code of the error to be reported | 3031 * @param errorCode the error code of the error to be reported |
| 2863 * @param token the token specifying the location of the error | 3032 * @param token the token specifying the location of the error |
| 2864 * @param arguments the arguments to the error, used to compose the error mess
age | 3033 * @param arguments the arguments to the error, used to compose the error mess
age |
| 2865 */ | 3034 */ |
| 2866 void reportError3(ErrorCode errorCode, Token token, List<Object> arguments) { | 3035 void reportError3(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ |
| 2867 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, [arguments])); | 3036 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, [arguments])); |
| 2868 } | 3037 } |
| 2869 /** | 3038 /** |
| 2870 * Add scopes for each of the given labels. | 3039 * Add scopes for each of the given labels. |
| 2871 * @param labels the labels for which new scopes are to be added | 3040 * @param labels the labels for which new scopes are to be added |
| 2872 * @return the scope that was in effect before the new scopes were added | 3041 * @return the scope that was in effect before the new scopes were added |
| 2873 */ | 3042 */ |
| 2874 LabelScope addScopesFor(NodeList<Label> labels) { | 3043 LabelScope addScopesFor(NodeList<Label> labels) { |
| 2875 LabelScope outerScope = _labelScope; | 3044 LabelScope outerScope = _labelScope; |
| 2876 for (Label label in labels) { | 3045 for (Label label in labels) { |
| 2877 SimpleIdentifier labelNameNode = label.label; | 3046 SimpleIdentifier labelNameNode = label.label; |
| 2878 String labelName = labelNameNode.name; | 3047 String labelName = labelNameNode.name; |
| 2879 LabelElement labelElement = labelNameNode.element as LabelElement; | 3048 LabelElement labelElement = labelNameNode.element as LabelElement; |
| 2880 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); | 3049 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); |
| 2881 } | 3050 } |
| 2882 return outerScope; | 3051 return outerScope; |
| 2883 } | 3052 } |
| 2884 } | 3053 } |
| 2885 /** | 3054 /** |
| 2886 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta
sks. First, they | 3055 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta
sks. First, they |
| 2887 * compute the static type of every expression. Second, they look for any static
type errors or | 3056 * compute the static type of every expression. Second, they look for any static
type errors or |
| 2888 * warnings that might need to be generated. The requirements for the type analy
zer are: | 3057 * warnings that might need to be generated. The requirements for the type analy
zer are: |
| 2889 * <ol> | 3058 * <ol> |
| 2890 * <li>Every element that refers to types should be fully populated. | 3059 * <li>Every element that refers to types should be fully populated. |
| 2891 * <li>Every node representing an expression should be resolved to the Type of t
he expression.</li> | 3060 * <li>Every node representing an expression should be resolved to the Type of t
he expression.</li> |
| 2892 * </ol> | 3061 * </ol> |
| 3062 * @coverage dart.engine.resolver |
| 2893 */ | 3063 */ |
| 2894 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { | 3064 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { |
| 2895 /** | 3065 /** |
| 2896 * The object providing access to the types defined by the language. | 3066 * The object providing access to the types defined by the language. |
| 2897 */ | 3067 */ |
| 2898 TypeProvider _typeProvider; | 3068 TypeProvider _typeProvider; |
| 2899 /** | 3069 /** |
| 2900 * The type representing the type 'dynamic'. | 3070 * The type representing the type 'dynamic'. |
| 2901 */ | 3071 */ |
| 2902 Type2 _dynamicType; | 3072 Type2 _dynamicType; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2971 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound | 3141 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound |
| 2972 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound | 3142 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound |
| 2973 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v | 3143 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v |
| 2974 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in | 3144 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in |
| 2975 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e<
sub>2</sub>] op= | 3145 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e<
sub>2</sub>] op= |
| 2976 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su
b>)(e<sub>1</sub>, | 3146 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su
b>)(e<sub>1</sub>, |
| 2977 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in | 3147 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in |
| 2978 * <i>e<sub>3</sub></i>. </blockquote> | 3148 * <i>e<sub>3</sub></i>. </blockquote> |
| 2979 */ | 3149 */ |
| 2980 Object visitAssignmentExpression(AssignmentExpression node) { | 3150 Object visitAssignmentExpression(AssignmentExpression node) { |
| 2981 TokenType operator11 = node.operator.type; | 3151 sc.TokenType operator11 = node.operator.type; |
| 2982 if (operator11 != TokenType.EQ) { | 3152 if (operator11 != sc.TokenType.EQ) { |
| 2983 return recordReturnType(node, node.element); | 3153 return recordReturnType(node, node.element); |
| 2984 } | 3154 } |
| 2985 return recordType(node, getType(node.rightHandSide)); | 3155 return recordType(node, getType(node.rightHandSide)); |
| 2986 } | 3156 } |
| 2987 /** | 3157 /** |
| 2988 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean | 3158 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean |
| 2989 * expression is {@code bool}.</blockquote> | 3159 * expression is {@code bool}.</blockquote> |
| 2990 * <p> | 3160 * <p> |
| 2991 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form | 3161 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form |
| 2992 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 3162 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3015 * e<sub>2</sub></i> is equivalent to the method invocation | 3185 * e<sub>2</sub></i> is equivalent to the method invocation |
| 3016 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 3186 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 3017 * <p> | 3187 * <p> |
| 3018 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form | 3188 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form |
| 3019 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 3189 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 3020 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op | 3190 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op |
| 3021 * e<sub>2</sub></i> is equivalent to the method invocation | 3191 * e<sub>2</sub></i> is equivalent to the method invocation |
| 3022 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 3192 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 3023 */ | 3193 */ |
| 3024 Object visitBinaryExpression(BinaryExpression node) { | 3194 Object visitBinaryExpression(BinaryExpression node) { |
| 3025 TokenType operator12 = node.operator.type; | 3195 sc.TokenType operator12 = node.operator.type; |
| 3026 while (true) { | 3196 while (true) { |
| 3027 if (operator12 == TokenType.AMPERSAND_AMPERSAND || operator12 == TokenType
.BAR_BAR || operator12 == TokenType.EQ_EQ || operator12 == TokenType.BANG_EQ) { | 3197 if (operator12 == sc.TokenType.AMPERSAND_AMPERSAND || operator12 == sc.Tok
enType.BAR_BAR || operator12 == sc.TokenType.EQ_EQ || operator12 == sc.TokenType
.BANG_EQ) { |
| 3028 return recordType(node, _typeProvider.boolType); | 3198 return recordType(node, _typeProvider.boolType); |
| 3029 } | 3199 } |
| 3030 break; | 3200 break; |
| 3031 } | 3201 } |
| 3032 return recordReturnType(node, node.element); | 3202 return recordReturnType(node, node.element); |
| 3033 } | 3203 } |
| 3034 /** | 3204 /** |
| 3035 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is{@code bool}.</blockquote> | 3205 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is{@code bool}.</blockquote> |
| 3036 */ | 3206 */ |
| 3037 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi
der.boolType); | 3207 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi
der.boolType); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3265 * <p> | 3435 * <p> |
| 3266 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i)
{var r = a[i]; a[i] | 3436 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i)
{var r = a[i]; a[i] |
| 3267 * = r - 1; return r}(e1, e2)</i></blockquote> | 3437 * = r - 1; return r}(e1, e2)</i></blockquote> |
| 3268 */ | 3438 */ |
| 3269 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT
ype(node.operand)); | 3439 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT
ype(node.operand)); |
| 3270 /** | 3440 /** |
| 3271 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. | 3441 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. |
| 3272 */ | 3442 */ |
| 3273 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 3443 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 3274 SimpleIdentifier prefixedIdentifier = node.identifier; | 3444 SimpleIdentifier prefixedIdentifier = node.identifier; |
| 3275 Element element23 = prefixedIdentifier.element; | 3445 Element element24 = prefixedIdentifier.element; |
| 3276 if (element23 is VariableElement) { | 3446 if (element24 is VariableElement) { |
| 3277 Type2 variableType = ((element23 as VariableElement)).type; | 3447 Type2 variableType = ((element24 as VariableElement)).type; |
| 3278 recordType(prefixedIdentifier, variableType); | 3448 recordType(prefixedIdentifier, variableType); |
| 3279 return recordType(node, variableType); | 3449 return recordType(node, variableType); |
| 3280 } else if (element23 is PropertyAccessorElement) { | 3450 } else if (element24 is PropertyAccessorElement) { |
| 3281 Type2 propertyType = getType2((element23 as PropertyAccessorElement)); | 3451 Type2 propertyType = getType2((element24 as PropertyAccessorElement)); |
| 3282 recordType(prefixedIdentifier, propertyType); | 3452 recordType(prefixedIdentifier, propertyType); |
| 3283 return recordType(node, propertyType); | 3453 return recordType(node, propertyType); |
| 3284 } else if (element23 is MethodElement) { | 3454 } else if (element24 is MethodElement) { |
| 3285 Type2 returnType = ((element23 as MethodElement)).type; | 3455 Type2 returnType = ((element24 as MethodElement)).type; |
| 3286 recordType(prefixedIdentifier, returnType); | 3456 recordType(prefixedIdentifier, returnType); |
| 3287 return recordType(node, returnType); | 3457 return recordType(node, returnType); |
| 3288 } else { | 3458 } else { |
| 3289 } | 3459 } |
| 3290 recordType(prefixedIdentifier, _dynamicType); | 3460 recordType(prefixedIdentifier, _dynamicType); |
| 3291 return recordType(node, _dynamicType); | 3461 return recordType(node, _dynamicType); |
| 3292 } | 3462 } |
| 3293 /** | 3463 /** |
| 3294 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form | 3464 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form |
| 3295 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the | 3465 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the |
| 3296 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> | 3466 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> |
| 3297 */ | 3467 */ |
| 3298 Object visitPrefixExpression(PrefixExpression node) { | 3468 Object visitPrefixExpression(PrefixExpression node) { |
| 3299 TokenType operator13 = node.operator.type; | 3469 sc.TokenType operator13 = node.operator.type; |
| 3300 if (identical(operator13, TokenType.BANG)) { | 3470 if (identical(operator13, sc.TokenType.BANG)) { |
| 3301 return recordType(node, _typeProvider.boolType); | 3471 return recordType(node, _typeProvider.boolType); |
| 3302 } | 3472 } |
| 3303 return recordReturnType(node, node.element); | 3473 return recordReturnType(node, node.element); |
| 3304 } | 3474 } |
| 3305 /** | 3475 /** |
| 3306 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of | 3476 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of |
| 3307 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> | 3477 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> |
| 3308 * is the name of a method member of <i>o</i>, then | 3478 * is the name of a method member of <i>o</i>, then |
| 3309 * <ul> | 3479 * <ul> |
| 3310 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …,
r<sub>n</sub>, | 3480 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …,
r<sub>n</sub>, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3340 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it
exists or dynamic | 3510 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it
exists or dynamic |
| 3341 * otherwise. | 3511 * otherwise. |
| 3342 * <p> | 3512 * <p> |
| 3343 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m
</i> is an | 3513 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m
</i> is an |
| 3344 * identifier ... | 3514 * identifier ... |
| 3345 * <p> | 3515 * <p> |
| 3346 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block
quote> | 3516 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block
quote> |
| 3347 */ | 3517 */ |
| 3348 Object visitPropertyAccess(PropertyAccess node) { | 3518 Object visitPropertyAccess(PropertyAccess node) { |
| 3349 SimpleIdentifier propertyName2 = node.propertyName; | 3519 SimpleIdentifier propertyName2 = node.propertyName; |
| 3350 Element element24 = propertyName2.element; | 3520 Element element25 = propertyName2.element; |
| 3351 if (element24 is MethodElement) { | 3521 if (element25 is MethodElement) { |
| 3352 FunctionType type15 = ((element24 as MethodElement)).type; | 3522 FunctionType type15 = ((element25 as MethodElement)).type; |
| 3353 recordType(propertyName2, type15); | 3523 recordType(propertyName2, type15); |
| 3354 return recordType(node, type15); | 3524 return recordType(node, type15); |
| 3355 } else if (element24 is PropertyAccessorElement) { | 3525 } else if (element25 is PropertyAccessorElement) { |
| 3356 Type2 propertyType = getType2((element24 as PropertyAccessorElement)); | 3526 Type2 propertyType = getType2((element25 as PropertyAccessorElement)); |
| 3357 recordType(propertyName2, propertyType); | 3527 recordType(propertyName2, propertyType); |
| 3358 return recordType(node, propertyType); | 3528 return recordType(node, propertyType); |
| 3359 } else { | 3529 } else { |
| 3360 } | 3530 } |
| 3361 recordType(propertyName2, _dynamicType); | 3531 recordType(propertyName2, _dynamicType); |
| 3362 return recordType(node, _dynamicType); | 3532 return recordType(node, _dynamicType); |
| 3363 } | 3533 } |
| 3364 /** | 3534 /** |
| 3365 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression | 3535 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression |
| 3366 * <i>e</i> of the form <i>id</i> proceeds as follows: | 3536 * <i>e</i> of the form <i>id</i> proceeds as follows: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3397 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is
equivalent to the | 3567 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is
equivalent to the |
| 3398 * getter invocation <i>id</i>. | 3568 * getter invocation <i>id</i>. |
| 3399 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be
it function, | 3569 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be
it function, |
| 3400 * method, getter, or setter) or variable initializer, evaluation of e causes
a NoSuchMethodError | 3570 * method, getter, or setter) or variable initializer, evaluation of e causes
a NoSuchMethodError |
| 3401 * to be thrown. | 3571 * to be thrown. |
| 3402 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id<
/i>. | 3572 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id<
/i>. |
| 3403 * </ul> | 3573 * </ul> |
| 3404 * </blockquote> | 3574 * </blockquote> |
| 3405 */ | 3575 */ |
| 3406 Object visitSimpleIdentifier(SimpleIdentifier node) { | 3576 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 3407 Element element25 = node.element; | 3577 Element element26 = node.element; |
| 3408 if (element25 == null) { | 3578 if (element26 == null) { |
| 3409 return recordType(node, _dynamicType); | 3579 return recordType(node, _dynamicType); |
| 3410 } else if (element25 is ClassElement) { | 3580 } else if (element26 is ClassElement) { |
| 3411 if (isTypeName(node)) { | 3581 if (isTypeName(node)) { |
| 3412 return recordType(node, ((element25 as ClassElement)).type); | 3582 return recordType(node, ((element26 as ClassElement)).type); |
| 3413 } | 3583 } |
| 3414 return recordType(node, _typeProvider.typeType); | 3584 return recordType(node, _typeProvider.typeType); |
| 3415 } else if (element25 is TypeVariableElement) { | 3585 } else if (element26 is TypeVariableElement) { |
| 3416 return recordType(node, ((element25 as TypeVariableElement)).type); | 3586 return recordType(node, ((element26 as TypeVariableElement)).type); |
| 3417 } else if (element25 is TypeAliasElement) { | 3587 } else if (element26 is TypeAliasElement) { |
| 3418 return recordType(node, ((element25 as TypeAliasElement)).type); | 3588 return recordType(node, ((element26 as TypeAliasElement)).type); |
| 3419 } else if (element25 is VariableElement) { | 3589 } else if (element26 is VariableElement) { |
| 3420 return recordType(node, ((element25 as VariableElement)).type); | 3590 return recordType(node, ((element26 as VariableElement)).type); |
| 3421 } else if (element25 is MethodElement) { | 3591 } else if (element26 is MethodElement) { |
| 3422 return recordType(node, ((element25 as MethodElement)).type); | 3592 return recordType(node, ((element26 as MethodElement)).type); |
| 3423 } else if (element25 is PropertyAccessorElement) { | 3593 } else if (element26 is PropertyAccessorElement) { |
| 3424 return recordType(node, getType2((element25 as PropertyAccessorElement))); | 3594 return recordType(node, getType2((element26 as PropertyAccessorElement))); |
| 3425 } else if (element25 is ExecutableElement) { | 3595 } else if (element26 is ExecutableElement) { |
| 3426 return recordType(node, ((element25 as ExecutableElement)).type); | 3596 return recordType(node, ((element26 as ExecutableElement)).type); |
| 3427 } else if (element25 is PrefixElement) { | 3597 } else if (element26 is PrefixElement) { |
| 3428 return null; | 3598 return null; |
| 3429 } else { | 3599 } else { |
| 3430 return recordType(node, _dynamicType); | 3600 return recordType(node, _dynamicType); |
| 3431 } | 3601 } |
| 3432 } | 3602 } |
| 3433 /** | 3603 /** |
| 3434 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 3604 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> |
| 3435 */ | 3605 */ |
| 3436 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node,
_typeProvider.stringType); | 3606 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node,
_typeProvider.stringType); |
| 3437 /** | 3607 /** |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3500 return _dynamicType; | 3670 return _dynamicType; |
| 3501 } | 3671 } |
| 3502 return type; | 3672 return type; |
| 3503 } | 3673 } |
| 3504 /** | 3674 /** |
| 3505 * Return the type that should be recorded for a node that resolved to the giv
en accessor. | 3675 * Return the type that should be recorded for a node that resolved to the giv
en accessor. |
| 3506 * @param accessor the accessor that the node resolved to | 3676 * @param accessor the accessor that the node resolved to |
| 3507 * @return the type that should be recorded for a node that resolved to the gi
ven accessor | 3677 * @return the type that should be recorded for a node that resolved to the gi
ven accessor |
| 3508 */ | 3678 */ |
| 3509 Type2 getType2(PropertyAccessorElement accessor) { | 3679 Type2 getType2(PropertyAccessorElement accessor) { |
| 3680 FunctionType functionType = accessor.type; |
| 3681 if (functionType == null) { |
| 3682 return _dynamicType; |
| 3683 } |
| 3510 if (accessor.isSetter()) { | 3684 if (accessor.isSetter()) { |
| 3685 List<Type2> parameterTypes = functionType.normalParameterTypes; |
| 3686 if (parameterTypes != null && parameterTypes.length > 0) { |
| 3687 return parameterTypes[0]; |
| 3688 } |
| 3511 PropertyAccessorElement getter4 = accessor.variable.getter; | 3689 PropertyAccessorElement getter4 = accessor.variable.getter; |
| 3512 if (getter4 == null) { | 3690 if (getter4 != null) { |
| 3513 List<Type2> parameterTypes = accessor.type.normalParameterTypes; | 3691 functionType = getter4.type; |
| 3514 if (parameterTypes.length > 0) { | 3692 if (functionType != null) { |
| 3515 return parameterTypes[0]; | 3693 return functionType.returnType; |
| 3516 } else { | |
| 3517 return _dynamicType; | |
| 3518 } | 3694 } |
| 3519 } | 3695 } |
| 3520 accessor = getter4; | |
| 3521 } | |
| 3522 if (accessor.type == null) { | |
| 3523 return _dynamicType; | 3696 return _dynamicType; |
| 3524 } | 3697 } |
| 3525 return accessor.type.returnType; | 3698 return functionType.returnType; |
| 3526 } | 3699 } |
| 3527 /** | 3700 /** |
| 3528 * Return the type represented by the given type name. | 3701 * Return the type represented by the given type name. |
| 3529 * @param typeName the type name representing the type to be returned | 3702 * @param typeName the type name representing the type to be returned |
| 3530 * @return the type represented by the type name | 3703 * @return the type represented by the type name |
| 3531 */ | 3704 */ |
| 3532 Type2 getType3(TypeName typeName) { | 3705 Type2 getType3(TypeName typeName) { |
| 3533 Type2 type16 = typeName.type; | 3706 Type2 type16 = typeName.type; |
| 3534 if (type16 == null) { | 3707 if (type16 == null) { |
| 3535 return _dynamicType; | 3708 return _dynamicType; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3630 } | 3803 } |
| 3631 break; | 3804 break; |
| 3632 } | 3805 } |
| 3633 } | 3806 } |
| 3634 } | 3807 } |
| 3635 functionType.normalParameterTypes = new List.from(normalParameterTypes); | 3808 functionType.normalParameterTypes = new List.from(normalParameterTypes); |
| 3636 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); | 3809 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); |
| 3637 functionType.namedParameterTypes = namedParameterTypes; | 3810 functionType.namedParameterTypes = namedParameterTypes; |
| 3638 functionType.returnType = returnType11; | 3811 functionType.returnType = returnType11; |
| 3639 } | 3812 } |
| 3813 get thisType_J2DAccessor => _thisType; |
| 3814 set thisType_J2DAccessor(__v) => _thisType = __v; |
| 3640 } | 3815 } |
| 3641 /** | 3816 /** |
| 3642 * The interface {@code TypeProvider} defines the behavior of objects that provi
de access to types | 3817 * The interface {@code TypeProvider} defines the behavior of objects that provi
de access to types |
| 3643 * defined by the language. | 3818 * defined by the language. |
| 3819 * @coverage dart.engine.resolver |
| 3644 */ | 3820 */ |
| 3645 abstract class TypeProvider { | 3821 abstract class TypeProvider { |
| 3646 /** | 3822 /** |
| 3647 * Return the type representing the built-in type 'bool'. | 3823 * Return the type representing the built-in type 'bool'. |
| 3648 * @return the type representing the built-in type 'bool' | 3824 * @return the type representing the built-in type 'bool' |
| 3649 */ | 3825 */ |
| 3650 InterfaceType get boolType; | 3826 InterfaceType get boolType; |
| 3651 /** | 3827 /** |
| 3652 * Return the type representing the type 'bottom'. | 3828 * Return the type representing the type 'bottom'. |
| 3653 * @return the type representing the type 'bottom' | 3829 * @return the type representing the type 'bottom' |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3700 InterfaceType get stringType; | 3876 InterfaceType get stringType; |
| 3701 /** | 3877 /** |
| 3702 * Return the type representing the built-in type 'Type'. | 3878 * Return the type representing the built-in type 'Type'. |
| 3703 * @return the type representing the built-in type 'Type' | 3879 * @return the type representing the built-in type 'Type' |
| 3704 */ | 3880 */ |
| 3705 InterfaceType get typeType; | 3881 InterfaceType get typeType; |
| 3706 } | 3882 } |
| 3707 /** | 3883 /** |
| 3708 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language | 3884 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language |
| 3709 * by looking for those types in the element model for the core library. | 3885 * by looking for those types in the element model for the core library. |
| 3886 * @coverage dart.engine.resolver |
| 3710 */ | 3887 */ |
| 3711 class TypeProviderImpl implements TypeProvider { | 3888 class TypeProviderImpl implements TypeProvider { |
| 3712 /** | 3889 /** |
| 3713 * The type representing the built-in type 'bool'. | 3890 * The type representing the built-in type 'bool'. |
| 3714 */ | 3891 */ |
| 3715 InterfaceType _boolType; | 3892 InterfaceType _boolType; |
| 3716 /** | 3893 /** |
| 3717 * The type representing the type 'bottom'. | 3894 * The type representing the type 'bottom'. |
| 3718 */ | 3895 */ |
| 3719 Type2 _bottomType; | 3896 Type2 _bottomType; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3809 _stackTraceType = getType(namespace, "StackTrace"); | 3986 _stackTraceType = getType(namespace, "StackTrace"); |
| 3810 _stringType = getType(namespace, "String"); | 3987 _stringType = getType(namespace, "String"); |
| 3811 _typeType = getType(namespace, "Type"); | 3988 _typeType = getType(namespace, "Type"); |
| 3812 } | 3989 } |
| 3813 } | 3990 } |
| 3814 /** | 3991 /** |
| 3815 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty
pes associated with | 3992 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty
pes associated with |
| 3816 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, | 3993 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, |
| 3817 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building | 3994 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building |
| 3818 * the type hierarchy. | 3995 * the type hierarchy. |
| 3996 * @coverage dart.engine.resolver |
| 3819 */ | 3997 */ |
| 3820 class TypeResolverVisitor extends ScopedVisitor { | 3998 class TypeResolverVisitor extends ScopedVisitor { |
| 3821 /** | 3999 /** |
| 3822 * The type representing the type 'dynamic'. | 4000 * The type representing the type 'dynamic'. |
| 3823 */ | 4001 */ |
| 3824 Type2 _dynamicType; | 4002 Type2 _dynamicType; |
| 3825 /** | 4003 /** |
| 3826 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 4004 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 3827 * @param library the library containing the compilation unit being resolved | 4005 * @param library the library containing the compilation unit being resolved |
| 3828 * @param source the source representing the compilation unit being visited | 4006 * @param source the source representing the compilation unit being visited |
| 3829 * @param typeProvider the object used to access the types from the core libra
ry | 4007 * @param typeProvider the object used to access the types from the core libra
ry |
| 3830 */ | 4008 */ |
| 3831 TypeResolverVisitor(Library library, Source source, TypeProvider typeProvider)
: super(library, source, typeProvider) { | 4009 TypeResolverVisitor(Library library, Source source, TypeProvider typeProvider)
: super(library, source, typeProvider) { |
| 3832 _dynamicType = typeProvider.dynamicType; | 4010 _dynamicType = typeProvider.dynamicType; |
| 3833 } | 4011 } |
| 3834 Object visitCatchClause(CatchClause node) { | 4012 Object visitCatchClause(CatchClause node) { |
| 3835 super.visitCatchClause(node); | 4013 super.visitCatchClause(node); |
| 3836 SimpleIdentifier exception = node.exceptionParameter; | 4014 SimpleIdentifier exception = node.exceptionParameter; |
| 3837 if (exception != null) { | 4015 if (exception != null) { |
| 3838 TypeName exceptionTypeName = node.exceptionType; | 4016 TypeName exceptionTypeName = node.exceptionType; |
| 3839 Type2 exceptionType; | 4017 Type2 exceptionType; |
| 3840 if (exceptionTypeName == null) { | 4018 if (exceptionTypeName == null) { |
| 3841 exceptionType = typeProvider.objectType; | 4019 exceptionType = typeProvider.objectType; |
| 3842 } else { | 4020 } else { |
| 3843 exceptionType = getType4(exceptionTypeName); | 4021 exceptionType = getType4(exceptionTypeName); |
| 3844 } | 4022 } |
| 3845 recordType(exception, exceptionType); | 4023 recordType(exception, exceptionType); |
| 3846 Element element26 = exception.element; | 4024 Element element27 = exception.element; |
| 3847 if (element26 is VariableElementImpl) { | 4025 if (element27 is VariableElementImpl) { |
| 3848 ((element26 as VariableElementImpl)).type = exceptionType; | 4026 ((element27 as VariableElementImpl)).type = exceptionType; |
| 3849 } else { | 4027 } else { |
| 3850 } | 4028 } |
| 3851 } | 4029 } |
| 3852 SimpleIdentifier stackTrace = node.stackTraceParameter; | 4030 SimpleIdentifier stackTrace = node.stackTraceParameter; |
| 3853 if (stackTrace != null) { | 4031 if (stackTrace != null) { |
| 3854 recordType(stackTrace, typeProvider.stackTraceType); | 4032 recordType(stackTrace, typeProvider.stackTraceType); |
| 3855 } | 4033 } |
| 3856 return null; | 4034 return null; |
| 3857 } | 4035 } |
| 3858 Object visitClassDeclaration(ClassDeclaration node) { | 4036 Object visitClassDeclaration(ClassDeclaration node) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3886 superclassType = typeProvider.objectType; | 4064 superclassType = typeProvider.objectType; |
| 3887 } | 4065 } |
| 3888 if (classElement != null && superclassType != null) { | 4066 if (classElement != null && superclassType != null) { |
| 3889 classElement.supertype = superclassType; | 4067 classElement.supertype = superclassType; |
| 3890 } | 4068 } |
| 3891 resolve(classElement, node.withClause, node.implementsClause); | 4069 resolve(classElement, node.withClause, node.implementsClause); |
| 3892 return null; | 4070 return null; |
| 3893 } | 4071 } |
| 3894 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 4072 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 3895 super.visitConstructorDeclaration(node); | 4073 super.visitConstructorDeclaration(node); |
| 3896 ExecutableElementImpl element27 = node.element as ExecutableElementImpl; | 4074 ExecutableElementImpl element28 = node.element as ExecutableElementImpl; |
| 3897 FunctionTypeImpl type = new FunctionTypeImpl.con1(element27); | 4075 FunctionTypeImpl type = new FunctionTypeImpl.con1(element28); |
| 3898 setTypeInformation(type, null, element27.parameters); | 4076 setTypeInformation(type, null, element28.parameters); |
| 3899 type.returnType = ((element27.enclosingElement as ClassElement)).type; | 4077 type.returnType = ((element28.enclosingElement as ClassElement)).type; |
| 3900 element27.type = type; | 4078 element28.type = type; |
| 4079 return null; |
| 4080 } |
| 4081 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 4082 super.visitDeclaredIdentifier(node); |
| 4083 Type2 declaredType; |
| 4084 TypeName typeName = node.type; |
| 4085 if (typeName == null) { |
| 4086 declaredType = _dynamicType; |
| 4087 } else { |
| 4088 declaredType = getType4(typeName); |
| 4089 } |
| 4090 LocalVariableElementImpl element29 = node.element as LocalVariableElementImp
l; |
| 4091 element29.type = declaredType; |
| 3901 return null; | 4092 return null; |
| 3902 } | 4093 } |
| 3903 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 4094 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 3904 super.visitDefaultFormalParameter(node); | 4095 super.visitDefaultFormalParameter(node); |
| 3905 return null; | 4096 return null; |
| 3906 } | 4097 } |
| 3907 Object visitFieldFormalParameter(FieldFormalParameter node) { | 4098 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 3908 super.visitFieldFormalParameter(node); | 4099 super.visitFieldFormalParameter(node); |
| 3909 Element element28 = node.identifier.element; | 4100 Element element30 = node.identifier.element; |
| 3910 if (element28 is ParameterElementImpl) { | 4101 if (element30 is ParameterElementImpl) { |
| 3911 ParameterElementImpl parameter = element28 as ParameterElementImpl; | 4102 ParameterElementImpl parameter = element30 as ParameterElementImpl; |
| 3912 Type2 type; | 4103 Type2 type; |
| 3913 TypeName typeName = node.type; | 4104 TypeName typeName = node.type; |
| 3914 if (typeName == null) { | 4105 if (typeName == null) { |
| 3915 type = _dynamicType; | 4106 type = _dynamicType; |
| 3916 } else { | 4107 } else { |
| 3917 type = getType4(typeName); | 4108 type = getType4(typeName); |
| 3918 } | 4109 } |
| 3919 parameter.type = type; | 4110 parameter.type = type; |
| 3920 } else { | 4111 } else { |
| 3921 } | 4112 } |
| 3922 return null; | 4113 return null; |
| 3923 } | 4114 } |
| 3924 Object visitFunctionDeclaration(FunctionDeclaration node) { | 4115 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 3925 super.visitFunctionDeclaration(node); | 4116 super.visitFunctionDeclaration(node); |
| 3926 ExecutableElementImpl element29 = node.element as ExecutableElementImpl; | 4117 ExecutableElementImpl element31 = node.element as ExecutableElementImpl; |
| 3927 FunctionTypeImpl type = new FunctionTypeImpl.con1(element29); | 4118 FunctionTypeImpl type = new FunctionTypeImpl.con1(element31); |
| 3928 setTypeInformation(type, node.returnType, element29.parameters); | 4119 setTypeInformation(type, node.returnType, element31.parameters); |
| 3929 element29.type = type; | 4120 element31.type = type; |
| 3930 return null; | 4121 return null; |
| 3931 } | 4122 } |
| 3932 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 4123 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 3933 super.visitFunctionTypeAlias(node); | 4124 super.visitFunctionTypeAlias(node); |
| 3934 TypeAliasElementImpl element30 = node.element as TypeAliasElementImpl; | 4125 TypeAliasElementImpl element32 = node.element as TypeAliasElementImpl; |
| 3935 FunctionTypeImpl type18 = element30.type as FunctionTypeImpl; | 4126 FunctionTypeImpl type18 = element32.type as FunctionTypeImpl; |
| 3936 setTypeInformation(type18, node.returnType, element30.parameters); | 4127 setTypeInformation(type18, node.returnType, element32.parameters); |
| 3937 return null; | 4128 return null; |
| 3938 } | 4129 } |
| 3939 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 4130 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 3940 super.visitFunctionTypedFormalParameter(node); | 4131 super.visitFunctionTypedFormalParameter(node); |
| 3941 ParameterElementImpl element31 = node.identifier.element as ParameterElement
Impl; | 4132 ParameterElementImpl element33 = node.identifier.element as ParameterElement
Impl; |
| 3942 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement
)); | 4133 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement
)); |
| 3943 setTypeInformation(type, node.returnType, getElements(node.parameters)); | 4134 setTypeInformation(type, node.returnType, getElements(node.parameters)); |
| 3944 element31.type = type; | 4135 element33.type = type; |
| 3945 return null; | 4136 return null; |
| 3946 } | 4137 } |
| 3947 Object visitMethodDeclaration(MethodDeclaration node) { | 4138 Object visitMethodDeclaration(MethodDeclaration node) { |
| 3948 super.visitMethodDeclaration(node); | 4139 super.visitMethodDeclaration(node); |
| 3949 ExecutableElementImpl element32 = node.element as ExecutableElementImpl; | 4140 ExecutableElementImpl element34 = node.element as ExecutableElementImpl; |
| 3950 FunctionTypeImpl type = new FunctionTypeImpl.con1(element32); | 4141 FunctionTypeImpl type = new FunctionTypeImpl.con1(element34); |
| 3951 setTypeInformation(type, node.returnType, element32.parameters); | 4142 setTypeInformation(type, node.returnType, element34.parameters); |
| 3952 element32.type = type; | 4143 element34.type = type; |
| 3953 if (element32 is PropertyAccessorElementImpl) { | 4144 if (element34 is PropertyAccessorElementImpl) { |
| 3954 PropertyAccessorElementImpl accessor = element32 as PropertyAccessorElemen
tImpl; | 4145 PropertyAccessorElementImpl accessor = element34 as PropertyAccessorElemen
tImpl; |
| 3955 PropertyInducingElementImpl variable5 = accessor.variable as PropertyInduc
ingElementImpl; | 4146 PropertyInducingElementImpl variable5 = accessor.variable as PropertyInduc
ingElementImpl; |
| 3956 if (accessor.isGetter()) { | 4147 if (accessor.isGetter()) { |
| 3957 variable5.type = type.returnType; | 4148 variable5.type = type.returnType; |
| 3958 } else if (variable5.type == null) { | 4149 } else if (variable5.type == null) { |
| 3959 List<Type2> parameterTypes = type.normalParameterTypes; | 4150 List<Type2> parameterTypes = type.normalParameterTypes; |
| 3960 if (parameterTypes != null && parameterTypes.length > 0) { | 4151 if (parameterTypes != null && parameterTypes.length > 0) { |
| 3961 variable5.type = parameterTypes[0]; | 4152 variable5.type = parameterTypes[0]; |
| 3962 } | 4153 } |
| 3963 } | 4154 } |
| 3964 } | 4155 } |
| 3965 return null; | 4156 return null; |
| 3966 } | 4157 } |
| 3967 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 4158 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 3968 super.visitSimpleFormalParameter(node); | 4159 super.visitSimpleFormalParameter(node); |
| 3969 Type2 declaredType; | 4160 Type2 declaredType; |
| 3970 TypeName typeName = node.type; | 4161 TypeName typeName = node.type; |
| 3971 if (typeName == null) { | 4162 if (typeName == null) { |
| 3972 declaredType = _dynamicType; | 4163 declaredType = _dynamicType; |
| 3973 } else { | 4164 } else { |
| 3974 declaredType = getType4(typeName); | 4165 declaredType = getType4(typeName); |
| 3975 } | 4166 } |
| 3976 Element element33 = node.identifier.element; | 4167 Element element35 = node.identifier.element; |
| 3977 if (element33 is ParameterElement) { | 4168 if (element35 is ParameterElement) { |
| 3978 ((element33 as ParameterElementImpl)).type = declaredType; | 4169 ((element35 as ParameterElementImpl)).type = declaredType; |
| 3979 } else { | 4170 } else { |
| 3980 } | 4171 } |
| 3981 return null; | 4172 return null; |
| 3982 } | 4173 } |
| 3983 Object visitTypeName(TypeName node) { | 4174 Object visitTypeName(TypeName node) { |
| 3984 super.visitTypeName(node); | 4175 super.visitTypeName(node); |
| 3985 Identifier typeName = node.name; | 4176 Identifier typeName = node.name; |
| 3986 TypeArgumentList argumentList = node.typeArguments; | 4177 TypeArgumentList argumentList = node.typeArguments; |
| 3987 Element element = nameScope.lookup(typeName, definingLibrary); | 4178 Element element = nameScope.lookup(typeName, definingLibrary); |
| 3988 if (element == null) { | 4179 if (element == null) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4042 typeName.staticType = _dynamicType; | 4233 typeName.staticType = _dynamicType; |
| 4043 node.type = _dynamicType; | 4234 node.type = _dynamicType; |
| 4044 return null; | 4235 return null; |
| 4045 } | 4236 } |
| 4046 if (argumentList != null) { | 4237 if (argumentList != null) { |
| 4047 NodeList<TypeName> arguments5 = argumentList.arguments; | 4238 NodeList<TypeName> arguments5 = argumentList.arguments; |
| 4048 int argumentCount = arguments5.length; | 4239 int argumentCount = arguments5.length; |
| 4049 List<Type2> parameters = getTypeArguments(type); | 4240 List<Type2> parameters = getTypeArguments(type); |
| 4050 int parameterCount = parameters.length; | 4241 int parameterCount = parameters.length; |
| 4051 int count = Math.min(argumentCount, parameterCount); | 4242 int count = Math.min(argumentCount, parameterCount); |
| 4052 List<Type2> typeArguments = new List<Type2>(count); | 4243 List<Type2> typeArguments = new List<Type2>(); |
| 4053 for (int i = 0; i < count; i++) { | 4244 for (int i = 0; i < count; i++) { |
| 4054 Type2 argumentType = getType4(arguments5[i]); | 4245 Type2 argumentType = getType4(arguments5[i]); |
| 4055 if (argumentType != null) { | 4246 if (argumentType != null) { |
| 4056 typeArguments.add(argumentType); | 4247 typeArguments.add(argumentType); |
| 4057 } | 4248 } |
| 4058 } | 4249 } |
| 4059 if (argumentCount != parameterCount) { | 4250 if (argumentCount != parameterCount) { |
| 4060 reportError(getInvalidTypeParametersErrorCode(node), node, [typeName.nam
e, argumentCount, parameterCount]); | 4251 reportError(getInvalidTypeParametersErrorCode(node), node, [typeName.nam
e, argumentCount, parameterCount]); |
| 4061 } | 4252 } |
| 4062 argumentCount = typeArguments.length; | 4253 argumentCount = typeArguments.length; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4091 } | 4282 } |
| 4092 Object visitVariableDeclaration(VariableDeclaration node) { | 4283 Object visitVariableDeclaration(VariableDeclaration node) { |
| 4093 super.visitVariableDeclaration(node); | 4284 super.visitVariableDeclaration(node); |
| 4094 Type2 declaredType; | 4285 Type2 declaredType; |
| 4095 TypeName typeName = ((node.parent as VariableDeclarationList)).type; | 4286 TypeName typeName = ((node.parent as VariableDeclarationList)).type; |
| 4096 if (typeName == null) { | 4287 if (typeName == null) { |
| 4097 declaredType = _dynamicType; | 4288 declaredType = _dynamicType; |
| 4098 } else { | 4289 } else { |
| 4099 declaredType = getType4(typeName); | 4290 declaredType = getType4(typeName); |
| 4100 } | 4291 } |
| 4101 Element element34 = node.name.element; | 4292 Element element36 = node.name.element; |
| 4102 if (element34 is VariableElement) { | 4293 if (element36 is VariableElement) { |
| 4103 ((element34 as VariableElementImpl)).type = declaredType; | 4294 ((element36 as VariableElementImpl)).type = declaredType; |
| 4104 if (element34 is FieldElement) { | 4295 if (element36 is FieldElement) { |
| 4105 FieldElement field = element34 as FieldElement; | 4296 FieldElement field = element36 as FieldElement; |
| 4106 PropertyAccessorElementImpl getter5 = field.getter as PropertyAccessorEl
ementImpl; | 4297 PropertyAccessorElementImpl getter5 = field.getter as PropertyAccessorEl
ementImpl; |
| 4107 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter5); | 4298 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter5); |
| 4108 getterType.returnType = declaredType; | 4299 getterType.returnType = declaredType; |
| 4109 getter5.type = getterType; | 4300 getter5.type = getterType; |
| 4110 PropertyAccessorElementImpl setter4 = field.setter as PropertyAccessorEl
ementImpl; | 4301 PropertyAccessorElementImpl setter4 = field.setter as PropertyAccessorEl
ementImpl; |
| 4111 if (setter4 != null) { | 4302 if (setter4 != null) { |
| 4112 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter4); | 4303 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter4); |
| 4113 setterType.returnType = VoidTypeImpl.instance; | 4304 setterType.returnType = VoidTypeImpl.instance; |
| 4114 setterType.normalParameterTypes = <Type2> [declaredType]; | 4305 setterType.normalParameterTypes = <Type2> [declaredType]; |
| 4115 setter4.type = setterType; | 4306 setter4.type = setterType; |
| 4116 } | 4307 } |
| 4117 } | 4308 } |
| 4118 } else { | 4309 } else { |
| 4119 } | 4310 } |
| 4120 return null; | 4311 return null; |
| 4121 } | 4312 } |
| 4122 /** | 4313 /** |
| 4123 * Return the class element that represents the class whose name was provided. | 4314 * Return the class element that represents the class whose name was provided. |
| 4124 * @param identifier the name from the declaration of a class | 4315 * @param identifier the name from the declaration of a class |
| 4125 * @return the class element that represents the class | 4316 * @return the class element that represents the class |
| 4126 */ | 4317 */ |
| 4127 ClassElementImpl getClassElement(SimpleIdentifier identifier) { | 4318 ClassElementImpl getClassElement(SimpleIdentifier identifier) { |
| 4128 if (identifier == null) { | 4319 if (identifier == null) { |
| 4129 return null; | 4320 return null; |
| 4130 } | 4321 } |
| 4131 Element element35 = identifier.element; | 4322 Element element37 = identifier.element; |
| 4132 if (element35 is! ClassElementImpl) { | 4323 if (element37 is! ClassElementImpl) { |
| 4133 return null; | 4324 return null; |
| 4134 } | 4325 } |
| 4135 return element35 as ClassElementImpl; | 4326 return element37 as ClassElementImpl; |
| 4136 } | 4327 } |
| 4137 /** | 4328 /** |
| 4138 * Return an array containing all of the elements associated with the paramete
rs in the given | 4329 * Return an array containing all of the elements associated with the paramete
rs in the given |
| 4139 * list. | 4330 * list. |
| 4140 * @param parameterList the list of parameters whose elements are to be return
ed | 4331 * @param parameterList the list of parameters whose elements are to be return
ed |
| 4141 * @return the elements associated with the parameters | 4332 * @return the elements associated with the parameters |
| 4142 */ | 4333 */ |
| 4143 List<ParameterElement> getElements(FormalParameterList parameterList) { | 4334 List<ParameterElement> getElements(FormalParameterList parameterList) { |
| 4144 List<ParameterElement> elements = new List<ParameterElement>(); | 4335 List<ParameterElement> elements = new List<ParameterElement>(); |
| 4145 for (FormalParameter parameter in parameterList.parameters) { | 4336 for (FormalParameter parameter in parameterList.parameters) { |
| 4146 ParameterElement element36 = parameter.identifier.element as ParameterElem
ent; | 4337 ParameterElement element38 = parameter.identifier.element as ParameterElem
ent; |
| 4147 if (element36 != null) { | 4338 if (element38 != null) { |
| 4148 elements.add(element36); | 4339 elements.add(element38); |
| 4149 } | 4340 } |
| 4150 } | 4341 } |
| 4151 return new List.from(elements); | 4342 return new List.from(elements); |
| 4152 } | 4343 } |
| 4153 /** | 4344 /** |
| 4154 * The number of type arguments in the given type name does not match the numb
er of parameters in | 4345 * The number of type arguments in the given type name does not match the numb
er of parameters in |
| 4155 * the corresponding class element. Return the error code that should be used
to report this | 4346 * the corresponding class element. Return the error code that should be used
to report this |
| 4156 * error. | 4347 * error. |
| 4157 * @param node the type name with the wrong number of type arguments | 4348 * @param node the type name with the wrong number of type arguments |
| 4158 * @return the error code that should be used to report that the wrong number
of type arguments | 4349 * @return the error code that should be used to report that the wrong number
of type arguments |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4294 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode undef
inedError, ErrorCode nonTypeError, ErrorCode nonInterfaceType) { | 4485 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode undef
inedError, ErrorCode nonTypeError, ErrorCode nonInterfaceType) { |
| 4295 List<InterfaceType> types = new List<InterfaceType>(); | 4486 List<InterfaceType> types = new List<InterfaceType>(); |
| 4296 for (TypeName typeName in typeNames) { | 4487 for (TypeName typeName in typeNames) { |
| 4297 InterfaceType type = resolveType(typeName, undefinedError, nonTypeError, n
onInterfaceType); | 4488 InterfaceType type = resolveType(typeName, undefinedError, nonTypeError, n
onInterfaceType); |
| 4298 if (type != null) { | 4489 if (type != null) { |
| 4299 types.add(type); | 4490 types.add(type); |
| 4300 } | 4491 } |
| 4301 } | 4492 } |
| 4302 return new List.from(types); | 4493 return new List.from(types); |
| 4303 } | 4494 } |
| 4304 void setElement(Identifier typeName, Element element49) { | 4495 void setElement(Identifier typeName, Element element51) { |
| 4305 if (element49 != null) { | 4496 if (element51 != null) { |
| 4306 if (typeName is SimpleIdentifier) { | 4497 if (typeName is SimpleIdentifier) { |
| 4307 ((typeName as SimpleIdentifier)).element = element49; | 4498 ((typeName as SimpleIdentifier)).element = element51; |
| 4308 } else if (typeName is PrefixedIdentifier) { | 4499 } else if (typeName is PrefixedIdentifier) { |
| 4309 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; | 4500 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; |
| 4310 identifier.identifier.element = element49; | 4501 identifier.identifier.element = element51; |
| 4311 SimpleIdentifier prefix9 = identifier.prefix; | 4502 SimpleIdentifier prefix9 = identifier.prefix; |
| 4312 Element prefixElement = nameScope.lookup(prefix9, definingLibrary); | 4503 Element prefixElement = nameScope.lookup(prefix9, definingLibrary); |
| 4313 if (prefixElement != null) { | 4504 if (prefixElement != null) { |
| 4314 prefix9.element = prefixElement; | 4505 prefix9.element = prefixElement; |
| 4315 } | 4506 } |
| 4316 } | 4507 } |
| 4317 } | 4508 } |
| 4318 } | 4509 } |
| 4319 /** | 4510 /** |
| 4320 * Set the return type and parameter type information for the given function t
ype based on the | 4511 * Set the return type and parameter type information for the given function t
ype based on the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4350 } | 4541 } |
| 4351 if (returnType12 == null) { | 4542 if (returnType12 == null) { |
| 4352 functionType.returnType = _dynamicType; | 4543 functionType.returnType = _dynamicType; |
| 4353 } else { | 4544 } else { |
| 4354 functionType.returnType = returnType12.type; | 4545 functionType.returnType = returnType12.type; |
| 4355 } | 4546 } |
| 4356 } | 4547 } |
| 4357 } | 4548 } |
| 4358 /** | 4549 /** |
| 4359 * Instances of the class {@code ClassScope} implement the scope defined by a cl
ass. | 4550 * Instances of the class {@code ClassScope} implement the scope defined by a cl
ass. |
| 4551 * @coverage dart.engine.resolver |
| 4360 */ | 4552 */ |
| 4361 class ClassScope extends EnclosedScope { | 4553 class ClassScope extends EnclosedScope { |
| 4362 /** | 4554 /** |
| 4363 * Initialize a newly created scope enclosed within another scope. | 4555 * Initialize a newly created scope enclosed within another scope. |
| 4364 * @param enclosingScope the scope in which this scope is lexically enclosed | 4556 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 4365 * @param typeElement the element representing the type represented by this sc
ope | 4557 * @param typeElement the element representing the type represented by this sc
ope |
| 4366 */ | 4558 */ |
| 4367 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { | 4559 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { |
| 4368 defineTypeParameters(typeElement); | 4560 defineTypeParameters(typeElement); |
| 4369 defineMembers(typeElement); | 4561 defineMembers(typeElement); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4387 void defineTypeParameters(ClassElement typeElement) { | 4579 void defineTypeParameters(ClassElement typeElement) { |
| 4388 Scope parameterScope = enclosingScope; | 4580 Scope parameterScope = enclosingScope; |
| 4389 for (TypeVariableElement parameter in typeElement.typeVariables) { | 4581 for (TypeVariableElement parameter in typeElement.typeVariables) { |
| 4390 parameterScope.define(parameter); | 4582 parameterScope.define(parameter); |
| 4391 } | 4583 } |
| 4392 } | 4584 } |
| 4393 } | 4585 } |
| 4394 /** | 4586 /** |
| 4395 * Instances of the class {@code EnclosedScope} implement a scope that is lexica
lly enclosed in | 4587 * Instances of the class {@code EnclosedScope} implement a scope that is lexica
lly enclosed in |
| 4396 * another scope. | 4588 * another scope. |
| 4589 * @coverage dart.engine.resolver |
| 4397 */ | 4590 */ |
| 4398 class EnclosedScope extends Scope { | 4591 class EnclosedScope extends Scope { |
| 4399 /** | 4592 /** |
| 4400 * The scope in which this scope is lexically enclosed. | 4593 * The scope in which this scope is lexically enclosed. |
| 4401 */ | 4594 */ |
| 4402 Scope _enclosingScope; | 4595 Scope _enclosingScope; |
| 4403 /** | 4596 /** |
| 4404 * Initialize a newly created scope enclosed within another scope. | 4597 * Initialize a newly created scope enclosed within another scope. |
| 4405 * @param enclosingScope the scope in which this scope is lexically enclosed | 4598 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 4406 */ | 4599 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4417 Element lookup3(String name, LibraryElement referencingLibrary) { | 4610 Element lookup3(String name, LibraryElement referencingLibrary) { |
| 4418 Element element = localLookup(name, referencingLibrary); | 4611 Element element = localLookup(name, referencingLibrary); |
| 4419 if (element != null) { | 4612 if (element != null) { |
| 4420 return element; | 4613 return element; |
| 4421 } | 4614 } |
| 4422 return _enclosingScope.lookup3(name, referencingLibrary); | 4615 return _enclosingScope.lookup3(name, referencingLibrary); |
| 4423 } | 4616 } |
| 4424 } | 4617 } |
| 4425 /** | 4618 /** |
| 4426 * Instances of the class {@code FunctionScope} implement the scope defined by a
function. | 4619 * Instances of the class {@code FunctionScope} implement the scope defined by a
function. |
| 4620 * @coverage dart.engine.resolver |
| 4427 */ | 4621 */ |
| 4428 class FunctionScope extends EnclosedScope { | 4622 class FunctionScope extends EnclosedScope { |
| 4429 /** | 4623 /** |
| 4430 * Initialize a newly created scope enclosed within another scope. | 4624 * Initialize a newly created scope enclosed within another scope. |
| 4431 * @param enclosingScope the scope in which this scope is lexically enclosed | 4625 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 4432 * @param functionElement the element representing the type represented by thi
s scope | 4626 * @param functionElement the element representing the type represented by thi
s scope |
| 4433 */ | 4627 */ |
| 4434 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { | 4628 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { |
| 4435 defineParameters(functionElement); | 4629 defineParameters(functionElement); |
| 4436 } | 4630 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4449 for (ParameterElement parameter in functionElement.parameters) { | 4643 for (ParameterElement parameter in functionElement.parameters) { |
| 4450 if (!parameter.isInitializingFormal()) { | 4644 if (!parameter.isInitializingFormal()) { |
| 4451 parameterScope.define(parameter); | 4645 parameterScope.define(parameter); |
| 4452 } | 4646 } |
| 4453 } | 4647 } |
| 4454 } | 4648 } |
| 4455 } | 4649 } |
| 4456 /** | 4650 /** |
| 4457 * Instances of the class {@code FunctionTypeScope} implement the scope defined
by a function type | 4651 * Instances of the class {@code FunctionTypeScope} implement the scope defined
by a function type |
| 4458 * alias. | 4652 * alias. |
| 4653 * @coverage dart.engine.resolver |
| 4459 */ | 4654 */ |
| 4460 class FunctionTypeScope extends EnclosedScope { | 4655 class FunctionTypeScope extends EnclosedScope { |
| 4461 /** | 4656 /** |
| 4462 * Initialize a newly created scope enclosed within another scope. | 4657 * Initialize a newly created scope enclosed within another scope. |
| 4463 * @param enclosingScope the scope in which this scope is lexically enclosed | 4658 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 4464 * @param typeElement the element representing the type alias represented by t
his scope | 4659 * @param typeElement the element representing the type alias represented by t
his scope |
| 4465 */ | 4660 */ |
| 4466 FunctionTypeScope(Scope enclosingScope, TypeAliasElement typeElement) : super(
new EnclosedScope(enclosingScope)) { | 4661 FunctionTypeScope(Scope enclosingScope, TypeAliasElement typeElement) : super(
new EnclosedScope(enclosingScope)) { |
| 4467 defineTypeParameters(typeElement); | 4662 defineTypeParameters(typeElement); |
| 4468 } | 4663 } |
| 4469 /** | 4664 /** |
| 4470 * Define the type parameters for the function type alias. | 4665 * Define the type parameters for the function type alias. |
| 4471 * @param typeElement the element representing the type represented by this sc
ope | 4666 * @param typeElement the element representing the type represented by this sc
ope |
| 4472 */ | 4667 */ |
| 4473 void defineTypeParameters(TypeAliasElement typeElement) { | 4668 void defineTypeParameters(TypeAliasElement typeElement) { |
| 4474 Scope parameterScope = enclosingScope; | 4669 Scope parameterScope = enclosingScope; |
| 4475 for (TypeVariableElement parameter in typeElement.typeVariables) { | 4670 for (TypeVariableElement parameter in typeElement.typeVariables) { |
| 4476 parameterScope.define(parameter); | 4671 parameterScope.define(parameter); |
| 4477 } | 4672 } |
| 4478 } | 4673 } |
| 4479 } | 4674 } |
| 4480 /** | 4675 /** |
| 4481 * Instances of the class {@code LabelScope} represent a scope in which a single
label is defined. | 4676 * Instances of the class {@code LabelScope} represent a scope in which a single
label is defined. |
| 4677 * @coverage dart.engine.resolver |
| 4482 */ | 4678 */ |
| 4483 class LabelScope { | 4679 class LabelScope { |
| 4484 /** | 4680 /** |
| 4485 * The label scope enclosing this label scope. | 4681 * The label scope enclosing this label scope. |
| 4486 */ | 4682 */ |
| 4487 LabelScope _outerScope; | 4683 LabelScope _outerScope; |
| 4488 /** | 4684 /** |
| 4489 * The label defined in this scope. | 4685 * The label defined in this scope. |
| 4490 */ | 4686 */ |
| 4491 String _label; | 4687 String _label; |
| 4492 /** | 4688 /** |
| 4493 * The element to which the label resolves. | 4689 * The element to which the label resolves. |
| 4494 */ | 4690 */ |
| 4495 LabelElement _element; | 4691 LabelElement _element; |
| 4496 /** | 4692 /** |
| 4497 * The marker used to look up a label element for an unlabeled {@code break} o
r {@code continue}. | 4693 * The marker used to look up a label element for an unlabeled {@code break} o
r {@code continue}. |
| 4498 */ | 4694 */ |
| 4499 static String EMPTY_LABEL = ""; | 4695 static String EMPTY_LABEL = ""; |
| 4500 /** | 4696 /** |
| 4501 * The label element returned for scopes that can be the target of an unlabele
d {@code break} or{@code continue}. | 4697 * The label element returned for scopes that can be the target of an unlabele
d {@code break} or{@code continue}. |
| 4502 */ | 4698 */ |
| 4503 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w StringToken(TokenType.IDENTIFIER, "", 0)); | 4699 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); |
| 4504 /** | 4700 /** |
| 4505 * Initialize a newly created scope to represent the potential target of an un
labeled{@code break} or {@code continue}. | 4701 * Initialize a newly created scope to represent the potential target of an un
labeled{@code break} or {@code continue}. |
| 4506 * @param outerScope the label scope enclosing the new label scope | 4702 * @param outerScope the label scope enclosing the new label scope |
| 4507 * @param onSwitchStatement {@code true} if this label is associated with a {@
code switch}statement | 4703 * @param onSwitchStatement {@code true} if this label is associated with a {@
code switch}statement |
| 4508 * @param onSwitchMember {@code true} if this label is associated with a {@cod
e switch} member | 4704 * @param onSwitchMember {@code true} if this label is associated with a {@cod
e switch} member |
| 4509 */ | 4705 */ |
| 4510 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { | 4706 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { |
| 4511 _jtd_constructor_231_impl(outerScope, onSwitchStatement, onSwitchMember); | 4707 _jtd_constructor_237_impl(outerScope, onSwitchStatement, onSwitchMember); |
| 4512 } | 4708 } |
| 4513 _jtd_constructor_231_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { | 4709 _jtd_constructor_237_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { |
| 4514 _jtd_constructor_232_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); | 4710 _jtd_constructor_238_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); |
| 4515 } | 4711 } |
| 4516 /** | 4712 /** |
| 4517 * Initialize a newly created scope to represent the given label. | 4713 * Initialize a newly created scope to represent the given label. |
| 4518 * @param outerScope the label scope enclosing the new label scope | 4714 * @param outerScope the label scope enclosing the new label scope |
| 4519 * @param label the label defined in this scope | 4715 * @param label the label defined in this scope |
| 4520 * @param element the element to which the label resolves | 4716 * @param element the element to which the label resolves |
| 4521 */ | 4717 */ |
| 4522 LabelScope.con2(LabelScope outerScope2, String label4, LabelElement element18)
{ | 4718 LabelScope.con2(LabelScope outerScope2, String label4, LabelElement element19)
{ |
| 4523 _jtd_constructor_232_impl(outerScope2, label4, element18); | 4719 _jtd_constructor_238_impl(outerScope2, label4, element19); |
| 4524 } | 4720 } |
| 4525 _jtd_constructor_232_impl(LabelScope outerScope2, String label4, LabelElement
element18) { | 4721 _jtd_constructor_238_impl(LabelScope outerScope2, String label4, LabelElement
element19) { |
| 4526 this._outerScope = outerScope2; | 4722 this._outerScope = outerScope2; |
| 4527 this._label = label4; | 4723 this._label = label4; |
| 4528 this._element = element18; | 4724 this._element = element19; |
| 4529 } | 4725 } |
| 4530 /** | 4726 /** |
| 4531 * Return the label element corresponding to the given label, or {@code null}
if the given label | 4727 * Return the label element corresponding to the given label, or {@code null}
if the given label |
| 4532 * is not defined in this scope. | 4728 * is not defined in this scope. |
| 4533 * @param targetLabel the label being looked up | 4729 * @param targetLabel the label being looked up |
| 4534 * @return the label element corresponding to the given label | 4730 * @return the label element corresponding to the given label |
| 4535 */ | 4731 */ |
| 4536 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; | 4732 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; |
| 4537 /** | 4733 /** |
| 4538 * Return the label element corresponding to the given label, or {@code null}
if the given label | 4734 * Return the label element corresponding to the given label, or {@code null}
if the given label |
| 4539 * is not defined in this scope. | 4735 * is not defined in this scope. |
| 4540 * @param targetLabel the label being looked up | 4736 * @param targetLabel the label being looked up |
| 4541 * @return the label element corresponding to the given label | 4737 * @return the label element corresponding to the given label |
| 4542 */ | 4738 */ |
| 4543 LabelElement lookup2(String targetLabel) { | 4739 LabelElement lookup2(String targetLabel) { |
| 4544 if (_label == targetLabel) { | 4740 if (_label == targetLabel) { |
| 4545 return _element; | 4741 return _element; |
| 4546 } else if (_outerScope != null) { | 4742 } else if (_outerScope != null) { |
| 4547 return _outerScope.lookup2(targetLabel); | 4743 return _outerScope.lookup2(targetLabel); |
| 4548 } else { | 4744 } else { |
| 4549 return null; | 4745 return null; |
| 4550 } | 4746 } |
| 4551 } | 4747 } |
| 4552 } | 4748 } |
| 4553 /** | 4749 /** |
| 4554 * Instances of the class {@code LibraryImportScope} represent the scope contain
ing all of the names | 4750 * Instances of the class {@code LibraryImportScope} represent the scope contain
ing all of the names |
| 4555 * available from imported libraries. | 4751 * available from imported libraries. |
| 4752 * @coverage dart.engine.resolver |
| 4556 */ | 4753 */ |
| 4557 class LibraryImportScope extends Scope { | 4754 class LibraryImportScope extends Scope { |
| 4558 /** | 4755 /** |
| 4559 * The element representing the library in which this scope is enclosed. | 4756 * The element representing the library in which this scope is enclosed. |
| 4560 */ | 4757 */ |
| 4561 LibraryElement _definingLibrary; | 4758 LibraryElement _definingLibrary; |
| 4562 /** | 4759 /** |
| 4563 * The listener that is to be informed when an error is encountered. | 4760 * The listener that is to be informed when an error is encountered. |
| 4564 */ | 4761 */ |
| 4565 AnalysisErrorListener _errorListener; | 4762 AnalysisErrorListener _errorListener; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4620 void createImportedNamespaces(LibraryElement definingLibrary) { | 4817 void createImportedNamespaces(LibraryElement definingLibrary) { |
| 4621 NamespaceBuilder builder = new NamespaceBuilder(); | 4818 NamespaceBuilder builder = new NamespaceBuilder(); |
| 4622 for (ImportElement element in definingLibrary.imports) { | 4819 for (ImportElement element in definingLibrary.imports) { |
| 4623 _importedNamespaces.add(builder.createImportNamespace(element)); | 4820 _importedNamespaces.add(builder.createImportNamespace(element)); |
| 4624 } | 4821 } |
| 4625 } | 4822 } |
| 4626 } | 4823 } |
| 4627 /** | 4824 /** |
| 4628 * Instances of the class {@code LibraryScope} implement a scope containing all
of the names defined | 4825 * Instances of the class {@code LibraryScope} implement a scope containing all
of the names defined |
| 4629 * in a given library. | 4826 * in a given library. |
| 4827 * @coverage dart.engine.resolver |
| 4630 */ | 4828 */ |
| 4631 class LibraryScope extends EnclosedScope { | 4829 class LibraryScope extends EnclosedScope { |
| 4632 /** | 4830 /** |
| 4633 * Initialize a newly created scope representing the names defined in the give
n library. | 4831 * Initialize a newly created scope representing the names defined in the give
n library. |
| 4634 * @param definingLibrary the element representing the library represented by
this scope | 4832 * @param definingLibrary the element representing the library represented by
this scope |
| 4635 * @param errorListener the listener that is to be informed when an error is e
ncountered | 4833 * @param errorListener the listener that is to be informed when an error is e
ncountered |
| 4636 */ | 4834 */ |
| 4637 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { | 4835 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { |
| 4638 defineTopLevelNames(definingLibrary); | 4836 defineTopLevelNames(definingLibrary); |
| 4639 } | 4837 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4668 } | 4866 } |
| 4669 defineLocalNames(definingLibrary.definingCompilationUnit); | 4867 defineLocalNames(definingLibrary.definingCompilationUnit); |
| 4670 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { | 4868 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { |
| 4671 defineLocalNames(compilationUnit); | 4869 defineLocalNames(compilationUnit); |
| 4672 } | 4870 } |
| 4673 } | 4871 } |
| 4674 } | 4872 } |
| 4675 /** | 4873 /** |
| 4676 * Instances of the class {@code Namespace} implement a mapping of identifiers t
o the elements | 4874 * Instances of the class {@code Namespace} implement a mapping of identifiers t
o the elements |
| 4677 * represented by those identifiers. Namespaces are the building blocks for scop
es. | 4875 * represented by those identifiers. Namespaces are the building blocks for scop
es. |
| 4876 * @coverage dart.engine.resolver |
| 4678 */ | 4877 */ |
| 4679 class Namespace { | 4878 class Namespace { |
| 4680 /** | 4879 /** |
| 4681 * A table mapping names that are defined in this namespace to the element rep
resenting the thing | 4880 * A table mapping names that are defined in this namespace to the element rep
resenting the thing |
| 4682 * declared with that name. | 4881 * declared with that name. |
| 4683 */ | 4882 */ |
| 4684 Map<String, Element> _definedNames; | 4883 Map<String, Element> _definedNames; |
| 4685 /** | 4884 /** |
| 4686 * An empty namespace. | 4885 * An empty namespace. |
| 4687 */ | 4886 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4698 * Return the element in this namespace that is available to the containing sc
ope using the given | 4897 * Return the element in this namespace that is available to the containing sc
ope using the given |
| 4699 * name. | 4898 * name. |
| 4700 * @param name the name used to reference the | 4899 * @param name the name used to reference the |
| 4701 * @return the element represented by the given identifier | 4900 * @return the element represented by the given identifier |
| 4702 */ | 4901 */ |
| 4703 Element get(String name) => _definedNames[name]; | 4902 Element get(String name) => _definedNames[name]; |
| 4704 /** | 4903 /** |
| 4705 * Return a table containing the same mappings as those defined by this namesp
ace. | 4904 * Return a table containing the same mappings as those defined by this namesp
ace. |
| 4706 * @return a table containing the same mappings as those defined by this names
pace | 4905 * @return a table containing the same mappings as those defined by this names
pace |
| 4707 */ | 4906 */ |
| 4708 Map<String, Element> get definedNames => new Map<String, Element>(); | 4907 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); |
| 4709 } | 4908 } |
| 4710 /** | 4909 /** |
| 4711 * Instances of the class {@code NamespaceBuilder} are used to build a {@code Na
mespace}. Namespace | 4910 * Instances of the class {@code NamespaceBuilder} are used to build a {@code Na
mespace}. Namespace |
| 4712 * builders are thread-safe and re-usable. | 4911 * builders are thread-safe and re-usable. |
| 4912 * @coverage dart.engine.resolver |
| 4713 */ | 4913 */ |
| 4714 class NamespaceBuilder { | 4914 class NamespaceBuilder { |
| 4715 /** | 4915 /** |
| 4716 * Initialize a newly created namespace builder. | 4916 * Initialize a newly created namespace builder. |
| 4717 */ | 4917 */ |
| 4718 NamespaceBuilder() : super() { | 4918 NamespaceBuilder() : super() { |
| 4719 } | 4919 } |
| 4720 /** | 4920 /** |
| 4721 * Create a namespace representing the export namespace of the given library. | 4921 * Create a namespace representing the export namespace of the given library. |
| 4722 * @param library the library whose export namespace is to be created | 4922 * @param library the library whose export namespace is to be created |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4887 if (element != null) { | 5087 if (element != null) { |
| 4888 newNames[name] = element; | 5088 newNames[name] = element; |
| 4889 } | 5089 } |
| 4890 } | 5090 } |
| 4891 return newNames; | 5091 return newNames; |
| 4892 } | 5092 } |
| 4893 } | 5093 } |
| 4894 /** | 5094 /** |
| 4895 * The abstract class {@code Scope} defines the behavior common to name scopes u
sed by the resolver | 5095 * The abstract class {@code Scope} defines the behavior common to name scopes u
sed by the resolver |
| 4896 * to determine which names are visible at any given point in the code. | 5096 * to determine which names are visible at any given point in the code. |
| 5097 * @coverage dart.engine.resolver |
| 4897 */ | 5098 */ |
| 4898 abstract class Scope { | 5099 abstract class Scope { |
| 4899 /** | 5100 /** |
| 4900 * The prefix used to mark an identifier as being private to its library. | 5101 * The prefix used to mark an identifier as being private to its library. |
| 4901 */ | 5102 */ |
| 4902 static String PRIVATE_NAME_PREFIX = "_"; | 5103 static String PRIVATE_NAME_PREFIX = "_"; |
| 4903 /** | 5104 /** |
| 4904 * The suffix added to the declared name of a setter when looking up the sette
r. Used to | 5105 * The suffix added to the declared name of a setter when looking up the sette
r. Used to |
| 4905 * disambiguate between a getter and a setter that have the same name. | 5106 * disambiguate between a getter and a setter that have the same name. |
| 4906 */ | 5107 */ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5017 return "${accessor.name}${SETTER_SUFFIX}"; | 5218 return "${accessor.name}${SETTER_SUFFIX}"; |
| 5018 } | 5219 } |
| 5019 } | 5220 } |
| 5020 return element.name; | 5221 return element.name; |
| 5021 } | 5222 } |
| 5022 } | 5223 } |
| 5023 /** | 5224 /** |
| 5024 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo
king for additional | 5225 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo
king for additional |
| 5025 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors | 5226 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors |
| 5026 * and warnings related to constant expressions. | 5227 * and warnings related to constant expressions. |
| 5228 * @coverage dart.engine.resolver |
| 5027 */ | 5229 */ |
| 5028 class ConstantVerifier extends RecursiveASTVisitor<Object> { | 5230 class ConstantVerifier extends RecursiveASTVisitor<Object> { |
| 5029 /** | 5231 /** |
| 5030 * The error reporter by which errors will be reported. | 5232 * The error reporter by which errors will be reported. |
| 5031 */ | 5233 */ |
| 5032 ErrorReporter _errorReporter; | 5234 ErrorReporter _errorReporter; |
| 5033 /** | 5235 /** |
| 5034 * The constant evaluator used to evaluate constants. | 5236 * The constant evaluator used to evaluate constants. |
| 5035 */ | 5237 */ |
| 5036 ConstantEvaluator _evaluator; | 5238 ConstantEvaluator _evaluator; |
| 5037 /** | 5239 /** |
| 5038 * Initialize a newly created constant verifier. | 5240 * Initialize a newly created constant verifier. |
| 5039 * @param errorReporter the error reporter by which errors will be reported | 5241 * @param errorReporter the error reporter by which errors will be reported |
| 5040 */ | 5242 */ |
| 5041 ConstantVerifier(ErrorReporter errorReporter) { | 5243 ConstantVerifier(ErrorReporter errorReporter) { |
| 5042 this._errorReporter = errorReporter; | 5244 this._errorReporter = errorReporter; |
| 5043 _evaluator = new ConstantEvaluator(); | 5245 _evaluator = new ConstantEvaluator(errorReporter); |
| 5044 } | 5246 } |
| 5045 Object visitFunctionExpression(FunctionExpression node) { | 5247 Object visitFunctionExpression(FunctionExpression node) { |
| 5046 super.visitFunctionExpression(node); | 5248 super.visitFunctionExpression(node); |
| 5047 validateDefaultValues(node.parameters); | 5249 validateDefaultValues(node.parameters); |
| 5048 return null; | 5250 return null; |
| 5049 } | 5251 } |
| 5050 Object visitListLiteral(ListLiteral node) { | 5252 Object visitListLiteral(ListLiteral node) { |
| 5051 super.visitListLiteral(node); | 5253 super.visitListLiteral(node); |
| 5052 if (node.modifier != null) { | 5254 if (node.modifier != null) { |
| 5053 for (Expression element in node.elements) { | 5255 for (Expression element in node.elements) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 if (defaultValue2 != null) { | 5335 if (defaultValue2 != null) { |
| 5134 validate(defaultValue2, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALU
E); | 5336 validate(defaultValue2, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALU
E); |
| 5135 } | 5337 } |
| 5136 } | 5338 } |
| 5137 } | 5339 } |
| 5138 } | 5340 } |
| 5139 } | 5341 } |
| 5140 /** | 5342 /** |
| 5141 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin
g for additional | 5343 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin
g for additional |
| 5142 * errors and warnings not covered by the parser and resolver. | 5344 * errors and warnings not covered by the parser and resolver. |
| 5345 * @coverage dart.engine.resolver |
| 5143 */ | 5346 */ |
| 5144 class ErrorVerifier extends RecursiveASTVisitor<Object> { | 5347 class ErrorVerifier extends RecursiveASTVisitor<Object> { |
| 5145 /** | 5348 /** |
| 5146 * The error reporter by which errors will be reported. | 5349 * The error reporter by which errors will be reported. |
| 5147 */ | 5350 */ |
| 5148 ErrorReporter _errorReporter; | 5351 ErrorReporter _errorReporter; |
| 5149 /** | 5352 /** |
| 5150 * The current library that is being analyzed. | 5353 * The current library that is being analyzed. |
| 5151 */ | 5354 */ |
| 5152 LibraryElement _currentLibrary; | 5355 LibraryElement _currentLibrary; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5163 * method or function. | 5366 * method or function. |
| 5164 */ | 5367 */ |
| 5165 ExecutableElement _currentFunction; | 5368 ExecutableElement _currentFunction; |
| 5166 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider) { | 5369 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider) { |
| 5167 this._errorReporter = errorReporter; | 5370 this._errorReporter = errorReporter; |
| 5168 this._currentLibrary = currentLibrary; | 5371 this._currentLibrary = currentLibrary; |
| 5169 this._typeProvider = typeProvider; | 5372 this._typeProvider = typeProvider; |
| 5170 _dynamicType = typeProvider.dynamicType; | 5373 _dynamicType = typeProvider.dynamicType; |
| 5171 } | 5374 } |
| 5172 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { | 5375 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { |
| 5173 SimpleIdentifier identifier13 = node.identifier; | 5376 checkForArgumentDefinitionTestNonParameter(node); |
| 5174 Element element42 = identifier13.element; | |
| 5175 if (element42 != null && element42 is! ParameterElement) { | |
| 5176 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N
ON_PARAMETER, identifier13, [identifier13.name]); | |
| 5177 } | |
| 5178 return super.visitArgumentDefinitionTest(node); | 5377 return super.visitArgumentDefinitionTest(node); |
| 5179 } | 5378 } |
| 5180 Object visitAssertStatement(AssertStatement node) { | 5379 Object visitAssertStatement(AssertStatement node) { |
| 5181 Expression expression = node.condition; | 5380 checkForNonBoolExpression(node); |
| 5182 Type2 type = getType(expression); | |
| 5183 if (type is InterfaceType) { | |
| 5184 if (!type.isAssignableTo(_typeProvider.boolType)) { | |
| 5185 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex
pression, []); | |
| 5186 } | |
| 5187 } else if (type is FunctionType) { | |
| 5188 FunctionType functionType = type as FunctionType; | |
| 5189 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { | |
| 5190 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex
pression, []); | |
| 5191 } | |
| 5192 } | |
| 5193 return super.visitAssertStatement(node); | 5381 return super.visitAssertStatement(node); |
| 5194 } | 5382 } |
| 5195 Object visitAssignmentExpression(AssignmentExpression node) { | 5383 Object visitAssignmentExpression(AssignmentExpression node) { |
| 5196 Expression lhs = node.leftHandSide; | 5384 checkForInvalidAssignment(node); |
| 5197 Expression rhs = node.rightHandSide; | |
| 5198 Type2 leftType = getType(lhs); | |
| 5199 Type2 rightType = getType(rhs); | |
| 5200 if (!rightType.isAssignableTo(leftType)) { | |
| 5201 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs,
[leftType.name, rightType.name]); | |
| 5202 } | |
| 5203 return super.visitAssignmentExpression(node); | 5385 return super.visitAssignmentExpression(node); |
| 5204 } | 5386 } |
| 5205 Object visitClassDeclaration(ClassDeclaration node) { | 5387 Object visitClassDeclaration(ClassDeclaration node) { |
| 5206 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_NAME); | 5388 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_NAME); |
| 5207 return super.visitClassDeclaration(node); | 5389 return super.visitClassDeclaration(node); |
| 5208 } | 5390 } |
| 5209 Object visitClassTypeAlias(ClassTypeAlias node) { | 5391 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 5210 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); | 5392 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); |
| 5211 return super.visitClassTypeAlias(node); | 5393 return super.visitClassTypeAlias(node); |
| 5212 } | 5394 } |
| 5213 Object visitConditionalExpression(ConditionalExpression node) { | 5395 Object visitConditionalExpression(ConditionalExpression node) { |
| 5214 checkForNonBoolCondition(node.condition); | 5396 checkForNonBoolCondition(node.condition); |
| 5215 return super.visitConditionalExpression(node); | 5397 return super.visitConditionalExpression(node); |
| 5216 } | 5398 } |
| 5217 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 5399 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 5218 ExecutableElement previousFunction = _currentFunction; | 5400 ExecutableElement previousFunction = _currentFunction; |
| 5219 try { | 5401 try { |
| 5220 _currentFunction = node.element; | 5402 _currentFunction = node.element; |
| 5403 checkForConstConstructorWithNonFinalField(node); |
| 5404 checkForConflictingConstructorNameAndMember(node); |
| 5221 return super.visitConstructorDeclaration(node); | 5405 return super.visitConstructorDeclaration(node); |
| 5222 } finally { | 5406 } finally { |
| 5223 _currentFunction = previousFunction; | 5407 _currentFunction = previousFunction; |
| 5224 } | 5408 } |
| 5225 } | 5409 } |
| 5226 Object visitDoStatement(DoStatement node) { | 5410 Object visitDoStatement(DoStatement node) { |
| 5227 checkForNonBoolCondition(node.condition); | 5411 checkForNonBoolCondition(node.condition); |
| 5228 return super.visitDoStatement(node); | 5412 return super.visitDoStatement(node); |
| 5229 } | 5413 } |
| 5414 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 5415 checkForConstFormalParameter(node); |
| 5416 return super.visitFieldFormalParameter(node); |
| 5417 } |
| 5230 Object visitFunctionDeclaration(FunctionDeclaration node) { | 5418 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 5231 ExecutableElement previousFunction = _currentFunction; | 5419 ExecutableElement previousFunction = _currentFunction; |
| 5232 try { | 5420 try { |
| 5233 _currentFunction = node.element; | 5421 _currentFunction = node.element; |
| 5234 return super.visitFunctionDeclaration(node); | 5422 return super.visitFunctionDeclaration(node); |
| 5235 } finally { | 5423 } finally { |
| 5236 _currentFunction = previousFunction; | 5424 _currentFunction = previousFunction; |
| 5237 } | 5425 } |
| 5238 } | 5426 } |
| 5239 Object visitFunctionExpression(FunctionExpression node) { | 5427 Object visitFunctionExpression(FunctionExpression node) { |
| 5240 ExecutableElement previousFunction = _currentFunction; | 5428 ExecutableElement previousFunction = _currentFunction; |
| 5241 try { | 5429 try { |
| 5242 _currentFunction = node.element; | 5430 _currentFunction = node.element; |
| 5243 return super.visitFunctionExpression(node); | 5431 return super.visitFunctionExpression(node); |
| 5244 } finally { | 5432 } finally { |
| 5245 _currentFunction = previousFunction; | 5433 _currentFunction = previousFunction; |
| 5246 } | 5434 } |
| 5247 } | 5435 } |
| 5248 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 5436 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 5249 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); | 5437 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); |
| 5250 return super.visitFunctionTypeAlias(node); | 5438 return super.visitFunctionTypeAlias(node); |
| 5251 } | 5439 } |
| 5252 Object visitIfStatement(IfStatement node) { | 5440 Object visitIfStatement(IfStatement node) { |
| 5253 checkForNonBoolCondition(node.condition); | 5441 checkForNonBoolCondition(node.condition); |
| 5254 return super.visitIfStatement(node); | 5442 return super.visitIfStatement(node); |
| 5255 } | 5443 } |
| 5256 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 5444 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 5257 ConstructorName constructorName4 = node.constructorName; | 5445 ConstructorName constructorName4 = node.constructorName; |
| 5258 TypeName typeName = constructorName4.type; | 5446 TypeName typeName = constructorName4.type; |
| 5259 Type2 createdType = typeName.type; | 5447 Type2 type20 = typeName.type; |
| 5260 if (createdType is InterfaceType) { | 5448 if (type20 is InterfaceType) { |
| 5261 if (((createdType as InterfaceType)).element.isAbstract()) { | 5449 InterfaceType interfaceType = type20 as InterfaceType; |
| 5262 ConstructorElement element43 = node.element; | 5450 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); |
| 5263 if (element43 != null && !element43.isFactory()) { | 5451 checkForTypeArgumentNotMatchingBounds(node, constructorName4.element, type
Name); |
| 5264 if (identical(((node.keyword as KeywordToken)).keyword, Keyword.CONST)
) { | |
| 5265 _errorReporter.reportError(StaticWarningCode.CONST_WITH_ABSTRACT_CLA
SS, typeName, []); | |
| 5266 } else { | |
| 5267 _errorReporter.reportError(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS
, typeName, []); | |
| 5268 } | |
| 5269 } | |
| 5270 } | |
| 5271 if (typeName.typeArguments != null) { | |
| 5272 ConstructorElement constructorElement = constructorName4.element; | |
| 5273 if (constructorElement != null) { | |
| 5274 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; | |
| 5275 List<TypeVariableElement> boundingElts = constructorElement.enclosingE
lement.typeVariables; | |
| 5276 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.l
ength); | |
| 5277 for (int i = 0; i < loopThroughIndex; i++) { | |
| 5278 TypeName argTypeName = typeNameArgList[i]; | |
| 5279 Type2 argType = argTypeName.type; | |
| 5280 Type2 boundType = boundingElts[i].bound; | |
| 5281 if (argType != null && boundType != null) { | |
| 5282 if (!argType.isSubtypeOf(boundType)) { | |
| 5283 _errorReporter.reportError(StaticTypeWarningCode.TYPE_ARGUMENT_N
OT_MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].name]); | |
| 5284 } | |
| 5285 } | |
| 5286 } | |
| 5287 } | |
| 5288 } | |
| 5289 } else { | 5452 } else { |
| 5290 _errorReporter.reportError(CompileTimeErrorCode.NON_CONSTANT_MAP_KEY, type
Name, []); | 5453 _errorReporter.reportError(CompileTimeErrorCode.NON_CONSTANT_MAP_KEY, type
Name, []); |
| 5291 } | 5454 } |
| 5292 return super.visitInstanceCreationExpression(node); | 5455 return super.visitInstanceCreationExpression(node); |
| 5293 } | 5456 } |
| 5294 Object visitMethodDeclaration(MethodDeclaration node) { | 5457 Object visitMethodDeclaration(MethodDeclaration node) { |
| 5295 ExecutableElement previousFunction = _currentFunction; | 5458 ExecutableElement previousFunction = _currentFunction; |
| 5296 try { | 5459 try { |
| 5297 _currentFunction = node.element; | 5460 _currentFunction = node.element; |
| 5298 return super.visitMethodDeclaration(node); | 5461 return super.visitMethodDeclaration(node); |
| 5299 } finally { | 5462 } finally { |
| 5300 _currentFunction = previousFunction; | 5463 _currentFunction = previousFunction; |
| 5301 } | 5464 } |
| 5302 } | 5465 } |
| 5303 Object visitReturnStatement(ReturnStatement node) { | 5466 Object visitReturnStatement(ReturnStatement node) { |
| 5304 FunctionType functionType = _currentFunction == null ? null : _currentFuncti
on.type; | 5467 checkForReturnOfInvalidType(node); |
| 5305 Type2 expectedReturnType = functionType == null ? null : functionType.return
Type; | |
| 5306 Expression returnExpression = node.expression; | |
| 5307 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr
ession != null) { | |
| 5308 Type2 actualReturnType = getType(returnExpression); | |
| 5309 if (!actualReturnType.isAssignableTo(expectedReturnType)) { | |
| 5310 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [actualReturnType.name, expectedReturnType.name]); | |
| 5311 } | |
| 5312 } | |
| 5313 return super.visitReturnStatement(node); | 5468 return super.visitReturnStatement(node); |
| 5314 } | 5469 } |
| 5470 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 5471 checkForConstFormalParameter(node); |
| 5472 return super.visitSimpleFormalParameter(node); |
| 5473 } |
| 5315 Object visitSwitchStatement(SwitchStatement node) { | 5474 Object visitSwitchStatement(SwitchStatement node) { |
| 5316 Expression expression16 = node.expression; | 5475 checkForCaseExpressionTypeImplementsEquals(node); |
| 5317 Type2 type = expression16.staticType; | |
| 5318 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { | |
| 5319 Element element44 = type.element; | |
| 5320 if (element44 is ClassElement) { | |
| 5321 ClassElement classElement = element44 as ClassElement; | |
| 5322 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); | |
| 5323 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { | |
| 5324 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I
MPLEMENTS_EQUALS, expression16, [element44.name]); | |
| 5325 } | |
| 5326 } | |
| 5327 } | |
| 5328 return super.visitSwitchStatement(node); | 5476 return super.visitSwitchStatement(node); |
| 5329 } | 5477 } |
| 5330 Object visitTypeParameter(TypeParameter node) { | 5478 Object visitTypeParameter(TypeParameter node) { |
| 5331 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_VARIABLE_NAME); | 5479 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_VARIABLE_NAME); |
| 5332 return super.visitTypeParameter(node); | 5480 return super.visitTypeParameter(node); |
| 5333 } | 5481 } |
| 5334 Object visitVariableDeclarationList(VariableDeclarationList node) { | 5482 Object visitVariableDeclarationList(VariableDeclarationList node) { |
| 5483 checkForBuiltInIdentifierAsName2(node); |
| 5484 return super.visitVariableDeclarationList(node); |
| 5485 } |
| 5486 Object visitWhileStatement(WhileStatement node) { |
| 5487 checkForNonBoolCondition(node.condition); |
| 5488 return super.visitWhileStatement(node); |
| 5489 } |
| 5490 /** |
| 5491 * This verifies that the passed argument definition test identifier is a para
meter. |
| 5492 * @param node the {@link ArgumentDefinitionTest} to evaluate |
| 5493 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5494 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER |
| 5495 */ |
| 5496 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { |
| 5497 SimpleIdentifier identifier14 = node.identifier; |
| 5498 Element element44 = identifier14.element; |
| 5499 if (element44 != null && element44 is! ParameterElement) { |
| 5500 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N
ON_PARAMETER, identifier14, [identifier14.name]); |
| 5501 return true; |
| 5502 } |
| 5503 return false; |
| 5504 } |
| 5505 /** |
| 5506 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 5507 * on the identifier if it is a keyword. |
| 5508 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| 5509 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
| 5510 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_
IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T
YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_
NAME} |
| 5511 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5512 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME |
| 5513 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME |
| 5514 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME |
| 5515 */ |
| 5516 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { |
| 5517 sc.Token token13 = identifier.token; |
| 5518 if (identical(token13.type, sc.TokenType.KEYWORD)) { |
| 5519 _errorReporter.reportError(errorCode, identifier, [identifier.name]); |
| 5520 return true; |
| 5521 } |
| 5522 return false; |
| 5523 } |
| 5524 /** |
| 5525 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. |
| 5526 * @param node the variable declaration list to check |
| 5527 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5528 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE |
| 5529 */ |
| 5530 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { |
| 5335 TypeName typeName = node.type; | 5531 TypeName typeName = node.type; |
| 5336 if (typeName != null) { | 5532 if (typeName != null) { |
| 5337 Identifier identifier = typeName.name; | 5533 Identifier identifier = typeName.name; |
| 5338 if (identifier is SimpleIdentifier) { | 5534 if (identifier is SimpleIdentifier) { |
| 5339 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; | 5535 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; |
| 5340 Token token13 = simpleIdentifier.token; | 5536 sc.Token token14 = simpleIdentifier.token; |
| 5341 if (identical(token13.type, TokenType.KEYWORD)) { | 5537 if (identical(token14.type, sc.TokenType.KEYWORD)) { |
| 5342 if (((token13 as KeywordToken)).keyword != Keyword.DYNAMIC) { | 5538 if (((token14 as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { |
| 5343 _errorReporter.reportError(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_
AS_TYPE, identifier, [identifier.name]); | 5539 _errorReporter.reportError(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_
AS_TYPE, identifier, [identifier.name]); |
| 5540 return true; |
| 5344 } | 5541 } |
| 5345 } | 5542 } |
| 5346 } | 5543 } |
| 5347 } | 5544 } |
| 5348 return super.visitVariableDeclarationList(node); | 5545 return false; |
| 5349 } | 5546 } |
| 5350 Object visitWhileStatement(WhileStatement node) { | 5547 /** |
| 5351 checkForNonBoolCondition(node.condition); | 5548 * This verifies that the passed switch statement does not have a case express
ion with the |
| 5352 return super.visitWhileStatement(node); | 5549 * operator '==' overridden. |
| 5353 } | 5550 * @param node the switch statement to evaluate |
| 5354 /** | 5551 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5355 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 5552 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS |
| 5356 * on the identifier if it is a keyword. | 5553 */ |
| 5357 * @param identifier the identifier to check to ensure that it is not a keywor
d | 5554 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { |
| 5358 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 5555 Expression expression16 = node.expression; |
| 5359 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_
IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T
YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_
NAME} | 5556 Type2 type = expression16.staticType; |
| 5360 */ | 5557 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { |
| 5361 void checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { | 5558 Element element45 = type.element; |
| 5362 Token token14 = identifier.token; | 5559 if (element45 is ClassElement) { |
| 5363 if (identical(token14.type, TokenType.KEYWORD)) { | 5560 ClassElement classElement = element45 as ClassElement; |
| 5364 _errorReporter.reportError(errorCode, identifier, [identifier.name]); | 5561 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); |
| 5365 } | 5562 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { |
| 5563 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I
MPLEMENTS_EQUALS, expression16, [element45.name]); |
| 5564 return true; |
| 5565 } |
| 5566 } |
| 5567 } |
| 5568 return false; |
| 5569 } |
| 5570 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node)
{ |
| 5571 ConstructorElement constructorElement = node.element; |
| 5572 SimpleIdentifier constructorName = node.name; |
| 5573 if (constructorName != null && constructorElement != null && !constructorNam
e.isSynthetic()) { |
| 5574 String name20 = constructorName.name; |
| 5575 ClassElement classElement = constructorElement.enclosingElement; |
| 5576 List<FieldElement> fields3 = classElement.fields; |
| 5577 for (FieldElement field in fields3) { |
| 5578 if (field.name == name20) { |
| 5579 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO
R_NAME_AND_FIELD, node, [name20]); |
| 5580 return true; |
| 5581 } |
| 5582 } |
| 5583 List<MethodElement> methods3 = classElement.methods; |
| 5584 for (MethodElement method in methods3) { |
| 5585 if (method.name == name20) { |
| 5586 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO
R_NAME_AND_METHOD, node, [name20]); |
| 5587 return true; |
| 5588 } |
| 5589 } |
| 5590 } |
| 5591 return false; |
| 5592 } |
| 5593 /** |
| 5594 * This verifies that the passed constructor declaration is not 'const' if it
has a non-final |
| 5595 * instance variable. |
| 5596 * @param node the instance creation expression to evaluate |
| 5597 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5598 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD |
| 5599 */ |
| 5600 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { |
| 5601 if (node.constKeyword == null) { |
| 5602 return false; |
| 5603 } |
| 5604 ConstructorElement constructorElement = node.element; |
| 5605 if (constructorElement != null) { |
| 5606 ClassElement classElement = constructorElement.enclosingElement; |
| 5607 List<FieldElement> elements = classElement.fields; |
| 5608 for (FieldElement field in elements) { |
| 5609 if (!field.isFinal() && !field.isConst()) { |
| 5610 _errorReporter.reportError(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH
_NON_FINAL_FIELD, node, []); |
| 5611 return true; |
| 5612 } |
| 5613 } |
| 5614 } |
| 5615 return false; |
| 5616 } |
| 5617 /** |
| 5618 * This verifies that the passed normal formal parameter is not 'const'. |
| 5619 * @param node the normal formal parameter to evaluate |
| 5620 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5621 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER |
| 5622 */ |
| 5623 bool checkForConstFormalParameter(NormalFormalParameter node) { |
| 5624 if (node.isConst()) { |
| 5625 _errorReporter.reportError(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, no
de, []); |
| 5626 return true; |
| 5627 } |
| 5628 return false; |
| 5629 } |
| 5630 /** |
| 5631 * This verifies that the passed instance creation expression is not being inv
oked on an abstract |
| 5632 * class. |
| 5633 * @param node the instance creation expression to evaluate |
| 5634 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to |
| 5635 * @param type the type being constructed with this {@link InstanceCreationExp
ression} |
| 5636 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5637 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS |
| 5638 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS |
| 5639 */ |
| 5640 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { |
| 5641 if (type.element.isAbstract()) { |
| 5642 ConstructorElement element46 = node.element; |
| 5643 if (element46 != null && !element46.isFactory()) { |
| 5644 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { |
| 5645 _errorReporter.reportError(StaticWarningCode.CONST_WITH_ABSTRACT_CLASS
, typeName, []); |
| 5646 } else { |
| 5647 _errorReporter.reportError(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); |
| 5648 } |
| 5649 return true; |
| 5650 } |
| 5651 } |
| 5652 return false; |
| 5653 } |
| 5654 /** |
| 5655 * This verifies that the passed assignment expression represents a valid assi
gnment. |
| 5656 * @param node the assignment expression to evaluate |
| 5657 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5658 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
| 5659 */ |
| 5660 bool checkForInvalidAssignment(AssignmentExpression node) { |
| 5661 Expression lhs = node.leftHandSide; |
| 5662 Expression rhs = node.rightHandSide; |
| 5663 Type2 leftType = getType(lhs); |
| 5664 Type2 rightType = getType(rhs); |
| 5665 if (!rightType.isAssignableTo(leftType)) { |
| 5666 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs,
[leftType.name, rightType.name]); |
| 5667 return true; |
| 5668 } |
| 5669 return false; |
| 5366 } | 5670 } |
| 5367 /** | 5671 /** |
| 5368 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 5672 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 5369 * reported on the expression. | 5673 * reported on the expression. |
| 5674 * @param condition the conditional expression to test |
| 5675 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5370 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 5676 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
| 5371 * @param condition the conditional expression to test | 5677 */ |
| 5372 */ | 5678 bool checkForNonBoolCondition(Expression condition) { |
| 5373 void checkForNonBoolCondition(Expression condition) { | |
| 5374 Type2 conditionType = getType(condition); | 5679 Type2 conditionType = getType(condition); |
| 5375 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { | 5680 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { |
| 5376 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi
tion, []); | 5681 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi
tion, []); |
| 5377 } | 5682 return true; |
| 5683 } |
| 5684 return false; |
| 5685 } |
| 5686 /** |
| 5687 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. |
| 5688 * @param node the assert statement to evaluate |
| 5689 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5690 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION |
| 5691 */ |
| 5692 bool checkForNonBoolExpression(AssertStatement node) { |
| 5693 Expression expression = node.condition; |
| 5694 Type2 type = getType(expression); |
| 5695 if (type is InterfaceType) { |
| 5696 if (!type.isAssignableTo(_typeProvider.boolType)) { |
| 5697 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex
pression, []); |
| 5698 return true; |
| 5699 } |
| 5700 } else if (type is FunctionType) { |
| 5701 FunctionType functionType = type as FunctionType; |
| 5702 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { |
| 5703 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex
pression, []); |
| 5704 return true; |
| 5705 } |
| 5706 } |
| 5707 return false; |
| 5708 } |
| 5709 /** |
| 5710 * This checks that the return type matches the type of the declared return ty
pe in the enclosing |
| 5711 * method or function. |
| 5712 * @param node the return statement to evaluate |
| 5713 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5714 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
| 5715 */ |
| 5716 bool checkForReturnOfInvalidType(ReturnStatement node) { |
| 5717 FunctionType functionType = _currentFunction == null ? null : _currentFuncti
on.type; |
| 5718 Type2 expectedReturnType = functionType == null ? null : functionType.return
Type; |
| 5719 Expression returnExpression = node.expression; |
| 5720 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr
ession != null) { |
| 5721 Type2 actualReturnType = getType(returnExpression); |
| 5722 if (!actualReturnType.isAssignableTo(expectedReturnType)) { |
| 5723 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [actualReturnType.name, expectedReturnType.name]); |
| 5724 return true; |
| 5725 } |
| 5726 } |
| 5727 return false; |
| 5728 } |
| 5729 /** |
| 5730 * This verifies that the type arguments in the passed instance creation expre
ssion are all within |
| 5731 * their bounds as specified by the class element where the constructor [that
is being invoked] is |
| 5732 * declared. |
| 5733 * @param node the instance creation expression to evaluate |
| 5734 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to |
| 5735 * @param constructorElement the {@link ConstructorElement} from the instance
creation expression |
| 5736 * @return return <code>true</code> if and only if an error code is generated
on the passed node |
| 5737 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS |
| 5738 */ |
| 5739 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { |
| 5740 if (typeName.typeArguments != null && constructorElement != null) { |
| 5741 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; |
| 5742 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; |
| 5743 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); |
| 5744 for (int i = 0; i < loopThroughIndex; i++) { |
| 5745 TypeName argTypeName = typeNameArgList[i]; |
| 5746 Type2 argType = argTypeName.type; |
| 5747 Type2 boundType = boundingElts[i].bound; |
| 5748 if (argType != null && boundType != null) { |
| 5749 if (!argType.isSubtypeOf(boundType)) { |
| 5750 _errorReporter.reportError(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_M
ATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].name]); |
| 5751 return true; |
| 5752 } |
| 5753 } |
| 5754 } |
| 5755 } |
| 5756 return false; |
| 5378 } | 5757 } |
| 5379 /** | 5758 /** |
| 5380 * Return the type of the given expression that is to be used for type analysi
s. | 5759 * Return the type of the given expression that is to be used for type analysi
s. |
| 5381 * @param expression the expression whose type is to be returned | 5760 * @param expression the expression whose type is to be returned |
| 5382 * @return the type of the given expression | 5761 * @return the type of the given expression |
| 5383 */ | 5762 */ |
| 5384 Type2 getType(Expression expression) { | 5763 Type2 getType(Expression expression) { |
| 5385 Type2 type = expression.staticType; | 5764 Type2 type = expression.staticType; |
| 5386 return type == null ? _dynamicType : type; | 5765 return type == null ? _dynamicType : type; |
| 5387 } | 5766 } |
| 5388 } | 5767 } |
| 5389 /** | 5768 /** |
| 5390 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the | 5769 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the |
| 5391 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 5770 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
| 5392 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 5771 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 5393 * when appropriate, how the problem can be corrected. | 5772 * when appropriate, how the problem can be corrected. |
| 5773 * @coverage dart.engine.resolver |
| 5394 */ | 5774 */ |
| 5395 class ResolverErrorCode implements ErrorCode { | 5775 class ResolverErrorCode implements ErrorCode { |
| 5396 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); | 5776 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); |
| 5397 static final ResolverErrorCode CANNOT_BE_RESOLVED = new ResolverErrorCode('CAN
NOT_BE_RESOLVED', 1, ErrorType.STATIC_WARNING, "Cannot resolve the name '%s'"); | 5777 static final ResolverErrorCode CANNOT_BE_RESOLVED = new ResolverErrorCode('CAN
NOT_BE_RESOLVED', 1, ErrorType.STATIC_WARNING, "Cannot resolve the name '%s'"); |
| 5398 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 2, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); | 5778 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 2, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); |
| 5399 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 3, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); | 5779 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 3, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); |
| 5400 static final ResolverErrorCode MISSING_PART_OF_DIRECTIVE = new ResolverErrorCo
de('MISSING_PART_OF_DIRECTIVE', 4, ErrorType.COMPILE_TIME_ERROR, "The included p
art must have a part-of directive"); | 5780 static final ResolverErrorCode MISSING_PART_OF_DIRECTIVE = new ResolverErrorCo
de('MISSING_PART_OF_DIRECTIVE', 4, ErrorType.COMPILE_TIME_ERROR, "The included p
art must have a part-of directive"); |
| 5401 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ANNOT_BE_RESOLVED, CONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART
, MISSING_PART_OF_DIRECTIVE]; | 5781 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ANNOT_BE_RESOLVED, CONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART
, MISSING_PART_OF_DIRECTIVE]; |
| 5402 final String __name; | 5782 final String __name; |
| 5403 final int __ordinal; | 5783 final int __ordinal; |
| 5784 int get ordinal => __ordinal; |
| 5404 /** | 5785 /** |
| 5405 * The type of this error. | 5786 * The type of this error. |
| 5406 */ | 5787 */ |
| 5407 ErrorType _type; | 5788 ErrorType _type; |
| 5408 /** | 5789 /** |
| 5409 * The message template used to create the message to be displayed for this er
ror. | 5790 * The message template used to create the message to be displayed for this er
ror. |
| 5410 */ | 5791 */ |
| 5411 String _message; | 5792 String _message; |
| 5412 /** | 5793 /** |
| 5413 * Initialize a newly created error code to have the given type and message. | 5794 * Initialize a newly created error code to have the given type and message. |
| 5414 * @param type the type of this error | 5795 * @param type the type of this error |
| 5415 * @param message the message template used to create the message to be displa
yed for the error | 5796 * @param message the message template used to create the message to be displa
yed for the error |
| 5416 */ | 5797 */ |
| 5417 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message)
{ | 5798 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message)
{ |
| 5418 this._type = type; | 5799 this._type = type; |
| 5419 this._message = message; | 5800 this._message = message; |
| 5420 } | 5801 } |
| 5421 ErrorSeverity get errorSeverity => _type.severity; | 5802 ErrorSeverity get errorSeverity => _type.severity; |
| 5422 String get message => _message; | 5803 String get message => _message; |
| 5423 ErrorType get type => _type; | 5804 ErrorType get type => _type; |
| 5424 bool needsRecompilation() => true; | 5805 bool needsRecompilation() => true; |
| 5425 String toString() => __name; | 5806 String toString() => __name; |
| 5426 } | 5807 } |
| OLD | NEW |