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); |