(root)/
gcc-13.2.0/
gcc/
rust/
rust-location.h
       1  // Copyright (C) 2020-2023 Free Software Foundation, Inc.
       2  
       3  // This file is part of GCC.
       4  
       5  // GCC is free software; you can redistribute it and/or modify it under
       6  // the terms of the GNU General Public License as published by the Free
       7  // Software Foundation; either version 3, or (at your option) any later
       8  // version.
       9  
      10  // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11  // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13  // for more details.
      14  
      15  // You should have received a copy of the GNU General Public License
      16  // along with GCC; see the file COPYING3.  If not see
      17  // <http://www.gnu.org/licenses/>.
      18  
      19  // rust-location.h -- GCC specific Location declaration.   -*- C++ -*-
      20  
      21  #ifndef RUST_LOCATION_H
      22  #define RUST_LOCATION_H
      23  
      24  #include "rust-system.h"
      25  
      26  // A location in an input source file.
      27  
      28  class Location
      29  {
      30  public:
      31    Location () : gcc_loc_ (UNKNOWN_LOCATION) {}
      32  
      33    explicit Location (location_t loc) : gcc_loc_ (loc) {}
      34  
      35    location_t gcc_location () const { return gcc_loc_; }
      36  
      37    Location operator+= (location_t rhs)
      38    {
      39      gcc_loc_ += rhs;
      40      return *this;
      41    }
      42  
      43    Location operator-= (location_t rhs)
      44    {
      45      gcc_loc_ -= rhs;
      46      return *this;
      47    }
      48  
      49    bool operator== (location_t rhs) { return rhs == gcc_loc_; }
      50  
      51  private:
      52    location_t gcc_loc_;
      53  };
      54  
      55  // The Rust frontend requires the ability to compare Locations.
      56  
      57  inline bool
      58  operator< (Location loca, Location locb)
      59  {
      60    return loca.gcc_location () < locb.gcc_location ();
      61  }
      62  
      63  inline bool
      64  operator== (Location loca, Location locb)
      65  {
      66    return loca.gcc_location () == locb.gcc_location ();
      67  }
      68  
      69  inline Location
      70  operator+ (Location lhs, location_t rhs)
      71  {
      72    lhs += rhs;
      73    return lhs;
      74  }
      75  
      76  inline Location
      77  operator- (Location lhs, location_t rhs)
      78  {
      79    lhs -= rhs;
      80    return lhs;
      81  }
      82  
      83  class RichLocation
      84  {
      85  public:
      86    RichLocation (Location root);
      87    ~RichLocation ();
      88  
      89    void add_range (Location loc);
      90  
      91    void add_fixit_insert_before (const std::string &new_parent);
      92  
      93    void add_fixit_insert_before (Location where, const std::string &new_parent);
      94  
      95    void add_fixit_insert_after (const std::string &new_parent);
      96  
      97    void add_fixit_insert_after (Location where, const std::string &new_parent);
      98  
      99    const rich_location &get () const { return gcc_rich_loc; }
     100  
     101  private:
     102    rich_location gcc_rich_loc;
     103  };
     104  
     105  #endif // !defined(RUST_LOCATION_H)