Example #1
0
string
Doxygen::getQualifiedPrototype(SgNode *node)
{
    SgClassDeclaration *cd = dynamic_cast<SgClassDeclaration *>(node);
    if (cd) return getProtoName(cd);
    SgUnparse_Info info;
    info.set_SkipSemiColon();
    info.set_SkipFunctionDefinition();
    info.set_forceQualifiedNames();
    info.set_skipCheckAccess();
    info.set_SkipClassSpecifier();
    info.set_SkipInitializer();
    info.set_current_scope(TransformationSupport::getGlobalScope(node));

    string proto = node->unparseToString(&info);
    while (proto[proto.size()-1] == '\n') { /* sometimes the prototype will be unparsed with a newline at the end */
        proto.resize(proto.size()-1);
    }
    return proto;
}
Example #2
0
string
Doxygen::getProtoName(SgDeclarationStatement *st)
{
    SgScopeStatement *scope;
    if (SgVariableDeclaration* varDeclSt = isSgVariableDeclaration(st))
    {
        // TODO: uncomment SgVariableDeclaration::get_scope removing need for this code
        scope = varDeclSt->get_variables().front()->get_scope();
    }
    else
    {
        scope = st->get_scope();
    }
    if (isSgGlobal(scope))
    {
        return getDeclStmtName(st);
    }
    else
    {
        SgUnparse_Info info;
        info.set_SkipSemiColon();
        info.set_SkipFunctionDefinition();
        info.set_forceQualifiedNames();
        info.set_skipCheckAccess();
        info.set_SkipInitializer();
        info.set_SkipClassSpecifier();
        //AS(091507) In the new version of ROSE global qualifiers are paret of the qualified name of
        //a scope statement. For the documentation work we do not want that and we therefore use string::substr()
        //to trim of  "::" from the front of the qualified name.

        if( scope->get_qualified_name().getString().length() > 2 )
        {
            return scope->get_qualified_name().getString().substr(2)+("::"+getDeclStmtName(st));
        } else {
            return getDeclStmtName(st);

        }

        //return scope->get_qualified_name().str()+("::"+getDeclStmtName(st));
    }
}
string
PrefixSuffixGenerationTraversal::DeclarationOrCommentListElement::
generateDeclarationString ( SgDeclarationStatement* declaration ) const
   {
  // This function generates a string for a declaration. The string is required for 
  // the intermediate file to make sure that all transformation code will compile 
  // (since it could depend on declarations defined within the code).

  // Details:
  //   1) Only record declarations found within the source file (exclude all header files 
  //      since they will be seen when the same header files are included).
  //   2) Resort the variable declarations to remove redundent entries.
  //        WRONG: variable declarations could have dependences upon class declarations!
  //   3) Don't sort all declarations since some could have dependences.
  //        a) class declarations
  //        b) typedefs
  //        c) function declarations
  //        d) template declarations
  //        e) variable definition???

      ROSE_ASSERT (this != NULL);
      ROSE_ASSERT ( declaration != NULL );
      string declarationString;

   // Build a SgUnparse_Info object to represent formatting options for
   // this statement (use the default values).
      SgUnparse_Info info;

   // exclude comments
      info.set_SkipComments();

   // exclude all CPP directives (since they have already been evaluated by the front-end)
      info.set_SkipCPPDirectives();

      switch ( declaration->variantT() )
        {
       // Enum declarations should not skip their definition since 
       // this is where the constants are declared.
          case V_SgEnumDeclaration:

          case V_SgVariableDeclaration:
          case V_SgTemplateDeclaration:
          case V_SgTypedefDeclaration:
            // Need to figure out if a forward declaration would work or be 
            // more conservative and always output the complete class definition.

            // turn off output of initializer values
               info.set_SkipInitializer();
            // output the declaration as a string
               declarationString = globalUnparseToString(declaration,&info);
               break;

          case V_SgClassDeclaration:
            // Need to figure out if a forward declaration would work or be 
            // more conservative and always output the complete class definition.

            // turn off the generation of the function definitions only 
            // (we still want the restof the class definition since these 
            // define all member data and member functions).
            // info.set_SkipClassDefinition();
               info.set_SkipFunctionDefinition();
               info.set_AddSemiColonAfterDeclaration();

            // output the declaration as a string
               declarationString = globalUnparseToString(declaration,&info);
               break;

       // For functions just output the declaration and skip the definition
       // (This also avoids the generation of redundent definitions since the 
       // function we are in when we generate all declarations would be included).
          case V_SgMemberFunctionDeclaration:
          case V_SgFunctionDeclaration:
             {
            // turn off the generation of the definition
               info.set_SkipFunctionDefinition();
               info.set_AddSemiColonAfterDeclaration();

            // output the declaration as a string
               declarationString = globalUnparseToString(declaration,&info);
               break;
             }

          case V_SgFunctionParameterList:
             {
            // Handle generation of declaration strings this case differnetly from unparser
            // since want to generate declaration strings and not function parameter lists
            // (function parameter lists would be delimited by "," while declarations would
            // be delimited by ";").
               SgFunctionParameterList* parameterListDeclaration = dynamic_cast<SgFunctionParameterList*>(declaration);
               ROSE_ASSERT (parameterListDeclaration != NULL);
               SgInitializedNamePtrList & argList = parameterListDeclaration->get_args();
               SgInitializedNamePtrList::iterator i;
               for (i = argList.begin(); i != argList.end(); i++)
                  {
                    printf ("START: Calling unparseToString on type! \n");
                    ROSE_ASSERT((*i) != NULL);
                    ROSE_ASSERT((*i)->get_type() != NULL);
                    string typeNameString = (*i)->get_type()->unparseToString();
                    printf ("DONE: Calling unparseToString on type! \n");

                    string variableName;
                    if ( (*i)->get_name().getString() != "")
                       {
                         variableName   = (*i)->get_name().getString();
                         declarationString += typeNameString + " " + variableName + "; ";
                       }
                      else
                       {
                      // Don't need the tailing ";" if there is no variable name (I think)
                         declarationString += typeNameString + " ";
                       }
                  }
               break;
             }

       // ignore this case ... not really a declaration
          case V_SgCtorInitializerList:
            // printf ("Ignore the SgCtorInitializerList (constructor initializer list) \n");
               break;

          case V_SgVariableDefinition:
               printf ("ERROR: SgVariableDefinition nodes not used in AST \n");
               ROSE_ABORT();
               break;

       // default case should always be an error
          default:
               printf ("Default reached in AST_Rewrite::AccumulatedDeclarationsAttribute::generateDeclarationString() \n");
               printf ("     declaration->sage_class_name() = %s \n",declaration->sage_class_name());
               ROSE_ABORT();
               break;
        }

  // Add a space to make it easier to read (not required)
     declarationString += " ";

  // printf ("For this scope: declarationString = %s \n",declarationString.c_str());

     return declarationString;
   }