Changeset 513e165
- Timestamp:
- Sep 13, 2017, 3:09:12 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 121c3c0
- Parents:
- 7aa257ae
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r7aa257ae r513e165 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Sep 12 10:00:29 201713 // Update Count : 6 7212 // Last Modified On : Wed Sep 13 14:54:19 2017 13 // Update Count : 683 14 14 // 15 15 … … 250 250 sepString( str, units, '"' ); // separate constant from units 251 251 252 BasicType::Kind strtype = BasicType::Char; // default string type253 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" 252 Type * strtype; 253 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1 254 254 case 'u': 255 if ( str[1] == '8' ) break; // utf-8 characters 256 strtype = BasicType::ShortUnsignedInt; 255 if ( str[1] == '8' ) goto Default; // utf-8 characters => array of char 256 // lookup type of associated typedef 257 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char16_t", false ); 257 258 break; 258 259 case 'U': 259 strtype = BasicType::UnsignedInt;260 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char32_t", false ); 260 261 break; 261 262 case 'L': 262 strtype = BasicType::SignedInt;263 strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "wchar_t", false ); 263 264 break; 265 Default: // char default string type 266 default: 267 strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ); 264 268 } // switch 265 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ),269 ArrayType * at = new ArrayType( noQualifiers, strtype, 266 270 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 267 271 false, false ); … … 344 348 345 349 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) { 346 Type * targetType = maybeMoveBuildType( decl_node ); 347 Expression * castArg = maybeMoveBuild< Expression >( expr_node ); 348 return new VirtualCastExpr( castArg, targetType ); 350 return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) ); 349 351 } // build_virtual_cast 350 352 351 353 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) { 352 UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) ); 353 return ret; 354 return new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) ); 354 355 } // build_fieldSel 355 356 … … 363 364 364 365 Expression * build_addressOf( ExpressionNode * expr_node ) { 365 366 return new AddressExpr( maybeMoveBuild< Expression >(expr_node) ); 366 367 } // build_addressOf 367 368 … … 422 423 } // build_cond 423 424 424 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {425 return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );426 } // build_comma427 428 425 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) { 429 426 return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) ); … … 449 446 return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) ); 450 447 } // build_range 451 452 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) {453 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );454 } // build_asmexpr455 456 Expression * build_valexpr( StatementNode * s ) {457 return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );458 } // build_valexpr459 460 Expression * build_typevalue( DeclarationNode * decl ) {461 return new TypeExpr( maybeMoveBuildType( decl ) );462 } // build_typevalue463 448 464 449 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) { -
src/Parser/ParseNode.h
r7aa257ae r513e165 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 10 09:56:32201713 // Update Count : 80 112 // Last Modified On : Wed Sep 13 12:35:10 2017 13 // Update Count : 807 14 14 // 15 15 … … 122 122 123 123 template<typename T> 124 bool isExpressionType() const { 125 return nullptr != dynamic_cast<T>(expr.get()); 126 } 124 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); } 127 125 128 126 Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); } … … 172 170 173 171 NameExpr * build_varref( const std::string * name ); 174 Expression * build_typevalue( DeclarationNode * decl );175 172 176 173 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); … … 191 188 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); 192 189 Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ); 193 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );194 190 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ); 195 191 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ); … … 197 193 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ); 198 194 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); 199 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand );200 Expression * build_valexpr( StatementNode * s );201 195 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ); 202 196 -
src/Parser/parser.yy
r7aa257ae r513e165 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 11 18:12:00 201713 // Update Count : 2 78712 // Last Modified On : Wed Sep 13 11:01:20 2017 13 // Update Count : 2803 14 14 // 15 15 … … 56 56 #include "LinkageSpec.h" 57 57 #include "Common/SemanticError.h" // error_str 58 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... 58 59 59 60 extern DeclarationNode * parseTree; … … 438 439 { $$ = $2; } 439 440 | '(' compound_statement ')' // GCC, lambda expression 440 { $$ = new ExpressionNode( build_valexpr( $2) ); }441 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 441 442 | primary_expression '{' argument_expression_list '}' // CFA, constructor call 442 443 { … … 618 619 // VIRTUAL cannot be opt because of look ahead issues 619 620 | '(' VIRTUAL ')' cast_expression 620 { $$ = new ExpressionNode( build_virtual_cast( nullptr, $4) ); }621 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } 621 622 | '(' VIRTUAL type_no_function ')' cast_expression 622 { $$ = new ExpressionNode( build_virtual_cast( $3, $5) ); }623 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 623 624 // | '(' type_no_function ')' tuple 624 625 // { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } … … 771 772 assignment_expression 772 773 | comma_expression ',' assignment_expression 773 { $$ = new ExpressionNode( build_comma( $1, $3) ); }774 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression >( $3 ) ) ); } 774 775 ; 775 776 … … 1154 1155 asm_operand: // GCC 1155 1156 string_literal '(' constant_expression ')' 1156 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3) ); }1157 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ), $1, maybeMoveBuild< Expression >( $3 ) ) ); } 1157 1158 | '[' constant_expression ']' string_literal '(' constant_expression ')' 1158 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6) ); }1159 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( $2 ), $4, maybeMoveBuild< Expression >( $6 ) ) ); } 1159 1160 ; 1160 1161 … … 1165 1166 { $$ = new ExpressionNode( $1 ); } 1166 1167 | asm_clobbers_list_opt ',' string_literal 1167 // set_last return ParseNode *1168 // set_last returns ParseNode * 1168 1169 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1169 1170 ; … … 2165 2166 type_list: // CFA 2166 2167 type 2167 { $$ = new ExpressionNode( build_typevalue( $1) ); }2168 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2168 2169 | assignment_expression 2169 2170 | type_list ',' type 2170 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3) ) ) ); }2171 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2171 2172 | type_list ',' assignment_expression 2172 2173 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
Note: See TracChangeset
for help on using the changeset viewer.