Exemple #1
0
std::string CompassAnalyses::AllowedFunctions::Traversal::
typeVariantT( SgType *type, int vT )
{
  switch( vT )
  {
    case V_SgArrayType:
    {
      SgType *baseType = isSgArrayType(type)->get_base_type();
      ROSE_ASSERT(baseType != NULL);

      return this->typeVariantT( baseType, baseType->variantT() ) + "[]";
    } break;
    case V_SgMemberFunctionType:          //fall
    case V_SgPartialFunctionType:         //fall
    case V_SgPartialFunctionModifierType: //fall thru
    case V_SgFunctionType:
    {
      SgFunctionType *fType = isSgFunctionType(type);
      ROSE_ASSERT(fType != NULL);

      return fType->get_mangled_type().getString();
    } break;
    case V_SgModifierType:
    {
      SgType *baseType = isSgModifierType(type)->get_base_type();
      ROSE_ASSERT(baseType != NULL);

      return this->typeVariantT(baseType,baseType->variantT());
    } break;
    case V_SgClassType:    //fall
    case V_SgEnumType:     //fall
    case V_SgTypedefType:  //fall thru
    case V_SgNamedType:
    {
      SgNamedType *nType = isSgNamedType(type);
      ROSE_ASSERT(nType != NULL);

      return nType->get_name().getString();
    } break;
    case V_SgPointerMemberType:   //fall thru
    case V_SgPointerType:
    {
      SgType *baseType = isSgPointerType(type)->get_base_type();
      ROSE_ASSERT(baseType != NULL);

      return "*" + this->typeVariantT(baseType,baseType->variantT());
    } break;
    case V_SgQualifiedNameType:
    {
      SgType *baseType = isSgQualifiedNameType(type)->get_base_type();
      ROSE_ASSERT(baseType != NULL);

      return this->typeVariantT(baseType,baseType->variantT());
    } break;
    case V_SgReferenceType:
    {
      SgType *baseType = isSgReferenceType(type)->get_base_type();
      ROSE_ASSERT(baseType != NULL);

      return "&" + this->typeVariantT(baseType,baseType->variantT());
    } break;
    case V_SgTemplateType:
    {
      return "template<T>";
//      return isSgTemplateType(type)->get_mangled().getString();
    } break;
    case V_SgTypeBool: return "bool";
    case V_SgTypeChar: return "char";
    case V_SgTypeComplex: return "complex";
    case V_SgTypeDefault: return "default";
    case V_SgTypeDouble: return "double";
    case V_SgTypeEllipse: return "...";
    case V_SgTypeFloat: return "float";
    case V_SgTypeGlobalVoid: return "global void";
    case V_SgTypeImaginary: return "imaginary";
    case V_SgTypeInt: return "int";
    case V_SgTypeLong: return "long";
    case V_SgTypeLongDouble: return "long double";
    case V_SgTypeLongLong: return "long long";
    case V_SgTypeShort: return "short";
    case V_SgTypeSignedChar: return "signed char";
    case V_SgTypeSignedInt: return "signed int";
    case V_SgTypeSignedLong: return "signed long";
    case V_SgTypeSignedShort: return "signed short";
    case V_SgTypeString: return "string";
    case V_SgTypeUnknown: return isSgTypeUnknown(type)->get_mangled().getString();
    case V_SgTypeUnsignedChar: return "unsigned char";
    case V_SgTypeUnsignedInt: return "unsigned int";
    case V_SgTypeUnsignedLong: return "unsigned long";
    case V_SgTypeUnsignedLongLong: return "unsigned long long";
    case V_SgTypeUnsignedShort: return "unsigned short";
    case V_SgTypeVoid: return "void";
    case V_SgTypeWchar: return "wchar";
    default: break;
  } //switch( vT )

  std::cerr << "Got Unknown Variant: " << vT << std::endl;

  return "unknown";
}
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--;
#endif
#if 0
               printf ("In contains_private_type(SgTemplateArgument*): case SgTemplateArgument::type_argument: DONE calling contains_private_type(templateArgumentType): returnValue = %s \n",returnValue ? "true" : "false");
