当前位置: 首页>>代码示例>>C++>>正文


C++ SgType::class_name方法代码示例

本文整理汇总了C++中SgType::class_name方法的典型用法代码示例。如果您正苦于以下问题:C++ SgType::class_name方法的具体用法?C++ SgType::class_name怎么用?C++ SgType::class_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SgType的用法示例。


在下文中一共展示了SgType::class_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: InheritedAttribute

InheritedAttribute
visitorTraversal::evaluateInheritedAttribute(SgNode* n, InheritedAttribute inheritedAttribute)
   {
    Sg_File_Info* s = n->get_startOfConstruct();
    Sg_File_Info* e = n->get_endOfConstruct();
    Sg_File_Info* f = n->get_file_info();
    for(int x=0; x < inheritedAttribute.depth; ++x) {
        printf(" ");
    }
    if(s != NULL && e != NULL && !isSgLabelStatement(n)) { 
        printf ("%s (%d, %d, %d)->(%d, %d): %s",n->sage_class_name(),s->get_file_id()+1,s->get_raw_line(),s->get_raw_col(),e->get_raw_line(),e->get_raw_col(),  verbose ? n->unparseToString().c_str() : "" );
        if(isSgAsmDwarfConstruct(n)) {
            printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str());
        }
        SgExprStatement * exprStmt = isSgExprStatement(n);
        if(exprStmt != NULL) {
            printf(" [expr type: %s]", exprStmt->get_expression()->sage_class_name());           
            SgFunctionCallExp * fcall = isSgFunctionCallExp(exprStmt->get_expression());
            if(fcall != NULL) {
               SgExpression * funcExpr = fcall->get_function();
               if(funcExpr != NULL) {
                    printf(" [function expr: %s]", funcExpr->class_name().c_str());
               }
               SgFunctionDeclaration * fdecl = fcall->getAssociatedFunctionDeclaration();
               if(fdecl != NULL) {
                    printf(" [called function: %s]", fdecl->get_name().str());
               }
            }
        }
        if(isSgFunctionDeclaration(n)) {
            printf(" [declares function: %s]", isSgFunctionDeclaration(n)->get_name().str());
        }
        SgStatement * sgStmt = isSgStatement(n);
        if(sgStmt != NULL) {
            printf(" [scope: %s, %p]", sgStmt->get_scope()->sage_class_name(), sgStmt->get_scope());
        }
        //SgLabelStatement * lblStmt = isSgLabelStatement(n);
        //if(lblStmt != NULL) {
        //    SgStatement * lblStmt2 = lblStmt->get_statement();
        //}
    } else if (f != NULL) {
		SgInitializedName * iname = isSgInitializedName(n);
		if(iname != NULL) {
            SgType* inameType = iname->get_type();
			printf("%s (%d, %d, %d): %s [type: %s", n->sage_class_name(),f->get_file_id()+1,f->get_raw_line(),f->get_raw_col(),n->unparseToString().c_str(),inameType->class_name().c_str());
			SgDeclarationStatement * ds = isSgDeclarationStatement(iname->get_parent());
			if(ds != NULL) {
				if(ds->get_declarationModifier().get_storageModifier().isStatic()) {
					printf(" static");
				}
			}
			
			SgArrayType * art = isSgArrayType(iname->get_type());
			if(art != NULL) {
				printf(" %d", art->get_rank());
			}
			
			printf("]");
            if(isSgAsmDwarfConstruct(n)) {
                printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str());
            }
            } else {
        	printf("%s (%d, %d, %d): %s", n->sage_class_name(),f->get_file_id()+1,f->get_raw_line(),f->get_raw_col(), verbose ? n->unparseToString().c_str() : "");
		}
    } else {
        printf("%s : %s", n->sage_class_name(), verbose ? n->unparseToString().c_str() : "");
        if(isSgAsmDwarfConstruct(n)) {
            printf(" [DWARF construct name: %s]", isSgAsmDwarfConstruct(n)->get_name().c_str());
        }
    }
    printf(" succ# %lu", n->get_numberOfTraversalSuccessors());
	printf("\n");
     return InheritedAttribute(inheritedAttribute.depth+1);
   }
