• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TypeIdentifierPtr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中TypeIdentifierPtr的典型用法代码示例。如果您正苦于以下问题:C++ TypeIdentifierPtr类的具体用法?C++ TypeIdentifierPtr怎么用?C++ TypeIdentifierPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TypeIdentifierPtr类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: expect

/*
 ‌ raw-value-style-enum → enum-name generic-parameter-clause opt : type-identifier{raw-value-style-enum-members opt}
 ‌ raw-value-style-enum-members → raw-value-style-enum-member raw-value-style-enum-members opt
 ‌ raw-value-style-enum-member → declaration | raw-value-style-enum-case-clause
 ‌ raw-value-style-enum-case-clause → attributes opt case raw-value-style-enum-case-list
 ‌ raw-value-style-enum-case-list → raw-value-style-enum-case | raw-value-style-enum-case,raw-value-style-enum-case-list
 ‌ raw-value-style-enum-case → enum-case-name raw-value-assignment opt
 ‌ raw-value-assignment → =literal
*/
DeclarationPtr Parser::parseRawValueEnum(const std::vector<AttributePtr>& attrs, const std::wstring& name, const TypeIdentifierPtr& baseType)
{
    Token token;
    expect(L"{", token);
    EnumDefPtr ret = nodeFactory->createEnum(token.state);
    ret->setAttributes(attrs);
    TypeIdentifierPtr typeId = nodeFactory->createTypeIdentifier(token.state);
    typeId->setName(name);
    ret->setIdentifier(typeId);
    ret->addParent(baseType);
    while(!predicate(L"}"))
    {
        if(match(Keyword::Case))
        {
            do
            {
                expect_identifier(token);
                ExpressionPtr val = NULL;
                if(match(L"="))
                {
                    val = parseLiteral();
                }
                ret->addConstant(token.token, val);
            }while(match(L","));
        }
        else
        {
            DeclarationPtr decl = parseDeclaration();
            ret->addDeclaration(decl);
        }
    }
    expect(L"}");
    return ret;
}
开发者ID:xiedantibu,项目名称:swallow,代码行数:43,代码来源:Parser_Declaration.cpp


示例2: expect_next

/*
  GRAMMAR OF A TYPE IDENTIFIER
 
 ‌ type-identifier → type-name generic-argument-clause opt | type-name generic-argument-clause opt . type-identifier
 ‌ type-name → identifier
*/
TypeIdentifierPtr Parser::parseTypeIdentifier()
{
    Token token;
    expect_next(token);
    if(token.type != TokenType::Identifier || (token.identifier.keyword != Keyword::_ && token.identifier.keyword != Keyword::SelfType))
    {
        ResultItems items = {token.token};
        error(token, Errors::E_EXPECT_IDENTIFIER_1, items);
        return nullptr;
    }
    TypeIdentifierPtr ret = nodeFactory->createTypeIdentifier(token.state);
    ret->setName(token.token);
    ENTER_CONTEXT(TokenizerContextType);
    if(match(L"<"))
    {
        do
        {
            TypeNodePtr arg = parseType();
            ret->addGenericArgument(arg);
        }while(match(L","));
        
        expect(L">");
    }
    if(match(L"."))
    {
        //read next
        TypeIdentifierPtr next = parseTypeIdentifier();
        ret->setNestedType(next);
    }
    return ret;
}
开发者ID:healerkx,项目名称:swallow,代码行数:37,代码来源:Parser_Type.cpp


示例3: TEST

