Beispiel #1
0
static
bool isVoidStar(SgType* type) {
  SgPointerType *ptr = isSgPointerType(ignoreModifiers(type));
  if (ptr == NULL)
    return false;
  return (isSgTypeVoid(ignoreModifiers(ptr->get_base_type())) != NULL);
}
Beispiel #2
0
void examineType(SgType *type, ostream &out) {
    int nr_stars = 0;
    stringstream ss1;
    if (NULL == type) {
        out << "void";
        return;
    }
    while (isSgArrayType(type) ||
            isSgPointerType(type)) {
        if (isSgArrayType(type)) {
            SgArrayType *atype = isSgArrayType(type);
            SgExpression *expr = atype->get_index();

            type = atype->get_base_type();
            /*
            ss1 << "[";
            if (expr)
                examineExpr(expr, ss1);
            ss1 << "]";
            */
            nr_stars++;
        } else {
            SgPointerType *ttype = isSgPointerType(type);
            type = ttype->get_base_type();
            nr_stars++;
        }
    }

    examinePrimTypeName(type, out);
    out << " ";
    for (int i = 0; i < nr_stars; ++i)
        out << "*";
    out << ss1.str();
}
Beispiel #3
0
/**
 * class: SgPointerType
 * term: pointer_type(type)
 * arg type: base type
 */
PrologCompTerm* 
RoseToTerm::getPointerTypeSpecific(SgType* mytype) {
  /* let rose do type testing and casting*/
  SgPointerType* ptype = isSgPointerType(mytype);
  ROSE_ASSERT(ptype != NULL);
  /* nested type */
  return new PrologCompTerm
    ("pointer_type", /*1,*/
     /* get base type with recursion*/
     getTypeSpecific(ptype->get_base_type()));
}
Beispiel #4
0
void examineInitializedName(SgInitializedName *name, ostream &out) {
    SgSymbol* symbol = name->get_symbol_from_symbol_table();
    if (NULL == symbol)
        return;
    SgType *type = symbol->get_type();
    int nr_stars = 0;
    stringstream ss1;
    
    while (isSgArrayType(type) ||
            isSgPointerType(type)) {
        if (isSgArrayType(type)) {
            SgArrayType *atype = isSgArrayType(type);
            SgExpression *expr = atype->get_index();

            type = atype->get_base_type();
            ss1 << "[";
            if (expr)
                examineExpr(expr, ss1);
            ss1 << "]";
        } else {
            SgPointerType *ttype = isSgPointerType(type);
            type = ttype->get_base_type();
            nr_stars++;
        }
    }
    examinePrimTypeName(type, out);
    out << " ";
    for (int i = 0; i < nr_stars; ++i)
        out << "*";
    out << symbol->get_name().getString();
    out << ss1.str();

    SgInitializer *initer = name->get_initializer();
    if (initer) {
        switch (initer->variantT()) {
            case V_SgAssignInitializer:
                SgAssignInitializer *ai = isSgAssignInitializer(initer);
                SgExpression *expr = ai->get_operand();
                if (expr) {
                    out << "=";
                    examineExpr(expr, out);
                }
                break;
            default:
                break;
        }
    }
}
Beispiel #5
0
 void basetype(ExprSynAttr *a) {
     stringstream ts;
     if (NULL == a)
         return;
     switch (a->sgtype->variantT()) {
         case V_SgArrayType:
         {
             SgArrayType *atype = isSgArrayType(a->sgtype);
             sgtype = atype->get_base_type();
             break;
         }
         case V_SgPointerType:
         {
             SgPointerType *ptype = isSgPointerType(a->sgtype);
             sgtype = ptype->get_base_type();
             break;
         }
         default:
             sgtype = a->sgtype;
     }
     examineType(sgtype, ts);
     type = ts.str();
 }
