Changeset a2e0687


Ignore:
Timestamp:
Jul 28, 2017, 8:58:23 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
59310bf, 86d5ba7c
Parents:
874960b
Message:

formatting

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r874960b ra2e0687  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 27 12:10:10 2017
    13 // Update Count     : 556
    14 //
    15 
    16 #include <cassert>
    17 #include <cctype>
    18 #include <climits>
    19 #include <cstdio>
    20 #include <algorithm>
     12// Last Modified On : Thu Jul 27 21:42:38 2017
     13// Update Count     : 567
     14//
     15
     16#include <climits>                                                                              // access INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX
    2117#include <sstream>
    2218
     
    2622#include "SynTree/Expression.h"
    2723#include "SynTree/Declaration.h"
    28 #include "Common/UnimplementedError.h"
    2924#include "parserutility.h"
    30 #include "Common/utility.h"
    3125
    3226using namespace std;
     
    5549static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5650
    57 Expression *build_constantInteger( const std::string & str ) {
     51Expression * build_constantInteger( const std::string & str ) {
    5852        static const BasicType::Kind kind[2][3] = {
    5953                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     
    135129} // build_constantInteger
    136130
    137 Expression *build_constantFloat( const std::string & str ) {
     131Expression * build_constantFloat( const std::string & str ) {
    138132        static const BasicType::Kind kind[2][3] = {
    139133                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
     
    170164} // build_constantFloat
    171165
    172 Expression *build_constantChar( const std::string & str ) {
     166Expression * build_constantChar( const std::string & str ) {
    173167        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
    174168        delete &str;                                                                            // created by lex
     
    176170} // build_constantChar
    177171
    178 ConstantExpr *build_constantStr( const std::string & str ) {
     172ConstantExpr * build_constantStr( const std::string & str ) {
    179173        // string should probably be a primitive type
    180         ArrayType *at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    181                                                                    new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ),  // +1 for '\0' and -2 for '"'
     174        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     175                                                                   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    182176                                                                   false, false );
    183         // constant 0 is ignored for pure string value
    184         ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) );
     177        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
    185178        delete &str;                                                                            // created by lex
    186179        return ret;
     
    214207} // build_field_name_fraction_constants
    215208
    216 
    217 
    218209Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {
    219210        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
     
    230221} // build_field_name_REALDECIMALconstant
    231222
    232 NameExpr * build_varref( const string *name ) {
    233         NameExpr *expr = new NameExpr( *name, nullptr );
     223NameExpr * build_varref( const string * name ) {
     224        NameExpr * expr = new NameExpr( *name, nullptr );
    234225        delete name;
    235226        return expr;
    236 }
    237 
    238 // Must harmonize with OperKinds.
    239 static const char *OperName[] = {
     227} // build_varref
     228
     229
     230static const char * OperName[] = {                                              // must harmonize with OperKinds
    240231        // diadic
    241232        "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
     
    245236        // monadic
    246237        "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"
    247 };
    248 
    249 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    250         Type *targetType = maybeMoveBuildType( decl_node );
     238}; // OperName
     239
     240Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     241        Type * targetType = maybeMoveBuildType( decl_node );
    251242        if ( dynamic_cast< VoidType * >( targetType ) ) {
    252243                delete targetType;
     
    255246                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
    256247        } // if
    257 }
    258 
    259 
    260 Expression *build_virtual_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    261         Type *targetType = maybeMoveBuildType( decl_node );
    262         Expression *castArg = maybeMoveBuild< Expression >( expr_node );
     248} // build_cast
     249
     250Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     251        Type * targetType = maybeMoveBuildType( decl_node );
     252        Expression * castArg = maybeMoveBuild< Expression >( expr_node );
    263253        return new VirtualCastExpr( castArg, targetType );
    264 }
    265 
    266 Expression *build_fieldSel( ExpressionNode *expr_node, Expression *member ) {
    267         UntypedMemberExpr *ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
    268         return ret;
    269 }
    270 
    271 Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ) {
    272         UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     254} // build_virtual_cast
     255
     256Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
     257        UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
     258        return ret;
     259} // build_fieldSel
     260
     261Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
     262        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    273263        deref->location = expr_node->location;
    274264        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
    275         UntypedMemberExpr *ret = new UntypedMemberExpr( member, deref );
    276         return ret;
    277 }
    278 
    279 Expression *build_addressOf( ExpressionNode *expr_node ) {
     265        UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
     266        return ret;
     267} // build_pfieldSel
     268
     269Expression * build_addressOf( ExpressionNode * expr_node ) {
    280270                return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
    281 }
    282 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
     271} // build_addressOf
     272
     273Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
    283274        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
    284 }
    285 Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     275} // build_sizeOfexpr
     276
     277Expression * build_sizeOftype( DeclarationNode * decl_node ) {
    286278        return new SizeofExpr( maybeMoveBuildType( decl_node ) );
    287 }
    288 Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
     279} // build_sizeOftype
     280
     281Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
    289282        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
    290 }
    291 Expression *build_alignOftype( DeclarationNode *decl_node ) {
     283} // build_alignOfexpr
     284
     285Expression * build_alignOftype( DeclarationNode * decl_node ) {
    292286        return new AlignofExpr( maybeMoveBuildType( decl_node) );
    293 }
    294 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
     287} // build_alignOftype
     288
     289Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
    295290        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    296291        delete member;
    297292        return ret;
    298 }
    299 
    300 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
     293} // build_offsetOf
     294
     295Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
    301296        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
    302 }
    303 
    304 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
     297} // build_and_or
     298
     299Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
    305300        std::list< Expression * > args;
    306301        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    307302        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    308 }
    309 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
     303} // build_unary_val
     304
     305Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    310306        std::list< Expression * > args;
    311307        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) );
    312308        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    313 }
    314 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     309} // build_unary_ptr
     310
     311Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    315312        std::list< Expression * > args;
    316313        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    317314        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    318315        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    319 }
    320 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     316} // build_binary_val
     317
     318Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    321319        std::list< Expression * > args;
    322320        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) );
    323321        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    324322        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    325 }
    326 
    327 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
     323} // build_binary_ptr
     324
     325Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
    328326        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
    329 }
    330 
    331 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     327} // build_cond
     328
     329Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    332330        return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
    333 }
    334 
    335 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
     331} // build_comma
     332
     333Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
    336334        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
    337 }
    338 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     335} // build_attrexpr
     336
     337Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
    339338        return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
    340 }
    341 
    342 Expression *build_tuple( ExpressionNode * expr_node ) {
     339} // build_attrtype
     340
     341Expression * build_tuple( ExpressionNode * expr_node ) {
    343342        std::list< Expression * > exprs;
    344343        buildMoveList( expr_node, exprs );
    345344        return new UntypedTupleExpr( exprs );;
    346 }
    347 
    348 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
     345} // build_tuple
     346
     347Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    349348        std::list< Expression * > args;
    350349        buildMoveList( expr_node, args );
    351350        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    352 }
    353 
    354 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
     351} // build_func
     352
     353Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
    355354        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
    356 }
    357 
    358 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
     355} // build_range
     356
     357Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) {
    359358        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    360 }
    361 
    362 Expression *build_valexpr( StatementNode *s ) {
     359} // build_asmexpr
     360
     361Expression * build_valexpr( StatementNode * s ) {
    363362        return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
    364 }
    365 Expression *build_typevalue( DeclarationNode *decl ) {
     363} // build_valexpr
     364
     365Expression * build_typevalue( DeclarationNode * decl ) {
    366366        return new TypeExpr( maybeMoveBuildType( decl ) );
    367 }
    368 
    369 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
     367} // build_typevalue
     368
     369Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
    370370        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    371371        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     
    393393                assert( false );
    394394        } // if
    395 }
     395} // build_compoundLiteral
    396396
    397397// Local Variables: //
  • src/Parser/lex.ll

    r874960b ra2e0687  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Jul 27 12:05:50 2017
    13  * Update Count     : 549
     12 * Last Modified On : Thu Jul 27 21:46:06 2017
     13 * Update Count     : 550
    1414 */
    1515
     
    418418
    419419                                /* unknown characters */
    420 .                       { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     420.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    421421
    422422%%
  • src/Parser/parser.yy

    r874960b ra2e0687  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 27 12:08:08 2017
    13 // Update Count     : 2467
     12// Last Modified On : Thu Jul 27 21:07:16 2017
     13// Update Count     : 2468
    1414//
    1515
     
    527527        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    528528                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    529         | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
     529        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    530530                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    531531        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
Note: See TracChangeset for help on using the changeset viewer.