Ejemplo n.º 1
0
TEST(TestProtocol, testPropertyRequirements)
{
    PARSE_STATEMENT(L"protocol SomeProtocol {\n"
                    L"var mustBeSettable: Int { get set }\n"
                    L"var doesNotNeedToBeSettable: Int { get }\n"
                    L"}");
    ProtocolDefPtr p;
    ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root));
    ASSERT_EQ(2, p->numDeclarations());
    ComputedPropertyPtr var;

    ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0)));
    ASSERT_EQ(L"mustBeSettable", var->getName());
    ASSERT_EQ(0, var->getModifiers());
    ASSERT_NOT_NULL(var->getGetter());
    ASSERT_NOT_NULL(var->getSetter());



    ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(1)));
    ASSERT_EQ(L"doesNotNeedToBeSettable", var->getName());
    ASSERT_NOT_NULL(var->getGetter());
    ASSERT_NULL(var->getSetter());

}
Ejemplo n.º 2
0
void FunctionAnalyzer::visitComputedProperty(const ComputedPropertyPtr& node)
{
    CodeBlockPtr didSet = node->getDidSet();
    CodeBlockPtr willSet = node->getWillSet();
    CodeBlockPtr getter = node->getGetter();
    CodeBlockPtr setter = node->getSetter();
    TypePtr type = declarationAnalyzer->resolveType(node->getDeclaredType(), true);
    assert(type != nullptr);

    shared_ptr<ComposedComputedProperty> property = static_pointer_cast<ComposedComputedProperty>(node);
    //prepare type for getter/setter
    /*
    std::vector<Parameter> params;
    TypePtr getterType = Type::newFunction(params, type, nullptr);
    params.push_back(Parameter(type));
    TypePtr setterType = Type::newFunction(params, symbolRegistry->getGlobalScope()->Void(), false);

    */
    SCOPED_SET(ctx->flags, (ctx->flags & (~SemanticContext::FLAG_PROCESS_DECLARATION)) | SemanticContext::FLAG_PROCESS_IMPLEMENTATION);
    if(!property->hasModifier(DeclarationModifiers::_Generated))
    {
        if(property->functions.getter)
            property->functions.getter->accept(semanticAnalyzer);
        if(property->functions.setter)
            property->functions.setter->accept(semanticAnalyzer);
        if(property->functions.willSet)
            property->functions.willSet->accept(semanticAnalyzer);
        if(property->functions.didSet)
            property->functions.didSet->accept(semanticAnalyzer);
    }
}
Ejemplo n.º 3
0
TEST(TestProtocol, testOptional)
{
    PARSE_STATEMENT(L"@objc protocol CounterDataSource {\n"
                    L"optional func incrementForCount(count: Int) -> Int\n"
                    L"optional var fixedIncrement: Int { get }\n"
                    L"}");
    ProtocolDefPtr p;
    ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root));
    ASSERT_EQ(2, p->numDeclarations());
    ASSERT_NOT_NULL(p->getAttribute(L"objc"));



    FunctionDefPtr f;

    ASSERT_NOT_NULL(f = std::dynamic_pointer_cast<FunctionDef>(p->getDeclaration(0)));
    ASSERT_EQ(L"incrementForCount", f->getName());
    ASSERT_TRUE(f->getModifiers() & DeclarationModifiers::Optional);

    ComputedPropertyPtr var;

    ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(1)));
    ASSERT_TRUE(f->getModifiers() & DeclarationModifiers::Optional);
    ASSERT_EQ(L"fixedIncrement", var->getName());
    ASSERT_NOT_NULL(var->getGetter());
    ASSERT_NULL(var->getSetter());

}
Ejemplo n.º 4
0
void NodeVisitor::visitComputedProperty(const ComputedPropertyPtr& node)
{
    ACCEPT(node->getInitializer());
    ACCEPT(node->getGetter());
    ACCEPT(node->getSetter());
    ACCEPT(node->getWillSet());
    ACCEPT(node->getDidSet());
}
Ejemplo n.º 5
0
TEST(TestProtocol, testPropertyRequirements2)
{
    PARSE_STATEMENT(L"protocol AnotherProtocol {\n"
                    L"class var someTypeProperty: Int { get set }\n"
                    L"}");
    ProtocolDefPtr p;
    ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root));
    ASSERT_EQ(1, p->numDeclarations());
    ComputedPropertyPtr var;

    ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0)));
    ASSERT_EQ((int)DeclarationModifiers::Class, var->getModifiers());
    ASSERT_EQ(L"someTypeProperty", var->getName());
    ASSERT_NOT_NULL(var->getGetter());
    ASSERT_NOT_NULL(var->getSetter());

}
Ejemplo n.º 6
0
TEST(TestProtocol, testPropertyRequirements3)
{
    PARSE_STATEMENT(L"protocol FullyNamed {\n"
                    L"var fullName: String { get }\n"
                    L"}");
    ProtocolDefPtr p;
    ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root));
    ASSERT_EQ(1, p->numDeclarations());
    ComputedPropertyPtr var;

    ASSERT_NOT_NULL(var = std::dynamic_pointer_cast<ComputedProperty>(p->getDeclaration(0)));
    ASSERT_EQ(0, var->getModifiers());
    ASSERT_EQ(L"fullName", var->getName());
    ASSERT_NOT_NULL(var->getGetter());
    ASSERT_NULL(var->getSetter());

}