Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('dart:uri'); | 7 #import('dart:uri'); |
| 8 | 8 |
| 9 #import('../tree/tree.dart'); | 9 #import('../tree/tree.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 10 #import('../scanner/scannerlib.dart'); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 bool isNative() => _isNative; | 288 bool isNative() => _isNative; |
| 289 | 289 |
| 290 FunctionElement asFunctionElement() => null; | 290 FunctionElement asFunctionElement() => null; |
| 291 | 291 |
| 292 Element cloneTo(Element enclosing, DiagnosticListener listener) { | 292 Element cloneTo(Element enclosing, DiagnosticListener listener) { |
| 293 listener.cancel("Unimplemented cloneTo", element: this); | 293 listener.cancel("Unimplemented cloneTo", element: this); |
| 294 } | 294 } |
| 295 | 295 |
| 296 bool get isPatched => false; | 296 bool get isPatched => false; |
| 297 | 297 |
| 298 static bool isInvalid(Element e) => e == null || e.isErroneous(); | 298 static bool isUnresolved(Element e) => e == null || e.isErroneous(); |
| 299 static bool isErroneousElement(Element e) => e != null && e.isErroneous(); | |
|
ngeoffray
2012/09/07 08:12:46
Why aren't these methods on Element*s* class?
karlklose
2012/09/07 09:24:01
Done, moved. I thought it reads better, but it is
| |
| 299 } | 300 } |
| 300 | 301 |
| 301 /** | 302 /** |
| 302 * Represents an unresolvable or duplicated element. | 303 * Represents an unresolvable or duplicated element. |
| 303 * | 304 * |
| 304 * An [ErroneousElement] is used instead of [null] to provide additional | 305 * An [ErroneousElement] is used instead of [null] to provide additional |
| 305 * information about the error that caused the element to be unresolvable | 306 * information about the error that caused the element to be unresolvable |
| 306 * or otherwise invalid. | 307 * or otherwise invalid. |
| 307 * | 308 * |
| 308 * Accessing any field or calling any method defined on [ErroneousElement] | 309 * Accessing any field or calling any method defined on [ErroneousElement] |
| 309 * except [isErroneous] will currently throw an exception. (This might | 310 * except [isErroneous] will currently throw an exception. (This might |
| 310 * change when we actually want more information on the erroneous element, | 311 * change when we actually want more information on the erroneous element, |
| 311 * e.g., the name of the element we were trying to resolve.) | 312 * e.g., the name of the element we were trying to resolve.) |
| 312 * | 313 * |
| 313 * Code that cannot not handle an [ErroneousElement] should use | 314 * Code that cannot not handle an [ErroneousElement] should use |
| 314 * [: Element.isInvalid(element) :] | 315 * [: Element.isInvalid(element) :] |
| 315 * to check for unresolvable elements instead of | 316 * to check for unresolvable elements instead of |
| 316 * [: element == null :]. | 317 * [: element == null :]. |
| 317 */ | 318 */ |
| 318 class ErroneousElement extends Element { | 319 class ErroneousElement extends Element { |
| 319 final Message errorMessage; | 320 final Message errorMessage; |
| 321 final SourceString targetName; | |
| 320 | 322 |
| 321 ErroneousElement(this.errorMessage, Element enclosing) | 323 ErroneousElement(this.errorMessage, this.targetName, Element enclosing) |
| 322 : super(const SourceString('erroneous element'), null, enclosing); | 324 : super(const SourceString('erroneous element'), null, enclosing); |
| 323 | 325 |
| 324 isErroneous() => true; | 326 isErroneous() => true; |
| 325 | 327 |
| 326 unsupported() { | 328 unsupported() { |
| 327 throw 'unsupported operation on erroneous element'; | 329 throw 'unsupported operation on erroneous element'; |
| 328 } | 330 } |
| 329 | 331 |
| 330 SourceString get name => unsupported(); | 332 SourceString get name => unsupported(); |
| 331 ElementKind get kind => unsupported(); | 333 ElementKind get kind => unsupported(); |
| 332 Link<MetadataAnnotation> get metadata => unsupported(); | 334 Link<MetadataAnnotation> get metadata => unsupported(); |
| 335 | |
| 336 getLibrary() => enclosingElement.getLibrary(); | |
| 333 } | 337 } |
| 334 | 338 |
| 335 class ErroneousFunctionElement extends ErroneousElement | 339 class ErroneousFunctionElement extends ErroneousElement |
| 336 implements FunctionElement { | 340 implements FunctionElement { |
| 337 ErroneousFunctionElement(errorMessage, Element enclosing) | 341 ErroneousFunctionElement(Message errorMessage, SourceString targetName, |
| 338 : super(errorMessage, enclosing); | 342 Element enclosing) |
| 343 : super(errorMessage, targetName, enclosing); | |
| 339 | 344 |
| 340 get type => unsupported(); | 345 get type => unsupported(); |
| 341 get cachedNode => unsupported(); | 346 get cachedNode => unsupported(); |
| 342 get functionSignature => unsupported(); | 347 get functionSignature => unsupported(); |
| 343 get patch => unsupported(); | 348 get patch => unsupported(); |
| 344 get defaultImplementation => unsupported(); | 349 get defaultImplementation => unsupported(); |
| 345 bool get isPatched => unsupported(); | 350 bool get isPatched => unsupported(); |
| 346 setPatch(patch) => unsupported(); | 351 setPatch(patch) => unsupported(); |
| 347 computeSignature(compiler) => unsupported(); | 352 computeSignature(compiler) => unsupported(); |
| 348 requiredParameterCount(compiler) => unsupported(); | 353 requiredParameterCount(compiler) => unsupported(); |
| 349 optionalParameterCount(compiler) => unsupported(); | 354 optionalParameterCount(compiler) => unsupported(); |
| 350 parameterCount(copmiler) => unsupported(); | 355 parameterCount(copmiler) => unsupported(); |
| 351 | |
| 352 getLibrary() => enclosingElement.getLibrary(); | |
| 353 } | 356 } |
| 354 | 357 |
| 355 class ContainerElement extends Element { | 358 class ContainerElement extends Element { |
| 356 Link<Element> localMembers = const EmptyLink<Element>(); | 359 Link<Element> localMembers = const EmptyLink<Element>(); |
| 357 | 360 |
| 358 ContainerElement(name, kind, enclosingElement) | 361 ContainerElement(name, kind, enclosingElement) |
| 359 : super(name, kind, enclosingElement); | 362 : super(name, kind, enclosingElement); |
| 360 | 363 |
| 361 void addMember(Element element, DiagnosticListener listener) { | 364 void addMember(Element element, DiagnosticListener listener) { |
| 362 localMembers = localMembers.prepend(element); | 365 localMembers = localMembers.prepend(element); |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 listener.internalErrorOnElement(this, 'unsupported operation'); | 1382 listener.internalErrorOnElement(this, 'unsupported operation'); |
| 1380 } | 1383 } |
| 1381 | 1384 |
| 1382 Link<DartType> get allSupertypesAndSelf { | 1385 Link<DartType> get allSupertypesAndSelf { |
| 1383 return allSupertypes.prepend(new InterfaceType(this)); | 1386 return allSupertypes.prepend(new InterfaceType(this)); |
| 1384 } | 1387 } |
| 1385 } | 1388 } |
| 1386 | 1389 |
| 1387 class Elements { | 1390 class Elements { |
| 1388 static bool isLocal(Element element) { | 1391 static bool isLocal(Element element) { |
| 1389 return !Element.isInvalid(element) | 1392 return !Element.isUnresolved(element) |
| 1390 && !element.isInstanceMember() | 1393 && !element.isInstanceMember() |
| 1391 && !isStaticOrTopLevelField(element) | 1394 && !isStaticOrTopLevelField(element) |
| 1392 && !isStaticOrTopLevelFunction(element) | 1395 && !isStaticOrTopLevelFunction(element) |
| 1393 && (element.kind === ElementKind.VARIABLE || | 1396 && (element.kind === ElementKind.VARIABLE || |
| 1394 element.kind === ElementKind.PARAMETER || | 1397 element.kind === ElementKind.PARAMETER || |
| 1395 element.kind === ElementKind.FUNCTION); | 1398 element.kind === ElementKind.FUNCTION); |
| 1396 } | 1399 } |
| 1397 | 1400 |
| 1398 static bool isInstanceField(Element element) { | 1401 static bool isInstanceField(Element element) { |
| 1399 return !Element.isInvalid(element) | 1402 return !Element.isUnresolved(element) |
| 1400 && element.isInstanceMember() | 1403 && element.isInstanceMember() |
| 1401 && (element.kind === ElementKind.FIELD | 1404 && (element.kind === ElementKind.FIELD |
| 1402 || element.kind === ElementKind.GETTER | 1405 || element.kind === ElementKind.GETTER |
| 1403 || element.kind === ElementKind.SETTER); | 1406 || element.kind === ElementKind.SETTER); |
| 1404 } | 1407 } |
| 1405 | 1408 |
| 1406 static bool isStaticOrTopLevel(Element element) { | 1409 static bool isStaticOrTopLevel(Element element) { |
| 1407 // TODO(ager): This should not be necessary when patch support has | 1410 // TODO(ager): This should not be necessary when patch support has |
| 1408 // been reworked. | 1411 // been reworked. |
| 1409 if (!Element.isInvalid(element) | 1412 if (!Element.isUnresolved(element) |
| 1410 && element.modifiers != null | 1413 && element.modifiers != null |
| 1411 && element.modifiers.isStatic()) { | 1414 && element.modifiers.isStatic()) { |
| 1412 return true; | 1415 return true; |
| 1413 } | 1416 } |
| 1414 return !Element.isInvalid(element) | 1417 return !Element.isUnresolved(element) |
| 1415 && !element.isInstanceMember() | 1418 && !element.isInstanceMember() |
| 1416 && !element.isPrefix() | 1419 && !element.isPrefix() |
| 1417 && element.enclosingElement !== null | 1420 && element.enclosingElement !== null |
| 1418 && (element.enclosingElement.kind == ElementKind.CLASS || | 1421 && (element.enclosingElement.kind == ElementKind.CLASS || |
| 1419 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || | 1422 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || |
| 1420 element.enclosingElement.kind == ElementKind.LIBRARY); | 1423 element.enclosingElement.kind == ElementKind.LIBRARY); |
| 1421 } | 1424 } |
| 1422 | 1425 |
| 1423 static bool isStaticOrTopLevelField(Element element) { | 1426 static bool isStaticOrTopLevelField(Element element) { |
| 1424 return isStaticOrTopLevel(element) | 1427 return isStaticOrTopLevel(element) |
| 1425 && (element.kind === ElementKind.FIELD | 1428 && (element.kind === ElementKind.FIELD |
| 1426 || element.kind === ElementKind.GETTER | 1429 || element.kind === ElementKind.GETTER |
| 1427 || element.kind === ElementKind.SETTER); | 1430 || element.kind === ElementKind.SETTER); |
| 1428 } | 1431 } |
| 1429 | 1432 |
| 1430 static bool isStaticOrTopLevelFunction(Element element) { | 1433 static bool isStaticOrTopLevelFunction(Element element) { |
| 1431 return isStaticOrTopLevel(element) | 1434 return isStaticOrTopLevel(element) |
| 1432 && (element.kind === ElementKind.FUNCTION); | 1435 && (element.kind === ElementKind.FUNCTION); |
| 1433 } | 1436 } |
| 1434 | 1437 |
| 1435 static bool isInstanceMethod(Element element) { | 1438 static bool isInstanceMethod(Element element) { |
| 1436 return !Element.isInvalid(element) | 1439 return !Element.isUnresolved(element) |
| 1437 && element.isInstanceMember() | 1440 && element.isInstanceMember() |
| 1438 && (element.kind === ElementKind.FUNCTION); | 1441 && (element.kind === ElementKind.FUNCTION); |
| 1439 } | 1442 } |
| 1440 | 1443 |
| 1441 static bool isInstanceSend(Send send, TreeElements elements) { | 1444 static bool isInstanceSend(Send send, TreeElements elements) { |
| 1442 Element element = elements[send]; | 1445 Element element = elements[send]; |
| 1443 if (element === null) return !isClosureSend(send, element); | 1446 if (element === null) return !isClosureSend(send, element); |
| 1444 return isInstanceMethod(element) || isInstanceField(element); | 1447 return isInstanceMethod(element) || isInstanceField(element); |
| 1445 } | 1448 } |
| 1446 | 1449 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 | 1655 |
| 1653 MetadataAnnotation ensureResolved(Compiler compiler) { | 1656 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1654 if (resolutionState == STATE_NOT_STARTED) { | 1657 if (resolutionState == STATE_NOT_STARTED) { |
| 1655 compiler.resolver.resolveMetadataAnnotation(this); | 1658 compiler.resolver.resolveMetadataAnnotation(this); |
| 1656 } | 1659 } |
| 1657 return this; | 1660 return this; |
| 1658 } | 1661 } |
| 1659 | 1662 |
| 1660 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1663 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1661 } | 1664 } |
| OLD | NEW |