Changes in src/Parser/ExpressionNode.cc [ac71a86:e82aa9df]
- File:
-
- 1 edited
-
src/Parser/ExpressionNode.cc (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rac71a86 re82aa9df 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 16 00:09:20201613 // Update Count : 49 512 // Last Modified On : Mon Aug 15 14:30:42 2016 13 // Update Count : 490 14 14 // 15 15 … … 32 32 using namespace std; 33 33 34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other. get_name()), extension( other.extension ) {}34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ), extension( other.extension ) {} 35 35 36 36 //############################################################################## … … 57 57 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 58 58 59 Expression *build_constantInteger( conststd::string & str ) {59 Expression *build_constantInteger( std::string & str ) { 60 60 static const BasicType::Kind kind[2][3] = { 61 61 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, … … 123 123 } // build_constantInteger 124 124 125 Expression *build_constantFloat( conststd::string & str ) {125 Expression *build_constantFloat( std::string & str ) { 126 126 static const BasicType::Kind kind[2][3] = { 127 127 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, … … 153 153 } // build_constantFloat 154 154 155 Expression *build_constantChar( conststd::string & str ) {155 Expression *build_constantChar( std::string & str ) { 156 156 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ); 157 157 } // build_constantChar 158 158 159 ConstantExpr *build_constantStr( conststd::string & str ) {159 ConstantExpr *build_constantStr( std::string & str ) { 160 160 // string should probably be a primitive type 161 161 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( emptyQualifiers, BasicType::Char ), … … 166 166 } // build_constantStr 167 167 168 //############################################################################## 169 168 170 NameExpr * build_varref( const string *name, bool labelp ) { 169 NameExpr *expr =new NameExpr( *name, nullptr );170 delete name; 171 return expr; 172 } 171 return new NameExpr( *name, nullptr ); 172 } 173 174 //############################################################################## 173 175 174 176 static const char *OperName[] = { … … 182 184 }; 183 185 186 //############################################################################## 187 184 188 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 185 189 Type *targetType = decl_node->buildType(); 186 190 if ( dynamic_cast< VoidType * >( targetType ) ) { 187 191 delete targetType; 188 return new CastExpr( maybe MoveBuild< Expression>(expr_node) );192 return new CastExpr( maybeBuild<Expression>(expr_node) ); 189 193 } else { 190 return new CastExpr( maybe MoveBuild< Expression>(expr_node), targetType );194 return new CastExpr( maybeBuild<Expression>(expr_node), targetType ); 191 195 } // if 192 196 } 193 197 194 198 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) { 195 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybe MoveBuild< Expression>(expr_node) );199 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild<Expression>(expr_node) ); 196 200 delete member; 197 201 return ret; … … 200 204 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) { 201 205 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 202 deref->get_args().push_back( maybe MoveBuild< Expression>(expr_node) );206 deref->get_args().push_back( maybeBuild<Expression>(expr_node) ); 203 207 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 204 208 delete member; … … 207 211 208 212 Expression *build_addressOf( ExpressionNode *expr_node ) { 209 return new AddressExpr( maybe MoveBuild< Expression>(expr_node) );213 return new AddressExpr( maybeBuild<Expression>(expr_node) ); 210 214 } 211 215 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 212 return new SizeofExpr( maybe MoveBuild< Expression>(expr_node) );216 return new SizeofExpr( maybeBuild<Expression>(expr_node) ); 213 217 } 214 218 Expression *build_sizeOftype( DeclarationNode *decl_node ) { 215 Expression* ret = new SizeofExpr( decl_node->buildType() ); 216 delete decl_node; 217 return ret; 219 return new SizeofExpr( decl_node->buildType() ); 218 220 } 219 221 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 220 return new AlignofExpr( maybe MoveBuild< Expression>(expr_node) );222 return new AlignofExpr( maybeBuild<Expression>(expr_node) ); 221 223 } 222 224 Expression *build_alignOftype( DeclarationNode *decl_node ) { … … 224 226 } 225 227 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) { 226 Expression* ret = new UntypedOffsetofExpr( decl_node->buildType(), member->get_name() ); 227 delete decl_node; 228 delete member; 229 return ret; 228 return new UntypedOffsetofExpr( decl_node->buildType(), member->get_name() ); 230 229 } 231 230 232 231 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 233 return new LogicalExpr( notZeroExpr( maybe MoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression>(expr_node2) ), kind );232 return new LogicalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind ); 234 233 } 235 234 236 235 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 237 std::list< Expression *> args;238 args.push_back( maybe MoveBuild< Expression>(expr_node) );236 std::list<Expression *> args; 237 args.push_back( maybeBuild<Expression>(expr_node) ); 239 238 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 240 239 } 241 240 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 242 std::list< Expression *> args;243 args.push_back( new AddressExpr( maybe MoveBuild< Expression>(expr_node) ) );241 std::list<Expression *> args; 242 args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node) ) ); 244 243 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 245 244 } 246 245 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 247 std::list< Expression *> args;248 args.push_back( maybe MoveBuild< Expression>(expr_node1) );249 args.push_back( maybe MoveBuild< Expression>(expr_node2) );246 std::list<Expression *> args; 247 args.push_back( maybeBuild<Expression>(expr_node1) ); 248 args.push_back( maybeBuild<Expression>(expr_node2) ); 250 249 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 251 250 } 252 251 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 253 std::list< Expression *> args;254 args.push_back( new AddressExpr( maybe MoveBuild< Expression>(expr_node1) ) );255 args.push_back( maybe MoveBuild< Expression>(expr_node2) );252 std::list<Expression *> args; 253 args.push_back( new AddressExpr( maybeBuild<Expression>(expr_node1) ) ); 254 args.push_back( maybeBuild<Expression>(expr_node2) ); 256 255 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 257 256 } 258 257 259 258 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 260 return new ConditionalExpr( notZeroExpr( maybe MoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression>(expr_node3) );259 return new ConditionalExpr( notZeroExpr( maybeBuild<Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) ); 261 260 } 262 261 263 262 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 264 return new CommaExpr( maybe MoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression>(expr_node2) );263 return new CommaExpr( maybeBuild<Expression>(expr_node1), maybeBuild<Expression>(expr_node2) ); 265 264 } 266 265 267 266 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) { 268 return new AttrExpr( var, maybe MoveBuild< Expression>(expr_node) );267 return new AttrExpr( var, maybeBuild<Expression>(expr_node) ); 269 268 } 270 269 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { … … 274 273 Expression *build_tuple( ExpressionNode * expr_node ) { 275 274 TupleExpr *ret = new TupleExpr(); 276 build MoveList( expr_node, ret->get_exprs() );275 buildList( expr_node, ret->get_exprs() ); 277 276 return ret; 278 277 } 279 278 280 279 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 281 std::list< Expression * > args; 282 buildMoveList( expr_node, args ); 283 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); 280 std::list<Expression *> args; 281 282 buildList( expr_node, args ); 283 return new UntypedExpr( maybeBuild<Expression>(function), args, nullptr ); 284 284 } 285 285 286 286 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) { 287 return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) ); 288 } 287 Expression *low_cexpr = maybeBuild<Expression>( low ); 288 Expression *high_cexpr = maybeBuild<Expression>( high ); 289 return new RangeExpr( low_cexpr, high_cexpr ); 290 } 291 292 //############################################################################## 289 293 290 294 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) { 291 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 292 } 295 return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild<Expression>(operand) ); 296 } 297 298 //############################################################################## 299 300 //void LabelNode::print( std::ostream &os, int indent ) const {} 301 302 //void LabelNode::printOneLine( std::ostream &os, int indent ) const {} 303 304 //############################################################################## 293 305 294 306 Expression *build_valexpr( StatementNode *s ) { 295 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr ); 296 } 307 return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr ); 308 } 309 310 //############################################################################## 311 297 312 Expression *build_typevalue( DeclarationNode *decl ) { 298 313 return new TypeExpr( decl->buildType() ); 299 314 } 300 315 316 //############################################################################## 317 301 318 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) { 302 Declaration * newDecl = maybeBuild< Declaration>(decl_node); // compound literal type319 Declaration * newDecl = maybeBuild<Declaration>(decl_node); // compound literal type 303 320 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 304 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybe MoveBuild< Initializer>(kids) );321 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) ); 305 322 // these types do not have associated type information 306 323 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 307 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );324 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) ); 308 325 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 309 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );326 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) ); 310 327 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 311 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );328 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) ); 312 329 } else { 313 330 assert( false );
Note:
See TracChangeset
for help on using the changeset viewer.