本文整理汇总了C++中SgVarRefExp::get_symbol方法的典型用法代码示例。如果您正苦于以下问题:C++ SgVarRefExp::get_symbol方法的具体用法?C++ SgVarRefExp::get_symbol怎么用?C++ SgVarRefExp::get_symbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SgVarRefExp
的用法示例。
在下文中一共展示了SgVarRefExp::get_symbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleInterLeaveAcrossArrays
/*
* 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);
}
示例2: 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;
}
示例3: visit
virtual void visit(SgNode* n) {
if (isSgVarRefExp(n)) {
SgVarRefExp* vr = isSgVarRefExp(n);
assert (vr->get_symbol());
if (vr->get_symbol()->get_declaration() == initname) {
if (inSimpleContext(vr) || !needSimpleContext) {
SgTreeCopy tc;
isSgExpression(n->get_parent())->replace_expression(
vr, isSgExpression(initexpr->copy(tc)));
}
}
}
}
示例4: visit
/**
* Matches assignment statements (including pointer association)
*/
void FortranAnalysis::visit(SgExprStatement * expr_stmt)
{
if (matchRegionAssignment(expr_stmt)) {
SgBinaryOp * bin_op = isSgBinaryOp(expr_stmt->get_expression());
SgVarRefExp * var = isSgVarRefExp(bin_op->get_lhs_operand());
if (var == NULL) return;
var->get_symbol()->setAttribute("halo_attr", new AstTextAttribute("HALO_VAR"));
printf("FortranAnalysis:: adding halo attr to %s\n",
var->get_symbol()->get_name().getString().c_str());
}
else if (HaloRefSearch::findHaloRef(expr_stmt)) {
expr_stmt->setAttribute("halo_ref", new AstTextAttribute("HAS_HALO_REF"));
printf("FortranAnalysis:: adding halo attr to statement\n");
}
}
示例5: frontend
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;
}
示例6: getBuffersizeNeededForFunction
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;
}
示例7: fixOpFunctions
/*
* 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));
}
}
}
}
示例8: 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__);
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
}
示例12: isSgVarRefExp
foreach(SgAssignOp* op, assigns)
{
SgVarRefExp* var = isSgVarRefExp(op->get_lhs_operand());
SgInitializedName* decl = var->get_symbol()->get_declaration();
std::cout << "Found assignment to " << var->get_symbol()->get_name().str();
if (decl->get_protected_declaration())
{
std::cout << ", which is protected.";
}
std::cout << "\t\t" << op->unparseToString();
std::cout << std::endl;
SgNode* assign_scope = SageInterface::getScope(op);
SgNode* var_scope = decl->get_scope();
if (SageInterface::isAncestor(var_scope, assign_scope))
{
std::cout << "\tAnd both are in the same scope.\n";
}
else
{
std::cout << "\tIn different scopes.\n";
}
}
示例13: isSgPntrArrRefExp
FortranOpSetDefinition::FortranOpSetDefinition (SgExprListExp * parameters)
{
/*
* ======================================================
* Get name of OP_SET dimension variable
* ======================================================
*/
if (isSgPntrArrRefExp (
parameters->get_expressions ()[index_setCardinalityName]) != NULL)
{
dimensionName
= isSgPntrArrRefExp (
parameters->get_expressions ()[index_setCardinalityName])->unparseToString ();
}
else
{
dimensionName
= isSgVarRefExp (
parameters->get_expressions ()[index_setCardinalityName])->get_symbol ()->get_name ().getString ();
}
/*
* ======================================================
* Get name of OP_SET
* ======================================================
*/
SgVarRefExp * opSetVariableReference;
if (isSgDotExp (parameters->get_expressions ()[index_OpSetName]) != NULL)
{
opSetVariableReference = isSgVarRefExp (isSgDotExp (
parameters->get_expressions ()[index_OpSetName])->get_rhs_operand ());
}
else
{
opSetVariableReference = isSgVarRefExp (
parameters->get_expressions ()[index_OpSetName]);
}
variableName
= opSetVariableReference->get_symbol ()->get_name ().getString ();
ROSE_ASSERT (dimensionName.empty () == false);
ROSE_ASSERT (variableName.empty () == false);
Debug::getInstance ()->debugMessage ("Found an OP_SET definition: '"
+ variableName + "'. Its dimension is contained in '" + dimensionName
+ "'", Debug::FUNCTION_LEVEL, __FILE__, __LINE__);
}
示例14: createFirstLoop
/*
* Create LHS of a loop dependent statement
*/
void createFirstLoop(SgExprStatement* exprStatement,
ArrayAssignmentStatementQueryInheritedAttributeType & arrayAssignmentStatementQueryInheritedData,
OperandDataBaseType & operandDataBase) {
//transformArrayRefAPP(exprStatement, arrayAssignmentStatementQueryInheritedData, operandDataBase);
// Change the LHS, it will the first PntrArrayRef
SgScopeStatement* scope = exprStatement->get_scope();
// Figure out the dimensionality of the statement globally
vector<SgExpression*> parameters;
int maxNumberOfIndexOffsets = 6; // default value for A++/P++ arrays
ROSE_ASSERT(arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE);
if (arrayAssignmentStatementQueryInheritedData.arrayStatementDimensionDefined == TRUE) {
// The the globally computed array dimension from the arrayAssignmentStatementQueryInheritedData
maxNumberOfIndexOffsets = arrayAssignmentStatementQueryInheritedData.arrayStatementDimension;
}
// Then we want the minimum of all the dimensions accesses (or is it the maximum?)
for (int n = 0; n < maxNumberOfIndexOffsets; n++) {
parameters.push_back(buildVarRefExp("_" + StringUtility::numberToString(n + 1), scope));
}
vector<SgVarRefExp*> varRefList = querySubTree<SgVarRefExp> (exprStatement, V_SgVarRefExp);
ROSE_ASSERT(varRefList.size() > 0);
SgVarRefExp* lhsVarRefExp = (*varRefList.begin()); // LHS should be the first ref
SgExpression* replaceExp;
if(isFunctionParenthesisOperator(isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent())))
{
replaceExp = isSgFunctionCallExp(lhsVarRefExp->get_parent()->get_parent());
}
else
{
replaceExp = lhsVarRefExp;
}
SgVarRefExp* newVarRefExp = buildVarRefExp("__T_pointer", scope);
string functionName = "SC_"+lhsVarRefExp->get_symbol()->get_declaration()->get_name();
SgFunctionCallExp* functionCallExp = buildFunctionCallExp(functionName, buildIntType(),
buildExprListExp(parameters), scope);
SgPntrArrRefExp* pntrArrRefExp2 = buildPntrArrRefExp(newVarRefExp, functionCallExp);
ROSE_ASSERT(replaceExp != NULL);
replaceExpression(replaceExp, pntrArrRefExp2);
return;
}
示例15: while
Rose_STL_Container<SgVarRefExp*>
buildListOfVariableReferenceExpressionsUsingGlobalVariables ( SgNode* node )
{
// This function builds a list of "uses" of variables (SgVarRefExp IR nodes) within the AST.
// return variable
Rose_STL_Container<SgVarRefExp*> globalVariableUseList;
// list of all variables (then select out the global variables by testing the scope)
Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree ( node, V_SgVarRefExp );
Rose_STL_Container<SgNode*>::iterator i = nodeList.begin();
while(i != nodeList.end())
{
SgVarRefExp *variableReferenceExpression = isSgVarRefExp(*i);
assert(variableReferenceExpression != NULL);
assert(variableReferenceExpression->get_symbol() != NULL);
assert(variableReferenceExpression->get_symbol()->get_declaration() != NULL);
assert(variableReferenceExpression->get_symbol()->get_declaration()->get_scope() != NULL);
// Note that variableReferenceExpression->get_symbol()->get_declaration() returns the
// SgInitializedName (not the SgVariableDeclaration where it was declared)!
SgInitializedName* variable = variableReferenceExpression->get_symbol()->get_declaration();
SgScopeStatement* variableScope = variable->get_scope();
// Check if this is a variable declared in global scope, if so, then save it
if (isSgGlobal(variableScope) != NULL)
{
globalVariableUseList.push_back(variableReferenceExpression);
}
i++;
}
return globalVariableUseList;
}