Beispiel #6
0
void
TypeTraversal::transformType(SgType* type)
   {
  // Since only the base_types of pointers are shared, we can take as input the pointer type and just change it internally.
  // The reference to the type from non-type IR nodes need not be modified.

     ROSE_ASSERT(type != NULL);

#if DEBUG_TYPE_TRAVERSAL
     printf ("Inside of TypeTraversal::transformType(): type = %p = %s \n",type,type->class_name().c_str());
#endif

  // How complex can be expect the type system to be (do we required a nested type traversal).
     SgPointerType* pointerType = isSgPointerType(type);
     if (pointerType != NULL)
        {
       // Check if the base type is marked as shared.
          SgModifierType* mod_type = isSgModifierType(pointerType->get_base_type());
          if (mod_type != NULL)
             {
#if DEBUG_TYPE_TRAVERSAL
               printf ("(mod_type != NULL): mod_type->get_typeModifier().displayString() = %s \n",mod_type->get_typeModifier().displayString().c_str());
#endif
               if (mod_type->get_typeModifier().get_upcModifier().get_isShared() == true)
                  {
#if DEBUG_TYPE_TRAVERSAL
                    printf ("TypeTraversal::transformType(): (mod_type != NULL): Detected a shared type! (transform the type) \n");
#endif
                 // Reset the base_type on the pointer to point to the base_type of the modifier.
                 // Note that a less elegant solution would be to call: mod_type->get_typeModifier().get_upcModifier().set_isShared(false).
                    SgType* modifier_base_type = mod_type->get_base_type();
                    ROSE_ASSERT(modifier_base_type != NULL);
#if DEBUG_TYPE_TRAVERSAL
                    printf ("TypeTraversal::transformType(): (mod_type != NULL): Removing shared base_type from pointerType = %p replacing with modifier_base_type = %p = %s \n",pointerType,modifier_base_type,modifier_base_type->class_name().c_str());
#endif
                    pointerType->set_base_type(modifier_base_type);
#if 1
                 // DQ (4/26/2014): Also mark this as not shared, since the cast expressions will refer directly to this SgModifierType type.
                    mod_type->get_typeModifier().get_upcModifier().set_isShared(false);
#else
#error "DEAD CODE!"
                    printf ("In TypeTraversal::transformType(): (mod_type != NULL): Skipping reset of upc modifier in SgModifierType: mod_type = %p \n",mod_type);
#endif
                  }
                 else
                  {
                 // DQ (5/16/2014): in the case of test2014_20.c the function parameter has a type with a short
                 // chain of SgModifierType IR nodes. In this case only the last one is marked as shared.
                 // There might be a more general AST post processing step for this, or it might be that we 
                 // need to build the attributes better to avoid such chains of SgModifierType IR nodes.
                    SgModifierType* nested_mod_type = isSgModifierType(mod_type->get_base_type());
                    if (nested_mod_type != NULL)
                       {
#if DEBUG_TYPE_TRAVERSAL
                         printf ("(mod_type != NULL): (nested_mod_type != NULL): nested_mod_type->get_typeModifier().displayString() = %s \n",nested_mod_type->get_typeModifier().displayString().c_str());
#endif
                         if (nested_mod_type->get_typeModifier().get_upcModifier().get_isShared() == true)
                            {
#if DEBUG_TYPE_TRAVERSAL
                              printf ("TypeTraversal::transformType(): (mod_type != NULL): (nested_mod_type != NULL): Detected a nested shared type! (transform the type) \n");
#endif
                           // Reset the base_type on the pointer to point to the base_type of the modifier.
                           // Note that a less elegant solution would be to call: mod_type->get_typeModifier().get_upcModifier().set_isShared(false).
                              SgType* nested_modifier_base_type = nested_mod_type->get_base_type();
                              ROSE_ASSERT(nested_modifier_base_type != NULL);
#if 0
                              printf ("TypeTraversal::transformType(): (mod_type != NULL): (nested_mod_type != NULL): Removing shared base_type from pointerType = %p replacing with modifier_base_type = %p = %s \n",pointerType,modifier_base_type,modifier_base_type->class_name().c_str());
#endif
                              mod_type->set_base_type(nested_modifier_base_type);
#if 1
                           // DQ (4/26/2014): Also mark this as not shared, since the cast expressions will refer directly to this SgModifierType type.
                              nested_mod_type->get_typeModifier().get_upcModifier().set_isShared(false);
#else
#error "DEAD CODE!"
                              printf ("In TypeTraversal::transformType(): (mod_type != NULL): (nested_mod_type != NULL): Skipping reset of upc modifier in SgModifierType: mod_type = %p \n",mod_type);
#endif
                            }
                       }
                  }
             }
        }
       else
        {
          SgModifierType* mod_type = isSgModifierType(type);
          if (mod_type != NULL)
             {
#if DEBUG_TYPE_TRAVERSAL
               printf ("Found a modifier type (not from a pointer type) \n");
#endif
#if DEBUG_TYPE_TRAVERSAL
               printf ("(Found a modifier type (not from a pointer type): mod_type->get_typeModifier().displayString() = %s \n",mod_type->get_typeModifier().displayString().c_str());
#endif
               SgType* base_type = mod_type->get_base_type();
#if DEBUG_TYPE_TRAVERSAL
               printf ("Found a modifier type (not from a pointer type): base_type = %p = %s \n",base_type,base_type->class_name().c_str());
#endif
            // DQ (5/31/2014): Reset the type to eliminate the shared keyword.
               mod_type->get_typeModifier().get_upcModifier().set_isShared(false);
             }
        }

   }