#endif
               if (returnValue == true)
                  {
                 // Find an alternative typedef to use instead.

                 // Note that this need not be a SgTypedefType (the lists are available in every SgType).
                    SgTypedefType* typedefType = isSgTypedefType(templateArgumentType);

                    if (typedefType == NULL && isSgModifierType(templateArgumentType) != NULL)
                       {
                         SgModifierType* modifierType = isSgModifierType(templateArgumentType);
                         SgType* base_type = modifierType->get_base_type();
#if 0
                         printf ("Found SgModifierType: --- 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 0
                         printf ("******* Reset the typedefType to what was found in the modifier type as a base type = %p = %s \n",base_type,base_type->class_name().c_str());
#endif
                         typedefType = isSgTypedefType(base_type);
                       }

                    if (typedefType != NULL)
                       {
                      // Check if this is a type from a typedef that is in the same scope as the target declaration (variable declaration).
                         SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(typedefType->get_declaration());
                         ROSE_ASSERT(typedefDeclaration != NULL);

                      // Test for the matching scope (an even better test would be to make sure that the targetScope is nested in the typedef scope).
                         SgScopeStatement* typedefDeclarationScope = typedefDeclaration->get_scope();
                         ROSE_ASSERT(targetScope != NULL);
                         ROSE_ASSERT(typedefDeclarationScope != NULL);
#if 0
                         printf ("targetScope             = %p = %s \n",targetScope,targetScope->class_name().c_str());
                         printf ("typedefDeclarationScope = %p = %s \n",typedefDeclarationScope,typedefDeclarationScope->class_name().c_str());
                         if (typedefDeclarationScope == targetScope)
                            {
                              printf ("In contains_private_type(SgTemplateArgument*): This is a typedef type from the same scope as the target declaration \n");
                              ROSE_ASSERT(false);
                            }
#endif

                      // Consult the list of alreanative typedefs.
                         SgTypedefSeq* typedef_table = typedefType->get_typedefs();
                         ROSE_ASSERT(typedef_table != NULL);

#if DEBUG_PRIVATE_TYPE || 0
                         printf ("Looking at typedef typedefType = %p = %s = %s \n",typedefType,typedefType->class_name().c_str(),typedefType->unparseToString().c_str());
#endif

                         SgTypePtrList & typedefList = typedef_table->get_typedefs();

                         bool foundNonPrivateTypeAlias = false;
                         SgType* suitableTypeAlias = NULL;

                         int counter = 0;
                         SgTypePtrList::iterator i = typedefList.begin();
                         while (foundNonPrivateTypeAlias == false && i != typedefList.end())
                           {
                             ROSE_ASSERT(*i != NULL);
#if DEBUG_PRIVATE_TYPE || 0
                             printf ("Looking for suitable type alias (#%d): *i = %p = %s = %s \n",counter,*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
#endif
#if DEBUGGING_USING_RECURSIVE_DEPTH
                             global_depth++;
#endif
                             bool isPrivateType = contains_private_type(*i,targetScope);

#if DEBUGGING_USING_RECURSIVE_DEPTH
                             global_depth--;
#endif
                             if (isPrivateType == false)
                                {
                                  suitableTypeAlias = *i;
                                  foundNonPrivateTypeAlias = true;
                                }

                          // foundNonPrivateTypeAlias = !isPrivateType;

                             i++;
                             counter++;
                           }
#if 0
                         printf ("foundNonPrivateTypeAlias = %s \n",foundNonPrivateTypeAlias ? "true" : "false");
#endif
                         if (foundNonPrivateTypeAlias == true)
                            {
                              ROSE_ASSERT(suitableTypeAlias != NULL);
#if DEBUG_PRIVATE_TYPE_TRANSFORMATION || 0
                              printf ("targetScope             = %p = %s \n",targetScope,targetScope->class_name().c_str());
                              printf ("typedefDeclarationScope = %p = %s \n",typedefDeclarationScope,typedefDeclarationScope->class_name().c_str());
                              targetScope->get_file_info()->display("targetScope: debug");
                              typedefDeclarationScope->get_file_info()->display("typedefDeclarationScope: debug");

                              printf ("Found private type to be replaced: typedefType       = %p = %s = %s \n",typedefType,typedefType->class_name().c_str(),typedefType->unparseToString().c_str());
                              printf ("Found suitable type alias:         suitableTypeAlias = %p = %s = %s \n",suitableTypeAlias,suitableTypeAlias->class_name().c_str(),suitableTypeAlias->unparseToString().c_str());
#endif
#if 0
                              printf ("SageInterface::whereAmI(targetScope): \n");
                              SageInterface::whereAmI(targetScope);
                              printf ("SageInterface::whereAmI(typedefDeclaration): \n");
                              SageInterface::whereAmI(typedefDeclaration);
#endif
#if 0
                              printf ("Selecting alternative type to use for unparsing: \n");
                              printf ("--- were going to use: %s \n",templateArgument->unparseToString().c_str());
                              printf ("--- selecing instead : %s \n",suitableTypeAlias->unparseToString().c_str());
#endif

                           // TV (10/05/2018): (ROSE-1431) Traverse the chain of all associated template arguments (coming from the same EDG template argument)
                              SgTemplateArgument * templateArgument_it = templateArgument;
                              while (templateArgument_it->get_previous_instance() != NULL) {
                                templateArgument_it = templateArgument_it->get_previous_instance();
                              }
                              ROSE_ASSERT(templateArgument_it != NULL && templateArgument_it->get_previous_instance() == NULL);
                              do {
#if 0
                                   printf ("  Update templateArgument = %p\n", templateArgument);
#endif
                                   templateArgument_it->set_unparsable_type_alias(suitableTypeAlias);

                                // DQ (1/9/2017): Also set the return result from get_type() so that the name qualification will be handled correctly.
                                   templateArgument_it->set_type(suitableTypeAlias);

                                   templateArgument_it = templateArgument_it->get_next_instance();
                                 }
                              while (templateArgument_it != NULL);

                              ROSE_ASSERT(templateArgument_it == NULL);

// #if DEBUG_PRIVATE_TYPE_TRANSFORMATION
#if 0
                              string typedefType_typeName       = generate_string_name (typedefType,NULL);
                              printf ("typedefType_typeName size = %zu \n",typedefType_typeName.length());
                              printf ("typedefType_typeName       = %s \n",typedefType_typeName.c_str());

                              string suitableTypeAlias_typeName = generate_string_name (suitableTypeAlias,NULL);
                              printf ("suitableTypeAlias_typeName size = %zu \n",suitableTypeAlias_typeName.length());
                              printf ("suitableTypeAlias_typeName size = %s \n",suitableTypeAlias_typeName.c_str());

                              ROSE_ASSERT(suitableTypeAlias_typeName.length() < typedefType_typeName.length() * 100);
                              ROSE_ASSERT(suitableTypeAlias_typeName.length() < 40000);
#endif
                            }
                       }
                      else
                       {
#if DEBUG_PRIVATE_TYPE
                         printf ("Alternative types not searched for in nontypedef types (not implemented) \n");
#endif
#if 0
                         printf ("####### Alternative types not searched: 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
                       }
                  }

               break;
             }

          default:
             {
#if DEBUG_PRIVATE_TYPE
               printf ("Ignoring non-type template arguments \n");
#endif
             }
        }

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

  // templateArgumentList.pop_back();
     templateArgumentSet.erase(templateArgument);

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

#if 0
     printf ("Leaving contains_private_type(SgTemplateArgument): templateArgument = %p returnValue = %s \n",templateArgument,returnValue ? "true" : "false");
#endif

     return returnValue;
   }
