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


C++ FunctionDefinition::accept方法代码示例

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


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

示例1: JIT

void CodeGenVisitor::JIT(Expression* e) {
	StatementList* sl = new StatementList();
	sl->addStatement(new ReturnStatement(e));
	FunctionDefinition* fd = new FunctionDefinition(Type::INT, "", new ParameterList(), sl);

	value_ = 0;
	fd->accept(this);

	if (!value_) {
		delete fd;
		throw "error evaluating expression";
	}

	llvm::Function* f = dynamic_cast<llvm::Function*>(value_);

	void* fPtr = ee_->getPointerToFunction(f);

	// some casting ... because we like magic
	int (*fP)() = (int (*)())(intptr_t)fPtr;

	std::cout << "Evaluated to: " << fP() << std::endl;

	// throw it away
	f->eraseFromParent();
}
开发者ID:catdog2,项目名称:scully,代码行数:25,代码来源:CodeGenVisitor.cpp

示例2: appendBaseConstructor

void Compiler::appendBaseConstructor(FunctionDefinition const& _constructor)
{
	CompilerContext::LocationSetter locationSetter(m_context, _constructor);
	FunctionType constructorType(_constructor);
	if (!constructorType.getParameterTypes().empty())
	{
		solAssert(m_baseArguments.count(&_constructor), "");
		std::vector<ASTPointer<Expression>> const* arguments = m_baseArguments[&_constructor];
		solAssert(arguments, "");
		for (unsigned i = 0; i < arguments->size(); ++i)
			compileExpression(*(arguments->at(i)), constructorType.getParameterTypes()[i]);
	}
	_constructor.accept(*this);
}
开发者ID:1600,项目名称:solidity,代码行数:14,代码来源:Compiler.cpp

示例3: appendConstructor

void Compiler::appendConstructor(FunctionDefinition const& _constructor)
{
	CompilerContext::LocationSetter locationSetter(m_context, _constructor);
	// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
	if (!_constructor.getParameters().empty())
	{
		unsigned argumentSize = 0;
		for (ASTPointer<VariableDeclaration> const& var: _constructor.getParameters())
			if (var->getType()->isDynamicallySized())
			{
				argumentSize = 0;
				break;
			}
			else
				argumentSize += var->getType()->getCalldataEncodedSize();

		CompilerUtils(m_context).fetchFreeMemoryPointer();
		if (argumentSize == 0)
		{
			// argument size is dynamic, use CODESIZE to determine it
			m_context.appendProgramSize(); // program itself
			// CODESIZE is program plus manually added arguments
			m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
		}
		else
			m_context << u256(argumentSize);
		// stack: <memptr> <argument size>
		m_context << eth::Instruction::DUP1;
		m_context.appendProgramSize();
		m_context << eth::Instruction::DUP4 << eth::Instruction::CODECOPY;
		m_context << eth::Instruction::ADD;
		CompilerUtils(m_context).storeFreeMemoryPointer();
		appendCalldataUnpacker(
			FunctionType(_constructor).getParameterTypes(),
			true,
			CompilerUtils::freeMemoryPointer + 0x20
		);
	}
	_constructor.accept(*this);
}
开发者ID:1600,项目名称:solidity,代码行数:40,代码来源:Compiler.cpp


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