Changeset 33b7d49 for src/Common


Ignore:
Timestamp:
Mar 15, 2022, 10:14:05 AM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
48a91e2
Parents:
d824715
Message:

Added another check to checkInvariants for code locations. I also went through and made sure you can put it every after every new AST pass not followed by a forceFillCodeLocations.

Location:
src/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/CodeLocationTools.cpp

    rd824715 r33b7d49  
    99// Author           : Andrew Beach
    1010// Created On       : Fri Dec  4 15:42:00 2020
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  1 09:14:39 2022
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar 14 15:14:00 2022
     13// Update Count     : 4
    1414//
    1515
     
    239239};
    240240
     241class LocalFillCore : public ast::WithGuards {
     242        CodeLocation const * parent;
     243public:
     244        LocalFillCore( CodeLocation const & location ) : parent( &location ) {
     245                assert( location.isSet() );
     246        }
     247
     248        template<typename node_t>
     249        auto previsit( node_t const * node )
     250                        -> typename std::enable_if<has_code_location<node_t>::value, node_t const *>::type {
     251                if ( node->location.isSet() ) {
     252                        GuardValue( parent ) = &node->location;
     253                        return node;
     254                } else {
     255                        node_t * mut = ast::mutate( node );
     256                        mut->location = *parent;
     257                        return mut;
     258                }
     259        }
     260};
     261
    241262} // namespace
    242263
     
    278299        ast::Pass<FillCore>::run( unit );
    279300}
     301
     302ast::Node const * localFillCodeLocations(
     303                CodeLocation const & location , ast::Node const * node ) {
     304        ast::Pass<LocalFillCore> visitor( location );
     305        return node->accept( visitor );
     306}
  • src/Common/CodeLocationTools.hpp

    rd824715 r33b7d49  
    1010// Created On       : Fri Dec  4 15:35:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Dec  9  9:53:00 2020
    13 // Update Count     : 1
     12// Last Modified On : Mon Mar 14 15:14:00 2022
     13// Update Count     : 2
    1414//
    1515
    1616#pragma once
    1717
     18class CodeLocation;
    1819namespace ast {
     20        class Node;
    1921        class TranslationUnit;
    2022}
     
    2830// Assign a nearby code-location to any unset code locations in the forest.
    2931void forceFillCodeLocations( ast::TranslationUnit & unit );
     32
     33// Fill in code-locations with a parent code location,
     34// using the provided CodeLocation as the base.
     35ast::Node const *
     36        localFillCodeLocations( CodeLocation const &, ast::Node const * );
Note: See TracChangeset for help on using the changeset viewer.