|
||
exprnode.ccGo to the documentation of this file.00001 // $Id: exprnode.cc,v 1.6 2003/08/07 23:13:04 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 exprNode::exprNode(NodeType typ, typeNode * type, const Coord coord) 00045 : Node(typ, coord), 00046 _type(type), 00047 _value(0) 00048 {} 00049 00050 // -------------------------------------------------------------------- 00051 // Const value 00052 // -------------------------------------------------------------------- 00053 00054 /* Obsolete 00055 constNode * exprNode::const_value() const 00056 { 00057 Node * val = value(); 00058 if (val && val->typ() == Const) 00059 return (constNode *) val; 00060 else 00061 return (constNode *) 0; 00062 } 00063 */ 00064 00065 // ------------------------------------------------------------ 00066 // Data type base 00067 // ------------------------------------------------------------ 00068 00069 typeNode * exprNode::base_type(bool TdefIndir) const 00070 { 00071 return type()->base_type(TdefIndir); 00072 } 00073 00074 // ------------------------------------------------------------ 00075 // Operator precedence 00076 // ------------------------------------------------------------ 00077 00078 int exprNode::precedence(Assoc & assoc) 00079 { 00080 // -- Default: highest precedence, left assoc 00081 00082 assoc = Left; 00083 return 20; 00084 } 00085 00086 // ------------------------------------------------------------ 00087 // Conversions 00088 // ------------------------------------------------------------ 00089 00090 exprNode * exprNode::integral_promotions(exprNode * old_expr) 00091 { 00092 typeNode * new_type = typeNode::integral_promotions(old_expr->type()); 00093 if (new_type) 00094 if ( old_expr->typ() == Operand ) 00095 ((operandNode *) old_expr)->cast(new_type); 00096 else 00097 return new castNode(new_type, old_expr, true, old_expr->coord()); 00098 else 00099 return old_expr; 00100 } 00101 00102 pair<exprNode *, exprNode *> 00103 exprNode::usual_arithmetic_conversions(exprNode * left, 00104 exprNode * right) 00105 { 00106 pair<typeNode *, typeNode *> types = 00107 typeNode::usual_arithmetic_conversions(left->type(), right->type()); 00108 00109 pair<exprNode *, exprNode *> out; 00110 00111 if (types.first) 00112 if ( left->typ() == Operand ) { 00113 ((operandNode *) left)->cast(types.first); 00114 out.first = left; 00115 } else 00116 out.first = new castNode(types.first, left, true, left->coord()); 00117 else 00118 out.first = left; 00119 00120 if (types.second) 00121 if ( right->typ() == Operand ) { 00122 ((operandNode *) right)->cast(types.second); 00123 out.second = right; 00124 } else 00125 out.second = new castNode(types.second, right, true, right->coord()); 00126 else 00127 out.second = right; 00128 00129 return out; 00130 } 00131 00132 // ------------------------------------------------------------ 00133 // Parens 00134 // ------------------------------------------------------------ 00135 00136 bool exprNode::parens(int outer_prec, 00137 Assoc outer_assoc) 00138 { 00139 Assoc my_assoc; 00140 int my_prec; 00141 00142 my_prec = precedence(my_assoc); 00143 00144 if (parenthesized()) 00145 return true; 00146 else if (my_prec < outer_prec) 00147 return true; 00148 else if (my_prec > outer_prec) 00149 return false; 00150 else 00151 return my_assoc != outer_assoc; 00152 } 00153 00154 // ------------------------------------------------------------ 00155 // Output 00156 // ------------------------------------------------------------ 00157 00158 void exprNode::output(output_context & ct, Node * parent) 00159 { 00160 output_expr(ct, parent, 0, Left); 00161 } 00162 00163 // ------------------------------------------------------------ 00164 // Destructor 00165 // ------------------------------------------------------------ 00166 00167 exprNode::~exprNode() 00168 { 00169 //delete _type; 00170 } |
Generated on August 27, 2003
Back to the C-Breeze home page