开发者ID:nchaimov,项目名称:undwarf,代码行数:74,代码来源:printRoseAST.cpp

示例2: ATgetAnnotation

SgType*
AtermSupport::getAtermTypeNodeAttribute (ATerm term, const std::string & annotationName )
   {
     SgType* returnNode = NULL;

     ATerm idannot = ATgetAnnotation(term, ATmake(annotationName.c_str()));
     if (idannot)
        {
#if 1
          printf ("In getAtermTypeNodeAttribute(): Found an annotation: annotationName = %s \n",annotationName.c_str());
#endif
          char* id = NULL;
       // Get the associated annotation string.
          if (ATmatch(idannot, "<str>", &id))
             {
#if 1
                printf ("In getAtermTypeNodeAttribute(): Found an string in the annotation: annotationName = %s id = %s \n",annotationName.c_str(),id);
#endif
               if (translationTypeMap.find(id) != translationTypeMap.end())
                  {
                    returnNode = translationTypeMap[id];
                    ROSE_ASSERT(returnNode != NULL);
#if 1
                    printf ("In getAtermTypeNodeAttribute translationTypeMap: id = %s returnNode = %p = %s \n",id,returnNode,returnNode->class_name().c_str());
#endif
                  }
                 else
                  {
#if 1
                    printf ("In getAtermTypeNodeAttribute(): Node not found in translationTypeMap: returing NULL pointer \n");
#endif
                  }
             }
            else
             {
            // Including types in the aterm annotations will put <term> entried in the associated term used for annotations.
            // so we need to handle ATmatch(idannot, "<term>", &term1)) as a pattern.
               ATerm term1;
               if (ATmatch(idannot, "<term>", &term1))
                  {
                    printf ("Found pattern used for nested types! \n");

                    string type_aterm_string = ATwriteToString(term1);
                    printf ("NOTE: type_aterm_string = %s \n",type_aterm_string.c_str());
                    printf ("DIAGNOSTIC: aterm_type_name = %s \n",aterm_type_name(term).c_str());

                    SgNode* n = generate_AST(term1);
                    ROSE_ASSERT(n != NULL);
                    returnNode = isSgType(n);
                    ROSE_ASSERT(returnNode != NULL);
                  }
                 else
                  {
                    printf ("Could not find nested type! \n");
                    ROSE_ASSERT(false);
                  }
#if 0
               printf ("Error: The nested aterm associated with the annotation must be available on the aterm: annotationName = %s \n",annotationName.c_str());
               ROSE_ASSERT(false);
#endif
             }
        }
       else
        {
          printf ("Error: The annotation not found on the aterm: annotationName = %s \n",annotationName.c_str());
          ROSE_ASSERT(false);
        }

#if 0
     printf ("In AtermSupport::getAtermTypeNodeAttribute(): not yet implemented \n");
     ROSE_ASSERT(false);
#endif

     return returnNode;
   }
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:75,代码来源:atermSupport.C

示例3: isSgVariableDeclaration

