Inferno
0.2
|
00001 /* 00002 * generate_implicit_casts.cpp 00003 * 00004 * Created on: 20 Oct 2009 00005 * Author: jgraley 00006 */ 00007 00008 #include "generate_implicit_casts.hpp" 00009 #include "tree/cpptree.hpp" 00010 #include "common/common.hpp" 00011 #include "sr/soft_patterns.hpp" 00012 #include "tree/typeof.hpp" 00013 00014 using namespace CPPTree; 00015 using namespace Steps; 00016 00017 GenerateImplicitCasts::GenerateImplicitCasts() 00018 { 00019 // Find a function call and use TypeOf to get the fucntion's declaration. 00020 // Select a single argument. Inforno does arguments via a map (as opposed 00021 // to ordering) and we couple the keys to an InstanceIdentifier widcard 00022 // in order to ensure we are always talking about the same argument. 00023 // 00024 // Restrict the search to argument expressions whose type (TypeOf again) 00025 // does not match the type of the param in the declaration. Then we can 00026 // simply insert a cast to the declaration param type at the root of the 00027 // expression. 00028 MakeTreePtr<Call> s_call; 00029 MakeTreePtr< TransformOf<Expression> > callee( &TypeOf::instance ); 00030 s_call->callee = callee; 00031 MakeTreePtr<CallableParams> s_proc; 00032 callee->pattern = s_proc; 00033 MakeTreePtr< Instance > s_param; 00034 MakeTreePtr< InstanceIdentifier > param_id; 00035 s_param->identifier = param_id; 00036 MakeTreePtr< Type > type; 00037 s_param->type = type; 00038 MakeTreePtr< Star<Instance> > s_other_params; 00039 s_proc->members = (s_param, s_other_params); 00040 MakeTreePtr< MapOperand > s_arg; 00041 s_arg->identifier = param_id; 00042 MakeTreePtr< TransformOf<Expression> > s_arg_value( &TypeOf::instance ); 00043 s_arg->value = s_arg_value; 00044 //s_arg_value->pattern = MakeTreePtr< Type >(); 00045 MakeTreePtr< NotMatch<Type> > s_arg_type; 00046 s_arg_value->pattern = s_arg_type; 00047 s_arg_type->pattern = type; 00048 MakeTreePtr< Star<MapOperand> > other_args; 00049 s_call->operands = ( s_arg, other_args ); 00050 00051 MakeTreePtr<Call> r_call; 00052 MakeTreePtr< MapOperand > r_arg; 00053 r_arg->identifier = param_id; 00054 MakeTreePtr<Cast> r_cast; 00055 r_arg->value = r_cast; 00056 r_cast->operand = s_arg->value; 00057 r_cast->type = type; 00058 r_call->operands = ( r_arg, other_args ); 00059 r_call->callee = callee; 00060 00061 Configure(s_call, r_call); 00062 }