本文整理汇总了C++中ArrayType::getRange方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayType::getRange方法的具体用法?C++ ArrayType::getRange怎么用?C++ ArrayType::getRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayType
的用法示例。
在下文中一共展示了ArrayType::getRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showMessage
void minipascal::InitializeVisitor::visit(minipascal::NVariable* node)
{
showMessage("NVariable -- " + node->getOutput());
context->setNodeBlockMap(node);
// is this variable declaration?
CodeGenContext::BlockStack* stack = &(context->blockstack);
CodeGenContext::BlockStack::reverse_iterator rit;
SymbolTable::iterator sit;
for(rit = stack->rbegin(); rit != stack->rend(); ++rit)
{
if((sit = (*rit)->getLocals()->find(node->getName())) != (*rit)->getLocals()->end())
{
Exps_list* exps = node->getExps();
for(Exps_list::iterator it = exps->begin(); it != exps->end(); ++it)
{
(*it)->accept(this);
}
// set type
NType* type = (*sit).second->declaration->getType();
for(int i = 0; i < exps->size(); ++i)
{
try{
ArrayType* temp = boost::polymorphic_cast<ArrayType*>(type);
type = temp->getType();
} catch(std::bad_cast& e){
showError("Variable " + node->getName() + " wrong dimention", node);
node->setFail(true);
return;
}
}
int i= 0;
for(Exps_list::iterator it = exps->begin(); it != exps->end(); ++i, ++it)
{
// if index is a constant
try{
NType* type = sit->second->declaration->getType();
ArrayType* arraytype = boost::polymorphic_cast<ArrayType*>(type);
ArrayType::Range range = arraytype->getRange();
// Is index out of range?
NInt* constant = boost::polymorphic_cast<NInt*>(it->get());
int index = constant->getValue();
if(index < range.first || index > range.second)
{
char num[3];
int count = sprintf(num, "%d", i);
std::string numstr = std::string(num, count);
showError("Variable " + node->getName() + "'s index["+ numstr +"] out of range", node);
node->setFail(true);
}
}catch(std::bad_cast& e){
// do nothing
}
}
node->setType(type);
break;
}
}
if(rit == stack->rend())
{
showError("Undeclared variable : " + node->getName(), node);
node->setFail(true);
return;
}
}