//! Returns 'true' if the given type is 'const'. static bool isReadOnlyType (const SgType* type) { ROSE_ASSERT (type); const SgModifierType* mod = 0; switch (type->variantT ()) { case V_SgModifierType: mod = isSgModifierType (type); break; case V_SgReferenceType: mod = isSgModifierType (isSgReferenceType (type)->get_base_type ()); break; case V_SgPointerType: mod = isSgModifierType (isSgPointerType (type)->get_base_type ()); break; default: mod = 0; break; } return mod && mod->get_typeModifier ().get_constVolatileModifier ().isConst (); }
static SgType *ignoreModifiers(SgType *type) { SgModifierType *mod = NULL; do { SgModifierType *mod = isSgModifierType(type); if (mod != NULL) type = mod->get_base_type(); } while (mod != NULL); return type; }
Type::Type( const SgType *t ) : orig_(t), t_(t), isConst_(false), isVolatile_(false) { while( true ) { t = t->stripType( SgType::STRIP_TYPEDEF_TYPE ); if( const SgModifierType *mt = isSgModifierType( t ) ) { const SgTypeModifier &m = mt->get_typeModifier(); const SgConstVolatileModifier &cv = m.get_constVolatileModifier(); isConst_ |= cv.isConst(); isVolatile_ |= cv.isVolatile(); t = mt->get_base_type(); } if( t_ == t ) break; else t_ = t; } }
void UnparseFortran_type::unparseModifierType(SgType* type, SgUnparse_Info& info) { SgModifierType* mod_type = isSgModifierType(type); ROSE_ASSERT(mod_type != NULL); // printf ("Not clear what the Fortran specific type modifiers will be, UnparseFortran_type::unparseModifierType() not implemented! \n"); unparseType(mod_type->get_base_type(), info); // DQ (12/1/2007): This has been moved from SgType to the SgModifierType SgExpression* kindExpression = mod_type->get_type_kind(); // DQ (10/2/2010): The type parameter is not longer used since the length is represented explicitly for strings in SgTypeString. // SgExpression* typeParameterExpression = mod_type->get_type_parameter(); // printf ("In UnparseFortran_type::unparseModifierType(): mod_type->get_type_kind() = %p mod_type->get_type_parameter() = %p \n",mod_type->get_type_kind(),mod_type->get_type_parameter()); // DQ (10/2/2010): The type parameter is not longer used since the length is represented explicitly for strings in SgTypeString. // if (kindExpression != NULL || typeParameterExpression != NULL) if (kindExpression != NULL) { curprint("("); if (kindExpression != NULL) { curprint("kind="); unp->u_fortran_locatedNode->unparseExpression(kindExpression,info); } #if 0 // DQ (10/2/2010): The type parameter is not longer used since the length is represented explicitly for strings in SgTypeString. if (typeParameterExpression != NULL) { if (kindExpression != NULL) { curprint(","); } curprint("len="); unp->u_fortran_locatedNode->unparseExpression(typeParameterExpression,info); } #endif curprint(")"); } }
void UnparseFortran_type::unparseReferenceType(SgType* type, SgUnparse_Info& info) { SgReferenceType* ref_type = isSgReferenceType(type); ROSE_ASSERT(ref_type != NULL); /* special cases: ptr to array, int (*p) [10] */ /* ptr to function, int (*p)(int) */ /* ptr to ptr to .. int (**p) (int) */ SgUnparse_Info ninfo(info); if (isSgReferenceType(ref_type->get_base_type()) || isSgPointerType(ref_type->get_base_type()) || isSgArrayType(ref_type->get_base_type()) || isSgFunctionType(ref_type->get_base_type()) || isSgMemberFunctionType(ref_type->get_base_type()) || isSgModifierType(ref_type->get_base_type()) ) { ninfo.set_isReferenceToSomething(); } if (ninfo.isTypeFirstPart()) { unparseType(ref_type->get_base_type(), ninfo); // curprint("& /* reference */ "); curprint("&"); } else { if (ninfo.isTypeSecondPart()) { unparseType(ref_type->get_base_type(), ninfo); } else { SgUnparse_Info ninfo2(ninfo); ninfo2.set_isTypeFirstPart(); unparseType(ref_type, ninfo2); ninfo2.set_isTypeSecondPart(); unparseType(ref_type, ninfo2); } } }
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 }
void ModelBuilder::add(Model::model_t & model, SgType * sg_type) { SgModifierType * modifier_type = isSgModifierType(sg_type); if (modifier_type != NULL) { add(model, modifier_type->get_base_type()); return; } Model::type_t element = Model::build<Model::e_model_type>(); element->node->type = sg_type; SgNamedType * named_type = isSgNamedType(sg_type); SgArrayType * array_type = isSgArrayType(sg_type); SgPointerType * pointer_type = isSgPointerType(sg_type); SgReferenceType * reference_type = isSgReferenceType(sg_type); if (named_type != NULL) { SgClassType * class_type = isSgClassType(named_type); SgEnumType * enum_type = isSgEnumType(named_type); SgTypedefType * typedef_type = isSgTypedefType(named_type); SgDeclarationStatement * decl_stmt = named_type->get_declaration()->get_firstNondefiningDeclaration(); assert(decl_stmt != NULL); SgSymbol * decl_sym = decl_stmt->get_symbol_from_symbol_table(); assert(decl_sym != NULL); if (class_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_class_type; SgClassSymbol * class_sym = isSgClassSymbol(decl_sym); assert(class_sym != NULL); element->node->base_class = model.lookup_class(class_sym); if (element->node->base_class == NULL) { add(model, class_sym); element->node->base_class = model.lookup_class(class_sym); } assert(element->node->base_class != NULL); } else if (enum_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_enum_type; SgEnumSymbol * enum_sym = isSgEnumSymbol(decl_sym); assert(enum_sym != NULL); element->node->enum_symbol = enum_sym; } else if (typedef_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_typedef_type; SgTypedefSymbol * typedef_sym = isSgTypedefSymbol(decl_sym); assert(typedef_sym != NULL); element->node->typedef_symbol = typedef_sym; element->node->base_type = model.lookup_type(typedef_type->get_base_type()); if (element->node->base_type == NULL) { add(model, typedef_type->get_base_type()); element->node->base_type = model.lookup_type(typedef_type->get_base_type()); } assert(element->node->base_type != NULL); } else assert(false); } else if (array_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_array_type; element->node->base_type = model.lookup_type(array_type->get_base_type()); if (element->node->base_type == NULL) { add(model, array_type->get_base_type()); element->node->base_type = model.lookup_type(array_type->get_base_type()); } assert(element->node->base_type != NULL); } else if (pointer_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_pointer_type; element->node->base_type = model.lookup_type(pointer_type->get_base_type()); if (element->node->base_type == NULL) { add(model, pointer_type->get_base_type()); element->node->base_type = model.lookup_type(pointer_type->get_base_type()); } assert(element->node->base_type != NULL); } else if (reference_type != NULL) { element->node->kind = Model::node_t<Model::e_model_type>::e_reference_type; element->node->base_type = model.lookup_type(reference_type->get_base_type()); if (element->node->base_type == NULL) { add(model, reference_type->get_base_type()); element->node->base_type = model.lookup_type(reference_type->get_base_type()); } assert(element->node->base_type != NULL); } else { element->node->kind = Model::node_t<Model::e_model_type>::e_native_type; } element->scope->parent.a_namespace = NULL; /// \todo model.types.push_back(element); }
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); } } }