void
FixupTemplateArguments::visit ( SgNode* node )
   {
     ROSE_ASSERT(node != NULL);

     SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(node);
     if (variableDeclaration != NULL)
        {
       // Check the type of the variable declaration, and any template arguments if it is a template type with template arguments.
       // SgType* type = variableDeclaration->get_type();
       // ROSE_ASSERT(type != NULL);
          SgInitializedName* initializedName = SageInterface::getFirstInitializedName(variableDeclaration);
          ROSE_ASSERT(initializedName != NULL);
          SgType* type = initializedName->get_type();
          ROSE_ASSERT(type != NULL);
#if 0
          printf ("\n**************************************************************************** \n");
          printf ("FixupTemplateArguments::visit(): variableDeclaration = %p = %s initializedName = %s \n",variableDeclaration,variableDeclaration->class_name().c_str(),initializedName->get_name().str());
          printf ("   --- type = %p = %s \n",type,type->class_name().c_str());
          string filename = initializedName->get_file_info()->get_filename();
          int linenumber  = initializedName->get_file_info()->get_line();
          printf ("   --- filename = %s line = %d \n",filename.c_str(),linenumber);
#endif
          SgScopeStatement* targetScope = variableDeclaration->get_scope();
          ROSE_ASSERT(targetScope != NULL);
#if 0
          printf ("In FixupTemplateArguments::visit(): targetScope for variableDeclaration = %p = %s \n",targetScope,targetScope->class_name().c_str());
#endif

       // DQ (2/16/2017): Don't process code in template instantiations.
          SgTemplateInstantiationDefn*               templateInstantiationDefn              = isSgTemplateInstantiationDefn(targetScope);
          SgFunctionDeclaration*                     functionDeclaration                    = TransformationSupport::getFunctionDeclaration(targetScope);
          SgTemplateInstantiationFunctionDecl*       templateInstantiationFunctionDec       = isSgTemplateInstantiationFunctionDecl(functionDeclaration);
          SgTemplateInstantiationMemberFunctionDecl* templateInstantiationMemberFunctionDec = isSgTemplateInstantiationMemberFunctionDecl(functionDeclaration);
       // if (templateInstantiationDefn == NULL)
          if (templateInstantiationDefn == NULL && templateInstantiationFunctionDec == NULL && templateInstantiationMemberFunctionDec == NULL)
             {
#if 1
            // DQ (2/15/2017): When this is run, we cause transformations that cause ROSE to have an infinte loop.
            // Since this is a second (redundant) invocaion, we likely should just not run this.  But it is not 
            // clear if this truely fixes the problem that I am seeing.
               bool result = contains_private_type(type,targetScope);

            // DQ (3/25/2017): Added a trivial use to eliminate Clang warning about the return value not being used.
            // But it might be that we should not run the function, however this is a complex subject from last month 
            // that I don't wish to revisit at the moment while being focused om eliminating warnings from Clang.
               ROSE_ASSERT(result == true || result == false);
#endif
#if 0
               if (result == true)
                  {
                    printf ("******** contains private type: variableDeclaration = %p = %s initializedName = %s \n",variableDeclaration,variableDeclaration->class_name().c_str(),initializedName->get_name().str());
                  }
#endif
             }
#if 0
          printf ("DONE: FixupTemplateArguments::visit(): variableDeclaration = %p = %s initializedName = %s \n",variableDeclaration,variableDeclaration->class_name().c_str(),initializedName->get_name().str());
#endif
#if 0
          printf ("Exiting as a test! \n");
          ROSE_ASSERT(false);
#endif
        }
   }
开发者ID:matzke1,项目名称:rose-develop,代码行数:64,代码来源:fixupTemplateArguments.C

示例4: printf

