SgType* findBaseType(SgType* sageType){ ROSE_ASSERT( sageType != NULL); SgType* baseType = sageType; switch(sageType->variantT()) { case V_SgReferenceType: { baseType = isSgReferenceType(sageType)->get_base_type(); break; } case V_SgPointerType: { baseType = isSgPointerType(sageType)->get_base_type(); break; } case V_SgTypedefType: { while(isSgTypedefType(baseType) != NULL) baseType = isSgTypedefType(baseType)->get_base_type(); break; } default: break; }; ROSE_ASSERT ( baseType != NULL ); return baseType; };
//! 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 (); }
void RtedTransformation::insertVariableCreateInitForParams( SgFunctionDefinition& fndef) { SgBasicBlock* body = fndef.get_body(); ROSE_ASSERT( body); SgInitializedNamePtrList names = fndef.get_declaration()->get_parameterList()->get_args(); BOOST_FOREACH( SgInitializedName* param, names) { SgType* initType = param->get_type(); // nov2010 code: // reference variables don't allocate new memory // if we call createVariable the RTS will think it's a double // allocation fault // \pp we skip array types because they will be handled elsewhere // \todo not sure if this is correct here, b/c arrays would decay // to pointers anyway. However, this decay is not represented // in the nov2010 code, thus we skip these initializations // here. if ( isSgReferenceType(initType) || isSgArrayType(skip_ModifierType(initType)) ) continue; SgFunctionDeclaration* fndecl = fndef.get_declaration(); std::cerr << ">>> " << fndecl->get_name() << std::endl; ROSE_ASSERT(isSgFunctionDefinition(param->get_scope())); body->prepend_statement( buildVariableCreateCallStmt(param, true) ); }
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); } } }
/*! * \brief Creates an assignment to "pack" a local variable back into * an outlined-function parameter that has been passed as a pointer * value. * * This routine takes the original "unpack" definition, of the form * * TYPE local_unpack_var = *outlined_func_arg; * int i = *(int *)(__out_argv[1]); // parameter wrapping case * * and creates the "re-pack" assignment expression, * * *outlined_func_arg = local_unpack_var * *(int *)(__out_argv[1]) =i; // parameter wrapping case * * C++ variables of reference types do not need this step. */ static SgAssignOp * createPackExpr (SgInitializedName* local_unpack_def) { if (!Outliner::temp_variable) { if (is_C_language()) //skip for pointer dereferencing used in C language return NULL; } // reference types do not need copy the value back in any cases if (isSgReferenceType (local_unpack_def->get_type ())) return NULL; if (local_unpack_def && !isReadOnlyType (local_unpack_def->get_type ())) // && !isSgReferenceType (local_unpack_def->get_type ())) { SgName local_var_name (local_unpack_def->get_name ()); SgAssignInitializer* local_var_init = isSgAssignInitializer (local_unpack_def->get_initializer ()); ROSE_ASSERT (local_var_init); // Create the LHS, which derefs the function argument, by // copying the original dereference expression. // SgPointerDerefExp* param_deref_unpack = isSgPointerDerefExp (local_var_init->get_operand_i ()); if (param_deref_unpack == NULL) { cout<<"packing statement is:"<<local_unpack_def->get_declaration()->unparseToString()<<endl; cout<<"local unpacking stmt's initializer's operand has non-pointer deferencing type:"<<local_var_init->get_operand_i ()->class_name()<<endl; ROSE_ASSERT (param_deref_unpack); } SgPointerDerefExp* param_deref_pack = isSgPointerDerefExp (ASTtools::deepCopy (param_deref_unpack)); ROSE_ASSERT (param_deref_pack); // Create the RHS, which references the local variable. SgScopeStatement* scope = local_unpack_def->get_scope (); ROSE_ASSERT (scope); SgVariableSymbol* local_var_sym = scope->lookup_var_symbol (local_var_name); ROSE_ASSERT (local_var_sym); SgVarRefExp* local_var_ref = SageBuilder::buildVarRefExp (local_var_sym); ROSE_ASSERT (local_var_ref); // Assemble the final assignment expression. return SageBuilder::buildAssignOp (param_deref_pack, local_var_ref); } return 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 }
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); }
bool Type::isReference() const { return isSgReferenceType(t_) != 0; }