Beispiel #1
0
NameQuerySynthesizedAttributeType
NameQuery::queryNameUnionFieldNames (SgNode * astNode)
{

  ROSE_ASSERT (astNode != 0);

  NameQuerySynthesizedAttributeType returnNameList;

// SgNode *sageReturnNode = NULL;

  SgClassDefinition *sageClassDefinition = isSgClassDefinition (astNode);

  if (sageClassDefinition != NULL)
    {
      ROSE_ASSERT (sageClassDefinition->get_declaration () != NULL);
      if (sageClassDefinition->get_declaration ()->get_class_type () ==
          SgClassDeclaration::e_struct)
        {
          SgDeclarationStatementPtrList declarationStatementPtrList =
            sageClassDefinition->get_members ();

        typedef SgDeclarationStatementPtrList::iterator LI;

        for (LI i = declarationStatementPtrList.begin ();
             i != declarationStatementPtrList.end (); ++i)
          {
            SgNode *listElement = *i;

            SgVariableDeclaration *sageVariableDeclaration =
              isSgVariableDeclaration (listElement);

            if (sageVariableDeclaration != NULL)
              {


                typedef SgInitializedNamePtrList::iterator INITLI;

                SgInitializedNamePtrList sageInitializedNameList = sageVariableDeclaration->get_variables ();

                for (INITLI i = sageInitializedNameList.begin ();
                     i != sageInitializedNameList.end (); ++i)
                  {
                    SgInitializedName* initializedListElement = *i;
                    ROSE_ASSERT (isSgInitializedName (initializedListElement) != NULL);

                    returnNameList.push_back (initializedListElement->get_name().str());

                  }             /* End iteration over declarationStatementPtrList */

              }                 /* End iteration over declarationStatementPtrList */
          }

        }
    }

  return returnNameList;

}                               /* End function queryUnionFieldNames() */
Beispiel #2
0
  NodeQuerySynthesizedAttributeType
NodeQuery::querySolverClassFields (SgNode * astNode)
{
  ROSE_ASSERT (astNode != 0);

  NodeQuerySynthesizedAttributeType returnNodeList;

  /*  cout << "The name of the node is: \" " << astNode->sage_class_name() << "\"\n";
      SgLocatedNode* sageLocatedNode = isSgLocatedNode(astNode);
      if(sageLocatedNode != NULL){
      cout << "The filename is: " << sageLocatedNode->getFileName() << " At line number :" << sageLocatedNode->get_file_info()->get_line() << "\n";
      } */
  // SgNode *sageReturnNode = NULL;

  SgClassDefinition *sageClassDefinition = isSgClassDefinition (astNode);

  if (sageClassDefinition != NULL)
  {
    ROSE_ASSERT (sageClassDefinition->get_declaration () != NULL);
    if (sageClassDefinition->get_declaration ()->get_class_type () ==
        SgClassDeclaration::e_class)
    {
      SgDeclarationStatementPtrList declarationStatementPtrList =
        sageClassDefinition->get_members ();

      typedef SgDeclarationStatementPtrList::iterator LI;
      for (LI i = declarationStatementPtrList.begin ();
          i != declarationStatementPtrList.end (); ++i)
      {
        SgNode *listElement = *i;

        if (isSgVariableDeclaration (listElement) != NULL){
          /*    if(isSgVariableDeclaration(listElement)->get_name().str() != NULL)
                cout << "The name of the variable declaration is: \"" << isSgVariableDeclaration(listElement)->get_name().str() << "\"\n";
                else
                cout << "The name of the variable declaration is: \"\"\n";*/
          returnNodeList.push_back (listElement);
        }

      }
    }
  }
  return returnNodeList;
}                               /* End function querySolverClassFields() */
Beispiel #3
0
  NodeQuerySynthesizedAttributeType