bool FixupTemplateArguments::contains_private_type (SgType* type, SgScopeStatement* targetScope)
   {
  // DQ (4/2/2018): Note that this function now addresses requirements of supporting both private and protected types.

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

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

     printf ("In contains_private_type(SgType*): global_depth = %zu \n",global_depth);
     ROSE_ASSERT(global_depth < 55);
#endif

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

#if DEBUG_PRIVATE_TYPE || 0
  // DQ (1/7/2016): It is a problem to do this for some files (failing about 35 files in Cxx_tests).
  // The issues appears to be in the unparsing of the template arguments of the qualified names for the types.
  // printf ("In contains_private_type(SgType*): type = %p = %s = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str());
     printf ("In contains_private_type(SgType*): type = %p = %s \n",type,type->class_name().c_str());
#endif

     SgTypedefType* typedefType = isSgTypedefType(type);
     if (typedefType != NULL)
        {
       // Get the associated declaration.
          SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(typedefType->get_declaration());
          ROSE_ASSERT(typedefDeclaration != NULL);

#if 0
          bool isPrivate = typedefDeclaration->get_declarationModifier().get_accessModifier().isPrivate();
#else
       // DQ (4/2/2018): Fix this to address requirements of both private and protected class members (see Cxx11_tests/test2018_71.C).
          bool isPrivate = typedefDeclaration->get_declarationModifier().get_accessModifier().isPrivate() ||
                           typedefDeclaration->get_declarationModifier().get_accessModifier().isProtected();
#endif
#if DEBUG_PRIVATE_TYPE || 0
          printf ("typedefDeclaration isPrivate = %s \n",isPrivate ? "true" : "false");
#endif

       // First we need to know if this is a visable type.
          bool isVisable = false;
#if 0
          printf ("targetScope                     = %p = %s \n",targetScope,targetScope->class_name().c_str());
       // printf ("typedefDeclaration              = %p = %s \n",typedefDeclaration,typedefDeclaration->class_name().c_str());
          printf ("typedefDeclaration->get_scope() = %p = %s \n",typedefDeclaration->get_scope(),typedefDeclaration->get_scope()->class_name().c_str());
#endif
#if 0
          printf ("SageInterface::whereAmI(targetScope): \n");
          SageInterface::whereAmI(targetScope);
          printf ("SageInterface::whereAmI(typedefDeclaration): \n");
          SageInterface::whereAmI(typedefDeclaration);
#endif
#if 0
          printf ("\ntargetScope symbol table: \n");
          targetScope->get_symbol_table()->print("targetScope");
          printf ("end of symbol table \n");
          printf ("\ntypedefDeclaration->get_scope() symbol table: \n");
          typedefDeclaration->get_scope()->get_symbol_table()->print("typedefDeclaration->get_scope()");
          printf ("end of symbol table \n\n");
#endif
       // Test for the trivial case of matching scope (an even better test (below) is be to make sure that the targetScope is nested in the typedef scope).
          if (typedefDeclaration->get_scope() == targetScope)
             {
#if 0
               printf ("In contains_private_type(SgType*): This is a typedef type from the same scope as the target declaration \n");
#endif
            // ROSE_ASSERT(false);
            // return false;
               isVisable = true;
             }
            else
             {
            // SgTypedefSymbol*   lookupTypedefSymbolInParentScopes  (const SgName & name, SgScopeStatement *currentScope = NULL);
               SgTypedefSymbol* typedefSymbol = SageInterface::lookupTypedefSymbolInParentScopes (typedefDeclaration->get_name(),targetScope);
               if (typedefSymbol != NULL)
                  {
#if 0
                    printf ("In contains_private_type(SgType*): This is not in the current scope but can be reached from the current scope \n");
#endif
                 // ROSE_ASSERT(false);
                 // return false;
                    isVisable = true;
                  }
                 else
                  {
#if 0
                    printf ("Symbol for typedef name = %s not found in parent scopes \n",typedefDeclaration->get_name().str());
#endif
                 // ROSE_ASSERT(false);
                  }
             }
#if 0
       // Testing codes because it seems that "BitSet" shuld be visiable and so we need to debug this first.
          if (typedefDeclaration->get_name() == "BitSet")
             {
               printf ("Exiting as a test! \n");
               ROSE_ASSERT(false);
             }
#endif
       // If this is not private, then we are looking at what would be possbile template arguments used in a possible name qualification.
       // if (isPrivate == false)
       // if (isPrivate == false && isVisable == false)
          if (isVisable == false)
             {
               if (isPrivate == true)
                  {
                    return true;
                  }
                 else
                  {

                 // Get the scope and see if it is a template instantiation.
                    SgScopeStatement* scope = typedefDeclaration->get_scope();
#if DEBUG_PRIVATE_TYPE || 0
                    printf ("++++++++++++++ Looking in parent scope for template arguments: scope = %p = %s \n",scope,scope->class_name().c_str());
#endif
                 // Get the associated declaration.
                    switch (scope->variantT())
                       {
                         case V_SgTemplateInstantiationDefn:
                            {
                              SgTemplateInstantiationDefn* templateInstantiationDefinition = isSgTemplateInstantiationDefn(scope);
                              ROSE_ASSERT(templateInstantiationDefinition != NULL);

                              SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(templateInstantiationDefinition->get_declaration());
                              ROSE_ASSERT(templateInstantiationDeclaration != NULL);

                              SgTemplateArgumentPtrList & templateArgumentPtrList = templateInstantiationDeclaration->get_templateArguments();
                              for (SgTemplateArgumentPtrList::iterator i = templateArgumentPtrList.begin(); i != templateArgumentPtrList.end(); i++)
                                 {
#if DEBUG_PRIVATE_TYPE
                                   printf ("recursive call to contains_private_type(%p): name = %s = %s \n",*i,(*i)->class_name().c_str(),(*i)->unparseToString().c_str());
#endif
#if DEBUGGING_USING_RECURSIVE_DEPTH
                                   global_depth++;
#endif

                                   bool isPrivateType = contains_private_type(*i,targetScope);

#if DEBUGGING_USING_RECURSIVE_DEPTH
                                   global_depth--;
#endif
                                   returnValue |= isPrivateType;
                                 }
                              break;
                            }

                         default:
                            {
#if DEBUG_PRIVATE_TYPE
                              printf ("Ignoring non-SgTemplateInstantiationDefn \n");
#endif
                            }
                       }
                  }
             }
            else
             {
            // If it is visible then it need not be qualified and we don't care about if it was private.
               ROSE_ASSERT(isVisable == true);

            // returnValue = true;
               returnValue = false;
             }
        }
       else
        {
#if DEBUG_PRIVATE_TYPE || 0
          printf ("could be a wrapped type: type = %p = %s (not a template class instantiaton) \n",type,type->class_name().c_str());
          if (isSgModifierType(type) != NULL)
             {
               SgModifierType* modifierType = isSgModifierType(type);
               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 this is a default SgModifierType then unwrap it.
#if 0
          SgModifierType* modifierType = isSgModifierType(type);
          if (modifierType != NULL)
             {

#error "DEAD CODE!"

            // What kind of modifier is this?
               printf ("What kind of type modifier: %s \n",modifierType->get_typeModifier().displayString().c_str());
               if (modifierType->get_typeModifier().isDefault() == true)
                  {
                 // This is a default mode modifier (acting as a wrapper type).
                    type = modifierType->get_base_type();
                  }
                 else
                  {
                    printf ("Not a default modifierType wrapper (need to handle this case) \n");
                    ROSE_ASSERT(false);
                  }
             }
#else
       // Strip past pointers and other wrapping modifiers (but not the typedef types, since the whole point is to detect private instatances).
          type = type->stripType(SgType::STRIP_MODIFIER_TYPE|SgType::STRIP_REFERENCE_TYPE|SgType::STRIP_RVALUE_REFERENCE_TYPE|SgType::STRIP_POINTER_TYPE|SgType::STRIP_ARRAY_TYPE);
#endif

#if 0
          printf ("After stripType(): type = %p = %s \n",type,type->class_name().c_str());
          SgNamedType* namedType = isSgNamedType(type);
          if (namedType != NULL)
             {
               printf ("--- stripType: name = %s \n",namedType->get_name().str());
             }
#endif
          ROSE_ASSERT(type != NULL);

       // Make sure this is not a simple template type (else we will have infinite recursion).
       // if (type != NULL && type->isIntegerType() == false && type->isFloatType() == false)
       // if (type != NULL)
          SgTemplateType*        templateType        = isSgTemplateType(type);
          SgClassType*           classType           = isSgClassType(type);
          SgTypeVoid*            voidType            = isSgTypeVoid(type);
          SgRvalueReferenceType* rvalueReferenceType = isSgRvalueReferenceType(type);
          SgFunctionType*        functionType        = isSgFunctionType(type);
          SgDeclType*            declType            = isSgDeclType(type);

       // DQ (12/7/2016): An enum type needs to be handled since the declaration might be private (but still debugging this for now).
          SgEnumType*            enumType            = isSgEnumType(type);

       // DQ (2/12/2017): Added specific type (causing infinite recursion for CompileTests/RoseExample_tests/testRoseHeaders_03.C.
          SgTypeEllipse*         typeEllipse         = isSgTypeEllipse(type);
          SgTypeUnknown*         typeUnknown         = isSgTypeUnknown(type);
          SgTypeComplex*         typeComplex         = isSgTypeComplex(type);

       // DQ (2/16/2017): This is a case causeing many C codes to fail.
          SgTypeOfType* typeOfType = isSgTypeOfType(type);

          if (type != NULL && templateType == NULL && classType == NULL && voidType == NULL && rvalueReferenceType == NULL && 
                              functionType == NULL && declType  == NULL && enumType == NULL && typeEllipse         == NULL && 
                              typeUnknown  == NULL && typeComplex == NULL && typeOfType == NULL)
             {
#if DEBUG_PRIVATE_TYPE || 0
               printf ("found unwrapped type = %p = %s = %s (not a template class instantiaton) \n",type,type->class_name().c_str(),type->unparseToString().c_str());
#endif
            // if (type->isIntegerType() == false && type->isFloatType() == false)
            // if (type->isIntegerType() == false && type->isFloatType() == false)
               if (type->isIntegerType() == false && type->isFloatType() == false)
                  {
#if DEBUG_PRIVATE_TYPE || 0
                    printf ("Making a recursive call to contains_private_type(type): not integer or float type: type = %p = %s  \n",type,type->class_name().c_str());
#endif
#if DEBUGGING_USING_RECURSIVE_DEPTH
                    depth++;
                    global_depth++;
#endif
                    bool isPrivateType = contains_private_type(type,targetScope);

#if DEBUGGING_USING_RECURSIVE_DEPTH
                    depth--;
                    global_depth--;
#endif
                    returnValue = isPrivateType;
                  }
                 else
                  {
                 // This can't be a private type.
#if DEBUG_PRIVATE_TYPE
                    printf ("This is an integer or float type (of some sort): type = %p = %s = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str());
#endif
                    returnValue = false;
                  }
             }
            else
             {
            // This is where we need to resolve is any types that are associated with declarations might be private (e.g. SgEnumType).

               if (classType != NULL)
                  {
                 // Check if this is associated with a template class instantiation.
#if 0
                    SgClassDeclaration* classDeclaration = isSgClassDeclaration(classType->get_declaration());
                    ROSE_ASSERT(classDeclaration != NULL);
                    printf ("--------- classDeclaration = %p = %s = %s \n",classDeclaration,classDeclaration->class_name().c_str(),classDeclaration->get_name().str());
#endif
                    SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(classType->get_declaration());
                    if (templateInstantiationDeclaration != NULL)
                       {
#if DEBUGGING_USING_RECURSIVE_DEPTH
                         global_depth++;
#endif
#if 0
                         printf ("Calling contains_private_type(SgTemplateArgumentPtrList): templateInstantiationDeclaration = %p = %s \n",
                              templateInstantiationDeclaration,templateInstantiationDeclaration->get_name().str());
#endif
                         returnValue = contains_private_type(templateInstantiationDeclaration->get_templateArguments(),targetScope);

#if DEBUGGING_USING_RECURSIVE_DEPTH
                         global_depth--;
#endif
#if 0
                         printf ("DONE: Calling contains_private_type(SgTemplateArgumentPtrList): templateInstantiationDeclaration = %p = %s \n",
                              templateInstantiationDeclaration,templateInstantiationDeclaration->get_name().str());
#endif
                       }
#if 0
                    printf ("DONE: --- classDeclaration = %p = %s = %s \n",classDeclaration,classDeclaration->class_name().c_str(),classDeclaration->get_name().str());
#endif
                  }
             }
        }

#if DEBUG_PRIVATE_TYPE || 0
     printf ("Leaving contains_private_type(SgType*): type = %p = %s = %s returnValue = %s \n",type,type->class_name().c_str(),type->unparseToString().c_str(),returnValue ? "true" : "false");
#endif

     return returnValue;
   }
Exemple #4
0
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
               if (isSgTypeEllipse(type))
                  {
                    term = ATmake("Ellipses");
                  }
                 else
                  {
                    std::string uniqueIdString = uniqueId(n);
#if 0
                    printf ("uniqueIdString = %s \n",uniqueIdString.c_str());
                    printf ("Calling generate ATerm for SgInitializedName->get_name() name = %s \n",name.str());
                    ATerm name_aterm = ATmake("Name(<str>)",name.str());
                 // ATerm name_aterm = ATmake(name.str());
                    printf ("Calling convertNodeToAterm(type) \n");
                    ATerm type_aterm = convertNodeToAterm(type);
                    printf ("Calling convertNodeToAterm(initializer) \n");
#endif
                    ATerm initializer_aterm = convertNodeToAterm(initializer);
#if 0
                    printf ("Calling ATmake() \n");
#endif
#if 1
                    term = ATmake("InitName(<str>, <term>, <term>) {[id, <str>]}", 
                                    (name.str() ? name.str() : ""), 
                                    convertNodeToAterm(type), 
                                    convertNodeToAterm(initializer),
                                    uniqueId(n).c_str());
                                 // uniqueIdString.c_str());
#else
                    term = ATmake("InitName(<term>,<term>)",
                                  //(name.str() ? name.str() : ""), 
                                  // name_aterm,
                                    type_aterm, 
                                    initializer_aterm
                                 // uniqueId(n).c_str());
                                 // uniqueIdString.c_str());
                                    );
#endif
#if 0
                    printf ("Calling ATsetAnnotation() \n");
#endif
                    term = ATsetAnnotation(term, ATmake("id"), ATmake("<str>", uniqueId(n).c_str()));
#if 0
                    printf ("DONE: Calling ATsetAnnotation() \n");
#endif
                  }

               break;
             }

    case V_SgFunctionDeclaration: {
      // Special case needed to include name
      SgFunctionDeclaration* fd = isSgFunctionDeclaration(n);
      term = ATmake("Function(<str>, <term>, <term>, <term>)", 
		    fd->get_name().str(), 
		    convertNodeToAterm(fd->get_orig_return_type()),
		    convertSgNodeRangeToAterm(fd->get_args().begin(),
					      fd->get_args().end()),
		    convertNodeToAterm(fd->get_definition()));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgClassDeclaration: {
      // Special case needed to distinguish forward/full definitions and to
      // include class name
      SgClassDeclaration* decl = isSgClassDeclaration(n);
      assert (decl);
      SgName sname = decl->get_name();
      const char* name = sname.str();
      // Suggestion: have a field named local_definition in each class
      // declaration that is 0 whenever the current declaration doesn't
      // have a definition attached, even if there is another declaration
      // which does have a definition attached.
      SgClassDefinition* defn = decl->get_definition();
      // cout << "defn = 0x" << hex << defn << endl << dec;
      if (decl->isForward())
	defn = 0;
      if (defn)
	term = ATmake("Class(<str>, <term>)", 
		      (name ? name : ""), // Will be simpler when SgName
		      // becomes string
		      convertNodeToAterm(defn));
      else
	term = ATmake("ClassFwd(<str>)", (name ? name : ""));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgEnumDeclaration: {
      // Special case to include enum name and enumerator names which are not
      // traversal children
      SgName sname = isSgEnumDeclaration(n)->get_name();
      const char* name = sname.str();
      const SgInitializedNamePtrList& enumerators = 
	isSgEnumDeclaration(n)->get_enumerators();
      term = ATmake("Enum(<str>, <term>)",
		    (name ? name : "{anonymous}"), 
		    convertSgNodeRangeToAterm(enumerators.begin(),
					      enumerators.end()));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgPointerType: {
      // Special case because types can't be traversed yet
      SgType* type = isSgPointerType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Pointer(<term>)", t);
    }
    break;

    case V_SgReferenceType: {
      // Special case because types can't be traversed yet
      SgType* type = isSgReferenceType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Reference(<term>)", t);
    }
    break;

    case V_SgModifierType: {
      // Special case for type traversal and to prettify modifier names
      SgType* type = isSgModifierType(n)->get_base_type();
      SgTypeModifier& modifier = isSgModifierType(n)->get_typeModifier();
      SgConstVolatileModifier& cvmod = modifier.get_constVolatileModifier();
      term = convertNodeToAterm(type);
      if (cvmod.isConst())
	term = ATmake("Const(<term>)", term);
      if (cvmod.isVolatile())
	term = ATmake("Volatile(<term>)", term);
    }
    break;

    case V_SgArrayType: {
      // Special case because types can't be traversed yet, and to get length
      SgType* type = isSgArrayType(n)->get_base_type();
      ATerm t = convertNodeToAterm(type);
      term = ATmake("Array(<term>, <term>)", t, (isSgArrayType(n)->get_index() ? convertNodeToAterm((n->get_traversalSuccessorContainer())[4]) : ATmake("<str>", "NULL")));
      assert (term);
    }
    break;

    case V_SgFunctionType: {
      // Special case to allow argument list to be traversed
      SgFunctionType* ft = isSgFunctionType(n);
      ATerm ret = convertNodeToAterm(ft->get_return_type());
      ATerm args_list = convertSgNodeRangeToAterm(ft->get_arguments().begin(),
						  ft->get_arguments().end());
      term = ATmake("FunctionType(<term>, <term>)", ret, args_list);
    }
    break;

    case V_SgEnumType:
    case V_SgClassType: 
    case V_SgTypedefType: {
      // Special cases to optionally put in type definition instead of
      // reference
      SgNamedType* nt = isSgNamedType(n);
      assert (nt);
      SgName sname = nt->get_name();
   // char* name = sname.str();
      SgDeclarationStatement* decl = nt->get_declaration();
      assert (decl);
      SgClassDefinition* defn = isSgClassDeclaration(decl) ?
				isSgClassDeclaration(decl)->get_definition() :
				0;
      term = ATmake("Type(<term>)",
		    (nt->get_autonomous_declaration() || !defn ? 
                     ATmake("id(<str>)", uniqueId(decl).c_str()) :
		     convertNodeToAterm(nt->get_declaration())));
    }
    break;

    case V_SgLabelStatement: {
      // Special case to put in label id
      const char* name = isSgLabelStatement(n)->get_name().str();
      term = ATmake("Label(<str>)", (name ? name : ""));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgGotoStatement: {
      // Special case to put in label id
      term = ATmake("Goto(<str>)", 
                    uniqueId(isSgGotoStatement(n)->get_label()).c_str());
    }
    break;

    case V_SgTypedefDeclaration: {
      // Special case to put in typedef name
      const SgName& name = isSgTypedefDeclaration(n)->get_name();
      SgType* type = isSgTypedefDeclaration(n)->get_base_type();
      term = ATmake("Typedef(<str>, <term>)", (name.str() ? name.str() : ""), 
		      convertNodeToAterm(type));
      term = ATsetAnnotation(term, ATmake("id"),
                             ATmake("<str>", uniqueId(n).c_str()));
    }
    break;

    case V_SgTemplateDeclaration: {
      // Traversal doesn't work for these
      SgTemplateDeclaration* td = isSgTemplateDeclaration(n);
      ROSE_ASSERT (td);
   // SgTemplateParameterPtrListPtr paramsPtr = td->get_templateParameters();
   // SgTemplateParameterPtrList & paramsPtr = td->get_templateParameters();
   // SgTemplateParameterPtrList params =	paramsPtr ? *paramsPtr : SgTemplateParameterPtrList();
      SgTemplateParameterPtrList & params =	td->get_templateParameters();
      string templateKindString;
      switch (td->get_template_kind()) {
	case SgTemplateDeclaration::e_template_none:
	  templateKindString = "None"; break;
	case SgTemplateDeclaration::e_template_class:
	  templateKindString = "Class"; break;
	case SgTemplateDeclaration::e_template_m_class:
	  templateKindString = "MemberClass"; break;
	case SgTemplateDeclaration::e_template_function:
	  templateKindString = "Function"; break;
	case SgTemplateDeclaration::e_template_m_function:
	  templateKindString = "MemberFunction"; break;
	case SgTemplateDeclaration::e_template_m_data:
	  templateKindString = "MemberData"; break;
	default: templateKindString = "Unknown"; break;
      }
      term = ATmake("TemplateDeclaration(<appl>, <str>, <term>, <str>)",
		    templateKindString.c_str(),
		    td->get_name().str(),
		    convertSgNodeRangeToAterm(params.begin(), params.end()),
		    td->get_string().str());
    }
    break;

    case V_SgTemplateInstantiationDecl: {
      // Traversal doesn't work for these
      SgTemplateInstantiationDecl* td = isSgTemplateInstantiationDecl(n);
      ROSE_ASSERT (td);
   // SgTemplateArgumentPtrListPtr argsPtr = td->get_templateArguments();
   // SgTemplateArgumentPtrList args = argsPtr ? *argsPtr : SgTemplateArgumentPtrList();
      SgTemplateArgumentPtrList & args = td->get_templateArguments();
      term = ATmake("TemplateInstantiationDecl(<str>, <term>)", td->get_templateDeclaration()->get_name().str(), convertSgNodeRangeToAterm(args.begin(), args.end()));
    }
    break;

    case V_SgTemplateParameter: {
      // Traversal doesn't work for these
      SgTemplateParameter* tp = isSgTemplateParameter(n);
      ROSE_ASSERT (tp);
      switch (tp->get_parameterType()) {
	case SgTemplateParameter::parameter_undefined: {
	  term = ATmake("Undefined");
	}
	break;

	case SgTemplateParameter::type_parameter: {
	  term = ATmake("Type(<term>)",
			convertNodeToAterm(tp->get_defaultTypeParameter()));
	}
	break;

	case SgTemplateParameter::nontype_parameter: {
	  term = ATmake("Nontype(<term>, <term>)",
			convertNodeToAterm(tp->get_type()),
			convertNodeToAterm(tp->get_defaultExpressionParameter()));
	}
	break;

	case SgTemplateParameter::template_parameter: {
	  term = ATmake("Template");
	}
	break;

	default: term = ATmake("Unknown"); break;
      }
    }
    break;

    case V_SgTemplateArgument: {
      // Traversal doesn't work for these
      SgTemplateArgument* ta = isSgTemplateArgument(n);
      ROSE_ASSERT (ta);
      switch (ta->get_argumentType()) {
	case SgTemplateArgument::argument_undefined:
	  term = ATmake("Undefined");
	  break;
	case SgTemplateArgument::type_argument:
	  term = ATmake("Type(<term>)", 
			convertNodeToAterm(ta->get_type()));
	  break;
	case SgTemplateArgument::nontype_argument:
	  term = ATmake("Nontype(<term>)", 
			convertNodeToAterm(ta->get_expression()));
	  break;
	// case SgTemplateArgument::template_argument:
	  // term = ATmake("Template");
	  // break;
	default: term = ATmake("Unknown"); break;
      }
    }
    break;

    default: {
      bool isContainer = 
	(AstTests::numSuccContainers(n) == 1) ||
	(!isSgType(n) && (n->get_traversalSuccessorContainer().size() == 0));
      term = ATmake((isContainer ? "<appl(<term>)>" : "<appl(<list>)>"), 
                    getShortVariantName((VariantT)(n->variantT())).c_str(),
                    (isSgType(n) ? ATmake("[]") : getTraversalChildrenAsAterm(n)));
               // Special case for types is because of traversal problems
    }
    break;
  }

#if 0
     printf ("Base of switch statement in convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif
     assert (term);

     term = ATsetAnnotation(term, ATmake("ptr"), pointerAsAterm(n));

#if 1
     if (n->get_file_info() != NULL)
        {
          term = ATsetAnnotation(term, ATmake("location"),convertFileInfoToAterm(n->get_file_info()));
        }

     if (isSgExpression(n))
        term = ATsetAnnotation(term, ATmake("type"), convertNodeToAterm(isSgExpression(n)->get_type()));
#endif

#if 0
     printf ("Leaving convertNodeToAterm(): n = %p = %s \n",n,n->class_name().c_str());
#endif
#if 0
     printf ("--- n->class_name() = %s ATwriteToString(term) = %s \n",n->class_name().c_str(),ATwriteToString(term));
#endif

  // cout << n->sage_class_name() << " -> " << ATwriteToString(term) << endl;
     return term;
   }
Exemple #5
0
void
TransformationSupport::getTransformationOptions ( SgNode* astNode, list<OptionDeclaration> & generatedList, string identifingTypeName )
   {
  // This function searches for variables of type ScopeBasedTransformationOptimization.  Variables
  // of type ScopeBasedTransformationOptimization are used to communicate optimizations from the
  // application to the preprocessor. If called from a project or file object it traverses down to
  // the global scope of the file and searches only the global scope, if called from and other
  // location within the AST it searches the current scope and then traverses the parent nodes to
  // find all enclosing scopes until in reaches the global scope.  At each scope it searches for
  // variables of type ScopeBasedTransformationOptimization.

  // printf ("######################### START OF TRANSFORMATION OPTION QUERY ######################## \n");

     ROSE_ASSERT (astNode != NULL);
     ROSE_ASSERT (identifingTypeName.c_str() != NULL);

#if 0
     printf ("In getTransformationOptions(): astNode->sage_class_name() = %s generatedList.size() = %d \n",
          astNode->sage_class_name(),generatedList.size());
     SgLocatedNode* locatedNode = isSgLocatedNode(astNode);
     if (locatedNode != NULL)
        {
          printf ("          locatedNode->get_file_info()->get_filename() = %s \n",locatedNode->get_file_info()->get_filename());
          printf ("          locatedNode->get_file_info()->get_line() = %d \n",locatedNode->get_file_info()->get_line());
        }
#endif

     switch (astNode->variant())
        {
          case ProjectTag:
             {
               SgProject* project = isSgProject(astNode);
               ROSE_ASSERT (project != NULL);

           //! Loop through all the files in the project and call the mainTransform function for each file
               int i = 0;
               for (i=0; i < project->numberOfFiles(); i++)
                  {
                    SgFile* file = &(project->get_file(i));

                 // printf ("Calling Query::traverse(SgFile,QueryFunctionType,QueryAssemblyFunctionType) \n");
                    getTransformationOptions ( file, generatedList, identifingTypeName );
                  }
               break;
             }

          case SourceFileTag:
             {
               SgSourceFile* file = isSgSourceFile(astNode);
               ROSE_ASSERT (file != NULL);
               SgGlobal* globalScope = file->get_globalScope();
               ROSE_ASSERT (globalScope != NULL);
               ROSE_ASSERT (isSgGlobal(globalScope) != NULL);
               getTransformationOptions ( globalScope, generatedList, identifingTypeName );
               break;
             }

       // Global Scope
          case GLOBAL_STMT:
             {
               SgGlobal* globalScope = isSgGlobal(astNode);
               ROSE_ASSERT (globalScope != NULL);

               SgSymbolTable* symbolTable = globalScope->get_symbol_table();
               ROSE_ASSERT (symbolTable != NULL);
               getTransformationOptions ( symbolTable, generatedList, identifingTypeName );

            // printf ("Processed global scope, exiting .. \n");
            // ROSE_ABORT();
               break;
             }

          case SymbolTableTag:
             {
            // List the variable in each scope
            // printf ("List all the variables in this symbol table! \n");
               SgSymbolTable* symbolTable = isSgSymbolTable(astNode);
               ROSE_ASSERT (symbolTable != NULL);

               bool foundTransformationOptimizationSpecifier = false;

            // printf ("Now print out the information in the symbol table for this scope: \n");
            // symbolTable->print();

#if 0
            // I don't know when a SymbolTable is given a name!
               printf ("SymbolTable has a name = %s \n",
                    (symbolTable->get_no_name()) ? "NO: it has no name" : "YES: it does have a name");
               if (!symbolTable->get_no_name())
                    printf ("SymbolTable name = %s \n",symbolTable->get_name().str());
                 else
                    ROSE_ASSERT (symbolTable->get_name().str() == NULL);
#endif

               if (symbolTable->get_table() != NULL)
                  {
                    SgSymbolTable::hash_iterator i = symbolTable->get_table()->begin();
                    int counter = 0;
                    while (i != symbolTable->get_table()->end())
                       {
                         ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );

                      // printf ("Initial info: number: %d pair.first (SgName) = %s pair.second (SgSymbol) sage_class_name() = %s \n",
                      //      counter,(*i).first.str(),(*i).second->sage_class_name());

                         SgSymbol* symbol = isSgSymbol((*i).second);
                         ROSE_ASSERT ( symbol != NULL );
                         SgType* type = symbol->get_type();
                         ROSE_ASSERT ( type != NULL );

                         SgNamedType* namedType = isSgNamedType(type);
                         string typeName;
                         if (namedType != NULL)
                            {
                              SgName n = namedType->get_name();
                              typeName = namedType->get_name().str();
                           // char* nameString = namedType->get_name().str();
                           // printf ("Type is: (named type) = %s \n",nameString);
                              ROSE_ASSERT (identifingTypeName.c_str() != NULL);
                           // ROSE_ASSERT (typeName != NULL);
                           // printf ("In getTransformationOptions(): typeName = %s identifingTypeName = %s \n",typeName.c_str(),identifingTypeName.c_str());
                           // if ( (typeName != NULL) && ( typeName == identifingTypeName) )
                              if ( typeName == identifingTypeName )
                                 {
                                // Now look at the parameter list to the constructor and save the
                                // values into the list.

                                // printf ("Now save the constructor arguments! \n");

                                   SgVariableSymbol* variableSymbol = isSgVariableSymbol(symbol);

                                   if ( variableSymbol != NULL )
                                      {
                                        SgInitializedName* initializedNameDeclaration = variableSymbol->get_declaration();
                                        ROSE_ASSERT (initializedNameDeclaration != NULL);

                                        SgDeclarationStatement* declarationStatement = initializedNameDeclaration->get_declaration();
                                        ROSE_ASSERT (declarationStatement != NULL);

                                        SgVariableDeclaration* variableDeclaration = isSgVariableDeclaration(declarationStatement);
                                        ROSE_ASSERT (variableDeclaration != NULL);

                                        getTransformationOptionsFromVariableDeclarationConstructorArguments(variableDeclaration,generatedList);

                                        foundTransformationOptimizationSpecifier = true;

                                     // printf ("Exiting after saving the constructor arguments! \n");
                                     // ROSE_ABORT();
                                      }
                                     else
                                      {
#if 0
                                        printf ("Not a SgVariableSymbol: symbol->sage_class_name() = %s \n",
                                             symbol->sage_class_name());
#endif
                                      }
                                 }
                                else
                                 {
#if 0
                                   printf ("typeName != identifingTypeName : symbol->sage_class_name() = %s \n",
                                        symbol->sage_class_name());
#endif
#if 0
                                // I don't think this should ever be NULL (but it is sometimes)
                                   if (typeName != NULL)
                                        printf ("typeName == NULL \n");
#endif
                                 }
                            }
                           else
                            {
                              typeName = (char *)type->sage_class_name();
                            }

                      // printf ("In while loop at the base: counter = %d \n",counter);
                         i++;
                         counter++;
                       }
                  }
                 else
                  {
                 // printf ("Pointer to symbol table is NULL \n");
                  }

            // printf ("foundTransformationOptimizationSpecifier = %s \n",foundTransformationOptimizationSpecifier ? "true" : "false");

            // SgSymbolTable objects don't have a parent node (specifically they lack a get_parent
            // member function in the interface)!
               break;
             }

          case BASIC_BLOCK_STMT:
             {
            // List the variable in each scope
            // printf ("List all the variables in this scope! \n");
               SgBasicBlock* basicBlock = isSgBasicBlock(astNode);
               ROSE_ASSERT (basicBlock != NULL);

               SgSymbolTable* symbolTable = basicBlock->get_symbol_table();
               ROSE_ASSERT (symbolTable != NULL);
               getTransformationOptions ( symbolTable, generatedList, identifingTypeName );

            // Next go (fall through this case) to the default case so that we traverse the parent
            // of the SgBasicBlock.
            // break;
             }

          default:
            // Most cases will be the default (this is by design)
            // printf ("default in switch found in globalQueryGetListOperandStringFunction() (sage_class_name = %s) \n",astNode->sage_class_name());

            // Need to recursively backtrack through the parents until we reach the SgGlobal (global scope)
               SgStatement* statement = isSgStatement(astNode);
               if (statement != NULL)
                  {
                    SgNode* parentNode = statement->get_parent();
                    ROSE_ASSERT (parentNode != NULL);
//                  printf ("parent = %p parentNode->sage_class_name() = %s \n",parentNode,parentNode->sage_class_name());
                    SgStatement* parentStatement = isSgStatement(parentNode);
                    if (parentStatement == NULL)
                       {
                         printf ("parentStatement == NULL: statement (%p) is a %s \n",statement,statement->sage_class_name());
                         printf ("parentStatement == NULL: statement->get_file_info()->get_filename() = %s \n",statement->get_file_info()->get_filename());
                         printf ("parentStatement == NULL: statement->get_file_info()->get_line() = %d \n",statement->get_file_info()->get_line());
                       }
                    ROSE_ASSERT (parentStatement != NULL);

                 // Call this function recursively (directly rather than through the query mechanism)
                    getTransformationOptions ( parentStatement, generatedList, identifingTypeName );
                  }
                 else
                  {
                 // printf ("astNode is not a SgStatement! \n");
                  }

               break;
        }

#if 0
     printf ("At BASE of getTransformationOptions(): astNode->sage_class_name() = %s size of generatedList = %d \n",
          astNode->sage_class_name(),generatedList.size());
#endif

  // printf ("######################### END OF TRANSFORMATION OPTION QUERY ######################## \n");
   }
Exemple #6
0
// DQ (8/27/2006): This functionality already exists elsewhere
// It is a shame that it is recreated here as well !!!
NameQuerySynthesizedAttributeType
NameQuery::queryNameTypeName (SgNode * astNode)
{
  ROSE_ASSERT (astNode != NULL);
  string typeName = "";
  Rose_STL_Container< string > returnList;
  SgType *type = isSgType (astNode);

  // printf ("In TransformationSupport::getTypeName(): type->sage_class_name() = %s \n",type->sage_class_name());

  if (type != NULL)
    switch (type->variantT ())
      {
      case V_SgTypeComplex:
        typeName = "complex";
        break;
      case V_SgTypeImaginary:
        typeName = "imaginary";
        break;
      case V_SgTypeBool:
        typeName = "bool";
        break;
      case V_SgEnumType:
        typeName = "enum";
        break;
      case V_SgTypeChar:
        typeName = "char";
        break;
      case V_SgTypeVoid:
        typeName = "void";
        break;
      case V_SgTypeInt:
        typeName = "int";
        break;
      case V_SgTypeDouble:
        typeName = "double";
        break;
      case V_SgTypeFloat:
        typeName = "float";
        break;
      case V_SgTypeLong:
        typeName = "long";
        break;
      case V_SgTypeLongDouble:
        typeName = "long double";
        break;
      case V_SgTypeEllipse:
        typeName = "ellipse";
        break;
      case V_SgTypeGlobalVoid:
        typeName = "void";
        break;
      case V_SgTypeLongLong:
        typeName = "long long";
        break;
      case V_SgTypeShort:
        typeName = "short";
        break;
      case V_SgTypeSignedChar:
        typeName = "signed char";
        break;
      case V_SgTypeSignedInt:
        typeName = "signed int";
        break;
      case V_SgTypeSignedLong:
        typeName = "signed long";
        break;
      case V_SgTypeSignedShort:
        typeName = "signed short";
        break;
      case V_SgTypeString:
        typeName = "string";
        break;
      case V_SgTypeUnknown:
        typeName = "unknown";
        break;
      case V_SgTypeUnsignedChar:
        typeName = "unsigned char";
        break;
      case V_SgTypeUnsignedInt:
        typeName = "unsigned int";
        break;
      case V_SgTypeUnsignedLong:
        typeName = "unsigned long";
        break;
      case V_SgTypeUnsignedShort:
        typeName = "unsigned short";
        break;
      case V_SgTypeUnsignedLongLong:
        typeName = "unsigned long long";
        break;
      case V_SgReferenceType:
        {
          ROSE_ASSERT (isSgReferenceType (type)->get_base_type () != NULL);

          Rose_STL_Container< string > subTypeNames = queryNameTypeName (isSgReferenceType (type)->get_base_type ());

          typedef Rose_STL_Container< string >::iterator typeIterator;

          //This iterator will only contain one name
          for (typeIterator i = subTypeNames.begin ();
               i != subTypeNames.end (); ++i)
            {
              string e = *i;
              typeName = e;
              break;
            }

          break;
        }
      case V_SgPointerType:
        {
          ROSE_ASSERT (isSgPointerType (type)->get_base_type () != NULL);

          Rose_STL_Container< string > subTypeNames =
            queryNameTypeName (isSgPointerType (type)->get_base_type ());

          typedef Rose_STL_Container< string >::iterator typeIterator;

          //This iterator will only contain one name
          for (typeIterator i = subTypeNames.begin ();
               i != subTypeNames.end (); ++i)
            {
              string e = *i;
              typeName = e;
              break;
            }

          break;
        }
      case V_SgModifierType:
        {
          ROSE_ASSERT (isSgModifierType (type)->get_base_type () != NULL);

          Rose_STL_Container< string > subTypeNames =
            queryNameTypeName (isSgModifierType (type)->get_base_type ());

          typedef Rose_STL_Container< string >::iterator typeIterator;

          //This iterator will only contain one name
          for (typeIterator i = subTypeNames.begin ();
               i != subTypeNames.end (); ++i)
            {
              string e = *i;
              typeName = e;
              break;
            }
          break;
        }
      case V_SgNamedType:
        {
          SgNamedType *sageNamedType = isSgNamedType (type);
          ROSE_ASSERT (sageNamedType != NULL);
          typeName = sageNamedType->get_name ().str ();
          break;
        }
      case V_SgClassType:
        {
          SgClassType *sageClassType = isSgClassType (type);
          ROSE_ASSERT (sageClassType != NULL);
          typeName = sageClassType->get_name ().str ();
          break;
        }
      case V_SgTypedefType:
        {
          SgTypedefType *sageTypedefType = isSgTypedefType (type);
          ROSE_ASSERT (sageTypedefType != NULL);
          typeName = sageTypedefType->get_name ().str ();
          break;
        }
      case V_SgPointerMemberType:
        {
          SgPointerMemberType *pointerMemberType =
            isSgPointerMemberType (type);
          ROSE_ASSERT (pointerMemberType != NULL);
          SgClassType *classType =
            isSgClassType(pointerMemberType->get_class_type()->stripTypedefsAndModifiers());
          ROSE_ASSERT (classType != NULL);
          SgClassDeclaration *classDeclaration =
            isSgClassDeclaration(classType->get_declaration());
          ROSE_ASSERT (classDeclaration != NULL);
          typeName = classDeclaration->get_name ().str ();
          break;
        }
      case V_SgArrayType:
        {
          ROSE_ASSERT (isSgArrayType (type)->get_base_type () != NULL);


          Rose_STL_Container< string > subTypeNames =
            queryNameTypeName (isSgArrayType (type)->get_base_type ());

          typedef Rose_STL_Container< string >::iterator typeIterator;

          //This iterator will only contain one name
          for (typeIterator i = subTypeNames.begin ();
               i != subTypeNames.end (); ++i)
            {
              string e = *i;
              typeName = e;
              break;
            }
          break;
        }
      case V_SgFunctionType:
        {
          SgFunctionType *functionType = isSgFunctionType (type);
          ROSE_ASSERT (functionType != NULL);
          typeName = functionType->get_mangled_type ().str ();
          break;
        }
      case V_SgMemberFunctionType:
        {
          SgMemberFunctionType *memberFunctionType =
            isSgMemberFunctionType (type);
          ROSE_ASSERT (memberFunctionType != NULL);
          SgClassType *classType =
            isSgClassType(memberFunctionType->get_class_type()->stripTypedefsAndModifiers());
          ROSE_ASSERT (classType != NULL);
          SgClassDeclaration *classDeclaration =
            isSgClassDeclaration(classType->get_declaration());
          ROSE_ASSERT (classDeclaration != NULL);
          typeName = classDeclaration->get_name ().str ();
          break;
        }
      case V_SgTypeWchar:
        typeName = "wchar";
        break;
      case V_SgTypeDefault:
        typeName = "default";
        break;
      default:
        printf
          ("default reached in switch within TransformationSupport::getTypeName type->sage_class_name() = %s variant = %d \n",
           type->sage_class_name (), type->variant ());
        ROSE_ABORT ();
        break;
      }

  // Fix for purify problem report
  // typeName = ROSE::stringDuplicate(typeName);

  if (typeName.size () > 0)
    returnList.push_back (typeName);
  //ROSE_ASSERT(typeName.c_str() != NULL);
  // return typeName;
  return returnList;
//return ROSE::stringDuplicate(typeName.c_str());
}