本文整理汇总了C++中expression::Ptr::GenerateAst方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GenerateAst方法的具体用法?C++ Ptr::GenerateAst怎么用?C++ Ptr::GenerateAst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类expression::Ptr
的用法示例。
在下文中一共展示了Ptr::GenerateAst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateAst
SymbolAstResult InvokeExpression::GenerateAst(shared_ptr<SymbolAstScope> scope, SymbolAstContext& context, shared_ptr<ast::AstDeclaration> state)
{
Expression::Ptr realFunction;
Expression::List realArguments;
bool invokeContinuation = false;
if (auto ref = dynamic_pointer_cast<ReferenceExpression>(function))
{
switch (ref->symbol->target)
{
case GrammarSymbolTarget::Invoke:
{
realFunction = arguments[0];
realArguments = dynamic_pointer_cast<ListExpression>(arguments[1])->elements;
}
break;
case GrammarSymbolTarget::InvokeContinuation:
{
realFunction = arguments[0];
realArguments = dynamic_pointer_cast<ListExpression>(arguments[1])->elements;
invokeContinuation = true;
}
break;
case GrammarSymbolTarget::NewTypeOfFields:
{
SymbolAstResult result;
vector<AstExpression::Ptr> exprs;
int exprStart = 0;
for (auto expr : dynamic_pointer_cast<ListExpression>(arguments[1])->elements)
{
result.MergeForExpression(expr->GenerateAst(scope, context, state), context, exprs, exprStart, state);
}
auto ast = make_shared<AstNewTypeExpression>();
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[0])->symbol);
ast->fields = exprs;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::NewArray:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstNewArrayExpression>();
ast->length = result.value;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::GetArrayItem:
{
SymbolAstResult result;
vector<AstExpression::Ptr> exprs;
int exprStart = 0;
for (auto expr : arguments)
{
result.MergeForExpression(expr->GenerateAst(scope, context, state), context, exprs, exprStart, state);
}
auto ast = make_shared<AstArrayAccessExpression>();
ast->target = exprs[1];
ast->index = exprs[0];
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::GetArrayLength:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstArrayLengthExpression>();
ast->target = result.value;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::IsType:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstTestTypeExpression>();
ast->target = result.value;
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[1])->symbol);
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::IsNotType:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto stat = make_shared<AstExpressionStatement>();
auto invoke = make_shared<AstInvokeExpression>();
stat->expression = invoke;
{
auto ref = make_shared<AstReferenceExpression>();
ref->reference = scope->opNot;
invoke->function = ref;
}
{
auto arg = make_shared<AstReferenceExpression>();
arg->reference = state;
invoke->arguments.push_back(arg);
}
{
auto arg = make_shared<AstTestTypeExpression>();
arg->target = result.value;
arg->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[1])->symbol);
invoke->arguments.push_back(arg);
}
auto lambda = Expression::GenerateContinuationLambdaAst(scope, context, state);
//.........这里部分代码省略.........
示例2: GenerateAst
SymbolAstResult InvokeExpression::GenerateAst(shared_ptr<SymbolAstScope> scope, SymbolAstContext& context, shared_ptr<ast::AstDeclaration> state)
{
Expression::Ptr func;
Expression::List args;
if (auto ref = dynamic_pointer_cast<ReferenceExpression>(function))
{
switch (ref->symbol->target)
{
case GrammarSymbolTarget::Invoke:
func = arguments[0];
break;
case GrammarSymbolTarget::InvokeWith:
func = arguments[0];
args = dynamic_pointer_cast<ListExpression>(arguments[1])->elements;
break;
case GrammarSymbolTarget::NewType:
{
auto ast = make_shared<AstNewTypeExpression>();
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[0])->symbol, ast);
return SymbolAstResult(ast);
}
case GrammarSymbolTarget::NewTypeOfFields:
{
SymbolAstResult result;
vector<AstExpression::Ptr> exprs;
int exprStart = 0;
for (auto expr : dynamic_pointer_cast<ListExpression>(arguments[1])->elements)
{
result.MergeForExpression(expr->GenerateAst(scope, context, state), context, exprs, exprStart, state);
}
auto ast = make_shared<AstNewTypeExpression>();
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[0])->symbol, ast);
ast->fields = exprs;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::NewArray:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstNewArrayExpression>();
ast->length = result.value;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::GetArrayItem:
{
SymbolAstResult result;
vector<AstExpression::Ptr> exprs;
int exprStart = 0;
for (auto expr : arguments)
{
result.MergeForExpression(expr->GenerateAst(scope, context, state), context, exprs, exprStart, state);
}
auto ast = make_shared<AstArrayAccessExpression>();
ast->target = exprs[1];
ast->index = exprs[0];
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::GetArrayLength:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstArrayLengthExpression>();
ast->target = result.value;
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::IsType:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstTestTypeExpression>();
ast->target = result.value;
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[1])->symbol, ast);
return result.ReplaceValue(ast);
}
case GrammarSymbolTarget::IsNotType:
{
SymbolAstResult result = arguments[0]->GenerateAst(scope, context, state);
auto ast = make_shared<AstTestTypeExpression>();
ast->target = result.value;
ast->type = scope->GetType(dynamic_pointer_cast<ReferenceExpression>(arguments[1])->symbol, ast);
auto unary = make_shared<AstUnaryExpression>();
unary->op = AstUnaryOperator::Not;
unary->operand = ast;
return result.ReplaceValue(unary);
}
case GrammarSymbolTarget::GetField:
{
SymbolAstResult result = arguments[1]->GenerateAst(scope, context, state);
auto ast = make_shared<AstFieldAccessExpression>();
ast->target = result.value;
ast->composedFieldName = dynamic_pointer_cast<ArgumentExpression>(arguments[0])->name->GetComposedName();
return result.ReplaceValue(ast);
}
}
}
if (!func)
{
func = function;
args = arguments;
//.........这里部分代码省略.........