TEST(TestDeclaration, testLet)
{
    PARSE_STATEMENT(L"let a : Int[] = [1, 2, 3]");
    ValueBindingsPtr c;
    IdentifierPtr id;
    ValueBindingPtr a;
    ArrayLiteralPtr value;
    ArrayTypePtr type;
    TypeIdentifierPtr Int;
    ASSERT_NOT_NULL(c = std::dynamic_pointer_cast<ValueBindings>(root));
    ASSERT_TRUE(c->isReadOnly());
    ASSERT_EQ(1, c->numBindings());
    ASSERT_NOT_NULL(a = c->get(0));
    ASSERT_NOT_NULL(id = std::dynamic_pointer_cast<Identifier>(a->getName()));
    ASSERT_EQ(L"a", id->getIdentifier());
    ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<ArrayType>(a->getDeclaredType()));
    ASSERT_NOT_NULL(Int = std::dynamic_pointer_cast<TypeIdentifier>(type->getInnerType()));
    ASSERT_EQ(L"Int", Int->getName());

    ASSERT_NOT_NULL(value = std::dynamic_pointer_cast<ArrayLiteral>(c->get(0)->getInitializer()));
    ASSERT_EQ(3, value->numElements());
    ASSERT_EQ(L"1", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(0))->valueAsString);
    ASSERT_EQ(L"2", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(1))->valueAsString);
    ASSERT_EQ(L"3", std::dynamic_pointer_cast<IntegerLiteral>(value->getElement(2))->valueAsString);

}
开发者ID:Jornason,项目名称:swallow,代码行数:26,代码来源:TestDeclaration.cpp


示例4: getOrDefineType

TypePtr DeclarationAnalyzer::getOrDefineType(const std::shared_ptr<TypeDeclaration>& node)
{
    SymbolScope* currentScope = symbolRegistry->getCurrentScope();
    TypeIdentifierPtr id = node->getIdentifier();
    TypePtr type = currentScope->getForwardDeclaration(id->getName());
    if(type)
        return type;
    type = defineType(node);
    return type;
}
开发者ID:lexchou,项目名称:swallow,代码行数:10,代码来源:DeclarationAnalyzer_Type.cpp


示例5: TEST

TEST(TestProtocol, testEmptyProtocol)
{
    PARSE_STATEMENT(L"protocol SomeProtocol {\n"
                    L"// protocol definition goes here\n"
                    L"}");
    ProtocolDefPtr p;
    TypeIdentifierPtr id;
    ASSERT_NOT_NULL(p = std::dynamic_pointer_cast<ProtocolDef>(root));
    ASSERT_NOT_NULL(id = std::dynamic_pointer_cast<TypeIdentifier>(p->getIdentifier()));
    ASSERT_EQ(L"SomeProtocol", id->getName());
}
开发者ID:healerkx,项目名称:swallow,代码行数:11,代码来源:TestProtocol.cpp


示例6: TEST

TEST(TestFunc, testFunc)
{
    PARSE_STATEMENT(L"func stepForward(input: Int) -> Int {"
                       L"return input + 1"
                       L"}");
    FunctionDefPtr func;
    ParametersNodePtr params;
    ParameterNodePtr param;
    TypeIdentifierPtr type;
    CodeBlockPtr cb;
    ReturnStatementPtr ret;
    BinaryOperatorPtr add;
    IdentifierPtr id;
    IntegerLiteralPtr i;
    ASSERT_NOT_NULL(func = std::dynamic_pointer_cast<FunctionDef>(root));
    ASSERT_EQ(L"stepForward", func->getName());
    ASSERT_EQ(1, func->numParameters());
    ASSERT_NOT_NULL(params = func->getParameters(0));
    ASSERT_EQ(1, params->numParameters());
    ASSERT_NOT_NULL(param = params->getParameter(0));
    ASSERT_EQ(ParameterNode::None, param->getAccessibility());
    ASSERT_FALSE(param->isShorthandExternalName());
    ASSERT_FALSE(param->isInout());
    ASSERT_NULL(param->getDefaultValue());
    ASSERT_EQ(L"", param->getExternalName());
    ASSERT_EQ(L"input", param->getLocalName());
    ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<TypeIdentifier>(param->getDeclaredType()));
    ASSERT_EQ(L"Int", type->getName());

    ASSERT_NOT_NULL(type = std::dynamic_pointer_cast<TypeIdentifier>(func->getReturnType()));
    ASSERT_EQ(L"Int", type->getName());

    ASSERT_NOT_NULL(cb = func->getBody());
    ASSERT_EQ(1, cb->numStatements());

    ASSERT_NOT_NULL(ret = std::dynamic_pointer_cast<ReturnStatement>(cb->getStatement(0)));
    ASSERT_NOT_NULL(add = std::dynamic_pointer_cast<BinaryOperator>(ret->getExpression()));
    ASSERT_EQ(L"+", add->getOperator());

    ASSERT_NOT_NULL(id = std::dynamic_pointer_cast<Identifier>(add->getLHS()));
    ASSERT_NOT_NULL(i = std::dynamic_pointer_cast<IntegerLiteral>(add->getRHS()));

    ASSERT_EQ(L"input", id->getIdentifier());
    ASSERT_EQ(L"1", i->valueAsString);


}
开发者ID:healerkx,项目名称:swallow,代码行数:47,代码来源:TestFunc.cpp


