|
||
suenode.ccGo to the documentation of this file.00001 // $Id: suenode.cc,v 1.4 2003/08/07 23:13:12 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 sueNode::sueNode(NodeType typ, const Coord coord) 00045 : typeNode(typ, NONE, 0, coord), 00046 _spec((suespecNode *)0), 00047 _elaborated(false) 00048 {} 00049 00050 // ------------------------------------------------------------ 00051 // --- Was SetSUnionNameFields from sue.c 00052 // ------------------------------------------------------------ 00053 00054 void sueNode::set_name_fields(idNode *id, decl_list * fields, 00055 const Coord left_coord, 00056 const Coord the_right_coord) 00057 { 00058 string a(""); 00059 string & my_name = a; 00060 00061 if (id) 00062 my_name = id->name(); 00063 00064 // -- If fields are specified, then this sue is elaborated.. 00065 00066 if (fields) 00067 _elaborated = true; 00068 00069 // -- Look up the tag... 00070 00071 suespecNode * sp = CBZ::current_unit->tags()->lookup(my_name); 00072 00073 // -- If it's there, update the information. 00074 00075 if (sp) 00076 sp->update(fields, this, the_right_coord); 00077 else { 00078 00079 // -- Tag does not exist; create a new sue... 00080 00081 sp = new suespecNode(my_name.c_str(), fields, typ(), 00082 CBZ::current_unit, left_coord); 00083 00084 // -- If there is no name, create an anonymous sue... 00085 00086 if (my_name.empty()) 00087 my_name = CBZ::current_unit->tags()->insert_unique(string("___sue"), sp); 00088 else 00089 suespecNode * unused = CBZ::current_unit->tags()->insert(my_name, sp); 00090 } 00091 00092 // -- Make sure the name is set... 00093 00094 sp->name(my_name); 00095 spec(sp); 00096 00097 //delete id; 00098 } 00099 00100 sueNode * sueNode::set_name_fields_and(idNode *id, decl_list * fields, 00101 const Coord left_coord, 00102 const Coord the_right_coord) 00103 { 00104 set_name_fields(id, fields, left_coord, the_right_coord); 00105 return this; 00106 } 00107 00108 // ------------------------------------------------------------ 00109 // -- Was SetSUnionName in sue.c 00110 // ------------------------------------------------------------ 00111 00112 void sueNode::set_name(idNode * id, const Coord the_coord) 00113 { 00114 set_name_fields(id, (decl_list *)0, the_coord, Coord::Unknown); 00115 _elaborated = false; 00116 } 00117 00118 sueNode * sueNode::set_name_and(idNode * id, const Coord the_coord) 00119 { 00120 set_name(id, the_coord); 00121 return this; 00122 } 00123 00124 // ------------------------------------------------------------ 00125 // -- Was ForceNewSU in sue.c 00126 // ------------------------------------------------------------ 00127 00128 void sueNode::force_new(const Coord the_coord) 00129 { 00130 // this procedure handles the "recondite" rule that says that 00131 // struct.or.union identifier ';' 00132 // creates a create struct/union even if the tag is defined in an outer 00133 // scope. See K&R2, p213 00134 00135 // assume that this tag is not already in the innermost scope, 00136 // 1) create a create struct/union 00137 // 2) add it to the current scope 00138 // 3) if there's a conflict, then the assumption was false 00139 // and we use the previous version instead 00140 00141 if (spec()->name().empty()) 00142 return; 00143 00144 // ignore sue->fields 00145 00146 // new_sue = (sueNode *) clone(); 00147 // coord(the_coord); 00148 00149 // sueNode * orig = CBZ::current_unit->tags()->insert(name(), new_sue); 00150 // if (orig && (orig != new_sue)) { 00151 // orig != new_sue implies conflict and memory leak of new_sue */ 00152 // This always happens! CBZ::Fail(__FILE__, __LINE__, "force_new failed"); 00153 // delete new_sue; 00154 // } 00155 } 00156 00157 sueNode * sueNode::force_new_and(const Coord the_coord) 00158 { 00159 force_new(the_coord); 00160 return this; 00161 } 00162 00163 // ------------------------------------------------------------ 00164 // Type Equal 00165 // ------------------------------------------------------------ 00166 00167 bool sueNode::qualified_equal_to(typeNode * node2, 00168 bool strict_toplevel, bool strict_recursive) 00169 { 00170 sueNode * n2 = (sueNode *) node2; 00171 00172 // -- Normal case 00173 00174 if (this == n2) 00175 return true; 00176 00177 // -- Check the tags also in case we are still just scanning 00178 00179 return spec()->same_tag_as(n2->spec()); 00180 } 00181 00182 // ------------------------------------------------------------ 00183 // Output 00184 // ------------------------------------------------------------ 00185 00186 void sueNode::output_type(output_context & ct, Node * parent, Assoc context, Type_qualifiers q) 00187 { 00188 if (context == Left) { 00189 const string & qs = type_qualifiers_name(q); 00190 const string & qs1 = type_qualifiers_name(); 00191 00192 ct << qs; 00193 ct.space(); 00194 ct << qs1; 00195 ct.space(); 00196 00197 switch (typ()) { 00198 case Struct: 00199 ct << "struct "; 00200 break; 00201 case Union: 00202 ct << "union "; 00203 break; 00204 case Enum: 00205 ct << "enum "; 00206 break; 00207 default: 00208 CBZ::Fail(__FILE__, __LINE__, "output_type(): Unrecognized type."); 00209 } 00210 00211 ct << spec()->name(); 00212 00213 if (elaborated()) 00214 spec()->output_type(ct, this, Left, NONE); 00215 } 00216 } 00217 00218 // ------------------------------------------------------------ 00219 // Destructor 00220 // ------------------------------------------------------------ 00221 00222 sueNode::~sueNode() 00223 { 00224 } |
Generated on August 27, 2003
Back to the C-Breeze home page