Changes in src/Parser/ExpressionNode.cc [cccc534:e8ccca3]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rcccc534 re8ccca3 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 2 11:12:00201713 // Update Count : 56811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 1 15:07:09 2017 13 // Update Count : 618 14 14 // 15 15 … … 58 58 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 59 59 60 Expression * build_constantInteger( const std::string & str ) { 60 static void sepNumeric( string & str, string & units ) { 61 string::size_type posn = str.find_first_of( "`" ); 62 if ( posn != string::npos ) { 63 units = "?" + str.substr( posn ); // extract units 64 str.erase( posn ); // remove units 65 } // if 66 } // sepNumeric 67 68 Expression * build_constantInteger( std::string & str ) { 61 69 static const BasicType::Kind kind[2][3] = { 62 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 63 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 64 72 }; 73 74 string units; // units 75 sepNumeric( str, units ); // separate constant from units 76 65 77 bool dec = true, Unsigned = false; // decimal, unsigned constant 66 78 int size; // 0 => int, 1 => long, 2 => long long … … 69 81 Expression * ret; 70 82 83 // ROB: what do we do with units on 0 and 1? 71 84 // special constants 72 85 if ( str == "0" ) { … … 134 147 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 135 148 CLEANUP: 149 if ( units.length() != 0 ) { 150 ret = new UntypedExpr( new NameExpr( units, ret ) ); 151 } // if 152 136 153 delete &str; // created by lex 137 154 return ret; 138 155 } // build_constantInteger 139 156 140 Expression * build_constantFloat( conststd::string & str ) {157 Expression * build_constantFloat( std::string & str ) { 141 158 static const BasicType::Kind kind[2][3] = { 142 159 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 143 160 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 144 161 }; 162 163 string units; // units 164 sepNumeric( str, units ); // separate constant from units 145 165 146 166 bool complx = false; // real, complex … … 169 189 170 190 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 191 if ( units.length() != 0 ) { 192 ret = new UntypedExpr( new NameExpr( units, ret ) ); 193 } // if 194 171 195 delete &str; // created by lex 172 196 return ret; 173 197 } // build_constantFloat 174 198 175 Expression * build_constantChar( const std::string & str ) { 199 static void sepString( string & str, string & units, char delimit ) { 200 string::size_type posn = str.find_last_of( delimit ) + 1; 201 if ( posn != str.length() ) { 202 units = "?" + str.substr( posn ); // extract units 203 str.erase( posn ); // remove units 204 } // if 205 } // sepString 206 207 Expression * build_constantChar( std::string & str ) { 208 string units; // units 209 sepString( str, units, '\'' ); // separate constant from units 210 176 211 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 212 if ( units.length() != 0 ) { 213 ret = new UntypedExpr( new NameExpr( units, ret ) ); 214 } // if 215 177 216 delete &str; // created by lex 178 217 return ret; 179 218 } // build_constantChar 180 219 181 ConstantExpr * build_constantStr( const std::string & str ) { 182 // string should probably be a primitive type 220 ConstantExpr * build_constantStr( std::string & str ) { 221 string units; // units 222 sepString( str, units, '"' ); // separate constant from units 223 183 224 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 184 185 225 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 226 false, false ); 186 227 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 228 // ROB: type mismatch 229 // if ( units.length() != 0 ) { 230 // ret = new UntypedExpr( new NameExpr( units, ret ) ); 231 // } // if 232 187 233 delete &str; // created by lex 188 234 return ret; … … 314 360 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 315 361 std::list< Expression * > args; 316 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.362 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx 317 363 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 318 364 } // build_unary_ptr
Note:
See TracChangeset
for help on using the changeset viewer.