NodeQuery::querySolverUnionFields (SgNode * astNode)
{


  ROSE_ASSERT (astNode != 0);

  NodeQuerySynthesizedAttributeType returnNodeList;

  // SgNode *sageReturnNode = NULL;

  SgClassDefinition *sageClassDefinition = isSgClassDefinition (astNode);

  if (sageClassDefinition != NULL)
  {
    ROSE_ASSERT (sageClassDefinition->get_declaration () != NULL);
    if (sageClassDefinition->get_declaration ()->get_class_type () ==
        SgClassDeclaration::e_union)
    {
      SgDeclarationStatementPtrList declarationStatementPtrList =
        sageClassDefinition->get_members ();

      typedef SgDeclarationStatementPtrList::iterator LI;

      for (LI i = declarationStatementPtrList.begin ();
          i != declarationStatementPtrList.end (); ++i)
      {
        SgNode *listElement = *i;

        if (isSgVariableDeclaration (listElement) != NULL)
          returnNodeList.push_back (listElement);

      }

    }
  }


  return returnNodeList;

}                               /* End function querySolverUnionFields() */
SgDerivedTypeStatement *
RoseStatementsAndExpressionsBuilder::buildTypeDeclaration (
    std::string const & typeName, SgScopeStatement * scope)
{
  SgClassDefinition * classDefinition = new SgClassDefinition (
      RoseHelper::getFileInfo ());
  classDefinition->set_endOfConstruct (RoseHelper::getFileInfo ());
  classDefinition->setCaseInsensitive (true);

  SgDerivedTypeStatement* classDeclaration = new SgDerivedTypeStatement (
      RoseHelper::getFileInfo (), typeName, SgClassDeclaration::e_struct, NULL,
      classDefinition);
  classDeclaration->set_endOfConstruct (RoseHelper::getFileInfo ());
  classDeclaration->set_definingDeclaration (classDeclaration);
  classDeclaration->get_declarationModifier ().get_accessModifier ().setUndefined ();

  SgDerivedTypeStatement* nondefiningClassDeclaration =
      new SgDerivedTypeStatement (RoseHelper::getFileInfo (), typeName,
          SgClassDeclaration::e_struct, NULL, NULL);
  nondefiningClassDeclaration->set_endOfConstruct (RoseHelper::getFileInfo ());
  nondefiningClassDeclaration->set_parent (scope);
  nondefiningClassDeclaration->get_declarationModifier ().get_accessModifier ().setUndefined ();

  nondefiningClassDeclaration->set_type (SgClassType::createType (
      nondefiningClassDeclaration));
  classDeclaration->set_type (nondefiningClassDeclaration->get_type ());

  classDeclaration->set_firstNondefiningDeclaration (
      nondefiningClassDeclaration);

  nondefiningClassDeclaration->set_firstNondefiningDeclaration (
      nondefiningClassDeclaration);
  nondefiningClassDeclaration->set_definingDeclaration (classDeclaration);

  nondefiningClassDeclaration->setForward ();

  classDefinition->set_declaration (classDeclaration);
  classDefinition->get_declaration ()->get_declarationModifier ().get_accessModifier ().setUndefined ();

  classDeclaration->set_scope (scope);
  nondefiningClassDeclaration->set_scope (scope);

  classDeclaration->set_parent (scope);

  SgClassSymbol * classSymbol = new SgClassSymbol (nondefiningClassDeclaration);

  scope->insert_symbol (typeName, classSymbol);

  return classDeclaration;
}
Beispiel #5
0
    bool findPublicVarMembers (SgNode *node, string &str) {
	SgVariableDeclaration *decl;
	if (decl = isSgVariableDeclaration(node)) {
	    SgDeclarationModifier &dfm = decl->get_declarationModifier();
	    if (dfm.get_accessModifier().isPublic()) {
		// check if it belongs to a class
		SgStatement *block = ((SgVariableDeclaration *) node)->get_scope();
		SgClassDefinition *classDef;
		if (classDef = isSgClassDefinition(block)) {
		    if (classDef->get_declaration()->get_class_type() == SgClassDeclaration::e_class) {
                        str = classDef->get_qualified_name().getString();		   
                        return true;
                    }
		}
	    } 
	}
	return false;
    }    
