本文整理汇总了C++中SgType::dereference方法的典型用法代码示例。如果您正苦于以下问题:C++ SgType::dereference方法的具体用法?C++ SgType::dereference怎么用?C++ SgType::dereference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgType
的用法示例。
在下文中一共展示了SgType::dereference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dereference
Type Type::dereference() const { // will deref pointer, reference, or array, else same type
SgType *t = const_cast<SgType *>(t_); // SgType::dereference should be const
return Type(t->dereference()); //XXX dereference may infinite loop for pointer to member!
}
示例2: DCL00_C
/**
* Const-qualify immutable objects
*
* \todo count assignments, if only one, report violation
*/
bool DCL00_C( const SgNode *node ) {
const SgInitializedName *varName = isSgInitializedName(node);
if (!varName)
return false;
/**
* Ignore variables generated by macros
*/
if ((varName->get_name().getString().substr(0,2) == "__")
|| isCompilerGeneratedNode(node))
return false;
/**
* Ignore global variables
*/
if (isGlobalVar(varName))
return false;
/**
* Ignore variables that are already const, are function pointers, or are
* declared inside of a struct, enum, or as an argument to a function
*/
SgType *varType = varName->get_type();
if (isConstType(varType)
|| isConstType(varType->dereference())
|| isConstType(varType->dereference()->dereference())
|| isSgFunctionType(varType)
|| isSgClassType(varType)
|| findParentOfType(varName, SgCtorInitializerList)
|| findParentOfType(varName, SgEnumDeclaration)
|| findParentOfType(varName, SgClassDeclaration))
return false;
/**
* DCL13-C is a subset of this rule, figure out which rule we are dealing
* with here
*/
std::string ruleStr;
std::string errStr;
if (findParentOfType(varName, SgFunctionParameterList)) {
/** ignore function prototypes, just worry about the definitions */
const SgFunctionDeclaration *fnDecl = findParentOfType(varName, SgFunctionDeclaration);
/**
* Disabling assertion due to C++ code
*/
if (!fnDecl)
return false;
// assert(fnDecl);
if (!fnDecl->get_definition())
return false;
if (isSgPointerType(varName->get_type())
|| isSgArrayType(varName->get_type())) {
ruleStr = "DCL13-C";
errStr = "Declare function parameters that are pointers to values not changed by the function as const: ";
} else {
return false;
}
} else {
ruleStr = "DCL00-C";
errStr = "Const-qualify immutable objects: ";
}
/**
* Ignore global variables or variables declared as extern
*/
const SgScopeStatement *varScope = varName->get_scope();
if (isSgGlobal(varScope) || isExternVar(varName))
return false;
FOREACH_SUBNODE(varScope, nodes, i, V_SgVarRefExp) {
const SgVarRefExp *iVar = isSgVarRefExp(*i);
assert(iVar);
if (getRefDecl(iVar) != varName)
continue;
const SgNode *parent = iVar->get_parent();
while(isSgCastExp(parent)) {
parent = parent->get_parent();
}
assert(parent);
/**
* If the variable is written to or it's address is taken, we can no
* longer be sure it should be const, if it's a struct and gets
* dereferenced, who knows what's getting written there :/
*/
if (varWrittenTo(iVar)
|| isSgArrowExp(parent)
|| findParentOfType(iVar, SgAddressOfOp))
return false;
/**
* If the variable is a pointer or array, and we pass it to a function
* or as an argument to pointer arithmetic, or assign it's value
* somewhere, we can longer be sure it should be const
//.........这里部分代码省略.........
示例3: instr
//.........这里部分代码省略.........
SgClassDefinition* altDecl_definition = SB::buildClassDefinition(altDecl);
SgDeclarationStatementPtrList originalMembers = originalDecl->get_definition()->get_members();
for(SgDeclarationStatementPtrList::iterator it = originalMembers.begin(); it != originalMembers.end(); it++)
{
SgDeclarationStatement* member = *it;
SgDeclarationStatement* membercpy = isSgDeclarationStatement(SI::copyStatement(member));
altDecl_definition->append_member(membercpy);
}
SgClassDeclaration* altDecl_nondef = new SgClassDeclaration(new Sg_File_Info(SI::getEnclosingFileNode(global)->getFileName()),altDecl_name,originalDecl->get_class_type());
altDecl_nondef->set_scope(global);
altDecl->set_scope(global);
altDecl->set_firstNondefiningDeclaration(altDecl_nondef);
altDecl_nondef->set_firstNondefiningDeclaration(altDecl_nondef);
altDecl->set_definingDeclaration(altDecl);
altDecl_nondef->set_definingDeclaration(altDecl);
SgClassType* altDecl_ct = SgClassType::createType(altDecl_nondef);
altDecl->set_type(altDecl_ct);
altDecl_nondef->set_type(altDecl_ct);
altDecl->set_isUnNamed(false);
altDecl_nondef->set_isUnNamed(false);
altDecl_nondef->set_forward(true);
SgSymbol* sym = new SgClassSymbol(altDecl_nondef);
global->insert_symbol(altDecl_name, sym);
altDecl->set_linkage("C");
altDecl_nondef->set_linkage("C");
ROSE_ASSERT(sym && sym->get_symbol_basis() == altDecl_nondef);
ROSE_ASSERT(altDecl->get_definingDeclaration() == altDecl);
ROSE_ASSERT(altDecl->get_firstNondefiningDeclaration() == altDecl_nondef);
ROSE_ASSERT(altDecl->search_for_symbol_from_symbol_table() == sym);
ROSE_ASSERT(altDecl->get_definition() == altDecl_definition);
ROSE_ASSERT(altDecl->get_scope() == global && altDecl->get_scope() == altDecl_nondef->get_scope());
ROSE_ASSERT(altDecl_ct->get_declaration() == altDecl_nondef);
//For some reason, this is not working...
//global->append_statement(altDecl);
//global->prepend_statement(altDecl_nondef);
//SI::setOneSourcePositionForTransformation(altDecl);
//SI::setOneSourcePositionForTransformation(altDecl_nondef);
}
SgType* baseType;
if(isSgPointerType(ptr))
baseType = ptr->dereference();
else
baseType = ptr->findBaseType();
baseType = baseType->stripTypedefsAndModifiers();
if(baseType == NULL || baseType == ptr)
{
//In this case, there is no base type.
rhs = SB::buildFunctionCallExp(SgName("ti_init"),SgTypeVoid::createType(),SB::buildExprListExp(
SB::buildStringVal(ptr->unparseToString()),
((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)),
SB::buildIntVal(getClassification(ptr))
),init_definition);
}
else
{
//The type has a base type.
std::string baseStructNameStr = prefix + Util::getNameForType(baseType).getString();
rhs = SB::buildFunctionCallExp(SgName("ti_init"),ti_type,SB::buildExprListExp(
SB::buildStringVal(ptr->unparseToString()),
((altDecl == NULL && !isSgTypeVoid(ptr)) ? (SgExpression*) SB::buildSizeOfOp(types[index]) : (SgExpression*) SB::buildIntVal(-1)),
SB::buildIntVal(getClassification(ptr))
),init_definition);
SgExprStatement* set_BT = SB::buildFunctionCallStmt(SgName("setBaseType"),ti_type,SB::buildExprListExp(
SB::buildVarRefExp(structNameStr),
SB::buildVarRefExp(baseStructNameStr)),
init_definition);
init_definition->append_statement(set_BT);
}
lhs = SB::buildVarRefExp(structNameStr);
SgExprStatement* assignstmt = SB::buildAssignStatement(lhs,rhs);
init_definition->prepend_statement(assignstmt);
std::remove(lst.begin(),lst.end(),structNameStr);
}
}
}