LexLoc.hxx

Go to the documentation of this file.
00001 #ifndef LIBSHERPA_LEXLOC_HXX
00002 #define LIBSHERPA_LEXLOC_HXX
00003 
00004 /**************************************************************************
00005  *
00006  * Copyright (C) 2008, The EROS Group, LLC.
00007  * Copyright (C) 2004, 2005, 2006, Johns Hopkins University.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or
00011  * without modification, are permitted provided that the following
00012  * conditions are met:
00013  *
00014  *   - Redistributions of source code must contain the above
00015  *     copyright notice, this list of conditions, and the following
00016  *     disclaimer.
00017  *
00018  *   - Redistributions in binary form must reproduce the above
00019  *     copyright notice, this list of conditions, and the following
00020  *     disclaimer in the documentation and/or other materials
00021  *     provided with the distribution.
00022  *
00023  *   - Neither the names of the copyright holders nor the names of any
00024  *     of any contributors may be used to endorse or promote products
00025  *     derived from this software without specific prior written
00026  *     permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  **************************************************************************/
00041 
00042 namespace sherpa {
00043 
00044   struct LexLoc {
00045     std::string origin;
00046     unsigned line;      // 0 indicates no real line
00047     unsigned offset;
00048 
00049     LexLoc()
00050     {
00051       this->origin = std::string();
00052       this->line = 0;
00053       this->offset = 0;
00054     }
00055 
00056     ~LexLoc()
00057     {
00058     }
00059 
00060     LexLoc(const std::string& origin, unsigned line, unsigned offset)
00061     {
00062       this->origin = origin;
00063       this->line = line;
00064       this->offset = offset;
00065     }
00066 
00067     LexLoc(const LexLoc& ll)
00068     {
00069       origin = ll.origin;
00070       line = ll.line;
00071       offset = ll.offset;
00072     }
00073 
00074     LexLoc& operator=(const LexLoc& ll)
00075     {
00076       origin = ll.origin;
00077       line = ll.line;
00078       offset = ll.offset;
00079       return *this;
00080     }
00081 
00082     inline bool operator==(const LexLoc& ll)
00083     {
00084       return ((origin == ll.origin) &&
00085               (line == ll.line) &&
00086               (offset == ll.offset));
00087     }
00088 
00089     inline bool operator!=(const LexLoc& ll)
00090     {
00091       return ((origin != ll.origin) ||
00092               (line != ll.line) ||
00093               (offset != ll.offset));
00094     }
00095 
00096     std::string asString() const;
00097 
00098     const char *c_str() const;
00099 
00100     LexLoc operator+(size_t sz) const
00101     {
00102       return LexLoc(origin, line, offset + sz);
00103     }
00104 
00105     void updateWith(const std::string& s);
00106 
00107     LexLoc with(const std::string& s);
00108   };
00109 
00110   inline
00111   std::ostream& operator<<(std::ostream& strm, const LexLoc& ll)
00112   {
00113     strm << ll.asString();
00114     return strm;
00115   }
00116 
00117 }
00118 
00119 #endif /* LIBSHERPA_LEXLOC_HXX */

Generated on Sat Feb 4 23:59:28 2012 for BitC Compiler by  doxygen 1.4.7