本文整理汇总了C++中ASTNode::getFirstLine方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::getFirstLine方法的具体用法?C++ ASTNode::getFirstLine怎么用?C++ ASTNode::getFirstLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::getFirstLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: semantic_error
//! Possible call target node types:
//! - SymbolASTNode
//! - ExprASTNode
//!
//! Possible call argument node types:
//! - ExprASTNode
//! - NULL
OperationSequence * ConversionController::convertCallStatement(CallStatementASTNode * statement)
{
ExecuteOperation * op = NULL;
try
{
// create operation from AST nodes
op = new ExecuteOperation();
bool isHAB = statement->isHAB();
op->setTarget(createTargetFromNode(statement->getTarget()));
// set argument value, which defaults to 0 if no expression was provided
uint32_t arg = 0;
ASTNode * argNode = statement->getArgument();
if (argNode)
{
ExprASTNode * argExprNode = dynamic_cast<ExprASTNode*>(argNode);
if (!argExprNode)
{
throw semantic_error(format_string("line %d: call argument is unexpected type", argNode->getFirstLine()));
}
argExprNode = argExprNode->reduce(m_context);
IntConstExprASTNode * intNode = dynamic_cast<IntConstExprASTNode*>(argExprNode);
if (!intNode)
{
throw semantic_error(format_string("line %d: call argument did not evaluate to an integer", argExprNode->getFirstLine()));
}
arg = intNode->getValue();
}
op->setArgument(arg);
// set call type
switch (statement->getCallType())
{
case CallStatementASTNode::kCallType:
op->setExecuteType(ExecuteOperation::kCall);
break;
case CallStatementASTNode::kJumpType:
op->setExecuteType(ExecuteOperation::kJump);
break;
}
// Set the HAB mode flag.
op->setIsHAB(isHAB);
return new OperationSequence(op);
}
catch (...)
{
// delete op and rethrow exception
if (op)
{
delete op;
}
throw;
}
}
示例2: runtime_error
DataSource * ConversionController::createIVTDataSource(IVTConstASTNode * ivtNode)
{
IVTDataSource * source = new IVTDataSource;
// Iterate over the assignment statements in the IVT definition.
ListASTNode * fieldList = ivtNode->getFieldAssignments();
if (fieldList)
{
ListASTNode::iterator it = fieldList->begin();
for (; it != fieldList->end(); ++it)
{
AssignmentASTNode * assignmentNode = dynamic_cast<AssignmentASTNode*>(*it);
if (!assignmentNode)
{
throw std::runtime_error(format_string("line %d: unexpected node type in IVT definition", (*it)->getFirstLine()));
}
// Get the IVT field name.
std::string * fieldName = assignmentNode->getIdent();
// Reduce the field expression and get the integer result.
ASTNode * valueNode = assignmentNode->getValue();
ExprASTNode * valueExpr = dynamic_cast<ExprASTNode*>(valueNode);
if (!valueExpr)
{
throw semantic_error("IVT field must have a valid expression");
}
IntConstExprASTNode * valueIntExpr = dynamic_cast<IntConstExprASTNode*>(valueExpr->reduce(m_context));
if (!valueIntExpr)
{
throw semantic_error(format_string("line %d: IVT field '%s' does not evaluate to an integer", valueNode->getFirstLine(), fieldName->c_str()));
}
uint32_t value = static_cast<uint32_t>(valueIntExpr->getValue());
// Set the field in the IVT data source.
if (!source->setFieldByName(*fieldName, value))
{
throw semantic_error(format_string("line %d: unknown IVT field '%s'", assignmentNode->getFirstLine(), fieldName->c_str()));
}
}
}
return source;
}