void
CompassAnalyses::VariableNameEqualsDatabaseName::Traversal::
visit(SgNode* node)
   { 
     if( isSgAssignInitializer(node) != NULL )
          assignExp = node;
  
     if( isSgAssignOp(node) != NULL )
          assignExp = node; 

     SgFunctionCallExp* funcCall = isSgFunctionCallExp(node);

  // See if we have a dot expression or arrow expression which
  // accesses the desired member function in the class we are looking for.
     if ( funcCall != NULL  )
        {
          SgExpression* funcExp = funcCall->get_function();

          if ( ( isSgDotExp(funcExp) != NULL ) | ( isSgArrowExp(funcExp) != NULL ) )
             {
               SgBinaryOp*     binOp = isSgBinaryOp(funcExp);
               SgExpression*   rhsOp = binOp->get_rhs_operand();
            // SgExpression*   lhsOp = binOp->get_lhs_operand();
               if ( SgMemberFunctionRefExp* funcRef = isSgMemberFunctionRefExp(rhsOp)  )
                  {
                 // std::cout << "c1\n" ;

                    SgMemberFunctionSymbol*      funcSymbol = funcRef->get_symbol();
                    ROSE_ASSERT(funcSymbol->get_declaration() != NULL);

                 // DQ (1/16/2008): Note that the defining declaration need not exist (see test2001_11.C)
                 // ROSE_ASSERT(funcSymbol->get_declaration()->get_definingDeclaration() != NULL);
                    if (funcSymbol->get_declaration()->get_definingDeclaration() != NULL)
                       {
                         SgMemberFunctionDeclaration* funcDecl   = isSgMemberFunctionDeclaration(funcSymbol->get_declaration()->get_definingDeclaration());
                         ROSE_ASSERT( funcDecl != NULL );

                         SgClassDefinition* clDef = isSgClassDefinition(funcDecl->get_scope());
                         SgClassDeclaration*          clDecl     = isSgClassDeclaration(clDef->get_declaration());  

                      // SgClassDeclaration*          clDecl     = funcDecl->get_associatedClassDeclaration();

                         ROSE_ASSERT( clDecl != NULL );
                         std::string className    = clDecl->get_name().getString();

                         ROSE_ASSERT(funcDecl != NULL);
                         std::string functionName = funcDecl->get_name().getString();
 
                      // If the class is the class we are looking for see if the member function
                      // access is to the member function we are interested in.
                      // std::cout << "className = " << className << std::endl;
                      // std::cout << "functionName = " << functionName << std::endl;

                         if ( (className == classToLookFor) && ( functionName == memberFunctionToLookFor ) )
                            {
                              SgExprListExp*         actualArgs    = funcCall->get_args();
                              SgExpressionPtrList&   actualExpArgs = actualArgs->get_expressions ();

                              ROSE_ASSERT(actualExpArgs.size() == 1);
                              Rose_STL_Container<SgNode*> nodeLst = NodeQuery::querySubTree(*actualExpArgs.begin(), V_SgStringVal);

                              ROSE_ASSERT( nodeLst.size() > 0);
                              SgStringVal* actualArg = isSgStringVal(*nodeLst.begin());
                              ROSE_ASSERT(actualArg != NULL);

                              std::string  stringArg = actualArg->get_value();

                              std::cout << "arg:" << stringArg << std::endl;

                              std::string varName;

                           // SgInitializedName* initName = NULL; 
                              if ( SgAssignInitializer* assignInit =  isSgAssignInitializer(assignExp) )
                                 {
                                   SgInitializedName* initName = isSgInitializedName(assignInit->get_parent());
                                   ROSE_ASSERT(initName != NULL);
                                 
                                   varName = initName->get_name().getString();
                                 }
                                else
                                 {
                                   if ( SgAssignOp* assignOp = isSgAssignOp(assignExp) )
                                      {
                                        SgExpression*     lhsOp  = assignOp->get_lhs_operand();
                                        SgVarRefExp*      varRef = isSgVarRefExp(lhsOp);
                                        ROSE_ASSERT(varRef!=NULL);
                                        SgVariableSymbol* varSymbol = varRef->get_symbol();
                                        ROSE_ASSERT(varSymbol != NULL);
                                        SgInitializedName* initName = varSymbol->get_declaration();
                                        varName = initName->get_name().getString();
                                      }
                                 }
 
                              if (varName != "")
                                 {
                                // we are only interested in the part of the argument after the last ":"
                                // Database scopes in ALE3D are separated by ":"

                                   size_t posCol = stringArg.find_last_of(':');
                                 
                                   if (posCol != std::string::npos)
                                        stringArg = stringArg.substr(posCol+1);

                                 //Find violations to the rule
                                   if ( stringArg != varName)
                                      {
                                        output->addOutput(new CheckerOutput(assignExp));
                                        std::cout << "violation" << varName << std::endl;
                                      }
                                     else 
                                      {
                                        std::cout << "non=violation" << varName << std::endl;
                                      }
                                 }
                            }
                       }
                  }
             } 
        }
   } // End of the visit function.
