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

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
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,36 @@
abstract List<Constant> getDependencies();
}
+class FunctionConstant extends Constant {
+ 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 _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
+ compiler.internalError(
+ "A constant function does not need specific JS code");
+ }
+
+ void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) {
+ buffer.add(handler.compiler.namer.isolatePropertiesAccess(element));
+ }
+
+ int hashCode() => element.hashCode();
ahe 2012/08/28 13:35:54 You should make sure that FunctionConstant has a d
+}
+
class PrimitiveConstant extends Constant {
abstract get value;
const PrimitiveConstant();
@@ -499,7 +530,10 @@
String get name => 'ConstantHandler';
void registerCompileTimeConstant(Constant constant) {
- Function ifAbsentThunk = (() => compiler.namer.getFreshGlobalName("CTC"));
+ Function ifAbsentThunk = (() {
+ return constant.isFunction()
+ ? null : compiler.namer.getFreshGlobalName("CTC");
+ });
compiledConstants.putIfAbsent(constant, ifAbsentThunk);
}
@@ -844,6 +878,12 @@
error(send);
}
return compiler.compileVariable(element);
+ } else if (Elements.isStaticOrTopLevelFunction(element)
+ && send.isPropertyAccess) {
+ compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
+ Constant constant = new FunctionConstant(element);
+ compiler.constantHandler.registerCompileTimeConstant(constant);
+ return constant;
} 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698