|
||
primnode.ccGo to the documentation of this file.00001 // $Id: primnode.cc,v 1.3 2003/08/07 23:13:11 pnav Exp $ 00002 // ---------------------------------------------------------------------- 00003 // 00004 // C-Breeze 00005 // C Compiler Framework 00006 // 00007 // Copyright (c) 2000 University of Texas at Austin 00008 // 00009 // Samuel Z. Guyer 00010 // Daniel A. Jimenez 00011 // Calvin Lin 00012 // 00013 // Permission is hereby granted, free of charge, to any person 00014 // obtaining a copy of this software and associated documentation 00015 // files (the "Software"), to deal in the Software without 00016 // restriction, including without limitation the rights to use, copy, 00017 // modify, merge, publish, distribute, sublicense, and/or sell copies 00018 // of the Software, and to permit persons to whom the Software is 00019 // furnished to do so, subject to the following conditions: 00020 // 00021 // The above copyright notice and this permission notice shall be 00022 // included in all copies or substantial portions of the Software. 00023 // 00024 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00025 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00026 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00027 // NONINFRINGEMENT. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT 00028 // AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00029 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00030 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00031 // THE SOFTWARE. 00032 // 00033 // We acknowledge the C-to-C Translator from MIT Laboratory for 00034 // Computer Science for inspiring parts of the C-Breeze design. 00035 // 00036 // ---------------------------------------------------------------------- 00037 00038 #include "c_breeze.h" 00039 00040 // -------------------------------------------------------------------- 00041 // Constructors 00042 // -------------------------------------------------------------------- 00043 00044 primNode::primNode(Type_qualifiers tq, basic_type basic, const Coord coord) 00045 : typeNode(Prim, tq, (typeNode *)0, coord), _basic(basic) 00046 {} 00047 00048 // MakeDefaultPrimType in type.c 00049 00050 primNode::primNode(Type_qualifiers tq, const Coord coord) 00051 : typeNode(Prim, tq, 0, coord), 00052 _basic() 00053 { 00054 finish(); 00055 } 00056 00057 primNode::primNode(const Coord coord) 00058 : typeNode(Prim, NONE, 0, coord), 00059 _basic() 00060 { 00061 finish(); 00062 } 00063 00064 // StartPrimType in type.c 00065 00066 primNode::primNode(basic_type basic, const Coord coord) 00067 : typeNode(Prim, NONE, 0, coord), 00068 _basic(basic) 00069 {} 00070 00071 // ------------------------------------------------------------ 00072 // FinishPrimType from type.c 00073 // ------------------------------------------------------------ 00074 00075 // This function fills in defaults (e.g., if not specified 00076 // then an int is signed). 00077 00078 void primNode::finish() 00079 { 00080 // -- Fill in the blanks on the basic type... 00081 00082 basic().finish(); 00083 } 00084 00085 primNode * primNode::finish_and() 00086 { 00087 finish(); 00088 return this; 00089 } 00090 00091 // ------------------------------------------------------------ 00092 // MergePrimTypes from type.c 00093 // (the "other" object is deleted 00094 // ------------------------------------------------------------ 00095 00096 void primNode::merge_in(primNode * other) 00097 { 00098 basic_type & bt1 = basic(); 00099 basic_type & bt2 = other->basic(); 00100 00101 bt1.merge_in(bt2, coord()); 00102 00103 //delete other; 00104 } 00105 00106 primNode * primNode::merge_in_and(primNode * other) 00107 { 00108 merge_in(other); 00109 return this; 00110 } 00111 00112 // ------------------------------------------------------------ 00113 // Type Equal 00114 // ------------------------------------------------------------ 00115 00116 bool primNode::qualified_equal_to(typeNode * node2, 00117 bool strict_toplevel, bool strict_recursive) 00118 { 00119 primNode * n2 = (primNode *) node2; 00120 return basic() == n2->basic(); 00121 } 00122 00123 // ------------------------------------------------------------ 00124 // Conversions 00125 // ------------------------------------------------------------ 00126 00127 #define UCHAR_TO_INT_OVF 0 00128 #define USHORT_TO_INT_OVF 0 00129 00130 // -- UsualUnaryConversionType is used by parser to check that 00131 // old-style function decls contain only "usual unary conversions" 00132 // types -- in particular, float and char won't be allowed as 00133 // parameter types. 00134 00135 /* REPLACED by integral promotions 00136 00137 typeNode * primNode::usual_unary_conversion_type() 00138 { 00139 basic_type & b = basic(); 00140 00141 if (b.is_char()) { 00142 if (b.is_unsigned()) 00143 return (typeNode *) new primNode(basic_type::UInt); 00144 else 00145 return (typeNode *) new primNode(basic_type::SInt); 00146 } 00147 00148 if (b.is_int() && b.is_short()) { 00149 if (b.is_unsigned()) 00150 return (typeNode *) new primNode(basic_type::UInt); 00151 else 00152 return (typeNode *) new primNode(basic_type::SInt); 00153 } 00154 00155 if (b.is_float()) 00156 return (typeNode *) new primNode(basic_type::Double); 00157 00158 return (typeNode *) this; 00159 } 00160 00161 */ 00162 00163 // ------------------------------------------------------------ 00164 // Walker 00165 // ------------------------------------------------------------ 00166 00167 void primNode::visit(Visitor * the_visitor) 00168 { 00169 the_visitor->at_prim(this); 00170 } 00171 00172 void primNode::walk(Walker & the_walker) 00173 { 00174 Walker::Order ord = the_walker.order(); 00175 00176 if (ord == Walker::Preorder || ord == Walker::Both) 00177 the_walker.at_prim(this, Walker::Preorder); 00178 00179 if (ord == Walker::Postorder || ord == Walker::Both) 00180 the_walker.at_prim(this, Walker::Postorder); 00181 } 00182 00183 // ------------------------------------------------------------ 00184 // Output 00185 // ------------------------------------------------------------ 00186 00187 void primNode::output_type(output_context & ct, Node * parent, Assoc context, Type_qualifiers q) 00188 { 00189 if (context == Left) { 00190 const string & qs = type_qualifiers_name(); 00191 const string & bs = basic().to_string(); 00192 00193 ct << qs; 00194 00195 if (! bs.empty()) 00196 ct.space(); 00197 00198 ct << bs; 00199 } 00200 } 00201 00202 // ------------------------------------------------------------ 00203 // Changer 00204 // ------------------------------------------------------------ 00205 00206 Node * primNode::change(Changer & the_changer, bool redispatch) 00207 { 00208 Changer::Order ord = the_changer.order(); 00209 primNode * the_prim = this; 00210 00211 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch) 00212 the_prim = (primNode *) the_changer.at_prim(the_prim, Changer::Preorder); 00213 00214 if (the_prim) { 00215 00216 if (the_prim != this) 00217 return the_prim->change(the_changer, true); 00218 00219 } 00220 00221 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch) 00222 the_prim = (primNode *) the_changer.at_prim(the_prim, Changer::Postorder); 00223 00224 return the_prim; 00225 } 00226 00227 00228 // ------------------------------------------------------------ 00229 // Destructor 00230 // ------------------------------------------------------------ 00231 00232 primNode::~primNode() 00233 { 00234 } |
Generated on August 27, 2003
Back to the C-Breeze home page