LToken.hxx

Go to the documentation of this file.
00001 #ifndef LIBSHERPA_LTOKEN_HXX
00002 #define LIBSHERPA_LTOKEN_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 #include <stdio.h>
00043 #include <libsherpa/EnumSet.hxx>
00044 #include <libsherpa/LexLoc.hxx>
00045 
00046 enum TokenFlagValues {
00048   TF_NO_FLAGS = 0,
00049 
00051   TF_INSERTED = 0x1u,
00052 
00054   TF_BY_PARSER = 0x2u,
00055 
00057   TF_AT_FIRST = 0x4u,
00058 
00060   TF_REPROCESS = 0x8u,
00061 
00063   TF_FIRST_ON_LINE = 0x10u,
00064 };
00065 typedef sherpa::EnumSet<TokenFlagValues> TokenFlags;
00066 
00087 namespace sherpa {
00088 
00089   struct LToken {
00090     int tokType;                // as decided by Bison
00091     int prevTokType;
00092 
00093     TokenFlags flags;
00094 
00095     LexLoc loc;
00096     LexLoc endLoc;
00097     std::string str;
00098 
00099     char operator[](size_t pos) const
00100     {
00101       return str[pos];
00102     }
00103 
00104     LToken()
00105       :loc(), endLoc(), str()
00106     {
00107       tokType = EOF;
00108       prevTokType = EOF;
00109       flags = TF_NO_FLAGS;
00110     }
00111 
00112 #if 0
00113     LToken(int tokType, const LexLoc& loc, const std::string& s)
00114     {
00115       this->tokType = tokType;
00116       this->flags = TF_NO_FLAGS;
00117       this->loc = loc;
00118       this->endLoc = LexLoc();
00119       this->str = s;
00120     }
00121 #endif
00122 
00123     LToken(int tokType, const LexLoc& loc, const LexLoc& endLoc, 
00124            const std::string& s)
00125     {
00126       this->tokType = tokType;
00127       this->prevTokType = prevTokType;
00128       this->flags = TF_NO_FLAGS;
00129       this->loc = loc;
00130       this->endLoc = endLoc;
00131       this->str = s;
00132     }
00133 
00134     LToken(int tokType, const LToken& that)
00135     {
00136       this->tokType = that.tokType;
00137       this->prevTokType = that.prevTokType;
00138       this->flags = that.flags;
00139       this->loc = that.loc;
00140       this->endLoc = that.endLoc;
00141       this->str = that.str;
00142     }
00143 
00144     LToken(int tokType, const std::string& str)
00145     {
00146       this->tokType = tokType;
00147       this->prevTokType = 0;
00148       this->flags = TF_NO_FLAGS;
00149       this->loc = LexLoc();
00150       this->endLoc = LexLoc();
00151       this->str = str;
00152     }
00153 
00154     LToken& operator=(const LToken& that)
00155     {
00156       this->tokType = that.tokType;
00157       this->prevTokType = that.prevTokType;
00158       this->flags = that.flags;
00159       this->loc = that.loc;
00160       this->endLoc = that.endLoc;
00161       this->str = that.str;
00162       return *this;
00163     }
00164 
00165 #if 0
00166     bool operator==(const LToken& that)
00167     {
00168       return ((this->tokType == that.tokType) &&
00169               (this->flags == that.flags) &&
00170               (this->loc == that.loc) &&
00171               (this->endLoc == that.endLoc) &&
00172               (this->str == that.str));
00173     }
00174 #endif
00175   };
00176 
00177 } /* namespace sherpa */
00178 
00179 #endif /* LIBSHERPA_LTOKEN_HXX */

Generated on Thu May 17 23:59:16 2012 for BitC Compiler by  doxygen 1.4.7