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