Changeset 7880579 for src/Parser/ExpressionNode.cc
- Timestamp:
- Aug 16, 2016, 8:59:49 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 0da3e2c, 13e3b50, 7527e63
- Parents:
- b1848a0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:30:42201613 // Update Count : 49 012 // Last Modified On : Tue Aug 16 00:09:20 2016 13 // Update Count : 495 14 14 // 15 15 … … 32 32 using namespace std; 33 33 34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other. name), extension( other.extension ) {}34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {} 35 35 36 36 //############################################################################## … … 166 166 } // build_constantStr 167 167 168 //##############################################################################169 170 168 NameExpr * build_varref( const string *name, bool labelp ) { 171 169 return new NameExpr( *name, nullptr ); 172 170 } 173 174 //##############################################################################175 171 176 172 static const char *OperName[] = { … … 184 180 }; 185 181 186 //##############################################################################187 188 182 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 189 183 Type *targetType = decl_node->buildType(); 190 184 if ( dynamic_cast< VoidType * >( targetType ) ) { 191 185 delete targetType; 192 return new CastExpr( maybeBuild< Expression>(expr_node) );186 return new CastExpr( maybeBuild< Expression >(expr_node) ); 193 187 } else { 194 return new CastExpr( maybeBuild< Expression>(expr_node), targetType );188 return new CastExpr( maybeBuild< Expression >(expr_node), targetType ); 195 189 } // if 196 190 } 197 191 198 192 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) { 199 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression>(expr_node) );193 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression >(expr_node) ); 200 194 delete member; 201 195 return ret; … … 204 198 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) { 205 199 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 206 deref->get_args().push_back( maybeBuild< Expression>(expr_node) );200 deref->get_args().push_back( maybeBuild< Expression >(expr_node) ); 207 201 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 208 202 delete member; … … 211 205 212 206 Expression *build_addressOf( ExpressionNode *expr_node ) { 213 return new AddressExpr( maybeBuild< Expression>(expr_node) );207 return new AddressExpr( maybeBuild< Expression >(expr_node) ); 214 208 } 215 209 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 216 return new SizeofExpr( maybeBuild< Expression>(expr_node) );210 return new SizeofExpr( maybeBuild< Expression >(expr_node) ); 217 211 } 218 212 Expression *build_sizeOftype( DeclarationNode *decl_node ) { … … 220 214 } 221 215 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 222 return new AlignofExpr( maybeBuild< Expression>(expr_node) );216 return new AlignofExpr( maybeBuild< Expression >(expr_node) ); 223 217 } 224 218 Expression *build_alignOftype( DeclarationNode *decl_node ) { … … 230 224 231 225 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 232 return new LogicalExpr( notZeroExpr( maybeBuild< Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind );226 return new LogicalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), notZeroExpr( maybeBuild< Expression >(expr_node2) ), kind ); 233 227 } 234 228 235 229 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 236 std::list< Expression *> args;237 args.push_back( maybeBuild< Expression>(expr_node) );230 std::list< Expression * > args; 231 args.push_back( maybeBuild< Expression >(expr_node) ); 238 232 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 239 233 } 240 234 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 241 std::list< Expression *> args;242 args.push_back( new AddressExpr( maybeBuild< Expression>(expr_node) ) );235 std::list< Expression * > args; 236 args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node) ) ); 243 237 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 244 238 } 245 239 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 246 std::list< Expression *> args;247 args.push_back( maybeBuild< Expression>(expr_node1) );248 args.push_back( maybeBuild< Expression>(expr_node2) );240 std::list< Expression * > args; 241 args.push_back( maybeBuild< Expression >(expr_node1) ); 242 args.push_back( maybeBuild< Expression >(expr_node2) ); 249 243 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 250 244 } 251 245 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *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) );246 std::list< Expression * > args; 247 args.push_back( new AddressExpr( 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 258 252 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 259 return new ConditionalExpr( notZeroExpr( maybeBuild< Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) );253 return new ConditionalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), maybeBuild< Expression >(expr_node2), maybeBuild< Expression >(expr_node3) ); 260 254 } 261 255 262 256 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 263 return new CommaExpr( maybeBuild< Expression>(expr_node1), maybeBuild<Expression>(expr_node2) );257 return new CommaExpr( maybeBuild< Expression >(expr_node1), maybeBuild< Expression >(expr_node2) ); 264 258 } 265 259 266 260 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) { 267 return new AttrExpr( var, maybeBuild< Expression>(expr_node) );261 return new AttrExpr( var, maybeBuild< Expression >(expr_node) ); 268 262 } 269 263 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { … … 278 272 279 273 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 280 std::list< Expression *> args;274 std::list< Expression * > args; 281 275 282 276 buildList( expr_node, args ); 283 return new UntypedExpr( maybeBuild< Expression>(function), args, nullptr );277 return new UntypedExpr( maybeBuild< Expression >(function), args, nullptr ); 284 278 } 285 279 286 280 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) { 287 Expression *low_cexpr = maybeBuild< Expression>( low );288 Expression *high_cexpr = maybeBuild< Expression>( high );281 Expression *low_cexpr = maybeBuild< Expression >( low ); 282 Expression *high_cexpr = maybeBuild< Expression >( high ); 289 283 return new RangeExpr( low_cexpr, high_cexpr ); 290 284 } 291 285 292 //##############################################################################293 294 286 Expression *build_asmexpr( 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 //############################################################################## 287 return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild< Expression >(operand) ); 288 } 305 289 306 290 Expression *build_valexpr( StatementNode *s ) { 307 return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr ); 308 } 309 310 //############################################################################## 311 291 return new UntypedValofExpr( maybeBuild< Statement >(s), nullptr ); 292 } 312 293 Expression *build_typevalue( DeclarationNode *decl ) { 313 294 return new TypeExpr( decl->buildType() ); 314 295 } 315 296 316 //##############################################################################317 318 297 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) { 319 Declaration * newDecl = maybeBuild< Declaration>(decl_node); // compound literal type298 Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type 320 299 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 321 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer>(kids) );300 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer >(kids) ); 322 301 // these types do not have associated type information 323 302 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 324 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer>(kids) );303 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer >(kids) ); 325 304 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 326 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer>(kids) );305 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer >(kids) ); 327 306 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 328 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer>(kids) );307 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer >(kids) ); 329 308 } else { 330 309 assert( false );
Note: See TracChangeset
for help on using the changeset viewer.