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

Side by Side Diff: pkg/compiler/lib/src/tree/nodes.dart

Issue 2876813002: Implement generalized function types. (Closed)
Patch Set: Address comments. Created 3 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
OLDNEW
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 import 'dart:collection' show IterableMixin; 5 import 'dart:collection' show IterableMixin;
6 6
7 import 'package:front_end/src/fasta/fasta_codes.dart' show FastaMessage; 7 import 'package:front_end/src/fasta/fasta_codes.dart' show FastaMessage;
8 import 'package:front_end/src/fasta/scanner.dart' show BeginGroupToken, Token; 8 import 'package:front_end/src/fasta/scanner.dart' show BeginGroupToken, Token;
9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as Tokens 9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as Tokens
10 show PLUS_TOKEN; 10 show PLUS_TOKEN;
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 /** Bit pattern to easy check what modifiers are present. */ 1970 /** Bit pattern to easy check what modifiers are present. */
1971 final int flags; 1971 final int flags;
1972 1972
1973 static const int FLAG_STATIC = 1; 1973 static const int FLAG_STATIC = 1;
1974 static const int FLAG_ABSTRACT = FLAG_STATIC << 1; 1974 static const int FLAG_ABSTRACT = FLAG_STATIC << 1;
1975 static const int FLAG_FINAL = FLAG_ABSTRACT << 1; 1975 static const int FLAG_FINAL = FLAG_ABSTRACT << 1;
1976 static const int FLAG_VAR = FLAG_FINAL << 1; 1976 static const int FLAG_VAR = FLAG_FINAL << 1;
1977 static const int FLAG_CONST = FLAG_VAR << 1; 1977 static const int FLAG_CONST = FLAG_VAR << 1;
1978 static const int FLAG_FACTORY = FLAG_CONST << 1; 1978 static const int FLAG_FACTORY = FLAG_CONST << 1;
1979 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1; 1979 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1;
1980 static const int FLAG_COVARIANT = FLAG_EXTERNAL << 1;
1980 1981
1981 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); 1982 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes));
1982 1983
1983 Modifiers.withFlags(this.nodes, this.flags); 1984 Modifiers.withFlags(this.nodes, this.flags);
1984 1985
1985 static int computeFlags(Link<Node> nodes) { 1986 static int computeFlags(Link<Node> nodes) {
1986 int flags = 0; 1987 int flags = 0;
1987 for (; !nodes.isEmpty; nodes = nodes.tail) { 1988 for (; !nodes.isEmpty; nodes = nodes.tail) {
1988 String value = nodes.head.asIdentifier().source; 1989 String value = nodes.head.asIdentifier().source;
1989 if (identical(value, 'static')) 1990 if (identical(value, 'static'))
1990 flags |= FLAG_STATIC; 1991 flags |= FLAG_STATIC;
1991 else if (identical(value, 'abstract')) 1992 else if (identical(value, 'abstract'))
1992 flags |= FLAG_ABSTRACT; 1993 flags |= FLAG_ABSTRACT;
1993 else if (identical(value, 'final')) 1994 else if (identical(value, 'final'))
1994 flags |= FLAG_FINAL; 1995 flags |= FLAG_FINAL;
1995 else if (identical(value, 'var')) 1996 else if (identical(value, 'var'))
1996 flags |= FLAG_VAR; 1997 flags |= FLAG_VAR;
1997 else if (identical(value, 'const')) 1998 else if (identical(value, 'const'))
1998 flags |= FLAG_CONST; 1999 flags |= FLAG_CONST;
1999 else if (identical(value, 'factory')) 2000 else if (identical(value, 'factory'))
2000 flags |= FLAG_FACTORY; 2001 flags |= FLAG_FACTORY;
2001 else if (identical(value, 'external')) 2002 else if (identical(value, 'external'))
2002 flags |= FLAG_EXTERNAL; 2003 flags |= FLAG_EXTERNAL;
2004 else if (identical(value, 'covariant'))
2005 flags |= FLAG_COVARIANT;
2003 else 2006 else
2004 throw 'internal error: ${nodes.head}'; 2007 throw 'internal error: ${nodes.head}';
2005 } 2008 }
2006 return flags; 2009 return flags;
2007 } 2010 }
2008 2011
2009 Node findModifier(String modifier) { 2012 Node findModifier(String modifier) {
2010 Link<Node> nodeList = nodes.nodes; 2013 Link<Node> nodeList = nodes.nodes;
2011 for (; !nodeList.isEmpty; nodeList = nodeList.tail) { 2014 for (; !nodeList.isEmpty; nodeList = nodeList.tail) {
2012 String value = nodeList.head.asIdentifier().source; 2015 String value = nodeList.head.asIdentifier().source;
(...skipping 16 matching lines...) Expand all
2029 2032
2030 visitChildren1(Visitor1 visitor, arg) => nodes.accept1(visitor, arg); 2033 visitChildren1(Visitor1 visitor, arg) => nodes.accept1(visitor, arg);
2031 2034
2032 bool get isStatic => (flags & FLAG_STATIC) != 0; 2035 bool get isStatic => (flags & FLAG_STATIC) != 0;
2033 bool get isAbstract => (flags & FLAG_ABSTRACT) != 0; 2036 bool get isAbstract => (flags & FLAG_ABSTRACT) != 0;
2034 bool get isFinal => (flags & FLAG_FINAL) != 0; 2037 bool get isFinal => (flags & FLAG_FINAL) != 0;
2035 bool get isVar => (flags & FLAG_VAR) != 0; 2038 bool get isVar => (flags & FLAG_VAR) != 0;
2036 bool get isConst => (flags & FLAG_CONST) != 0; 2039 bool get isConst => (flags & FLAG_CONST) != 0;
2037 bool get isFactory => (flags & FLAG_FACTORY) != 0; 2040 bool get isFactory => (flags & FLAG_FACTORY) != 0;
2038 bool get isExternal => (flags & FLAG_EXTERNAL) != 0; 2041 bool get isExternal => (flags & FLAG_EXTERNAL) != 0;
2042 bool get isCovariant => (flags & FLAG_COVARIANT) != 0;
2039 2043
2040 Node getStatic() => findModifier('static'); 2044 Node getStatic() => findModifier('static');
2041 2045
2042 /** 2046 /**
2043 * Use this to check if the declaration is either explicitly or implicitly 2047 * Use this to check if the declaration is either explicitly or implicitly
2044 * final. 2048 * final.
2045 */ 2049 */
2046 bool get isFinalOrConst => isFinal || isConst; 2050 bool get isFinalOrConst => isFinal || isConst;
2047 2051
2048 String toString() { 2052 String toString() {
2049 return modifiersToString( 2053 return modifiersToString(
2050 isStatic: isStatic, 2054 isStatic: isStatic,
2051 isAbstract: isAbstract, 2055 isAbstract: isAbstract,
2052 isFinal: isFinal, 2056 isFinal: isFinal,
2053 isVar: isVar, 2057 isVar: isVar,
2054 isConst: isConst, 2058 isConst: isConst,
2055 isFactory: isFactory, 2059 isFactory: isFactory,
2056 isExternal: isExternal); 2060 isExternal: isExternal,
2061 isCovariant: isCovariant);
2057 } 2062 }
2058 } 2063 }
2059 2064
2060 class StringInterpolation extends StringNode { 2065 class StringInterpolation extends StringNode {
2061 final LiteralString string; 2066 final LiteralString string;
2062 final NodeList parts; 2067 final NodeList parts;
2063 2068
2064 StringInterpolation(this.string, this.parts); 2069 StringInterpolation(this.string, this.parts);
2065 2070
2066 StringInterpolation asStringInterpolation() => this; 2071 StringInterpolation asStringInterpolation() => this;
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 */ 3283 */
3279 Object getTreeElement(TreeElementMixin node) => node._element; 3284 Object getTreeElement(TreeElementMixin node) => node._element;
3280 3285
3281 /** 3286 /**
3282 * Do not call this method directly. Instead, use an instance of 3287 * Do not call this method directly. Instead, use an instance of
3283 * TreeElements. 3288 * TreeElements.
3284 */ 3289 */
3285 void setTreeElement(TreeElementMixin node, Object value) { 3290 void setTreeElement(TreeElementMixin node, Object value) {
3286 node._element = value; 3291 node._element = value;
3287 } 3292 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/resolved_ast_serialization.dart ('k') | pkg/compiler/lib/src/util/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698