示例#1
0
void
UnparseFortran_type::unparsePointerType(SgType* type, SgUnparse_Info& info, bool printAttrs)
{
#if 0
    // printf ("Inside of UnparserFort::unparsePointerType \n");
    // cur << "\n/* Inside of UnparserFort::unparsePointerType */\n";
    curprint ("\n! Inside of UnparserFort::unparsePointerType \n");
#endif

    // DQ (1/16/2011): Note that pointers in fortran are not expressed the same as in C/C++, are are
    // only a part of the type which is managed more directly using attributes in the variable declaration.
    // Not clear that we want to do anything here in the unparser...

    SgPointerType* pointer_type = isSgPointerType(type);
    ROSE_ASSERT(pointer_type != NULL);

#if 0
    /* special cases: ptr to array, int (*p) [10] */
    /*                ptr to function, int (*p)(int) */
    /*                ptr to ptr to .. int (**p) (int) */

    if (isSgReferenceType(pointer_type->get_base_type()) ||
            isSgPointerType(pointer_type->get_base_type()) ||
            isSgArrayType(pointer_type->get_base_type()) ||
            isSgFunctionType(pointer_type->get_base_type()) ||
            isSgMemberFunctionType(pointer_type->get_base_type()) ||
            isSgModifierType(pointer_type->get_base_type()) )
    {
        info.set_isPointerToSomething();
    }

    // If not isTypeFirstPart nor isTypeSecondPart this unparse call
    // is not controlled from the statement level but from the type level

    if (info.isTypeFirstPart() == true)
    {
        unparseType(pointer_type->get_base_type(), info);

        // DQ (9/21/2004): Moved this conditional into this branch (to fix test2004_93.C)
        // DQ (9/21/2004): I think we can assert this, and if so we can simplify the logic below
        ROSE_ASSERT(info.isTypeSecondPart() == false);

        curprint("*");
    }
    else
    {
        if (info.isTypeSecondPart() == true)
        {
            unparseType(pointer_type->get_base_type(), info);
        }
        else
        {
            SgUnparse_Info ninfo(info);
            ninfo.set_isTypeFirstPart();
            unparseType(pointer_type, ninfo);
            ninfo.set_isTypeSecondPart();
            unparseType(pointer_type, ninfo);
        }
    }
#else
    if (info.supressStrippedTypeName() == false)
    {
        // DQ (1/16/2011): We only want to output the name of the stripped type once!
        SgType* stripType = pointer_type->stripType();
        unparseType(stripType, info);
        info.set_supressStrippedTypeName();
    }

    curprint(type->get_isCoArray()? ", COPOINTER": ", POINTER");

    // DQ (1/16/2011): Plus unparse the base type...(unless it will just output the stripped types name).
    if (pointer_type->get_base_type()->containsInternalTypes() == true)
    {
        unparseType(pointer_type->get_base_type(), info, printAttrs);
    }
#endif

#if 0
    // printf ("Leaving of UnparserFort::unparsePointerType \n");
    // cur << "\n/* Leaving of UnparserFort::unparsePointerType */\n";
    curprint ("\n! Leaving UnparserFort::unparsePointerType \n");
#endif
}
示例#2
0
void
UnparseFortran_type::unparseArrayType(SgType* type, SgUnparse_Info& info, bool printDim)
{
    // Examples:
    //   real, dimension(10, 10) :: A1, A2
    //   real, dimension(:) :: B1
    //   character(len=*) :: s1
#if 0
    curprint ("\n! Inside of UnparserFort::unparseArrayType \n");
#endif

    SgArrayType* array_type = isSgArrayType(type);
    ROSE_ASSERT(array_type != NULL);

    // I think that supressStrippedTypeName() and SkipBaseType() are redundant...
    if (info.supressStrippedTypeName() == false)
    {
        // DQ (1/16/2011): We only want to output the name of the stripped type once!
        SgType* stripType = array_type->stripType();
        unparseType(stripType, info);
        info.set_supressStrippedTypeName();
    }

    // DQ (8/5/2010): It is an error to treat an array of char as a string (see test2010_16.f90).
#if 0
    // dimension information
    SgExprListExp* dim = array_type->get_dim_info();

    // if (isCharType(array_type->get_base_type()))
    // if (false && isCharType(array_type->get_base_type()))
    if (isCharType(array_type->get_base_type()))
    {
        // a character type: must be treated specially
        ROSE_ASSERT(array_type->get_rank() == 1);
        curprint("(len=");

        SgExpressionPtrList::iterator it = dim->get_expressions().begin();
        if (it != dim->get_expressions().end())
        {
            SgExpression* expr = *it;
            if (expr->variantT() == V_SgSubscriptExpression)
            {
                // this is a subscript expression but all we want to unparse is the length
                // of the string, which should be the upper bound of the subscript expression
                SgSubscriptExpression* sub_expr = isSgSubscriptExpression(expr);
                ROSE_ASSERT(sub_expr != NULL);

                ROSE_ASSERT(unp != NULL);
                ROSE_ASSERT(unp->u_fortran_locatedNode != NULL);
                unp->u_fortran_locatedNode->unparseExpression(sub_expr->get_upperBound(), info);
            }
            else
            {
                // unparse the entire expression
                ROSE_ASSERT(unp != NULL);
                ROSE_ASSERT(unp->u_fortran_locatedNode != NULL);
                unp->u_fortran_locatedNode->unparseExpression(*it, info);
            }
        }
        else
        {
            curprint("*");
        }
        curprint(")");
    }
    else
    {
        // a non-character type

        // explicit-shape (explicit rank and bounds/extents)
        // assumed-shape (explicit rank; unspecified bounds/extents)
        // deferred-shape (explicit rank; unspecified bounds/extents)
        // assumed-size (explicit ranks, explicit bounds/extents except last dim)
        ROSE_ASSERT(array_type->get_rank() >= 1);
        curprint(", DIMENSION");

        ROSE_ASSERT(unp != NULL);
        ROSE_ASSERT(unp->u_fortran_locatedNode != NULL);
        // unp->u_fortran_locatedNode->unparseExprList(dim, info); // adds parens
        // unp->u_fortran_locatedNode->UnparseLanguageIndependentConstructs::unparseExprList(dim, info); // adds parens

        // curprint("(");
        // curprint( StringUtility::numberToString(array_type->get_rank()) );
        // curprint(")");

        // unp->u_fortran_locatedNode->unparseExpression(array_type->get_dim_info(),info);
        unp->u_fortran_locatedNode->unparseExprList(array_type->get_dim_info(),info,/* output parens */ true);
    }
#else

    if (printDim)
    {
        ROSE_ASSERT(array_type->get_rank() >= 1);
        curprint(array_type->get_isCoArray()? ", CODIMENSION": ", DIMENSION");

        ROSE_ASSERT(unp != NULL);
        ROSE_ASSERT(unp->u_fortran_locatedNode != NULL);

        if (array_type->get_isCoArray())
        {   // print codimension info
            curprint("[");
            unp->u_fortran_locatedNode->unparseExprList(array_type->get_dim_info(),info,/* do not output parens */ false);
            curprint("]");
        }
        else  // print dimension info
            unp->u_fortran_locatedNode->unparseExprList(array_type->get_dim_info(),info,/* output parens */ true);
    }

    // DQ (1/16/2011): Plus unparse the base type...(unless it will just output the stripped types name).
    if (array_type->get_base_type()->containsInternalTypes() == true)
    {
        unparseType(array_type->get_base_type(), info, printDim);
    }
#endif

#if 0
    curprint ("\n! Leaving UnparserFort::unparseArrayType \n");
#endif
}