Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1927963002: Support compilation of Hello World (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.modelx; 5 library elements.modelx;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart' show Resolution, ParsingContext; 8 import '../common/resolution.dart' show Resolution, ParsingContext;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constant_constructors.dart'; 10 import '../constants/constant_constructors.dart';
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 bool get isLocal => false; 102 bool get isLocal => false;
103 103
104 // TODO(johnniwinther): This breaks for libraries (for which enclosing 104 // TODO(johnniwinther): This breaks for libraries (for which enclosing
105 // elements are null) and is invalid for top level variable declarations for 105 // elements are null) and is invalid for top level variable declarations for
106 // which the enclosing element is a VariableDeclarations and not a compilation 106 // which the enclosing element is a VariableDeclarations and not a compilation
107 // unit. 107 // unit.
108 bool get isTopLevel { 108 bool get isTopLevel {
109 return enclosingElement != null && enclosingElement.isCompilationUnit; 109 return enclosingElement != null && enclosingElement.isCompilationUnit;
110 } 110 }
111 111
112 @override
113 int get sourceOffset => position?.charOffset;
114
112 Token get position => null; 115 Token get position => null;
113 116
114 SourceSpan get sourcePosition { 117 SourceSpan get sourcePosition {
115 if (position == null) return null; 118 if (position == null) return null;
116 Uri uri = compilationUnit.script.resourceUri; 119 Uri uri = compilationUnit.script.resourceUri;
117 return new SourceSpan( 120 return new SourceSpan(uri, position.charOffset, position.charEnd);
118 uri, position.charOffset, position.charOffset + position.charCount);
119 } 121 }
120 122
121 Token findMyName(Token token) { 123 Token findMyName(Token token) {
122 return findNameToken(token, isConstructor, name, enclosingElement.name); 124 return findNameToken(token, isConstructor, name, enclosingElement.name);
123 } 125 }
124 126
125 static Token findNameToken( 127 static Token findNameToken(
126 Token token, bool isConstructor, String name, String enclosingClassName) { 128 Token token, bool isConstructor, String name, String enclosingClassName) {
127 // We search for the token that has the name of this element. 129 // We search for the token that has the name of this element.
128 // For constructors, that doesn't work because they may have 130 // For constructors, that doesn't work because they may have
(...skipping 28 matching lines...) Expand all
157 return element; 159 return element;
158 } 160 }
159 161
160 ClassElement get enclosingClass { 162 ClassElement get enclosingClass {
161 for (Element e = this; e != null; e = e.enclosingElement) { 163 for (Element e = this; e != null; e = e.enclosingElement) {
162 if (e.isClass) return e; 164 if (e.isClass) return e;
163 } 165 }
164 return null; 166 return null;
165 } 167 }
166 168
167 Element get enclosingClassOrCompilationUnit {
168 for (Element e = this; e != null; e = e.enclosingElement) {
169 if (e.isClass || e.isCompilationUnit) return e;
170 }
171 return null;
172 }
173
174 /** 169 /**
175 * Creates the scope for this element. 170 * Creates the scope for this element.
176 */ 171 */
177 Scope buildScope() => enclosingElement.buildScope(); 172 Scope buildScope() => enclosingElement.buildScope();
178 173
179 String toString() { 174 String toString() {
180 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an 175 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an
181 // invariant for all element types? 176 // invariant for all element types?
182 var nameText = name != null ? name : '?'; 177 var nameText = name != null ? name : '?';
183 if (enclosingElement != null && !isTopLevel) { 178 if (enclosingElement != null && !isTopLevel) {
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 implements ClassElement { 2475 implements ClassElement {
2481 final int id; 2476 final int id;
2482 2477
2483 DartType supertype; 2478 DartType supertype;
2484 Link<DartType> interfaces; 2479 Link<DartType> interfaces;
2485 int supertypeLoadState; 2480 int supertypeLoadState;
2486 int resolutionState; 2481 int resolutionState;
2487 bool isProxy = false; 2482 bool isProxy = false;
2488 bool hasIncompleteHierarchy = false; 2483 bool hasIncompleteHierarchy = false;
2489 2484
2490 // backendMembers are members that have been added by the backend to simplify
2491 // compilation. They don't have any user-side counter-part.
2492 Link<Element> backendMembers = const Link<Element>();
2493
2494 OrderedTypeSet allSupertypesAndSelf; 2485 OrderedTypeSet allSupertypesAndSelf;
2495 2486
2496 BaseClassElementX(String name, Element enclosing, this.id, int initialState) 2487 BaseClassElementX(String name, Element enclosing, this.id, int initialState)
2497 : supertypeLoadState = initialState, 2488 : supertypeLoadState = initialState,
2498 resolutionState = initialState, 2489 resolutionState = initialState,
2499 super(name, ElementKind.CLASS, enclosing); 2490 super(name, ElementKind.CLASS, enclosing);
2500 2491
2501 int get hashCode => id; 2492 int get hashCode => id;
2502 2493
2503 bool get hasBackendMembers => !backendMembers.isEmpty;
2504
2505 bool get isUnnamedMixinApplication => false; 2494 bool get isUnnamedMixinApplication => false;
2506 2495
2507 @override 2496 @override
2508 bool get isEnumClass => false; 2497 bool get isEnumClass => false;
2509 2498
2510 InterfaceType computeType(Resolution resolution) { 2499 InterfaceType computeType(Resolution resolution) {
2511 if (isPatch) { 2500 if (isPatch) {
2512 origin.computeType(resolution); 2501 origin.computeType(resolution);
2513 thisTypeCache = origin.thisType; 2502 thisTypeCache = origin.thisType;
2514 rawTypeCache = origin.rawType; 2503 rawTypeCache = origin.rawType;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 void ensureResolved(Resolution resolution) { 2536 void ensureResolved(Resolution resolution) {
2548 if (resolutionState == STATE_NOT_STARTED) { 2537 if (resolutionState == STATE_NOT_STARTED) {
2549 resolution.resolveClass(this); 2538 resolution.resolveClass(this);
2550 resolution.registerClass(this); 2539 resolution.registerClass(this);
2551 } 2540 }
2552 } 2541 }
2553 2542
2554 void setDefaultConstructor( 2543 void setDefaultConstructor(
2555 FunctionElement constructor, DiagnosticReporter reporter); 2544 FunctionElement constructor, DiagnosticReporter reporter);
2556 2545
2557 void addBackendMember(Element member) {
2558 // TODO(ngeoffray): Deprecate this method.
2559 assert(member.isGenerativeConstructorBody);
2560 backendMembers = backendMembers.prepend(member);
2561 }
2562
2563 void reverseBackendMembers() {
2564 backendMembers = backendMembers.reverse();
2565 }
2566
2567 /// Lookup a synthetic element created by the backend.
2568 Element lookupBackendMember(String memberName) {
2569 for (Element element in backendMembers) {
2570 if (element.name == memberName) {
2571 return element;
2572 }
2573 }
2574 return null;
2575 }
2576
2577 ConstructorElement lookupDefaultConstructor() { 2546 ConstructorElement lookupDefaultConstructor() {
2578 ConstructorElement constructor = lookupConstructor(""); 2547 ConstructorElement constructor = lookupConstructor("");
2579 // This method might be called on constructors that have not been 2548 // This method might be called on constructors that have not been
2580 // resolved. As we query the live world, we return `null` in such cases 2549 // resolved. As we query the live world, we return `null` in such cases
2581 // as no default constructor exists in the live world. 2550 // as no default constructor exists in the live world.
2582 if (constructor != null && 2551 if (constructor != null &&
2583 constructor.hasFunctionSignature && 2552 constructor.hasFunctionSignature &&
2584 constructor.functionSignature.requiredParameterCount == 0) { 2553 constructor.functionSignature.requiredParameterCount == 0) {
2585 return constructor; 2554 return constructor;
2586 } 2555 }
2587 return null; 2556 return null;
2588 } 2557 }
2589 2558
2590 /** 2559 /**
2591 * Returns the super class, if any. 2560 * Returns the super class, if any.
2592 * 2561 *
2593 * The returned element may not be resolved yet. 2562 * The returned element may not be resolved yet.
2594 */ 2563 */
2595 ClassElement get superclass { 2564 ClassElement get superclass {
2596 assert(invariant(this, supertypeLoadState == STATE_DONE, 2565 assert(invariant(this, supertypeLoadState == STATE_DONE,
2597 message: "Superclass has not been computed for $this.")); 2566 message: "Superclass has not been computed for $this."));
2598 return supertype == null ? null : supertype.element; 2567 return supertype == null ? null : supertype.element;
2599 } 2568 }
2600 2569
2601 void forEachBackendMember(void f(Element member)) {
2602 backendMembers.forEach(f);
2603 }
2604
2605 // TODO(johnniwinther): Remove these when issue 18630 is fixed. 2570 // TODO(johnniwinther): Remove these when issue 18630 is fixed.
2606 ClassElement get patch => super.patch; 2571 ClassElement get patch => super.patch;
2607 ClassElement get origin => super.origin; 2572 ClassElement get origin => super.origin;
2608 2573
2609 // A class declaration is defined by the declaration element. 2574 // A class declaration is defined by the declaration element.
2610 AstElement get definingElement => declaration; 2575 AstElement get definingElement => declaration;
2611 } 2576 }
2612 2577
2613 abstract class ClassElementX extends BaseClassElementX { 2578 abstract class ClassElementX extends BaseClassElementX {
2614 Link<Element> localMembersReversed = const Link<Element>(); 2579 Link<Element> localMembersReversed = const Link<Element>();
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
3274 if (definingElement.isField) { 3239 if (definingElement.isField) {
3275 FieldElement field = definingElement; 3240 FieldElement field = definingElement;
3276 body = field.initializer; 3241 body = field.initializer;
3277 } else if (node != null && node.asFunctionExpression() != null) { 3242 } else if (node != null && node.asFunctionExpression() != null) {
3278 body = node.asFunctionExpression().body; 3243 body = node.asFunctionExpression().body;
3279 } 3244 }
3280 return new ParsedResolvedAst( 3245 return new ParsedResolvedAst(
3281 declaration, node, body, definingElement.treeElements); 3246 declaration, node, body, definingElement.treeElements);
3282 } 3247 }
3283 } 3248 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698