本文整理汇总了C++中Expression::accept方法的典型用法代码示例。如果您正苦于以下问题:C++ Expression::accept方法的具体用法?C++ Expression::accept怎么用?C++ Expression::accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::accept方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
void CodeGenVisitor::visit(FunctionCallExpression* e) {
llvm::Function* cf = module_->getFunction(e->getId());
if (!cf) {
throw "function to call not found";
return;
}
auto values = e->getValues()->getValues();
if (cf->arg_size() != values.size()) {
throw "argument size mismatch";
return;
}
std::vector<llvm::Value*> args;
auto iter = values.begin();
auto end = values.end();
for (; iter != end; ++iter) {
Expression *expr = (*iter);
expr->accept(this);
if (!value_) {
throw "error evaluating expression";
}
args.push_back(value_);
}
if (cf->getFunctionType()->getReturnType() == typeToLLVMType(Type::VOID)) {
builder_->CreateCall(cf, args);
// just handle void functions as if they returned 0
value_ = llvm::ConstantInt::get(llvm::getGlobalContext(), llvm::APInt(0, 32, 10));
} else {
value_ = builder_->CreateCall(cf, args, "calltmp");
}
}
示例2: visitMethodCall
//=====================================================================================================================
void visitMethodCall(MethodCall *p) {
fprintf(m_outputfile, "#### METHC\n");
// Visit variable and method name
p->m_methodid->accept(this);
p->m_variableid->accept(this);
// Grab variable's classname (for jump label) from offset table
OffsetTable* table = currMethodOffset; bool inClass=false;
const char* varname = dynamic_cast<VariableIDImpl*>(p->m_variableid)->m_symname->spelling();
if(!table->exist(varname)) {table = currClassOffset; inClass=true;}
assert(table->exist(varname));
CompoundType type = table->get_type(varname);
const char* name;
name = type.classID;
// Visit parameters in reverse order, so their results will end up on the stack in x86 convention order
int numparams = 0;
list<Expression_ptr> *l = p->m_expression_list;
list<Expression_ptr>::iterator it;
Expression* exp; Expression_ptr ptr;
for(it=l->end(); it!=l->begin();) {
--it;
ptr = (Expression_ptr)*it;
exp = dynamic_cast<Expression*> (ptr);
exp->accept(this);
numparams++;
}
// Push referenced object's pointer to stack as final parameter
if(!inClass) {
fprintf( m_outputfile, " pushl %i(%%ebp)\n", table->get_offset(varname));
} else {
fprintf( m_outputfile, " movl 8(%%ebp), %%ebx\n");
fprintf( m_outputfile, " pushl %i(%%ebx)\n", table->get_offset(varname));
}
numparams++;
// Find class/superclass that contains the function
const char* funcname = dynamic_cast<MethodIDImpl*>(p->m_methodid)->m_symname->spelling();
ClassNode* node = m_classtable->lookup(name);
assert(node!=NULL);
while(!(node->scope->exist(funcname))) {
assert(node->superClass != NULL);
node = m_classtable->lookup(node->superClass);
}
// Call the function
fprintf(m_outputfile, " call %s_%s\n", node->name->spelling(), funcname);
// Clean up parameters
fprintf(m_outputfile, " addl $%i, %%esp\n", numparams*4);
// Push return value
fprintf(m_outputfile, " pushl %%ebx\n");
fprintf(m_outputfile, "####\n");
}
示例3: print
void Interpreter::print(Instruction* instruction) {
OutputVisitor ov(std::cout);
for (u32_t i = 0; i < instruction->getOperandAmount(); i++) {
Expression* exp = this->resolveExpression(instruction->getOperand(i));
exp->accept(ov);
}
std::cout << '\n';
}
示例4:
void
SemanticAnalysis::visitExpressionStatement(ExpressionStatement *node)
{
Expression *expr = node->expr();
expr->accept(this);
if (!expr->hasSideEffects())
cc_.report(node->loc(), rmsg::expr_has_no_side_effects);
}
示例5: check
void check(Loc loc, Declaration *d)
{
assert(d);
VarDeclaration *v = d->isVarDeclaration();
if (v && v->toParent2() == sc->func)
{
if (v->isDataseg())
return;
if ((v->storage_class & (STCref | STCout)) == 0)
{
error(loc, "escaping reference to local variable %s", v);
return;
}
if (global.params.useDIP25 &&
(v->storage_class & (STCref | STCout)) && !(v->storage_class & (STCreturn | STCforeach)))
{
if (sc->func->flags & FUNCFLAGreturnInprocess)
{
//printf("inferring 'return' for variable '%s'\n", v->toChars());
v->storage_class |= STCreturn;
if (v == sc->func->vthis)
{
TypeFunction *tf = (TypeFunction *)sc->func->type;
if (tf->ty == Tfunction)
{
//printf("'this' too\n");
tf->isreturn = true;
}
}
}
else if (sc->module && sc->module->isRoot())
{
//printf("escaping reference to local ref variable %s\n", v->toChars());
//printf("storage class = x%llx\n", v->storage_class);
error(loc, "escaping reference to local ref variable %s", v);
}
return;
}
if (v->storage_class & STCref &&
v->storage_class & (STCforeach | STCtemp) &&
v->init)
{
// (ref v = ex; ex)
if (ExpInitializer *ez = v->init->isExpInitializer())
{
assert(ez->exp && ez->exp->op == TOKconstruct);
Expression *ex = ((ConstructExp *)ez->exp)->e2;
ex->accept(this);
return;
}
}
}
}
示例6: visit
void visit(StructLiteralExp *e)
{
if (e->elements)
{
for (size_t i = 0; i < e->elements->dim; i++)
{
Expression *ex = (*e->elements)[i];
if (ex)
ex->accept(this);
}
}
}
示例7: visit
void visit(StructLiteralExp *e)
{
size_t dim = e->elements ? e->elements->dim : 0;
buf->printf("S%u", dim);
for (size_t i = 0; i < dim; i++)
{
Expression *ex = (*e->elements)[i];
if (ex)
ex->accept(this);
else
buf->writeByte('v'); // 'v' for void
}
}
示例8: InvalidFunctionParametersException
Expression * GetDerivativeVisitor::visit(Fcn::Cosh * expression) {
ExpressionList * parameters = expression->getParameterList();
if (parameters->getLength() != 1) {
throw InvalidFunctionParametersException();
}
Expression * parameterExpr = parameters->getExpressionAt(0);
std::unique_ptr<Expression> derivedParameterExprPtr((Expression *)parameterExpr->accept(this));
return new Op::Multiplication(
new Fcn::Sinh(parameterExpr->copy()),
derivedParameterExprPtr.release()
);
}
示例9: visit
void visit(CallExp *e)
{
/* If the function returns by ref, check each argument that is
* passed as 'return ref'.
*/
Type *t1 = e->e1->type->toBasetype();
TypeFunction *tf;
if (t1->ty == Tdelegate)
tf = (TypeFunction *)((TypeDelegate *)t1)->next;
else if (t1->ty == Tfunction)
tf = (TypeFunction *)t1;
else
return;
if (tf->isref)
{
if (e->arguments && e->arguments->dim)
{
/* j=1 if _arguments[] is first argument,
* skip it because it is not passed by ref
*/
int j = (tf->linkage == LINKd && tf->varargs == 1);
for (size_t i = j; i < e->arguments->dim; ++i)
{
Expression *arg = (*e->arguments)[i];
size_t nparams = Parameter::dim(tf->parameters);
if (i - j < nparams && i >= j)
{
Parameter *p = Parameter::getNth(tf->parameters, i - j);
if ((p->storageClass & (STCout | STCref)) && (p->storageClass & STCreturn))
arg->accept(this);
}
}
}
// If 'this' is returned by ref, check it too
if (tf->isreturn && e->e1->op == TOKdotvar && t1->ty == Tfunction)
{
DotVarExp *dve = (DotVarExp *)e->e1;
dve->e1->accept(this);
}
}
else
{
error(e->loc, "escaping reference to stack allocated value returned by %s", e);
return;
}
}
示例10: visitArrayLiteral
void visitArrayLiteral(ArrayLiteral *node) override {
prefix();
fprintf(fp_, "[ ArrayLiteral\n");
indent();
for (size_t i = 0; i < node->expressions()->length(); i++) {
Expression *expr = node->expressions()->at(i);
indent();
expr->accept(this);
unindent();
}
if (node->repeatLastElement()) {
indent();
prefix();
fprintf(fp_, "...\n");
unindent();
}
}
示例11: visitSelfCall
//=====================================================================================================================
void visitSelfCall(SelfCall *p) {
fprintf(m_outputfile, "#### SELFC\n");
// Visit method name
p->m_methodid->accept(this);
// Visit parameters in reverse order, so their results will end up on the stack in x86 convention order
int numparams = 0;
list<Expression_ptr> *l = p->m_expression_list;
list<Expression_ptr>::iterator it;
Expression* exp; Expression_ptr ptr;
for(it=l->end(); it!=l->begin();) {
--it;
ptr = (Expression_ptr)*it;
exp = dynamic_cast<Expression*> (ptr);
exp->accept(this);
numparams++;
}
// Push current object's pointer to stack as final parameter
fprintf( m_outputfile, " pushl 8(%%ebp)\n");
numparams++;
// Find class/superclass that contains the function
const char* funcname = dynamic_cast<MethodIDImpl*>(p->m_methodid)->m_symname->spelling();
ClassNode* node = m_classtable->lookup(currClassName);
assert(node!=NULL);
while(!(node->scope->exist(funcname))) {
assert(node->superClass != NULL);
node = m_classtable->lookup(node->superClass);
}
// Call the function
fprintf(m_outputfile, " call %s_%s\n", node->name->spelling(), funcname);
// Clean up parameters
fprintf(m_outputfile, " addl $%i, %%esp\n", numparams*4);
// Push return value
fprintf(m_outputfile, " pushl %%ebx\n");
fprintf(m_outputfile, "####\n");
}
示例12: UnknownIdentifierException
Expression * GetDerivativeVisitor::visit(Variable * expression) {
Expression * resultExpr = (Expression *)0;
std::string varName = expression->getName();
if (varName == derivativeVariableName) {
resultExpr = new Number(1.0);
} else {
Expression * varExpr = (Expression *)0;
Scope * scope = getCurrentScope();
while (varExpr == 0 && scope != 0) {
varExpr = scope->getExpressionByIdentifier(varName);
scope = scope->getParentScope();
}
if (varExpr == 0) {
throw UnknownIdentifierException(varName);
}
resultExpr = varExpr->accept(this);
}
return resultExpr;
}