LitValue.hxx

Go to the documentation of this file.
00001 #ifndef LITVALUE_HXX
00002 #define LITVALUE_HXX
00003 
00004 /**************************************************************************
00005  *
00006  * Copyright (C) 2008, Johns Hopkins University.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or
00010  * without modification, are permitted provided that the following
00011  * conditions are met:
00012  *
00013  *   - Redistributions of source code must contain the above 
00014  *     copyright notice, this list of conditions, and the following
00015  *     disclaimer. 
00016  *
00017  *   - Redistributions in binary form must reproduce the above
00018  *     copyright notice, this list of conditions, and the following
00019  *     disclaimer in the documentation and/or other materials 
00020  *     provided with the distribution.
00021  *
00022  *   - Neither the names of the copyright holders nor the names of any
00023  *     of any contributors may be used to endorse or promote products
00024  *     derived from this software without specific prior written
00025  *     permission. 
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00028  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00029  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00030  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00031  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00032  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00033  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00034  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00035  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00036  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  **************************************************************************/
00040 
00041 #include <inttypes.h>
00042 #include <string>
00043 #include <libsherpa/BigNum.hxx>
00044 
00045 #include "ucs.hxx"
00046 
00047 enum LiteralType {
00048   lt_none,
00049   lt_bool,
00050   lt_char,
00051   lt_int,
00052   lt_float,
00053   lt_string
00054 };
00055 
00056 struct LitValue {
00057   LiteralType litType;
00058 
00059   bool   b;                        /* boolean Values */
00060   unsigned long c;                 /* utf32 code points */
00061   sherpa::BigNum i;                /* large precision integers */
00062   double d;                        /* doubles, floats          */
00063 
00064   static bool valid_char_printable(ucs4_t ucs4);
00065   static bool valid_charpoint(ucs4_t ucs4);
00066   static bool valid_charpunct(ucs4_t ucs4);
00067   static unsigned validate_string(const char *s);
00068 
00071   static long digitValue(ucs4_t, unsigned radix);
00072 
00073   // FIX: (shap) the original input is being saved in AST.s for replay
00074   // purposes. String literals need to be stored here as a vector of
00075   // character representations.
00076   std::string s;                /* String Literals          */
00077 
00078   struct EscapedLiteral {
00079     const char *s;
00080     ucs4_t codePoint;
00081   };
00082 
00083   static EscapedLiteral EscapedLiteralMap[];
00084   static const size_t EscapedLiteralMapLength;
00085   static ucs4_t GetEscapedCodePoint(const char *escapedLiteral);
00086 
00087   static ucs4_t DecodeNumericCharacter(const char *s, const char **next);
00088   static ucs4_t DecodeBlockCharacter(const char *s);
00089   static ucs4_t DecodeStringCharacter(const char *s, const char **next);
00090   static ucs4_t DecodeCharacter(const std::string&);
00091 
00092   std::string asString() const;
00093 
00094   LitValue() {
00095     litType = lt_none;
00096   }
00097 };
00098 
00099 inline
00100 std::ostream& operator<<(std::ostream& strm, const LitValue& lv)
00101 {
00102   strm << lv.asString();
00103   return strm;
00104 }
00105 
00106 #endif /* LITVALUE_HXX */

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