Beispiel #7
0
ExprSynAttr *examineVariableDeclaration(SgVariableDeclaration* decl, ostream &out) {
  SgInitializedNamePtrList& name_list = decl->get_variables();
  SgInitializedNamePtrList::const_iterator name_iter;
  ExprSynAttr *ret = NULL;
  ExprSynAttr *gc = NULL;
  ret = new ExprSynAttr();
  for (name_iter = name_list.begin(); 
       name_iter != name_list.end(); 
       name_iter++) {
    SgInitializedName* name = *name_iter;
    SgSymbol* symbol = name->get_symbol_from_symbol_table();
    SgType *type = symbol->get_type();
    int nr_stars = 0;
    stringstream ss1;
    
    while (isSgArrayType(type) ||
            isSgPointerType(type)) {
        if (isSgArrayType(type)) {
            SgArrayType *atype = isSgArrayType(type);
            SgExpression *expr = atype->get_index();

            type = atype->get_base_type();
            ss1 << "[";
            if (expr)
                examineExpr(expr, ss1);
            ss1 << "]";
        } else {
            SgPointerType *ttype = isSgPointerType(type);
            type = ttype->get_base_type();
            nr_stars++;
        }
    }

    examinePrimTypeName(type, ret->code);
    ret->code << " ";
    for (int i = 0; i < nr_stars; ++i)
        ret->code << "*";
    ret->code << symbol->get_name().getString();
    ret->code << ss1.str();

    ss1.str("");

    SgInitializer *initer = name->get_initializer();
    if (initer) {
        switch (initer->variantT()) {
            case V_SgAssignInitializer:
                SgAssignInitializer *ai = isSgAssignInitializer(initer);
                SgExpression *expr = ai->get_operand();
                if (expr) {
                    ret->code << "=";
                    gc = examineExpr(expr, ret->code);
                    if (gc != NULL)
                        delete gc;
                }
                break;
            default:
                break;
        }
    }

    /* end of this decl */
    ret->code << ";";
    out << ret->code.str();

    return ret;

    /*
    cout << "[Decl] Variable (name:"<<symbol->get_name().getString();
    cout << ",type:"<<symbol->get_type()->class_name();
    cout << ",init:";

    SgInitializer* init_expr = name->get_initializer();
    if (init_expr) 
      cout << init_expr->class_name();
    else
      cout << "none";
    cout << ")" << endl;
    */
  }
}