Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/elements/modelx.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/elements/modelx.dart b/sdk/lib/_internal/compiler/implementation/elements/modelx.dart |
| index b53316feecc2636131146928b347db145baaafb3..81c5ef5ec30d6eeb9e054afdb72d4322c3648782 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/elements/modelx.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/elements/modelx.dart |
| @@ -23,7 +23,8 @@ import '../dart2jslib.dart' show invariant, |
| Selector, |
| Constant, |
| Compiler, |
| - isPrivateName; |
| + isPrivateName, |
| + CodeBuffer; |
|
ahe
2013/11/27 19:28:53
This import doesn't belong here.
sigurdm
2013/11/29 10:39:37
Done.
|
| import '../dart_types.dart'; |
| @@ -293,6 +294,11 @@ class ElementX implements Element { |
| FunctionElement get targetConstructor => null; |
| void diagnose(Element context, DiagnosticListener listener) {} |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
| + compiler.internalError("This element does not support dumping of types", |
| + token: position()); |
| + } |
| } |
| /** |
| @@ -994,6 +1000,30 @@ class LibraryElementX extends ElementX implements LibraryElement { |
| if (this == other) return 0; |
| return getLibraryOrScriptName().compareTo(other.getLibraryOrScriptName()); |
| } |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
|
ahe
2013/11/27 19:28:53
This really doesn't seem to be an essential part o
sigurdm
2013/11/29 10:39:37
I agree
I have made a visitor
|
| + List contents = []; |
| + int size = compiler.backend.codeSizeCounter.generatedSize(this); |
| + if (size == 0) return null; |
| + |
| + forEachLocalMember((Element element) { |
| + Map info = element.collectInferredTypes(compiler); |
| + if (info != null) { |
| + contents.add(info); |
| + } |
| + }); |
| + |
| + String nameString = getLibraryName() == "" ? "<unnamed>" : getLibraryName(); |
| + contents.sort((Map m1, Map m2) => m1["name"].compareTo(m2["name"])); |
| + return { |
| + "type" : this.canonicalUri.toString(), |
|
ahe
2013/11/27 19:28:53
Generally, try to create classes instead of simple
sigurdm
2013/11/29 10:39:37
Yes - the map'o'maps was more for drafting purpose
|
| + "kind" : "library", |
| + "name" : nameString, |
| + "size" : size, |
| + "modifiers" : "", |
| + "contents" : contents |
| + }; |
| + } |
| } |
| class PrefixElementX extends ElementX implements PrefixElement { |
| @@ -1013,6 +1043,8 @@ class PrefixElementX extends ElementX implements PrefixElement { |
| void addImport(Element element, Import import, DiagnosticListener listener) { |
| importScope.addImport(this, element, import, listener); |
| } |
| + |
| + |
|
ahe
2013/11/27 19:28:53
Extra lines.
sigurdm
2013/11/29 10:39:37
Done.
|
| } |
| class TypedefElementX extends ElementX implements TypedefElement { |
| @@ -1096,6 +1128,18 @@ class TypedefElementX extends ElementX implements TypedefElement { |
| computeType(compiler).accept(visitor, null); |
| hasBeenCheckedForCycles = true; |
| } |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
| + if (thisType == null) { |
|
karlklose
2013/11/27 14:19:23
Merge this int l. 1136 using '?:' ?
sigurdm
2013/11/29 10:39:37
Done.
|
| + return null; |
| + } |
| + return { |
| + "type" : thisType.toString(), |
| + "kind" : "typedef", |
| + "name" : name, |
| + "modifiers" : "", |
| + }; |
| + } |
| } |
| class VariableElementX extends ElementX implements VariableElement { |
| @@ -1140,6 +1184,27 @@ class VariableElementX extends ElementX implements VariableElement { |
| // Note: cachedNode.getBeginToken() will not be correct in all |
| // cases, for example, for function typed parameters. |
| Token position() => findMyName(variables.position()); |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
| + if (type == null) { |
| + return null; |
| + } |
| + String modifiersString = modifiers.toString() == "" ? |
| + "" : modifiers.toString()+" "; |
| + List inferredType = [{ |
| + "kind" : "inferred type", |
| + "name" : "", |
| + "type" : compiler.typesTask.getGuaranteedTypeOfElement(this).toString(), |
| + "modifiers" : "" |
| + }]; |
| + return { |
| + "kind" : "field", |
| + "type" : type.toString(), |
| + "name" : name, |
| + "modifiers" : modifiersString, |
| + "contents" : inferredType |
| + }; |
| + } |
| } |
| /** |
| @@ -1549,6 +1614,67 @@ class FunctionElementX extends ElementX implements FunctionElement { |
| (isFunction() || isAccessor()) && |
| _hasNoBody; |
| } |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
| + CodeBuffer emittedCode = compiler.backend.emitCodeFor(this); |
| + if (emittedCode == null) { |
| + return null; |
| + } |
| + String modifiersString = modifiers.toString() == "" ? |
| + "" : modifiers.toString()+" "; |
| + String kindString = "function"; |
| + String nameString = name; |
| + if (isConstructor()) { |
| + nameString = name == "" ? "${enclosingElement.name}()" : |
| + "${enclosingElement.name}.$name"; |
| + kindString = "constructor"; |
| + } |
| + if (type == null) { |
| + return { |
| + "type" : "not used", |
| + "kind" : kindString, |
| + "name" : nameString, |
| + "modifiers" : modifiersString |
| + }; |
| + } |
| + List contents = []; |
| + FunctionSignature signature = computeSignature(compiler); |
| + signature.forEachParameter((parameter) { |
| + contents.add({ |
| + "kind" : "inferred", |
| + "name" : parameter.name, |
| + "modifiers" : "parameter type", |
| + "type" : |
| + compiler.typesTask.getGuaranteedTypeOfElement(parameter).toString() |
| + }); |
| + }); |
| + contents.add({ |
| + "kind" : "inferred", |
| + "name" : "", |
| + "modifiers" : "return type", |
| + "type" : |
| + compiler.typesTask.getGuaranteedReturnTypeOfElement(this).toString() |
| + }); |
| + contents.add({ |
| + "kind" : "inferred", |
| + "name" : "", |
| + "modifiers" : "side effects", |
| + "type" : compiler.world.getSideEffectsOfElement(this).toString() |
| + }); |
| + contents.add({ |
| + "name" : "Generated code", |
| + "presentation" : "code", |
| + "text" : emittedCode.getText() |
| + }); |
| + return { |
| + "type" : type.toString(), |
| + "kind" : kindString, |
| + "name" : nameString, |
| + "size" : emittedCode.length, |
| + "modifiers" : modifiersString, |
| + "contents" : contents |
| + }; |
| + } |
| } |
| class ConstructorBodyElementX extends FunctionElementX |
| @@ -1708,7 +1834,12 @@ abstract class BaseClassElementX extends ElementX implements ClassElement { |
| OrderedTypeSet allSupertypesAndSelf; |
| - Link<DartType> get allSupertypes => allSupertypesAndSelf.supertypes; |
| + Link<DartType> get allSupertypes { |
| + assert(invariant(this, allSupertypesAndSelf != null, |
|
ahe
2013/11/27 19:28:53
This invariant is unnecessary. You get a null poin
sigurdm
2013/11/29 10:39:37
Done.
|
| + message: "This class has not been resolved " |
| + "(trying to access allSupertypes)")); |
| + return allSupertypesAndSelf.supertypes; |
| + } |
| int get hierarchyDepth => allSupertypesAndSelf.maxDepth; |
| @@ -2101,6 +2232,32 @@ abstract class BaseClassElementX extends ElementX implements ClassElement { |
| void setNative(String name) { |
| nativeTagInfo = name; |
| } |
| + |
| + Map collectInferredTypes(Compiler compiler) { |
| + String modifiersString = modifiers.toString() == "" ? |
| + "" : modifiers.toString()+" "; |
| + if (!isResolved) return null; |
| + String supersString = allSupertypes == null ? "" : |
| + "implements $allSupertypes"; |
| + List contents = []; |
| + forEachLocalMember((Element element) { |
| + Map info = element.collectInferredTypes(compiler); |
| + if (info != null) { |
| + contents.add(info); |
| + } |
| + }); |
| + if (contents.isEmpty) { |
| + return null; |
| + } |
| + contents.sort((Map m1, Map m2) => m1["name"].compareTo(m2["name"])); |
| + return { |
| + "kind" : "class", |
| + "name" : name, |
| + "type" : supersString, |
| + "modifiers" : modifiersString, |
| + "contents" : contents |
| + }; |
| + } |
| } |
| abstract class ClassElementX extends BaseClassElementX { |