Chromium Code Reviews| Index: runtime/vm/kernel.cc |
| diff --git a/runtime/vm/kernel.cc b/runtime/vm/kernel.cc |
| index 9ba7963792eba361fca1a992fb6155c78315e323..a8a4ff4c9088b4a546323c5d0f9e46564c8d5232 100644 |
| --- a/runtime/vm/kernel.cc |
| +++ b/runtime/vm/kernel.cc |
| @@ -33,24 +33,6 @@ CanonicalName* CanonicalName::NewRoot() { |
| } |
| -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; |
| -} |
| - |
| - |
| -void CanonicalName::Unbind() { |
| - if (definition_ == NULL) return; |
| - ASSERT(definition_->canonical_name_ == this); |
| - definition_->canonical_name_ = NULL; |
| - definition_ = NULL; |
| -} |
| - |
| - |
| CanonicalName* CanonicalName::AddChild(String* name) { |
| CanonicalName* child = new CanonicalName(); |
| child->parent_ = this; |
| @@ -60,33 +42,153 @@ CanonicalName* CanonicalName::AddChild(String* name) { |
| } |
| -Library* CanonicalName::AsLibrary() { |
| - return Library::Cast(definition()); |
| +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] == '_'); |
| +} |
| + |
| + |
| +bool CanonicalName::IsRoot() { |
| + // The root is the only canonical name with no parent. |
| + return parent() == NULL; |
| +} |
| + |
| + |
| +bool CanonicalName::IsLibrary() { |
| + // Libraries are the only canonical names with the root as their parent. |
| + return !IsRoot() && parent()->IsRoot(); |
| } |
| -Class* CanonicalName::AsClass() { |
| - return Class::Cast(definition()); |
| +bool CanonicalName::IsClass() { |
| + // Classes have the library as their parent and are not an administrative |
| + // name starting with @. |
| + return !IsAdministrative() && !IsRoot() && parent()->IsLibrary(); |
| } |
| -Member* CanonicalName::AsMember() { |
| - return Member::Cast(definition()); |
| +bool CanonicalName::IsMember() { |
| + return IsConstructor() || IsField() || IsProcedure(); |
| } |
| -Field* CanonicalName::AsField() { |
| - return Field::Cast(definition()); |
| +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* parent = this->parent(); |
| + if (IsPrivate()) { |
| + parent = parent->parent(); |
| + } |
| + return memcmp(parent->name()->buffer(), "@fields", sizeof("@fields") - 1) == |
|
Vyacheslav Egorov (Google)
2017/03/29 13:19:51
GCC and clang seem to constant fold strlen("zzzzz"
Kevin Millikin (Google)
2017/03/29 13:43:41
Done.
|
| + 0; |
| } |
| -Constructor* CanonicalName::AsConstructor() { |
| - return Constructor::Cast(definition()); |
| +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 memcmp(kind->name()->buffer(), "@constructors", |
| + sizeof("@constructors") - 1) == 0; |
| } |
| -Procedure* CanonicalName::AsProcedure() { |
| - return Procedure::Cast(definition()); |
| +bool CanonicalName::IsProcedure() { |
| + return IsMethod() || IsGetter() || IsSetter() || IsFactory(); |
| +} |
| + |
| + |
| +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 memcmp(kind->name()->buffer(), "@methods", sizeof("@methods") - 1) == |
| + 0; |
| +} |
| + |
| + |
| +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 memcmp(kind->name()->buffer(), "@getters", sizeof("@getters") - 1) == |
| + 0; |
| +} |
| + |
| + |
| +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 memcmp(kind->name()->buffer(), "@setters", sizeof("@setters") - 1) == |
| + 0; |
| +} |
| + |
| + |
| +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 memcmp(kind->name()->buffer(), "@factories", |
| + sizeof("@factories") - 1) == 0; |
| +} |
| + |
| + |
| +CanonicalName* CanonicalName::Enclosing() { |
| + ASSERT(IsField() || IsConstructor() || IsProcedure()); |
| + CanonicalName* enclosing = parent()->parent(); |
| + if (IsPrivate()) { |
| + enclosing = enclosing->parent(); |
| + } |
| + ASSERT(enclosing->IsLibrary() || enclosing->IsClass()); |
| + return enclosing; |
| } |
| @@ -135,11 +237,6 @@ 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()); |
| @@ -158,11 +255,6 @@ 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()); |
| @@ -188,11 +280,6 @@ void Field::AcceptMemberVisitor(MemberVisitor* visitor) { |
| } |
| -void Field::AcceptReferenceVisitor(MemberReferenceVisitor* visitor) { |
| - visitor->VisitFieldReference(this); |
| -} |
| - |
| - |
| void Field::VisitChildren(Visitor* visitor) { |
| type()->AcceptDartTypeVisitor(visitor); |
| visitor->VisitName(name()); |
| @@ -208,11 +295,6 @@ void Constructor::AcceptMemberVisitor(MemberVisitor* visitor) { |
| } |
| -void Constructor::AcceptReferenceVisitor(MemberReferenceVisitor* visitor) { |
| - visitor->VisitConstructorReference(this); |
| -} |
| - |
| - |
| void Constructor::VisitChildren(Visitor* visitor) { |
| visitor->VisitName(name()); |
| visitor->VisitFunctionNode(function()); |
| @@ -228,11 +310,6 @@ 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()); |
| @@ -267,7 +344,6 @@ void FieldInitializer::AcceptInitializerVisitor(InitializerVisitor* visitor) { |
| void FieldInitializer::VisitChildren(Visitor* visitor) { |
| - visitor->VisitFieldReference(field()); |
| value()->AcceptExpressionVisitor(visitor); |
| } |
| @@ -281,7 +357,6 @@ void SuperInitializer::AcceptInitializerVisitor(InitializerVisitor* visitor) { |
| void SuperInitializer::VisitChildren(Visitor* visitor) { |
| - visitor->VisitConstructorReference(target()); |
| visitor->VisitArguments(arguments()); |
| } |
| @@ -296,7 +371,6 @@ void RedirectingInitializer::AcceptInitializerVisitor( |
| void RedirectingInitializer::VisitChildren(Visitor* visitor) { |
| - visitor->VisitConstructorReference(target()); |
| visitor->VisitArguments(arguments()); |
| } |
| @@ -413,7 +487,6 @@ void DirectPropertyGet::AcceptExpressionVisitor(ExpressionVisitor* visitor) { |
| void DirectPropertyGet::VisitChildren(Visitor* visitor) { |
| receiver()->AcceptExpressionVisitor(visitor); |
| - target()->AcceptReferenceVisitor(visitor); |
| } |
| @@ -427,7 +500,6 @@ void DirectPropertySet::AcceptExpressionVisitor(ExpressionVisitor* visitor) { |
| void DirectPropertySet::VisitChildren(Visitor* visitor) { |
| receiver()->AcceptExpressionVisitor(visitor); |
| - target()->AcceptReferenceVisitor(visitor); |
| value()->AcceptExpressionVisitor(visitor); |
| } |
| @@ -440,9 +512,7 @@ void StaticGet::AcceptExpressionVisitor(ExpressionVisitor* visitor) { |
| } |
| -void StaticGet::VisitChildren(Visitor* visitor) { |
| - target()->AcceptReferenceVisitor(visitor); |
| -} |
| +void StaticGet::VisitChildren(Visitor* visitor) {} |
| StaticSet::~StaticSet() {} |
| @@ -454,7 +524,6 @@ void StaticSet::AcceptExpressionVisitor(ExpressionVisitor* visitor) { |
| void StaticSet::VisitChildren(Visitor* visitor) { |
| - target()->AcceptReferenceVisitor(visitor); |
| expression()->AcceptExpressionVisitor(visitor); |
| } |
| @@ -513,7 +582,6 @@ void DirectMethodInvocation::AcceptExpressionVisitor( |
| void DirectMethodInvocation::VisitChildren(Visitor* visitor) { |
| receiver()->AcceptExpressionVisitor(visitor); |
| - visitor->VisitProcedureReference(target()); |
| visitor->VisitArguments(arguments()); |
| } |
| @@ -527,7 +595,6 @@ void StaticInvocation::AcceptExpressionVisitor(ExpressionVisitor* visitor) { |
| void StaticInvocation::VisitChildren(Visitor* visitor) { |
| - visitor->VisitProcedureReference(procedure()); |
| visitor->VisitArguments(arguments()); |
| } |
| @@ -542,7 +609,6 @@ void ConstructorInvocation::AcceptExpressionVisitor( |
| void ConstructorInvocation::VisitChildren(Visitor* visitor) { |
| - visitor->VisitConstructorReference(target()); |
| visitor->VisitArguments(arguments()); |
| } |
| @@ -1194,7 +1260,6 @@ void InterfaceType::AcceptDartTypeVisitor(DartTypeVisitor* visitor) { |
| void InterfaceType::VisitChildren(Visitor* visitor) { |
| - klass()->AcceptReferenceVisitor(visitor); |
| VisitList(&type_arguments(), visitor); |
| } |
| @@ -1258,7 +1323,6 @@ void Program::AcceptTreeVisitor(TreeVisitor* visitor) { |
| void Program::VisitChildren(Visitor* visitor) { |
| VisitList(&libraries(), visitor); |
| - visitor->VisitProcedureReference(main_method()); |
| } |