Beispiel #7
0
void
Unparse_Java::unparseEnumType(SgEnumType* type, SgUnparse_Info& info)
   {
     SgEnumType* enum_type = isSgEnumType(type);
     ROSE_ASSERT(enum_type);

     if (info.isTypeSecondPart() == false)
        {
          SgEnumDeclaration *edecl = isSgEnumDeclaration(enum_type->get_declaration());
          SgClassDefinition *cdefn = NULL;
          SgNamespaceDefinitionStatement* namespaceDefn = NULL;

          ROSE_ASSERT(edecl != NULL);

       // Build reference to any possible enclosing scope represented by a SgClassDefinition or SgNamespaceDefinition
       // to be used check if name qualification is required.
          unp->u_exprStmt->initializeDeclarationsFromParent ( edecl, cdefn, namespaceDefn );

          if (info.isTypeFirstPart() == true && info.SkipEnumDefinition() == false)
             {
               unp->u_exprStmt->unparseAttachedPreprocessingInfo(edecl, info, PreprocessingInfo::before);
             }

          curprint ( "enum ");

          SgNamedType *ptype = NULL;
          if (cdefn != NULL)
             {
               ptype = isSgNamedType(cdefn->get_declaration()->get_type());
             }

          if (SageInterface::is_C_language() == true || SageInterface::is_C99_language() == true)
             {
               curprint ( enum_type->get_name().getString() + " ");
             }
            else
             {
            // DQ (7/20/2011): Test compilation without the generateNameQualifier() functions.
            // The C++ support is more complex and can require qualified names!
            // SgName nameQualifier = unp->u_name->generateNameQualifier( edecl , info );
               SgName nameQualifier;

            // printf ("nameQualifier (from unp->u_name->generateNameQualifier function) = %s \n",nameQualifier.str());
            // curprint ( "\n/* nameQualifier (from unp->u_name->generateNameQualifier function) = " + nameQualifier + " */ \n ";
               curprint ( nameQualifier.str());
               SgName nm = enum_type->get_name();

               if (nm.getString() != "")
                  {
                 // printf ("Output qualifier of current types to the name = %s \n",nm.str());
                    curprint ( nm.getString() + " ");
                  }
             }
        }

     if (info.isTypeFirstPart() == true)
        {
      // info.display("info before constructing ninfo");
         SgUnparse_Info ninfo(info);

      // don't skip the semicolon in the output of the statement in the class definition
         ninfo.unset_SkipSemiColon();

         ninfo.set_isUnsetAccess();

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

         if ( info.SkipEnumDefinition() == false)
            {
              SgUnparse_Info ninfo(info);
              ninfo.set_inEnumDecl();
              SgInitializer *tmp_init = NULL;
              SgName tmp_name;

              SgEnumDeclaration *enum_stmt = isSgEnumDeclaration(enum_type->get_declaration());
              ROSE_ASSERT(enum_stmt != NULL);

           // This permits support of the empty enum case! "enum x{};"
              curprint ( "{");

              SgInitializedNamePtrList::iterator p = enum_stmt->get_enumerators().begin();
              if (p != enum_stmt->get_enumerators().end())
                 {
                // curprint ( "{";
                   while (1)
                      {
                        unp->u_exprStmt->unparseAttachedPreprocessingInfo(*p, info, PreprocessingInfo::before);
                        tmp_name=(*p)->get_name();
                        tmp_init=(*p)->get_initializer();
                        curprint ( tmp_name.str());
                        if(tmp_init)
                           {
                             curprint ( "=");
                             unp->u_exprStmt->unparseExpression(tmp_init, ninfo);
                           }
                        p++;
                        if (p != enum_stmt->get_enumerators().end())
                           {
                             curprint ( ",");
                           }
                          else
                             break;
                       }
                 // curprint ( "}";
                  }

            // Putting the "inside" info right here is just a wild guess as to where it might really belong.
               unp->u_exprStmt->unparseAttachedPreprocessingInfo(enum_stmt, info, PreprocessingInfo::inside);

               curprint ( "}");

               unp->u_exprStmt->unparseAttachedPreprocessingInfo(enum_stmt, info, PreprocessingInfo::after);
             }
        }
   }