bool
FixupTemplateArguments::contains_private_type (SgTemplateArgument* templateArgument, SgScopeStatement* targetScope)
   {
  // Note that within EDG and ROSE the template arguments may be shared so that we can support testing for equivalence.

  // static std::list<SgTemplateArgument*> templateArgumentList;
  // templateArgumentList.push_back(templateArgument);
     static std::set<SgTemplateArgument*> templateArgumentSet;

     if (templateArgumentSet.find(templateArgument) == templateArgumentSet.end())
        {
          templateArgumentSet.insert(templateArgument);
        }
       else
        {
#if DEBUGGING_USING_RECURSIVE_DEPTH
          printf ("@@@@@@@@@@@@@@@@@ Already been or being processed: templateArgument = %p = %s templateArgumentSet.size() = %zu \n",templateArgument,templateArgument->unparseToString().c_str(),templateArgumentSet.size());
#endif

#if 0
          printf ("Leaving contains_private_type(SgTemplateArgument): templateArgument = %p returning FALSE \n",templateArgument);
#endif

       // DQ (2/15/2017): Unclear if this is the correct return value, it might be that we want to record 
       // the associated value from the first time the argument list was processed and use that value.
       // Then again, if the value had already been substituted into the template argument then no further 
       // processing is required.
          return false;
        }

#if DEBUGGING_USING_RECURSIVE_DEPTH
     printf ("--- added templateArgument = %p templateArgumentSet.size() = %zu \n",templateArgument,templateArgumentSet.size());
#endif

#if DEBUGGING_USING_RECURSIVE_DEPTH
  // For debugging, keep track of the recursive depth.
     static size_t depth = 0;

     printf ("In contains_private_type(SgTemplateArgument*): depth = %zu \n",depth);
     ROSE_ASSERT(depth < 500);

     printf ("In contains_private_type(SgTemplateArgument*): global_depth = %zu \n",global_depth);
     if (global_depth >= 50)
        {
       // output the list of SgTemplateArgument in the list
          printf ("Error: too many elements in list: recursuion too deep \n");
          size_t counter = 0;
          for (std::set<SgTemplateArgument*>::iterator i = templateArgumentSet.begin(); i != templateArgumentSet.end(); i++)
             {
               printf ("--- templateArgumentSet[counter] = %p = %s \n",*i,templateArgument->unparseToString().c_str()); 
               counter++;
             }
        }
     ROSE_ASSERT(global_depth < 50);
#endif

  // Note this is the recursive function.
     bool returnValue = false;

#if DEBUG_PRIVATE_TYPE
     printf ("In contains_private_type(SgTemplateArgument*): templateArgument = %p = %s = %s \n",templateArgument,templateArgument->class_name().c_str(),templateArgument->unparseToString().c_str());
#endif

     switch (templateArgument->get_argumentType())
        {
          case SgTemplateArgument::type_argument:
             {
               ROSE_ASSERT (templateArgument->get_type() != NULL);

               SgType* templateArgumentType = templateArgument->get_type();
#if DEBUG_PRIVATE_TYPE
               printf ("templateArgumentType = %p = %s \n",templateArgumentType,templateArgumentType->class_name().c_str());
               if (isSgModifierType(templateArgumentType) != NULL)
                  {
                    SgModifierType* modifierType = isSgModifierType(templateArgumentType);
                    SgType* base_type = modifierType->get_base_type();
                    printf ("--- base_type = %p = %s \n",base_type,base_type->class_name().c_str());
                    SgNamedType* namedType = isSgNamedType(base_type);
                    if (namedType != NULL)
                       {
                         printf ("--- base_type: name = %s \n",namedType->get_name().str());
                       }
                  }
#endif
#if DEBUGGING_USING_RECURSIVE_DEPTH
               depth++;
               global_depth++;
#endif

#if 0
               printf ("In contains_private_type(SgTemplateArgument*): case SgTemplateArgument::type_argument: Calling contains_private_type(templateArgumentType) \n");
#endif
            // DQ (2/14/2017): We might want to generate a list of the private types used so
            // that we can check them against the scope of the declaration where they occur.
            // Note also that this does not address types that might appear in name qualification.
               returnValue = contains_private_type(templateArgumentType,targetScope);

#if DEBUGGING_USING_RECURSIVE_DEPTH
               depth--;
               global_depth--;
//.........这里部分代码省略.........
开发者ID:matzke1,项目名称:rose-develop,代码行数:101,代码来源:fixupTemplateArguments.C

示例5: convertNodeToAterm

ATerm convertNodeToAterm(SgNode* n) 
   {
     if (n == NULL)
        {
#if 0
          printf ("convertNodeToAterm(): n = %p = %s \n",n,"NULL");
#endif
          return ATmake("NULL");
        }

     ROSE_ASSERT(n != NULL);
#if 0
     printf ("convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif

     ATerm term;
     switch (n->variantT())
        {
       // case V_SgFile:
          case V_SgSourceFile:
            // Special case needed to include file name
            // term = ATmake("File(<str>, <term>)", isSgFile(n)->getFileName(), convertNodeToAterm(isSgFile(n)->get_root()));
               term = ATmake("File(<str>, <term>)", isSgSourceFile(n)->getFileName().c_str(), convertNodeToAterm(isSgSourceFile(n)->get_globalScope()));
               break;

          case V_SgPlusPlusOp:
          case V_SgMinusMinusOp:
            // Special cases needed to include prefix/postfix status
               term = ATmake("<appl(<appl>, <term>)>",
                  getShortVariantName((VariantT)(n->variantT())).c_str(),
                  (isSgUnaryOp(n)->get_mode() == SgUnaryOp::prefix ? "Prefix" :
                   isSgUnaryOp(n)->get_mode() == SgUnaryOp::postfix ? "Postfix" :
                   "Unknown"),
                   convertNodeToAterm(isSgUnaryOp(n)->get_operand()));
               break;

          case V_SgExpressionRoot:
            // Special case to remove this node
               term = convertNodeToAterm(isSgExpressionRoot(n)->get_operand());
               break;

    case V_SgCastExp:
    // Special case needed to include type
    term = ATmake("Cast(<term>, <term>)>",
	    convertNodeToAterm(isSgUnaryOp(n)->get_operand()),
	    convertNodeToAterm(isSgCastExp(n)->get_type()));
    break;

    case V_SgVarRefExp:
    // Special case needed to include id
    term = ATmake("Var(<str>)", 
		  uniqueId(isSgVarRefExp(n)->get_symbol()->get_declaration()).c_str());
    break;

    case V_SgFunctionRefExp:
    // Special case needed to include id
    term = ATmake(
                  "Func(<str>)", 
                  uniqueId(isSgFunctionRefExp(n)->get_symbol()->get_declaration()).c_str());
    break;

    case V_SgIntVal:
    // Special case needed to include value
    term = ATmake("IntC(<int>)", isSgIntVal(n)->get_value());
    break;

    case V_SgUnsignedIntVal:
    term = ATmake("UnsignedIntC(<int>)", isSgUnsignedIntVal(n)->get_value());
    break;

    case V_SgUnsignedLongVal: {
      ostringstream s;
      s << isSgUnsignedLongVal(n)->get_value();
      term = ATmake("UnsignedLongC(<str>)", s.str().c_str());
    }
    break;

    case V_SgUnsignedLongLongIntVal: {
      ostringstream s;
      s << isSgUnsignedLongLongIntVal(n)->get_value();
      term = ATmake("UnsignedLongLongC(<str>)", s.str().c_str());
    }
    break;

    case V_SgDoubleVal:
    term = ATmake("DoubleC(<real>)", isSgDoubleVal(n)->get_value());
    break;

          case V_SgInitializedName:
             {
            // Works around double initname problem
               SgInitializer* initializer = isSgInitializedName(n)->get_initializer();
               const SgName& name = isSgInitializedName(n)->get_name();
               SgType* type = isSgInitializedName(n)->get_type();

               ROSE_ASSERT(type != NULL);
#if 0
               printf ("convertNodeToAterm(): case V_SgInitializedName: name = %s initializer = %p type = %p = %s \n",name.str(),initializer,type,type->class_name().c_str());
#endif
            // Works around fact that ... is not really an initname and shouldn't be a type either
//.........这里部分代码省略.........
开发者ID:Tim02,项目名称:edg4x-rose,代码行数:101,代码来源:astToAtermImpl.C

示例6: initializeVariable

std::string initializeVariable(SgInitializedName* initName) {
	//if array type we need to get the index expression
	std::string index_expression_string;
	std::stringstream nameStringStream;
	SgName initNameName = initName->get_qualified_name();
	SgSymbol* initNameSym = initName->search_for_symbol_from_symbol_table();
	if (variablesOfNameX.find(initNameName.getString()) == variablesOfNameX.end()) {
		nameStringStream << initNameName.getString() << "_0";
		variablesOfNameX[initNameName.getString()] = 1;
	}
	else {
		int occurrence = variablesOfNameX[initNameName.getString()];
		nameStringStream << initNameName.getString() << "_" << occurrence;
		variablesOfNameX[initNameName.getString()] = occurrence+1;
	}
	SymbolToZ3[initNameSym] = nameStringStream.str();
	SymbolToInstances[initNameSym] = 0;
	SgType* initNameType = initName->get_type();
	std::string typeZ3;
	if (initNameType->isIntegerType()) {
		typeZ3 = "Int";
	}
	else if (initNameType->isFloatType()) {
		typeZ3 = "Real";
	}
	else if (isSgArrayType(initNameType)) {
		SgArrayType* arrTyp = isSgArrayType(initNameType);
		ROSE_ASSERT(arrTyp != NULL);
		SgType* underlying_type = arrTyp->get_base_type();
		std::string array_typeZ3;
		if (underlying_type->isIntegerType()) {
			array_typeZ3 = "Int";
		}
		else if (underlying_type->isFloatType()) {
			array_typeZ3 = "Real";
		}
		else {
			std::cout << "unknown underlying type of array!" << std::endl;
			std::cout << underlying_type->class_name() << std::endl;
			ROSE_ASSERT(false);
		}
		SgExpression* ind = arrTyp->get_index();
		std::stringstream arrStr;
		index_expression_string = getSgExpressionString(ind);
		typeZ3 = "(Array Int " + array_typeZ3 + ")";
	}
	else if (isSgClassType(initNameType)) {
		
		std::cout << "structs are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgPointerType(initNameType)) {
		std::cout << "pointers are not yet implemented" << std::endl;
		ROSE_ASSERT(false);
	}
	else if (isSgEnumType(initNameType)) {
		SgEnumType* et = isSgEnumType(initNameType);
		SgEnumDeclaration* enum_d = isSgEnumDeclaration(et->getAssociatedDeclaration());
		getSgDeclarationStatement(enum_d);	
		typeZ3 = et->get_name().getString(); 
	}
	else {
		std::cout << "unknown type: " << initNameType->class_name() << std::endl;
		ROSE_ASSERT(false);
	}		
	std::string name = nameStringStream.str() + "_0";
	std::stringstream streamZ3;
	if (isSgArrayType(initNameType)) {
	streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	streamZ3 << "\n(declare-fun " << name << "_len () Int)";
	streamZ3 << "\n(assert (= " << name << "_len " << index_expression_string << "))"; 	
	#ifdef ARRAY_TEST
	std::cout << "arrStream: " << streamZ3.str() << std::endl;
	#endif

	}
	else if (isSgEnumType(initNameType)) {
		streamZ3 << "(declare-const " << name << " " << typeZ3 << ")";
	}
	else {
	streamZ3 << "(declare-fun " << name << " () " << typeZ3 << ")";
	}
	return streamZ3.str();
}
开发者ID:8l,项目名称:rose,代码行数:84,代码来源:smtQueryLib.cpp

示例7: backend


//.........这里部分代码省略.........
        {
          SgFunctionCallExp* functionCallExp = isSgFunctionCallExp(functionCalls[i]);
          ROSE_ASSERT(functionCallExp != NULL);

          SgFunctionRefExp* functionRefExp = isSgFunctionRefExp(functionCallExp->get_function());
          if (functionRefExp != NULL)
             {
               SgFunctionSymbol* functionSymbol = functionRefExp->get_symbol();
               if (functionSymbol != NULL)
                  {
                    SgName functionName = functionSymbol->get_name();
                 // printf ("Function being called: %s \n",functionName.str());
                    if (functionName == "sprintf")
                       {
                      // Now we have something to do!
                         functionRefExp->set_symbol(snprintf_functionSymbol);

                      // Now add the "n" argument
                         SgExprListExp* functionArguments = functionCallExp->get_args();
                         SgExpressionPtrList & functionArgumentList = functionArguments->get_expressions();

                      // "sprintf" shuld have exactly 2 arguments (I guess the "..." don't count)
                         printf ("functionArgumentList.size() = %zu \n",functionArgumentList.size());
                      // ROSE_ASSERT(functionArgumentList.size() == 2);
                         SgExpressionPtrList::iterator i = functionArgumentList.begin();

                      // printf ("(*i) = %p = %s = %s \n",*i,(*i)->class_name().c_str(),SageInterface::get_name(*i).c_str());
                         SgVarRefExp* variableRefExp = isSgVarRefExp(*i);
                         ROSE_ASSERT(variableRefExp != NULL);

                      // printf ("variableRefExp->get_type() = %p = %s = %s \n",variableRefExp->get_type(),variableRefExp->get_type()->class_name().c_str(),SageInterface::get_name(variableRefExp->get_type()).c_str());

                         SgType* bufferType = variableRefExp->get_type();
                         SgExpression* bufferLengthExpression = NULL;
                         switch(bufferType->variantT())
                            {
                              case V_SgArrayType:
                                 {
                                   SgArrayType* arrayType = isSgArrayType(bufferType);
                                   bufferLengthExpression = arrayType->get_index();
                                   break;
                                 }

                              case V_SgPointerType:
                                 {
                                // SgPointerType* pointerType = isSgPointerType(bufferType);
                                   SgInitializedName* variableDeclaration = variableRefExp->get_symbol()->get_declaration();
                                   ROSE_ASSERT(variableDeclaration != NULL);
                                   SgExpression* initializer = variableDeclaration->get_initializer();
                                   if (initializer != NULL)
                                      {
                                        SgAssignInitializer* assignmentInitializer = isSgAssignInitializer(initializer);
                                        ROSE_ASSERT(assignmentInitializer != NULL);

                                     // This is the rhs of the initialization of the pointer (likely a malloc through a cast).
                                     // This assumes: buffer = (char*) malloc(bufferLengthExpression);
                                        SgExpression* initializationExpression = assignmentInitializer->get_operand();
                                        ROSE_ASSERT(initializationExpression != NULL);
                                        SgCastExp* castExp = isSgCastExp(initializationExpression);
                                        ROSE_ASSERT(castExp != NULL);
                                        SgFunctionCallExp* functionCall = isSgFunctionCallExp(castExp->get_operand());
                                        ROSE_ASSERT(functionCall != NULL);
                                        SgExprListExp* functionArguments = isSgExprListExp(functionCall->get_args());
                                        bufferLengthExpression = functionArguments->get_expressions()[0];
                                        ROSE_ASSERT(bufferLengthExpression != NULL);
                                      }
                                     else
                                      {
                                        printf ("Initializer not found, so no value for n in snprintf can be computed currently \n");
                                      }
                                   break;
                                 }

                              default:
                                 {
                                   printf ("Error: default reached in evaluation of buffer type = %p = %s \n",bufferType,bufferType->class_name().c_str());
                                   ROSE_ASSERT(false);
                                 }
                            }

                         ROSE_ASSERT(bufferLengthExpression != NULL);

                      // printf ("bufferLengthExpression = %p = %s = %s \n",bufferLengthExpression,bufferLengthExpression->class_name().c_str(),SageInterface::get_name(bufferLengthExpression).c_str());

                      // Jump over the first argument, the "n" is defined to be the 2nd argument (the rest are shifted one position).
                         i++;

                      // Build a deep copy of the expression used to define the static buffer (could be any complex expression).
                         SgTreeCopy copy_help;
                         SgExpression* bufferLengthExpression_copy = isSgExpression(bufferLengthExpression->copy(copy_help));

                      // Insert the "n" for the parameter list to work with "snprintf" instead of "sprintf"
                         functionArgumentList.insert(i,bufferLengthExpression_copy);
                       }
                  }
             }
        }

     return backend(project);
   }
开发者ID:billhoffman,项目名称:rose-develop,代码行数:101,代码来源:sprintf_to_snprintf.C


注:本文中的SgType::class_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。