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

Unified Diff: runtime/vm/kernel.cc

Issue 2782913003: Revert "Remove definitions from Kernel canonical names." (Closed)
Patch Set: Created 3 years, 9 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 | « runtime/vm/kernel.h ('k') | runtime/vm/kernel_binary.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel.cc
diff --git a/runtime/vm/kernel.cc b/runtime/vm/kernel.cc
index 6953cea46d1e422c17a00c924b2534c468227bfc..9ba7963792eba361fca1a992fb6155c78315e323 100644
--- a/runtime/vm/kernel.cc
+++ b/runtime/vm/kernel.cc
@@ -33,162 +33,60 @@ CanonicalName* CanonicalName::NewRoot() {
}
-CanonicalName* CanonicalName::AddChild(String* name) {
- CanonicalName* child = new CanonicalName();
- child->parent_ = this;
- child->name_ = name;
- children_.Add(child);
- return child;
-}
-
-
-bool CanonicalName::IsAdministrative() {
- // Administrative names start with '@'.
- return (name()->size() > 0) && (name()->buffer()[0] == '@');
-}
-
-
-bool CanonicalName::IsPrivate() {
- // Private names start with '_'.
- return (name()->size() > 0) && (name()->buffer()[0] == '_');
+void CanonicalName::BindTo(LinkedNode* new_target) {
+ ASSERT(new_target != NULL);
+ if (definition_ == new_target) return;
+ ASSERT(definition_ == NULL);
+ ASSERT(new_target->canonical_name_ == NULL);
+ definition_ = new_target;
+ new_target->canonical_name_ = this;
}
-bool CanonicalName::IsRoot() {
- // The root is the only canonical name with no parent.
- return parent() == NULL;
+void CanonicalName::Unbind() {
+ if (definition_ == NULL) return;
+ ASSERT(definition_->canonical_name_ == this);
+ definition_->canonical_name_ = NULL;
+ definition_ = NULL;
}
-bool CanonicalName::IsLibrary() {
- // Libraries are the only canonical names with the root as their parent.
- return !IsRoot() && parent()->IsRoot();
-}
-
-
-bool CanonicalName::IsClass() {
- // Classes have the library as their parent and are not an administrative
- // name starting with @.
- return !IsAdministrative() && !IsRoot() && parent()->IsLibrary();
-}
-
-
-bool CanonicalName::IsMember() {
- return IsConstructor() || IsField() || IsProcedure();
-}
-
-
-// Note the two occurrences of the parameter 'literal'.
-#define COMPARE_NAME(canonical_name, literal) \
- memcmp((canonical_name)->name()->buffer(), (literal), strlen(literal)) == 0
-
-bool CanonicalName::IsField() {
- // Fields with private names have the import URI of the library where they are
- // visible as the parent and the string "@fields" as the parent's parent.
- // Fields with non-private names have the string "@fields' as the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@fields");
-}
-
-
-bool CanonicalName::IsConstructor() {
- // Constructors with private names have the import URI of the library where
- // they are visible as the parent and the string "@constructors" as the
- // parent's parent. Constructors with non-private names have the string
- // "@constructors" as the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@constructors");
+CanonicalName* CanonicalName::AddChild(String* name) {
+ CanonicalName* child = new CanonicalName();
+ child->parent_ = this;
+ child->name_ = name;
+ children_.Add(child);
+ return child;
}
-bool CanonicalName::IsProcedure() {
- return IsMethod() || IsGetter() || IsSetter() || IsFactory();
+Library* CanonicalName::AsLibrary() {
+ return Library::Cast(definition());
}
-bool CanonicalName::IsMethod() {
- // Methods with private names have the import URI of the library where they
- // are visible as the parent and the string "@methods" as the parent's parent.
- // Methods with non-private names have the string "@methods" as the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@methods");
+Class* CanonicalName::AsClass() {
+ return Class::Cast(definition());
}
-bool CanonicalName::IsGetter() {
- // Getters with private names have the import URI of the library where they
- // are visible as the parent and the string "@getters" as the parent's parent.
- // Getters with non-private names have the string "@getters" as the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@getters");
+Member* CanonicalName::AsMember() {
+ return Member::Cast(definition());
}
-bool CanonicalName::IsSetter() {
- // Setters with private names have the import URI of the library where they
- // are visible as the parent and the string "@setters" as the parent's parent.
- // Setters with non-private names have the string "@setters" as the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@setters");
+Field* CanonicalName::AsField() {
+ return Field::Cast(definition());
}
-bool CanonicalName::IsFactory() {
- // Factories with private names have the import URI of the library where they
- // are visible as the parent and the string "@factories" as the parent's
- // parent. Factories with non-private names have the string "@factories" as
- // the parent.
- if (IsRoot()) {
- return false;
- }
- CanonicalName* kind = this->parent();
- if (IsPrivate()) {
- kind = kind->parent();
- }
- return COMPARE_NAME(kind, "@factories");
+Constructor* CanonicalName::AsConstructor() {
+ return Constructor::Cast(definition());
}
-#undef COMPARE_NAME
-
-CanonicalName* CanonicalName::EnclosingName() {
- ASSERT(IsField() || IsConstructor() || IsProcedure());
- CanonicalName* enclosing = parent()->parent();
- if (IsPrivate()) {
- enclosing = enclosing->parent();
- }
- ASSERT(enclosing->IsLibrary() || enclosing->IsClass());
- return enclosing;
+Procedure* CanonicalName::AsProcedure() {
+ return Procedure::Cast(definition());
}
@@ -237,6 +135,11 @@ void NormalClass::AcceptClassVisitor(ClassVisitor* visitor) {
}
+void NormalClass::AcceptReferenceVisitor(ClassReferenceVisitor* visitor) {
+ visitor->VisitNormalClassReference(this);
+}
+
+
void NormalClass::VisitChildren(Visitor* visitor) {
VisitList(&type_parameters(), visitor);
if (super_class() != NULL) visitor->VisitInterfaceType(super_class());
@@ -255,6 +158,11 @@ void MixinClass::AcceptClassVisitor(ClassVisitor* visitor) {
}
+void MixinClass::AcceptReferenceVisitor(ClassReferenceVisitor* visitor) {
+ visitor->VisitMixinClassReference(this);
+}
+
+
void MixinClass::VisitChildren(Visitor* visitor) {
VisitList(&type_parameters(), visitor);
visitor->VisitInterfaceType(first());
@@ -280,6 +188,11 @@ void Field::AcceptMemberVisitor(MemberVisitor* visitor) {
}
+void Field::AcceptReferenceVisitor(MemberReferenceVisitor* visitor) {
+ visitor->VisitFieldReference(this);
+}
+
+
void Field::VisitChildren(Visitor* visitor) {
type()->AcceptDartTypeVisitor(visitor);
visitor->VisitName(name());
@@ -295,6 +208,11 @@ void Constructor::AcceptMemberVisitor(MemberVisitor* visitor) {
}
+void Constructor::AcceptReferenceVisitor(MemberReferenceVisitor* visitor) {
+ visitor->VisitConstructorReference(this);
+}
+
+
void Constructor::VisitChildren(Visitor* visitor) {
visitor->VisitName(name());
visitor->VisitFunctionNode(function());
@@ -310,6 +228,11 @@ void Procedure::AcceptMemberVisitor(MemberVisitor* visitor) {
}
+void Procedure::AcceptReferenceVisitor(MemberReferenceVisitor* visitor) {
+ visitor->VisitProcedureReference(this);
+}
+
+
void Procedure::VisitChildren(Visitor* visitor) {
visitor->VisitName(name());
if (function() != NULL) visitor->VisitFunctionNode(function());
@@ -344,6 +267,7 @@ void FieldInitializer::AcceptInitializerVisitor(InitializerVisitor* visitor) {
void FieldInitializer::VisitChildren(Visitor* visitor) {
+ visitor->VisitFieldReference(field());
value()->AcceptExpressionVisitor(visitor);
}
@@ -357,6 +281,7 @@ void SuperInitializer::AcceptInitializerVisitor(InitializerVisitor* visitor) {
void SuperInitializer::VisitChildren(Visitor* visitor) {
+ visitor->VisitConstructorReference(target());
visitor->VisitArguments(arguments());
}
@@ -371,6 +296,7 @@ void RedirectingInitializer::AcceptInitializerVisitor(
void RedirectingInitializer::VisitChildren(Visitor* visitor) {
+ visitor->VisitConstructorReference(target());
visitor->VisitArguments(arguments());
}
@@ -487,6 +413,7 @@ void DirectPropertyGet::AcceptExpressionVisitor(ExpressionVisitor* visitor) {
void DirectPropertyGet::VisitChildren(Visitor* visitor) {
receiver()->AcceptExpressionVisitor(visitor);
+ target()->AcceptReferenceVisitor(visitor);
}
@@ -500,6 +427,7 @@ void DirectPropertySet::AcceptExpressionVisitor(ExpressionVisitor* visitor) {
void DirectPropertySet::VisitChildren(Visitor* visitor) {
receiver()->AcceptExpressionVisitor(visitor);
+ target()->AcceptReferenceVisitor(visitor);
value()->AcceptExpressionVisitor(visitor);
}
@@ -512,7 +440,9 @@ void StaticGet::AcceptExpressionVisitor(ExpressionVisitor* visitor) {
}
-void StaticGet::VisitChildren(Visitor* visitor) {}
+void StaticGet::VisitChildren(Visitor* visitor) {
+ target()->AcceptReferenceVisitor(visitor);
+}
StaticSet::~StaticSet() {}
@@ -524,6 +454,7 @@ void StaticSet::AcceptExpressionVisitor(ExpressionVisitor* visitor) {
void StaticSet::VisitChildren(Visitor* visitor) {
+ target()->AcceptReferenceVisitor(visitor);
expression()->AcceptExpressionVisitor(visitor);
}
@@ -582,6 +513,7 @@ void DirectMethodInvocation::AcceptExpressionVisitor(
void DirectMethodInvocation::VisitChildren(Visitor* visitor) {
receiver()->AcceptExpressionVisitor(visitor);
+ visitor->VisitProcedureReference(target());
visitor->VisitArguments(arguments());
}
@@ -595,6 +527,7 @@ void StaticInvocation::AcceptExpressionVisitor(ExpressionVisitor* visitor) {
void StaticInvocation::VisitChildren(Visitor* visitor) {
+ visitor->VisitProcedureReference(procedure());
visitor->VisitArguments(arguments());
}
@@ -609,6 +542,7 @@ void ConstructorInvocation::AcceptExpressionVisitor(
void ConstructorInvocation::VisitChildren(Visitor* visitor) {
+ visitor->VisitConstructorReference(target());
visitor->VisitArguments(arguments());
}
@@ -1260,6 +1194,7 @@ void InterfaceType::AcceptDartTypeVisitor(DartTypeVisitor* visitor) {
void InterfaceType::VisitChildren(Visitor* visitor) {
+ klass()->AcceptReferenceVisitor(visitor);
VisitList(&type_arguments(), visitor);
}
@@ -1323,6 +1258,7 @@ void Program::AcceptTreeVisitor(TreeVisitor* visitor) {
void Program::VisitChildren(Visitor* visitor) {
VisitList(&libraries(), visitor);
+ visitor->VisitProcedureReference(main_method());
}
« no previous file with comments | « runtime/vm/kernel.h ('k') | runtime/vm/kernel_binary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698