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

Unified Diff: lib/compiler/implementation/compile_time_constants.dart

Issue 10872059: Static and top-level methods can be compile time constants. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/compile_time_constants.dart
===================================================================
--- lib/compiler/implementation/compile_time_constants.dart (revision 11378)
+++ lib/compiler/implementation/compile_time_constants.dart (working copy)
@@ -16,6 +16,7 @@
bool isList() => false;
bool isMap() => false;
bool isConstructedObject() => false;
+ bool isFunction() => false;
/** Returns true if the constant is null, a bool, a number or a string. */
bool isPrimitive() => false;
/** Returns true if the constant is a list, a map or a constructed object. */
@@ -33,6 +34,31 @@
abstract List<Constant> getDependencies();
}
+class FunctionConstant extends Constant{
kasperl 2012/08/27 13:17:26 Space between Constant and {.
ngeoffray 2012/08/27 14:09:09 Done.
+ Element element;
+
+ FunctionConstant(this.element);
+
+ bool isFunction() => true;
+
+ bool operator ==(var other) {
+ if (other is !FunctionConstant) return false;
+ return other.element === element;
+ }
+
+ String toString() => element.toString();
+ List<Constant> getDependencies() => const <Constant>[];
+ DartString toDartString() {
+ return new DartString.literal(element.name.slowToString());
+ }
+
+ void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) {
kasperl 2012/08/27 13:17:26 Don't you need to also provide an implementation o
ngeoffray 2012/08/27 14:09:09 Yes, but it will never be called because there's n
+ buffer.add(handler.compiler.namer.isolatePropertiesAccess(element));
+ }
+
+ int hashCode() => element.hashCode();
+}
+
class PrimitiveConstant extends Constant {
abstract get value;
const PrimitiveConstant();
@@ -844,6 +870,10 @@
error(send);
}
return compiler.compileVariable(element);
+ } else if (Elements.isStaticOrTopLevelFunction(element)
+ && send.isPropertyAccess) {
+ compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
kasperl 2012/08/27 13:17:26 Could this registration happen later in the codege
ngeoffray 2012/08/27 14:09:09 It has to be done here, the codegen only handles u
+ return new FunctionConstant(element);
} else if (send.isPrefix) {
assert(send.isOperator);
Constant receiverConstant = evaluate(send.receiver);
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/codegen.dart » ('j') | lib/compiler/implementation/ssa/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698