本文整理汇总了C++中SgVarRefExp类的典型用法代码示例。如果您正苦于以下问题:C++ SgVarRefExp类的具体用法?C++ SgVarRefExp怎么用?C++ SgVarRefExp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SgVarRefExp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isSgIntVal
CPPImperialOpConstDefinition::CPPImperialOpConstDefinition (
SgExprListExp * parameters)
{
using boost::lexical_cast;
using std::string;
dimension
= isSgIntVal (parameters->get_expressions ()[indexDimenson])->get_value ();
SgAddressOfOp * addressOfOperator = isSgAddressOfOp (
parameters->get_expressions ()[indexData]);
if (addressOfOperator != NULL)
{
SgVarRefExp * operandExpression = isSgVarRefExp (
addressOfOperator->get_operand ());
ROSE_ASSERT (operandExpression != NULL);
variableName = operandExpression->get_symbol ()->get_name ().getString ();
}
else
{
variableName
= isSgVarRefExp (parameters->get_expressions ()[indexData])->get_symbol ()->get_name ().getString ();
}
ROSE_ASSERT (dimension > 0);
ROSE_ASSERT (variableName.empty () == false);
Debug::getInstance ()->debugMessage ("Found an OP_CONST declaration: '"
+ variableName + "' Its dimension is "
+ lexical_cast <string> (dimension), Debug::FUNCTION_LEVEL, __FILE__,
__LINE__);
}
示例2: main
int
main(int argc, char* argv[])
{
SgProject* project = frontend(argc, argv);
std::vector<SgIfStmt*> ifs = SageInterface::querySubTree<SgIfStmt>(project, V_SgIfStmt);
BOOST_FOREACH(SgIfStmt* if_stmt, ifs)
{
if (SgExpression *se = isSgExprStatement(if_stmt->get_conditional())->get_expression())
{
cout << "--->" << se->unparseToString() << "<---" << endl;
Rose_STL_Container<SgNode*> variableList = NodeQuery::querySubTree(se, V_SgVarRefExp);
for (Rose_STL_Container<SgNode*>::iterator i = variableList.begin(), end = variableList.end(); i != end; i++)
{
SgVarRefExp *varRef = isSgVarRefExp(*i);
SgVariableSymbol *currSym = varRef->get_symbol();
cout << "Looking at: --|" << currSym->get_name().str() << "|--" << endl;
SgDeclarationStatement *decl = currSym->get_declaration()->get_declaration();
cout << "declaration: " << decl->unparseToString() << endl;
SgConstVolatileModifier cvm = decl->get_declarationModifier().get_typeModifier().get_constVolatileModifier();
bool constness = cvm.isConst();
cout << "constness via isConst(): " << constness << endl;
cout << cvm.displayString() << endl;
}
}
}
return 0;
}
示例3: ROSE_ASSERT
/*
* Case to handle interleaveArrayOption
* C = interleaveAcrossArrays(A,B);
* i/p = A,B ; o/p = C ; operation = interleaveAcrossArrays
*/
void specificationTraversal::handleInterLeaveAcrossArrays(SgFunctionCallExp* funcCallExp) {
ROSE_ASSERT(isSgFunctionCallExp(funcCallExp) != NULL);
SgExpressionPtrList& args = funcCallExp->get_args()->get_expressions();
vector < string > inputArgs;
vector < string > outputArgs;
// Extract the argument and put it into the input list
for (SgExpressionPtrList::iterator expr = args.begin(); expr != args.end(); expr++) {
SgVarRefExp* varRefExp = isSgVarRefExp(*expr);
ROSE_ASSERT(varRefExp != NULL);
string argName = varRefExp->get_symbol()->get_declaration()->get_name().getString();
inputArgs.push_back(argName);
#if DEBUG
cout << " Input Arg: " << argName << endl;
#endif
}
// Extract the output
SgAssignOp* assignOp = isSgAssignOp(funcCallExp->get_parent());
SgVarRefExp* outputVarRefExp = isSgVarRefExp(assignOp->get_lhs_operand());
ROSE_ASSERT(outputVarRefExp != NULL);
string outputName = outputVarRefExp->get_symbol()->get_declaration()->get_name().getString();
outputArgs.push_back(outputName);
#if DEBUG
cout << " Output Arg: " << outputName << endl;
#endif
// Add to worklist
transformationWorklist.addToWorklist(LayoutOptions::InterleaveAcrossArrays, inputArgs, outputArgs);
}
示例4: isPotentiallyModifiedDuringLifeOf
// Within sc, is the variable toCheck modified between the declaration of
// lifetime and its last use? This is used to determine whether, whenever
// toCheck and lifetime are equal, one can be used as a substitute for the
// other.
bool isPotentiallyModifiedDuringLifeOf(SgBasicBlock* sc,
SgInitializedName* toCheck,
SgInitializedName* lifetime) {
SgStatementPtrList& stmts = sc->get_statements();
bool inLiveRange = false;
for (SgStatementPtrList::reverse_iterator i = stmts.rbegin();
i != stmts.rend(); ++i) {
if (containsVariableReference(*i, lifetime))
inLiveRange = true;
SgVariableSymbol* toCheckSym = new SgVariableSymbol(toCheck);
SgVarRefExp* toCheckVr = new SgVarRefExp(SgNULL_FILE, toCheckSym);
bool result = false;
if (inLiveRange && isPotentiallyModified(toCheckVr, *i)) {
result = true;
}
delete toCheckSym;
toCheckSym = NULL;
toCheckVr->set_symbol(NULL);
delete toCheckVr;
toCheckVr = NULL;
if (result) return true;
if (isSgVariableDeclaration(*i) &&
isDeclarationOf(isSgVariableDeclaration(*i), lifetime))
return false; // This must be last
}
return false;
}
示例5: isAPPArray
// Check if this is an A++ Array Reference
bool isAPPArray(SgNode *astNode) {
SgVarRefExp* varRefExp = isSgVarRefExp(astNode);
if (varRefExp == NULL)
return false;
SgVariableSymbol* variableSymbol = varRefExp->get_symbol();
ROSE_ASSERT(variableSymbol != NULL);
SgInitializedName* initializedName = variableSymbol->get_declaration();
ROSE_ASSERT(initializedName != NULL);
SgName variableName = initializedName->get_name();
// Now compute the offset to the index objects (form a special query for this???)
SgType* type = variableSymbol->get_type();
ROSE_ASSERT(type != NULL);
string typeName = TransformationSupport::getTypeName(type);
ROSE_ASSERT(typeName.c_str() != NULL);
// Recognize only these types at present
if (typeName == "intArray" || typeName == "floatArray" || typeName == "doubleArray") {
return true;
}
return false;
}
示例6: anyOfListPotentiallyModifiedIn
// Are any variables in syms modified anywhere within n, or is n a declaration
// of one of them?
// FIXME: move to inliner
bool anyOfListPotentiallyModifiedIn(const vector<SgVariableSymbol*>& syms,
SgNode* n) {
bool modified = false;
for (vector<SgVariableSymbol*>::const_iterator j = syms.begin();
j != syms.end(); ++j) {
SgVarRefExp* vr = new SgVarRefExp(SgNULL_FILE, *j);
vr->set_endOfConstruct(SgNULL_FILE);
if (isPotentiallyModified(vr, n)) {
modified = true;
}
delete vr;
if (modified) break;
if (isSgVariableDeclaration(n)) {
SgVariableDeclaration* decl = isSgVariableDeclaration(n);
for (SgInitializedNamePtrList::const_iterator i =
decl->get_variables().begin();
i != decl->get_variables().end(); ++i) {
if (*i == (*j)->get_declaration()) {
modified = true;
break;
}
}
}
if (modified) break;
}
return modified;
}
示例7: isSgFunctionCallExp
int BasicProgmemTransform::getBuffersizeNeededForFunction(SgFunctionDeclaration *func) {
int maxSize = 0;
Rose_STL_Container<SgNode *> funcCalls = NodeQuery::querySubTree(func, V_SgFunctionCallExp);
for(auto &funcCall: funcCalls) {
SgFunctionCallExp *fcall = isSgFunctionCallExp(funcCall);
Function callee(fcall);
// printf("function called: %s\n", callee.get_name().str());
if(isArduinoProgmemSafeFunction(callee)) {
continue;
}
param_pos_list ignoredPositions = getPositionsToIgnore(callee.get_name().getString());
SgExpressionPtrList params = fcall->get_args()->get_expressions();
int size = 0;
for(int pos = 0; pos < params.size(); pos++) {
if(ignoredPositions.find(pos) != ignoredPositions.end()) {
continue;
}
SgVarRefExp* var = isSgVarRefExp(params[pos]);
if(var) {
SgInitializedName *initName = var->get_symbol()->get_declaration();
if(isVarDeclToRemove(initName)) {
SgExpression *rhs = getRHSOfVarDecl(initName);
if(rhs && isSgStringVal(rhs)) {
size += isSgStringVal(rhs)->get_value().size() + 1;
}
}
}
}
if(size > maxSize) {
maxSize = size;
}
}
return maxSize;
}
示例8: isSgFunctionCallExp
/*
* Fix op structure calls and inject debug names
*/
void OPSource::fixOpFunctions(SgNode *n)
{
SgName var_name;
SgFunctionCallExp *fn = isSgFunctionCallExp(n);
if(fn != NULL)
{
string fn_name = fn->getAssociatedFunctionDeclaration()->get_name().getString();
if(fn_name.compare("op_decl_const")==0)
{
SgExprListExp* exprList = fn->get_args();
SgExpressionPtrList &exprs = exprList->get_expressions();
if( isSgStringVal(exprs.back()) == NULL )
{
SgVarRefExp* varExp = isSgVarRefExp(exprs[1]);
if(!varExp)
{
varExp = isSgVarRefExp(isSgAddressOfOp(exprs[1])->get_operand_i());
}
if(varExp)
{
var_name = varExp->get_symbol()->get_name();
}
cout << "---Injecting Debug Name for const: " << var_name.getString() << "---" << endl;
exprList->append_expression(buildStringVal(var_name));
}
}
}
}
示例9: visit
void
CompassAnalyses::SizeOfPointer::Traversal::
visit(SgNode* node)
{
int starCount;
SgSizeOfOp *szOf = isSgSizeOfOp(node);
if(!szOf) return;
Rose_STL_Container<SgNode*> pointers = NodeQuery::querySubTree(node,V_SgPointerType);
Rose_STL_Container<SgNode*> deRefs = NodeQuery::querySubTree(node,V_SgPointerDerefExp);
Rose_STL_Container<SgNode*> varRefs = NodeQuery::querySubTree(node,V_SgVarRefExp);
for (Rose_STL_Container<SgNode *>::iterator i = varRefs.begin(); i != varRefs.end(); i++)
{
SgVarRefExp *vRef = isSgVarRefExp((*i));
if (!vRef) return;
SgType *t = vRef->get_type();
std::string typeName = t->unparseToString();
//std::cout << countStars(typeName) << std::endl;
starCount = countStars(typeName);
if (!starCount or
(starCount == pointers.size() and
deRefs.size() == (starCount - 1)))
{
//std::cout << "IT'S OK!" << std::endl;
return;
}
}
output->addOutput(new CheckerOutput(node));
} //End of the visit function.
示例10: run
static void
run(Compass::Parameters parameters, Compass::OutputObject* output)
{
// We only care about source code in the user's space, not,
// for example, Boost or system files.
string target_directory =
parameters["general::target_directory"].front();
CompassAnalyses::ByteByByteStructureComparison::source_directory.assign(target_directory);
// Use the pre-built ROSE AST
SgProject* sageProject = Compass::projectPrerequisite.getProject();
// perform AST matching here
AstMatching match_functions;
MatchResult result_functions =
match_functions.performMatching("$r = SgFunctionCallExp(SgFunctionRefExp,SgExprListExp(_,_,_))", sageProject);
BOOST_FOREACH(SingleMatchVarBindings match, result_functions)
{
SgFunctionCallExp* function_call = (SgFunctionCallExp*)match["$r"];
AstMatching match_vars;
MatchResult result_vars;
if ("memcmp" == function_call->getAssociatedFunctionDeclaration()->get_name().getString())
result_vars = match_vars.performMatching("$s = SgVarRefExp", function_call);
else
continue;
bool struct_used = false;
BOOST_FOREACH(SingleMatchVarBindings var_match, result_vars)
{
SgVarRefExp* var = (SgVarRefExp*)var_match["$s"];
if (isSgClassType(var->get_type()->findBaseType()) != NULL)
struct_used = true;
}
示例11: visit
virtual void visit(SgNode* n) {
SgVarRefExp* vr = isSgVarRefExp(n);
if (!vr) return;
SgInitializedName* in = vr->get_symbol()->get_declaration();
paramMapType::const_iterator iter = paramMap.find(in);
if (iter == paramMap.end()) return; // This is not a parameter use
vr->set_symbol(iter->second);
}
示例12: visit
virtual void visit(SgNode* n) {
if (isSgBasicBlock(n)) {
SgBasicBlock* bb = isSgBasicBlock(n);
SgStatementPtrList& stmts = bb->get_statements();
size_t initi;
for (size_t decli = 0; decli < stmts.size(); ++decli) {
if (isSgVariableDeclaration(stmts[decli])) {
SgVariableDeclaration* decl = isSgVariableDeclaration(stmts[decli]);
SgInitializedNamePtrList& vars = decl->get_variables();
for (size_t vari = 0; vari != vars.size(); ++vari) {
SgInitializedName* in = vars[vari];
if (in->get_initializer() == 0) {
bool used = false;
for (initi = decli + 1; initi < stmts.size();
used |= containsVariableReference(stmts[initi], in),
++initi) {
SgExprStatement* initExprStmt = isSgExprStatement(stmts[initi]);
if (initExprStmt) {
SgExpression* top = initExprStmt->get_expression();
if (isSgAssignOp(top)) {
SgVarRefExp* vr = isSgVarRefExp(isSgAssignOp(top)->get_lhs_operand());
ROSE_ASSERT(isSgAssignOp(top) != NULL);
SgExpression* newinit = isSgAssignOp(top)->get_rhs_operand();
if (!used && vr && vr->get_symbol()->get_declaration() == in) {
ROSE_ASSERT(newinit != NULL);
// printf ("MoveDeclarationsToFirstUseVisitor::visit(): newinit = %p = %s \n",newinit,newinit->class_name().c_str());
ROSE_ASSERT(newinit->get_type() != NULL);
SgAssignInitializer* i = new SgAssignInitializer(SgNULL_FILE,newinit,newinit->get_type());
i->set_endOfConstruct(SgNULL_FILE);
// printf ("Built a SgAssignInitializer #1 \n");
vars[vari]->set_initializer(i);
stmts[initi] = decl;
newinit->set_parent(i);
// DQ (6/23/2006): Set the parent and file_info pointers
// printf ("Setting parent of i = %p = %s to parent = %p = %s \n",i,i->class_name().c_str(),in,in->class_name().c_str());
i->set_parent(in);
ROSE_ASSERT(i->get_parent() != NULL);
i->set_file_info(new Sg_File_Info(*(newinit->get_file_info())));
ROSE_ASSERT(i->get_file_info() != NULL);
// Assumes only one var per declaration FIXME
ROSE_ASSERT (vars.size() == 1);
stmts.erase(stmts.begin() + decli);
--decli; // To counteract ++decli in loop header
break; // To get out of initi loop
}
}
}
}
}
}
}
}
}
}
示例13: isSgPntrArrRefExp
InheritedAttribute
BugSeeding::evaluateInheritedAttribute (
SgNode* astNode,
InheritedAttribute inheritedAttribute )
{
// Use this if we only want to seed bugs in loops
bool isLoop = inheritedAttribute.isLoop ||
(isSgForStatement(astNode) != NULL) ||
(isSgWhileStmt(astNode) != NULL) ||
(isSgDoWhileStmt(astNode) != NULL);
// Add Fortran support
isLoop = isLoop || (isSgFortranDo(astNode) != NULL);
// Mark future noes in this subtree as being part of a loop
inheritedAttribute.isLoop = isLoop;
// To test this on simple codes, optionally allow it to be applied everywhere
bool applyEveryWhere = true;
if (isLoop == true || applyEveryWhere == true)
{
// The inherited attribute is true iff we are inside a loop and this is a SgPntrArrRefExp.
SgPntrArrRefExp *arrayReference = isSgPntrArrRefExp(astNode);
if (arrayReference != NULL)
{
// Mark as a vulnerability
inheritedAttribute.isVulnerability = true;
// Now change the array index (to seed the buffer overflow bug)
SgVarRefExp* arrayVarRef = isSgVarRefExp(arrayReference->get_lhs_operand());
ROSE_ASSERT(arrayVarRef != NULL);
ROSE_ASSERT(arrayVarRef->get_symbol() != NULL);
SgInitializedName* arrayName = isSgInitializedName(arrayVarRef->get_symbol()->get_declaration());
ROSE_ASSERT(arrayName != NULL);
SgArrayType* arrayType = isSgArrayType(arrayName->get_type());
ROSE_ASSERT(arrayType != NULL);
SgExpression* arraySize = arrayType->get_index();
SgTreeCopy copyHelp;
// Make a copy of the expression used to hold the array size in the array declaration.
SgExpression* arraySizeCopy = isSgExpression(arraySize->copy(copyHelp));
ROSE_ASSERT(arraySizeCopy != NULL);
// This is the existing index expression
SgExpression* indexExpression = arrayReference->get_rhs_operand();
ROSE_ASSERT(indexExpression != NULL);
// Build a new expression: "array[n]" --> "array[n+arraySizeCopy]", where the arraySizeCopy is a size of "array"
SgExpression* newIndexExpression = buildAddOp(indexExpression,arraySizeCopy);
// Substitute the new expression for the old expression
arrayReference->set_rhs_operand(newIndexExpression);
}
}
return inheritedAttribute;
}
示例14: simpleUndoFiniteDifferencingOne
// Propagate definitions of a variable to its uses.
// Assumptions: var is only assigned at the top level of body
// nothing var depends on is assigned within body
// Very simple algorithm designed to only handle simplest cases
void simpleUndoFiniteDifferencingOne(SgBasicBlock* body, SgExpression* var)
{
SgExpression* value = 0;
SgStatementPtrList& stmts = body->get_statements();
vector<SgStatement*> stmts_to_remove;
for (SgStatementPtrList::iterator i = stmts.begin(); i != stmts.end(); ++i)
{
// cout << "Next statement: value = " << (value ? value->unparseToString() : "(null)") << endl;
// cout << (*i)->unparseToString() << endl;
if (isSgExprStatement(*i) && isSgAssignOp(isSgExprStatement(*i)->get_expression()))
{
SgAssignOp* assignment = isSgAssignOp(isSgExprStatement(*i)->get_expression());
// cout << "In assignment statement " << assignment->unparseToString() << endl;
if (value)
replaceCopiesOfExpression(var, value, assignment->get_rhs_operand());
if (isSgVarRefExp(assignment->get_lhs_operand()) && isSgVarRefExp(var))
{
SgVarRefExp* vr = isSgVarRefExp(assignment->get_lhs_operand());
if (vr->get_symbol()->get_declaration() == isSgVarRefExp(var)->get_symbol()->get_declaration())
{
value = assignment->get_rhs_operand();
stmts_to_remove.push_back(*i);
}
}
}
else
{
if (value)
replaceCopiesOfExpression(var, value, *i);
}
}
for (vector<SgStatement*>::iterator i = stmts_to_remove.begin(); i != stmts_to_remove.end(); ++i) {
stmts.erase(std::find(stmts.begin(), stmts.end(), *i));
}
if (value)
{
// DQ (12/17/2006): Separate out the construction of the SgAssignOp from the SgExprStatement to support debugging and testing.
// stmts.push_back(new SgExprStatement(SgNULL_FILE, new SgAssignOp(SgNULL_FILE, var, value)));
var->set_lvalue(true);
SgAssignOp* assignmentOperator = new SgAssignOp(SgNULL_FILE, var, value);
var->set_parent(assignmentOperator);
value->set_parent(assignmentOperator);
printf ("In simpleUndoFiniteDifferencingOne(): assignmentOperator = %p \n",assignmentOperator);
// DQ: Note that the parent of the SgExprStatement will be set in AST post-processing (or it should be).
SgExprStatement* es = new SgExprStatement(SgNULL_FILE, assignmentOperator);
assignmentOperator->set_parent(es);
stmts.push_back(es);
es->set_parent(body);
}
}
示例15: switch
void HaloRefSearch::visit(SgNode * node)
{
switch (node->variantT()) {
case V_SgVarRefExp:
SgVarRefExp * var = isSgVarRefExp(node);
if (var->get_symbol()->getAttribute("halo_attr") != NULL) {
found = true;
}
break;
}
}