Changes in src/Parser/ExpressionNode.cc [a839867:2f22cc4]
- File:
- 
      - 1 edited
 
 - 
          
  src/Parser/ExpressionNode.cc (modified) (10 diffs)
 
Legend:
- Unmodified
- Added
- Removed
- 
      src/Parser/ExpressionNode.ccra839867 r2f22cc4 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 25 21:39:40201613 // Update Count : 50312 // Last Modified On : Wed Aug 10 11:07:38 2016 13 // Update Count : 486 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 }, … … 120 120 } // if 121 121 122 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) ); 123 delete &str; // created by lex 124 return ret; 122 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) ); 125 123 } // build_constantInteger 126 124 127 Expression *build_constantFloat( conststd::string & str ) {125 Expression *build_constantFloat( std::string & str ) { 128 126 static const BasicType::Kind kind[2][3] = { 129 127 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, … … 152 150 } // if 153 151 154 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) ); 155 delete &str; // created by lex 156 return ret; 152 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) ); 157 153 } // build_constantFloat 158 154 159 Expression *build_constantChar( const std::string & str ) { 160 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ); 161 delete &str; // created by lex 162 return ret; 155 Expression *build_constantChar( std::string & str ) { 156 return new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ); 163 157 } // build_constantChar 164 158 165 ConstantExpr *build_constantStr( conststd::string & str ) {159 ConstantExpr *build_constantStr( std::string & str ) { 166 160 // string should probably be a primitive type 167 161 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( emptyQualifiers, BasicType::Char ), … … 169 163 toString( str.size()+1-2 ) ) ), // +1 for '\0' and -2 for '"' 170 164 false, false ); 171 ConstantExpr * ret = new ConstantExpr( Constant( at, str ) ); 172 delete &str; // created by lex 173 return ret; 165 return new ConstantExpr( Constant( at, str ) ); 174 166 } // build_constantStr 175 167 168 //############################################################################## 169 176 170 NameExpr * build_varref( const string *name, bool labelp ) { 177 NameExpr *expr =new NameExpr( *name, nullptr );178 delete name; 179 return expr; 180 } 171 return new NameExpr( *name, nullptr ); 172 } 173 174 //############################################################################## 181 175 182 176 static const char *OperName[] = { … … 184 178 "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&", 185 179 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?", 186 "?=?", "? @=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",180 "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?", 187 181 "?[?]", "...", 188 182 // monadic … … 190 184 }; 191 185 186 //############################################################################## 187 192 188 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 193 Type *targetType = maybeMoveBuildType( decl_node);189 Type *targetType = decl_node->buildType(); 194 190 if ( dynamic_cast< VoidType * >( targetType ) ) { 195 191 delete targetType; 196 return new CastExpr( maybe MoveBuild< Expression>(expr_node) );192 return new CastExpr( maybeBuild<Expression>(expr_node) ); 197 193 } else { 198 return new CastExpr( maybe MoveBuild< Expression>(expr_node), targetType );194 return new CastExpr( maybeBuild<Expression>(expr_node), targetType ); 199 195 } // if 200 196 } 201 197 202 198 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) { 203 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybe MoveBuild< Expression>(expr_node) );199 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild<Expression>(expr_node) ); 204 200 delete member; 205 201 return ret; … … 208 204 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) { 209 205 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 210 deref->get_args().push_back( maybe MoveBuild< Expression>(expr_node) );206 deref->get_args().push_back( maybeBuild<Expression>(expr_node) ); 211 207 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 212 208 delete member; … … 215 211 216 212 Expression *build_addressOf( ExpressionNode *expr_node ) { 217 return new AddressExpr( maybe MoveBuild< Expression>(expr_node) );213 return new AddressExpr( maybeBuild<Expression>(expr_node) ); 218 214 } 219 215 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 220 return new SizeofExpr( maybe MoveBuild< Expression>(expr_node) );216 return new SizeofExpr( maybeBuild<Expression>(expr_node) ); 221 217 } 222 218 Expression *build_sizeOftype( DeclarationNode *decl_node ) { 223 return new SizeofExpr( maybeMoveBuildType( decl_node) );219 return new SizeofExpr( decl_node->buildType() ); 224 220 } 225 221 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 226 return new AlignofExpr( maybe MoveBuild< Expression>(expr_node) );222 return new AlignofExpr( maybeBuild<Expression>(expr_node) ); 227 223 } 228 224 Expression *build_alignOftype( DeclarationNode *decl_node ) { 229 return new AlignofExpr( maybeMoveBuildType( decl_node) );225 return new AlignofExpr( decl_node->buildType() ); 230 226 } 231 227 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) { 232 Expression* ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() ); 233 delete member; 234 return ret; 228 return new UntypedOffsetofExpr( decl_node->buildType(), member->get_name() ); 235 229 } 236 230 237 231 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 238 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 ); 239 233 } 240 234 241 235 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 242 std::list< Expression *> args;243 args.push_back( maybe MoveBuild< Expression>(expr_node) );236 std::list<Expression *> args; 237 args.push_back( maybeBuild<Expression>(expr_node) ); 244 238 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 245 239 } 246 240 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 247 std::list< Expression *> args;248 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) ) ); 249 243 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 250 244 } 251 245 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 252 std::list< Expression *> args;253 args.push_back( maybe MoveBuild< Expression>(expr_node1) );254 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) ); 255 249 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 256 250 } 257 251 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 258 std::list< Expression *> args;259 args.push_back( new AddressExpr( maybe MoveBuild< Expression>(expr_node1) ) );260 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) ); 261 255 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 262 256 } 263 257 264 258 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 265 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) ); 266 260 } 267 261 268 262 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 269 return new CommaExpr( maybe MoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression>(expr_node2) );263 return new CommaExpr( maybeBuild<Expression>(expr_node1), maybeBuild<Expression>(expr_node2) ); 270 264 } 271 265 272 266 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) { 273 return new AttrExpr( var, maybe MoveBuild< Expression>(expr_node) );267 return new AttrExpr( var, maybeBuild<Expression>(expr_node) ); 274 268 } 275 269 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { 276 return new AttrExpr( var, maybeMoveBuildType( decl_node) );270 return new AttrExpr( var, decl_node->buildType() ); 277 271 } 278 272 279 273 Expression *build_tuple( ExpressionNode * expr_node ) { 280 274 TupleExpr *ret = new TupleExpr(); 281 build MoveList( expr_node, ret->get_exprs() );275 buildList( expr_node, ret->get_exprs() ); 282 276 return ret; 283 277 } 284 278 285 279 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 286 std::list< Expression * > args; 287 buildMoveList( expr_node, args ); 288 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 ); 289 284 } 290 285 291 286 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) { 292 return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) ); 293 } 294 295 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) { 296 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 297 } 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 //############################################################################## 293 294 Expression *build_asm( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) { 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 //############################################################################## 298 305 299 306 Expression *build_valexpr( StatementNode *s ) { 300 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr ); 301 } 307 return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr ); 308 } 309 310 //############################################################################## 311 312 // ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) { 313 // if ( init_ == 0 ) 314 // init = 0; 315 // else { 316 // DeclarationNode *decl; 317 // ExpressionNode *exp; 318 319 // if (( decl = dynamic_cast<DeclarationNode *>(init_) ) != 0) 320 // init = new StatementNode( decl ); 321 // else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0) 322 // init = new StatementNode( StatementNode::Exp, exp ); 323 // else 324 // throw SemanticError("Error in for control expression"); 325 // } 326 // } 327 328 // ForCtlExprNode::ForCtlExprNode( const ForCtlExprNode &other ) 329 // : ExpressionNode( other ), init( maybeClone( other.init ) ), condition( maybeClone( other.condition ) ), change( maybeClone( other.change ) ) { 330 // } 331 332 // ForCtlExprNode::~ForCtlExprNode() { 333 // delete init; 334 // delete condition; 335 // delete change; 336 // } 337 338 // Expression *ForCtlExprNode::build() const { 339 // // this shouldn't be used! 340 // assert( false ); 341 // return 0; 342 // } 343 344 // void ForCtlExprNode::print( std::ostream &os, int indent ) const{ 345 // os << string( indent,' ' ) << "For Control Expression -- :" << endl; 346 347 // os << string( indent + 2, ' ' ) << "initialization:" << endl; 348 // if ( init != 0 ) 349 // init->printList( os, indent + 4 ); 350 351 // os << string( indent + 2, ' ' ) << "condition: " << endl; 352 // if ( condition != 0 ) 353 // condition->print( os, indent + 4 ); 354 // os << string( indent + 2, ' ' ) << "increment: " << endl; 355 // if ( change != 0 ) 356 // change->print( os, indent + 4 ); 357 // } 358 359 // void ForCtlExprNode::printOneLine( std::ostream &, int indent ) const { 360 // assert( false ); 361 // } 362 363 //############################################################################## 364 302 365 Expression *build_typevalue( DeclarationNode *decl ) { 303 return new TypeExpr( maybeMoveBuildType( decl ) ); 304 } 366 return new TypeExpr( decl->buildType() ); 367 } 368 369 //############################################################################## 305 370 306 371 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) { 307 Declaration * newDecl = maybeBuild< Declaration>(decl_node); // compound literal type372 Declaration * newDecl = maybeBuild<Declaration>(decl_node); // compound literal type 308 373 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 309 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybe MoveBuild< Initializer>(kids) );374 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild<Initializer>(kids) ); 310 375 // these types do not have associated type information 311 376 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 312 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );377 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild<Initializer>(kids) ); 313 378 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 314 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );379 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild<Initializer>(kids) ); 315 380 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 316 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybe MoveBuild< Initializer>(kids) );381 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild<Initializer>(kids) ); 317 382 } else { 318 383 assert( false ); 
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  