示例7: switch

TypePtr DeclarationAnalyzer::defineType(const std::shared_ptr<TypeDeclaration>& node)
{
    TypeIdentifierPtr id = node->getIdentifier();

    //Analyze the type's category
    Type::Category category;
    switch(node->getNodeType())
    {
        case NodeType::Enum:
            category = Type::Enum;
            break;
        case NodeType::Class:
            category = Type::Class;
            break;
        case NodeType::Struct:
            category = Type::Struct;
            break;
        case NodeType::Protocol:
            category = Type::Protocol;
            break;
        default:
            assert(0 && "Impossible to execute here.");
    }

    //it's inside the type's scope, so need to access parent scope;

    //prepare for generic types
    GenericParametersDefPtr genericParams = node->getGenericParametersDef();

    //check if it's defined as a nested type
    if(ctx->currentType)
    {
        if(genericParams)
        {
            error(node, Errors::E_GENERIC_TYPE_A_NESTED_IN_TYPE_B_IS_NOT_ALLOWED_2, id->getName(), ctx->currentType->getName());
            return nullptr;
        }
        if(ctx->currentType->isGenericType())
        {
            error(node, Errors::E_TYPE_A_NESTED_IN_GENERIC_TYPE_B_IS_NOT_ALLOWED_2, id->getName(), ctx->currentType->getName());
            return nullptr;
        }
    }
    
    //register this type
    SymbolScope* currentScope = symbolRegistry->getCurrentScope();
    TypeBuilderPtr type = static_pointer_cast<TypeBuilder>(currentScope->getForwardDeclaration(id->getName()));
    S_ASSERT(type == nullptr);
    type = static_pointer_cast<TypeBuilder>(Type::newType(id->getName(), category));
    currentScope->addForwardDeclaration(type);
    TypeDeclarationPtr tnode = dynamic_pointer_cast<TypeDeclaration>(node);
    type->setReference(tnode);    
    if(tnode)
        tnode->setType(type);

    assert(type != nullptr);
    assert(type->getCategory() == category);
    //prepare for generic
    if(!type->getGenericDefinition() && node->getGenericParametersDef())
    {
        GenericParametersDefPtr genericParams = node->getGenericParametersDef();
        GenericDefinitionPtr generic = prepareGenericTypes(genericParams);
        generic->registerTo(type->getScope());
        type->setGenericDefinition(generic);
    }
    
    if(node->hasModifier(DeclarationModifiers::Final))
        type->setFlags(SymbolFlagFinal, true);
    static_pointer_cast<TypeBuilder>(type)->setModuleName(ctx->currentModule->getName());
    ctx->allTypes.push_back(type);
    
    //check inheritance clause
    {
        TypePtr parent = nullptr;
        bool first = true;

        ScopeGuard scope(symbolRegistry, type->getScope());
        SCOPED_SET(ctx->currentType, type);
        for(const TypeIdentifierPtr& parentType : node->getParents())
        {
            parentType->accept(this);
            if(first)
                declareImmediately(parentType->getName());
            TypePtr ptr = resolveType(parentType, true);
            Type::Category pcategory = ptr->getCategory();
            if(pcategory == Type::Specialized)
                pcategory = ptr->getInnerType()->getCategory();
            if(pcategory == Type::Class && category == Type::Class)
            {
                if(!first)
                {
                    //only the first type can be class type
                    error(parentType, Errors::E_SUPERCLASS_MUST_APPEAR_FIRST_IN_INHERITANCE_CLAUSE_1, toString(parentType));
                    return nullptr;
                }
                parent = ptr;
                if(parent->hasFlags(SymbolFlagFinal))
                {
                    error(parentType, Errors::E_INHERITANCE_FROM_A_FINAL_CLASS_A_1, parentType->getName());
                    return nullptr;
//.........这里部分代码省略.........
开发者ID:lexchou,项目名称:swallow,代码行数:101,代码来源:DeclarationAnalyzer_Type.cpp


示例8: ENTER_CONTEXT

GenericParametersDefPtr Parser::parseGenericParametersDef()
{
    Token token;
    ENTER_CONTEXT(TokenizerContextType);
    expect(L"<", token);
    GenericParametersDefPtr ret = nodeFactory->createGenericParametersDef(token.state);
    // ‌ generic-parameter-list → generic-parameter | generic-parameter,generic-parameter-list
    do
    {
        // generic-parameter → type-name
        // generic-parameter → type-name:type-identifier
        //‌ generic-parameter → type-name:protocol-composition-type
        expect_identifier(token);
        std::wstring typeName = token.token;
        TypeIdentifierPtr typeId = nodeFactory->createTypeIdentifier(token.state);
        typeId->setName(typeName);
        ret->addGenericType(typeId);
        if(match(L":"))
        {
            TypeNodePtr expected;
            if(predicate(L"protocol"))
                expected = parseProtocolComposition();
            else
                expected = parseTypeIdentifier();
            GenericConstraintDefPtr c = nodeFactory->createGenericConstraintDef(token.state);
            typeId = nodeFactory->createTypeIdentifier(token.state);
            typeId->setName(typeName);
            c->setIdentifier(typeId);
            c->setConstraintType(GenericConstraintDef::AssignableTo);
            c->setExpectedType(expected);
            ret->addConstraint(c);
        }
    } while (match(L","));
    // ‌ requirement-clause → where requirement-list
    if(match(Keyword::Where))
    {
        // requirement-list → requirement | requirement,requirement-list
        do
        {
            TypeIdentifierPtr type = parseTypeIdentifier();
            // requirement → conformance-requirement | same-type-requirement
            if(match(L":"))
            {
                // conformance-requirement → type-identifier:type-identifier
                // conformance-requirement → type-identifier:protocol-composition-type
                TypeNodePtr expected;
                if (predicate(L"protocol"))
                    expected = this->parseProtocolComposition();
                else
                    expected = parseTypeIdentifier();
                GenericConstraintDefPtr c = nodeFactory->createGenericConstraintDef(*type->getSourceInfo());
                c->setConstraintType(GenericConstraintDef::AssignableTo);
                c->setIdentifier(type);
                c->setExpectedType(expected);
                ret->addConstraint(c);
            }
            else if(match(L"=="))
            {
                // same-type-requirement → type-identifier==type-identifier
                GenericConstraintDefPtr c = nodeFactory->createGenericConstraintDef(*type->getSourceInfo());
                ret->addConstraint(c);
                c->setIdentifier(type);
                TypeIdentifierPtr expectedType = parseTypeIdentifier();
                c->setConstraintType(GenericConstraintDef::EqualsTo);
                c->setExpectedType(expectedType);
            }
        } while (match(L","));

    }
    expect(L">");
    return ret;
}
开发者ID:healerkx,项目名称:swallow,代码行数:72,代码来源:Parser_Type.cpp


示例9: visitTypeIdentifier

void NodeSerializer::visitTypeIdentifier(const TypeIdentifierPtr& node)
{
    append(node->getName());
}
开发者ID:healerkx,项目名称:swallow,代码行数:4,代码来源:NodeSerializer.cpp


示例10: switch

TypePtr DeclarationAnalyzer::defineType(const std::shared_ptr<TypeDeclaration>& node)
{
    TypeIdentifierPtr id = node->getIdentifier();
    SymbolScope* scope = NULL;
    TypePtr type;

    //Analyze the type's category
    Type::Category category;
    switch(node->getNodeType())
    {
        case NodeType::Enum:
            category = Type::Enum;
            break;
        case NodeType::Class:
            category = Type::Class;
            break;
        case NodeType::Struct:
            category = Type::Struct;
            break;
        case NodeType::Protocol:
            category = Type::Protocol;
            break;
        default:
            assert(0 && "Impossible to execute here.");
    }

    //it's inside the type's scope, so need to access parent scope;
    SymbolScope* typeScope = symbolRegistry->getCurrentScope();
    SymbolScope* currentScope = typeScope->getParentScope();

    //check if this type is already defined
    symbolRegistry->lookupType(id->getName(), &scope, &type);
    if(type && scope == currentScope)
    {
        //invalid redeclaration of type T
        error(node, Errors::E_INVALID_REDECLARATION_1, id->getName());
        return nullptr;
    }
    //prepare for generic types
    GenericDefinitionPtr generic;
    GenericParametersDefPtr genericParams = node->getGenericParametersDef();

    //check if it's defined as a nested type
    if(ctx->currentType)
    {
        if(genericParams)
        {
            error(node, Errors::E_GENERIC_TYPE_A_NESTED_IN_TYPE_B_IS_NOT_ALLOWED_2, id->getName(), ctx->currentType->getName());
            return nullptr;
        }
        if(ctx->currentType->isGenericType())
        {
            error(node, Errors::E_TYPE_A_NESTED_IN_GENERIC_TYPE_B_IS_NOT_ALLOWED_2, id->getName(), ctx->currentType->getName());
            return nullptr;
        }
    }

    if(genericParams)
    {
        generic = prepareGenericTypes(genericParams);
        generic->registerTo(typeScope);
    }

    //check inheritance clause
    TypePtr parent = nullptr;
    std::vector<TypePtr> protocols;
    bool first = true;

    for(const TypeIdentifierPtr& parentType : node->getParents())
    {
        parentType->accept(semanticAnalyzer);
        TypePtr ptr = this->lookupType(parentType);
        if(ptr->getCategory() == Type::Class && category == Type::Class)
        {
            if(!first)
            {
                //only the first type can be class type
                error(parentType, Errors::E_SUPERCLASS_MUST_APPEAR_FIRST_IN_INHERITANCE_CLAUSE_1, toString(parentType));
                return nullptr;
            }
            parent = ptr;
            if(parent->hasFlags(SymbolFlagFinal))
            {
                error(parentType, Errors::E_INHERITANCE_FROM_A_FINAL_CLASS_A_1, parentType->getName());
                return nullptr;
            }
        }
        else if(category == Type::Enum && ptr->getCategory() != Type::Protocol)
        {

            if(parent)//already has a raw type
            {
                error(parentType, Errors::E_MULTIPLE_ENUM_RAW_TYPES_A_AND_B_2, parent->toString(), ptr->toString());
                return nullptr;
            }
            if(!first)
            {
                error(parentType, Errors::E_RAW_TYPE_A_MUST_APPEAR_FIRST_IN_THE_ENUM_INHERITANCE_CLAUSE_1, ptr->toString());
                return nullptr;
            }
//.........这里部分代码省略.........
开发者ID:voidException,项目名称:swallow,代码行数:101,代码来源:DeclarationAnalyzer_Type.cpp



注:本文中的TypeIdentifierPtr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TypeIndex类代码示例发布时间:2022-05-31
下一篇:
C++ TypeFunction类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap