Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/FixLabels.cpp

    r37eb41b ra5a08a05  
    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
Note: See TracChangeset for help on using the changeset viewer.