当前位置: 首页>>代码示例>>C++>>正文


C++ TypeFunction::setVirtual方法代码示例

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


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

示例1: addMethod

void Class::addMethod(std::string name, Type* t, std::vector<Argument*>* args, Stm* body, int method_state) {
	// Add this argument at the beginning of arg list
	if (!args)
		args = new std::vector<Argument*>();
	// TODO Do not do this for static methods
	if (!(method_state == 1))
	{
		args->insert(args->begin(), new Argument(new TypeClass(this), "this"));
	}
	
	TypeFunction* tf = new TypeFunction(t);
	tf->setVirtual(method_state == 2);
	tf->setClass(this);
	cy::Function* f = new cy::Function(tf, args, body);
	f->setOriginalName(name);
	this->methods->push_back(f);
	// Do specific operation
	tf->setStatic(false);
	f->setStatic(false);
	switch (method_state)
	{
		case 1:	// Method is static
			tf->setStatic(true);
			f->setStatic(true);
			break;
		case 2:	// Virtual method
			f->setVirtual(true);
			tf->setVirtual(true);
			this->setVTable();		// Set pointer to vtable attribute
			this->virtual_methods->push_back(f);
			break;
		case 3: // Overriden method
			tf->setOverridden(true);
			if (!this->getParent())
			{
				throw __FILE__ "(" QUOTE(__LINE__) "): Method " + name + " is overridden, but no super class.";
			}

			std::vector<Type*>* types = new std::vector<Type*>();
			std::vector<Argument*>::iterator itarg;
			for (itarg = args->begin(); itarg != args->end(); itarg++)
			{
				types->push_back((*itarg)->getType());
			}
			// Verify method with same name and same types exists in 
			if (!this->getParent()->getMethod(name, types))
			{
				throw __FILE__ "(" QUOTE(__LINE__) "): Method " + name + " is overridden, but not in super class.";
			}
			delete types;
			break;
	}
}
开发者ID:cybrown,项目名称:CyLang,代码行数:53,代码来源:Class.cpp

示例2: visit

void VisitorNodeTyper::visit(ExprSymbol *n){
    // TODO Set flag if global or local
    if (this->cur_class)
    {
        Type* t = this->cur_class->getAttrType(n->getName());   // Get type from class
        if (!t) // If no type returned, it might be an unmangled method name
        {
            if (this->look_for_mangled)
            {
                TypeFunction* tf = new TypeFunction();
                tf->setClass(this->cur_class);
                tf->setName(n->getName());
                t = tf;
            }
            else
            {
                throw __FILE__ "(" QUOTE(__LINE__) "): Attribute " + n->getName() + " not found in class" + this->cur_class->getName() + ".";
            }
        }
        n->setType(t);
    }
    else
    {
        Variable* v = this->symt->get(n->getName());
        if (!v)     // Symbol not found
        {
            if (this->look_for_mangled)     // Look for an unmangled name
            {
                TypeFunction* tf = new TypeFunction();
                tf->setName(n->getName());
                tf->setStatic(true);
                tf->setVirtual(false);
                n->setType(tf);
            }
            else
            {
                throw __FILE__ "(" QUOTE(__LINE__) "): Variable " + n->getName() + " not found.";
            }
        }
        else
        {
            n->setType(v->getType());
        }
    }
}
开发者ID:cybrown,项目名称:CyLang,代码行数:45,代码来源:VisitorNodeTyper.cpp


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