Changes in / [d7e9c12:8e5e945]


Ignore:
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslateNew.cpp

    rd7e9c12 r8e5e945  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Nov  8 11:53:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 18:49:58 2022
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Nov  8 16:50:00 2021
     13// Update Count     : 0
    1414//
    1515
     
    2222
    2323namespace ControlStruct {
     24
     25namespace {
    2426
    2527class TranslateThrowsCore : public ast::WithGuards {
     
    126128}
    127129
     130} // namespace
     131
    128132void translateThrows( ast::TranslationUnit & transUnit ) {
    129133        ast::Pass<TranslateThrowsCore>::run( transUnit );
  • src/ControlStruct/FixLabels.cpp

    rd7e9c12 r8e5e945  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Nov  1 09:39:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:19:17 2022
    13 // Update Count     : 9
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Nov  8 10:53:00 2021
     13// Update Count     : 3
    1414//
    1515
     
    2020#include "AST/Stmt.hpp"
    2121#include "ControlStruct/MultiLevelExit.hpp"
    22 using namespace ast;
    2322
    2423namespace ControlStruct {
    25 class FixLabelsCore final : public WithGuards {
     24
     25namespace {
     26
     27class FixLabelsCore final : public ast::WithGuards {
    2628        LabelToStmt labelTable;
    27   public:
     29public:
    2830        FixLabelsCore() : labelTable() {}
    2931
    30         void previsit( const FunctionDecl * );
    31         const FunctionDecl * postvisit( const FunctionDecl * );
    32         void previsit( const Stmt * );
    33         void previsit( const BranchStmt * );
    34         void previsit( const LabelAddressExpr * );
     32        void previsit( const ast::FunctionDecl * );
     33        const ast::FunctionDecl * postvisit( const ast::FunctionDecl * );
     34        void previsit( const ast::Stmt * );
     35        void previsit( const ast::BranchStmt * );
     36        void previsit( const ast::LabelAddressExpr * );
    3537
    36         void setLabelsDef( const std::vector<Label> &, const Stmt * );
    37         void setLabelsUsage( const Label & );
     38        void setLabelsDef( const std::vector<ast::Label> &, const ast::Stmt * );
     39        void setLabelsUsage( const ast::Label & );
    3840};
    3941
    40 void FixLabelsCore::previsit( const FunctionDecl * ) {
     42void FixLabelsCore::previsit( const ast::FunctionDecl * ) {
    4143        GuardValue( labelTable ).clear();
    4244}
    4345
    44 const FunctionDecl * FixLabelsCore::postvisit(
    45         const FunctionDecl * decl ) {
     46const ast::FunctionDecl * FixLabelsCore::postvisit(
     47                const ast::FunctionDecl * decl ) {
    4648        if ( nullptr == decl->stmts ) return decl;
    4749        for ( auto kvp : labelTable ) {
    4850                if ( nullptr == kvp.second ) {
    4951                        SemanticError( kvp.first.location,
    50                                                    "Use of undefined label: " + kvp.first.name );
     52                                "Use of undefined label: " + kvp.first.name );
    5153                }
    5254        }
    53         return mutate_field( decl, &FunctionDecl::stmts,
    54                                                  multiLevelExitUpdate( decl->stmts.get(), labelTable ) );
     55        return ast::mutate_field( decl, &ast::FunctionDecl::stmts,
     56                multiLevelExitUpdate( decl->stmts.get(), labelTable ) );
    5557}
    5658
    57 void FixLabelsCore::previsit( const Stmt * stmt ) {
     59void FixLabelsCore::previsit( const ast::Stmt * stmt ) {
    5860        if ( !stmt->labels.empty() ) {
    5961                setLabelsDef( stmt->labels, stmt );
     
    6163}
    6264
    63 void FixLabelsCore::previsit( const BranchStmt * stmt ) {
     65void FixLabelsCore::previsit( const ast::BranchStmt * stmt ) {
    6466        if ( !stmt->labels.empty() ) {
    6567                setLabelsDef( stmt->labels, stmt );
     
    7072}
    7173
    72 void FixLabelsCore::previsit( const LabelAddressExpr * expr ) {
     74void FixLabelsCore::previsit( const ast::LabelAddressExpr * expr ) {
    7375        assert( !expr->arg.empty() );
    7476        setLabelsUsage( expr->arg );
     
    7678
    7779void FixLabelsCore::setLabelsDef(
    78         const std::vector<Label> & labels, const Stmt * stmt ) {
     80                const std::vector<ast::Label> & labels, const ast::Stmt * stmt ) {
    7981        assert( !labels.empty() );
    8082        assert( stmt );
     
    8789                        // Duplicate definition, this is an error.
    8890                        SemanticError( label.location,
    89                                                    "Duplicate definition of label: " + label.name );
     91                                "Duplicate definition of label: " + label.name );
    9092                } else {
    9193                        // Perviously used, but not defined until now.
     
    9698
    9799// Label was used, if it is new add it to the table.
    98 void FixLabelsCore::setLabelsUsage( const Label & label ) {
     100void FixLabelsCore::setLabelsUsage( const ast::Label & label ) {
    99101        if ( labelTable.find( label ) == labelTable.end() ) {
    100102                labelTable[ label ] = nullptr;
     
    102104}
    103105
    104 void fixLabels( TranslationUnit & translationUnit ) {
    105         Pass<FixLabelsCore>::run( translationUnit );
     106} // namespace
     107
     108void fixLabels( ast::TranslationUnit & translationUnit ) {
     109        ast::Pass<FixLabelsCore>::run( translationUnit );
    106110}
     111
    107112} // namespace ControlStruct
    108113
  • src/ControlStruct/FixLabels.hpp

    rd7e9c12 r8e5e945  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Nov  1 09:36:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:18:43 2022
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Nov  1 09:40:00 2021
     13// Update Count     : 0
    1414//
    1515
     
    1717
    1818namespace ast {
    19 class TranslationUnit;
     19        class TranslationUnit;
    2020}
    2121
    2222namespace ControlStruct {
    23 // normalizes label definitions and generates multi-level exit labels
     23
     24/// normalizes label definitions and generates multi-level exit labels
    2425void fixLabels( ast::TranslationUnit & translationUnit );
     26
    2527}
    2628
  • src/Parser/ParseNode.h

    rd7e9c12 r8e5e945  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan 29 09:45:56 2022
    13 // Update Count     : 901
     12// Last Modified On : Wed Jul 14 17:28:53 2021
     13// Update Count     : 900
    1414//
    1515
     
    390390Statement * build_expr( ExpressionNode * ctl );
    391391
    392 struct CondCtl {
    393         CondCtl( DeclarationNode * decl, ExpressionNode * condition ) :
     392struct IfCtrl {
     393        IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) :
    394394                init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
    395395
     
    409409};
    410410
    411 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init );
    412 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
     411Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init );
     412Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    413413Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
    414414Statement * build_case( ExpressionNode * ctl );
    415415Statement * build_default();
    416 Statement * build_while( CondCtl * ctl, StatementNode * stmt );
     416Statement * build_while( IfCtrl * ctl, StatementNode * stmt );
    417417Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    418418Statement * build_for( ForCtrl * forctl, StatementNode * stmt );
  • src/Parser/StatementNode.cc

    rd7e9c12 r8e5e945  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan 29 09:45:51 2022
    13 // Update Count     : 384
     12// Last Modified On : Sat Oct 24 04:20:55 2020
     13// Update Count     : 383
    1414//
    1515
     
    7878} // build_expr
    7979
    80 Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init ) {
     80Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ) {
    8181        if ( ctl->init != 0 ) {
    8282                buildMoveList( ctl->init, init );
     
    100100} // build_if_control
    101101
    102 Statement * build_if( CondCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
     102Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    103103        Statement * thenb, * elseb = nullptr;
    104104        std::list< Statement * > branches;
     
    145145} // build_default
    146146
    147 Statement * build_while( CondCtl * ctl, StatementNode * stmt ) {
     147Statement * build_while( IfCtrl * ctl, StatementNode * stmt ) {
    148148        std::list< Statement * > branches;
    149149        buildMoveList< Statement, StatementNode >( stmt, branches );
  • src/Parser/parser.yy

    rd7e9c12 r8e5e945  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 30 09:41:13 2022
    13 // Update Count     : 5165
     12// Last Modified On : Fri Oct 15 09:20:17 2021
     13// Update Count     : 5163
    1414//
    1515
     
    238238        WaitForStmt * wfs;
    239239        Expression * constant;
    240         CondCtl * ifctl;
     240        IfCtrl * ifctl;
    241241        ForCtrl * fctl;
    242242        enum OperKinds compop;
     
    327327%type<en> comma_expression                              comma_expression_opt
    328328%type<en> argument_expression_list_opt  argument_expression_list        argument_expression                     default_initializer_opt
    329 %type<ifctl> conditional_declaration
     329%type<ifctl> if_control_expression
    330330%type<fctl> for_control_expression              for_control_expression_list
    331331%type<compop> inclexcl
     
    11231123
    11241124if_statement:
    1125         IF '(' conditional_declaration ')' statement            %prec THEN
     1125        IF '(' if_control_expression ')' statement                      %prec THEN
    11261126                // explicitly deal with the shift/reduce conflict on if/else
    11271127                { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); }
    1128         | IF '(' conditional_declaration ')' statement ELSE statement
     1128        | IF '(' if_control_expression ')' statement ELSE statement
    11291129                { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 ) ) ); }
    11301130        ;
    11311131
    1132 conditional_declaration:
     1132if_control_expression:
    11331133        comma_expression
    1134                 { $$ = new CondCtl( nullptr, $1 ); }
     1134                { $$ = new IfCtrl( nullptr, $1 ); }
    11351135        | c_declaration                                                                         // no semi-colon
    1136                 { $$ = new CondCtl( $1, nullptr ); }
     1136                { $$ = new IfCtrl( $1, nullptr ); }
    11371137        | cfa_declaration                                                                       // no semi-colon
    1138                 { $$ = new CondCtl( $1, nullptr ); }
     1138                { $$ = new IfCtrl( $1, nullptr ); }
    11391139        | declaration comma_expression                                          // semi-colon separated
    1140                 { $$ = new CondCtl( $1, $2 ); }
     1140                { $$ = new IfCtrl( $1, $2 ); }
    11411141        ;
    11421142
     
    11931193iteration_statement:
    11941194        WHILE '(' ')' statement                                                         // CFA => while ( 1 )
    1195                 { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
    1196         | WHILE '(' conditional_declaration ')' statement       %prec THEN
     1195                { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1196        | WHILE '(' if_control_expression ')' statement         %prec THEN
    11971197                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
    1198         | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA
     1198        | WHILE '(' if_control_expression ')' statement ELSE statement // CFA
    11991199                { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    12001200        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
Note: See TracChangeset for help on using the changeset viewer.