string
SIDL_TreeTraversal::generateSIDLFunctionDeclaration(SgFunctionDeclaration* functionDeclarationStatement )
{
    ROSE_ASSERT (functionDeclarationStatement != NULL);
    ROSE_ASSERT (functionDeclarationStatement->get_file_info() != NULL);
    const SgSpecialFunctionModifier &functionModifier = functionDeclarationStatement->get_specialFunctionModifier();

    string functionName = functionDeclarationStatement->get_name().str();
    string sidlFunctionName ;
    if (functionModifier.isConstructor()) {
        if (functionDeclarationStatement->get_args().size() == 0) return ""; // skip empty constructor
        sidlFunctionName = constructorName;
    }
    else {
        sidlFunctionName = functionName;
    }

    // We have to force the mangled name to be generated before we access it (else we just get "defaultName")
    string mangledFunctionName = functionDeclarationStatement->get_mangled_name().str();

    sidlFunctionName = stringifyOperatorWithoutSymbols(sidlFunctionName);

    // Get the class name
    SgClassDefinition* classDefinition   = isSgClassDefinition(functionDeclarationStatement->get_scope());

    // DQ (1/7/2004): Modified for make EDG version 3.3 work (member function declarations's normalized by EDG)
    if (classDefinition != NULL)
    {
        SgClassDeclaration* classDeclaration = classDefinition->get_declaration();

        string className = classDeclaration->get_name().str();

        overloadInformation info = isOverloaded(classDefinition,functionName,mangledFunctionName);
        int orderofOverloadedFunction = info.get_order();

        // If function is overloaded then append the number indicating the order of appearance in the
        // class declaration
        if (info.get_count() > 1)
        {
            vector<SgType*> types = info.get_types();

            // SgInitializedNamePtrList &args = functionDeclarationStatement->get_args ();
            int size = types.size();
            if(size > 0)
            {
                if(size < 3)
                {
                    sidlFunctionName += "[";
                    for(vector<SgType*>::iterator i = types.begin(); i!= types.end(); i++)
                    {
                        if(i != types.begin()) sidlFunctionName += "_";
                        if(isSgPointerType(*i) != NULL)	sidlFunctionName += "P";
                        sidlFunctionName += sidlOverloadExtension(TransformationSupport::getTypeName(*i));
                    }
                    sidlFunctionName += "]";
                }
                else
                    sidlFunctionName += "["+numberToOverloadString(orderofOverloadedFunction)+"]";
            }
        }
    }
    else
    {
        printf ("EDG version 3.3 can return a null pointer to the member function definition \n");
    }

    SgFunctionType* functionType = functionDeclarationStatement->get_type();
    ROSE_ASSERT(functionType != NULL);

    // SgType* returnType = functionType->get_return_type();
    // ROSE_ASSERT (returnType != NULL);
    // string returnTypeName = TransformationSupport::getTypeName(returnType);

    // printf ("function has_ellipses %s \n",(functionType->get_has_ellipses() != false) ? "true" : "false");
    // showSgFunctionType(cout, functionType, "Called from generateSIDLFunctionDeclaration", 0 );
    // printf ("Function return type = %s \n",returnTypeName.c_str());

#if 0
    SgTypePtrList & argumentTypeList = functionType->get_arguments();
    ROSE_ASSERT (argumentTypeList.size() >= 0);
    SgTypePtrList::iterator argumentIterator = argumentTypeList.begin();

    for (argumentIterator = argumentTypeList.begin(); argumentIterator != argumentTypeList.end(); argumentIterator++)
    {
        // showSgType(os,(*argumentIterator), label, depth+1);

        string argumentTypeName = TransformationSupport::getTypeName(*argumentIterator);
        printf ("-----> argument #%d  argumentTypeName = %s \n",argumentCounter++,argumentTypeName.c_str());
    }
#endif

    //Determine the SIDL parameter passing mechanism (in,out,inout)
    SgInitializedNamePtrList & argumentList = functionDeclarationStatement->get_args();
    string parameterTypesAndNames;
    SgInitializedNamePtrList::iterator i;

    unsigned int argumentCounter = 0;
    for (i = argumentList.begin(); i != argumentList.end(); i++)
    {
        SgType* type = (*i)->get_type();
        ROSE_ASSERT (type != NULL);

        string typeName = TransformationSupport::getTypeName(type);
        ROSE_ASSERT (typeName.c_str() != NULL);

        string sidlParameterPassingMechanim = "in";

        //it seems like the has_ellipses value is wrong, so we'll set it
        functionType->set_has_ellipses(false);
        if(type->variantT() == V_SgTypeEllipse)
        {
            sidlParameterPassingMechanim = "inout";
            functionType->set_has_ellipses(true);
        }
        //else if (type->variantT() == V_SgTypeVoid)
        /*else if (rose::stringDuplicate(type->sage_class_name()) == "SgTypeVoid")
        {
        	printf("found a void\n");
        	//void type is only viable for a pointer.  foo(void) will just become foo()
        	if(isSgPointerType(type) != NULL)
        	{
        		printf("found a void pointer\n");
        		sidlParameterPassingMechanim ="inout opaque";
        	}
        }*/
        else if (isSgReferenceType(type) != NULL)
        {
            sidlParameterPassingMechanim = "inout";
        }
        else if (isSgPointerType(type) != NULL)
        {
            sidlParameterPassingMechanim = "inout";
        }
        else if (isSgArrayType(type) != NULL)
        {
            SgArrayType array = isSgArrayType(type);
            sidlParameterPassingMechanim = "inout Array<";
            SgType* baseType = array.get_base_type();
            sidlParameterPassingMechanim += TransformationSupport::getTypeName(baseType);
            sidlParameterPassingMechanim += ",1>";
            //FIXME: I don't see a way to determine the dimention of the array
        }



        // Build the substring for each parameter

        parameterTypesAndNames += sidlParameterPassingMechanim;
        parameterTypesAndNames += " ";

        //if(type->variantT() != V_SgTypeGlobalVoid)
        //{
        if(type->variantT() == V_SgTypeEllipse)
        {
            parameterTypesAndNames += "Array<BabelBaseType,1> "; //FIXME: need to include a declaration for BaseType
            parameterTypesAndNames += "elips" +  argumentCounter; //this fails to actually append the counter, but I don't think it will matter: kmk
        }
        else
        {
            SgName name = (*i)->get_name();
            string nameString = name.str();
            string typeName = TransformationSupport::getTypeName(type);

            if(typeName == "void")
            {
                if(nameString!="")
                {
                    parameterTypesAndNames += "opaque ";
                    parameterTypesAndNames += nameString;
                }
            }
            else
            {
                parameterTypesAndNames += typeName;
                parameterTypesAndNames += " ";
                if(nameString != "") //will be empty if the function declaration doesn't provide a name
                    parameterTypesAndNames += nameString;
            }
        }

        // Add a "," to the string if there are more parameters in the list
        if ( argumentCounter < argumentList.size()-1 )
            parameterTypesAndNames += ",";
        //}else printf("avoiding the void\n");
        argumentCounter++;
    }

    SgType* returnType = functionType->get_return_type();
    ROSE_ASSERT (returnType != NULL);
    string returnTypeName = "void";
    if(returnType->variantT() != V_SgTypeVoid)
        returnTypeName = TransformationSupport::getTypeName(returnType);


    string sidlMemberFunctionDeclaration = "          $RETURN_TYPE $FUNCTION_NAME($PARAMETERS);\n";

    sidlMemberFunctionDeclaration = StringUtility::copyEdit ( sidlMemberFunctionDeclaration, "$RETURN_TYPE" , returnTypeName );
    sidlMemberFunctionDeclaration = StringUtility::copyEdit ( sidlMemberFunctionDeclaration, "$FUNCTION_NAME" , sidlFunctionName );
    sidlMemberFunctionDeclaration = StringUtility::copyEdit ( sidlMemberFunctionDeclaration, "$PARAMETERS" , parameterTypesAndNames );


    return sidlMemberFunctionDeclaration;
}