From 744e044abfaad2976a27fe1d45c528fb86dd661a Mon Sep 17 00:00:00 2001 From: Michi Henning Date: Mon, 8 Jul 2002 07:10:08 +0000 Subject: Changed parser to use new strToInt64() function. Makes for much cleaner code. --- cpp/include/Slice/Parser.h | 25 +++++++++---------------- cpp/src/Slice/GrammarUtil.h | 2 +- cpp/src/Slice/Parser.cpp | 12 ++++++------ cpp/src/Slice/Scanner.l | 23 ++++------------------- 4 files changed, 20 insertions(+), 42 deletions(-) (limited to 'cpp') diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index 6c230806f4e..18b9ab58a27 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -34,29 +35,21 @@ namespace Slice { #if defined(_WIN32) -# define STRTOLL(a, b, c) _atoi64(a) - typedef __int64 Long; typedef double Double; - const Long INT64_MAX = 0x7fffffffffffffffi64; - const Long INT64_MIN = -INT64_MAX - 1i64; - const Long INT32_MAX = 0x7fffffffi64; - const Long INT32_MIN = -INT32_MAX - 1i64; + const IceUtil::Int64 INT32MAX = 0x7fffffffi64; + const IceUtil::Int64 INT32MIN = -INT32MAX - 1i64; #elif(__linux__) && defined(i386) -# define STRTOLL(a, b, c) strtoll((a), (b), (c)) - typedef long long Long; typedef double Double; - const Long INT64_MAX = 0x7fffffffffffffffLL; - const Long INT64_MIN = -INT64_MAX - 1LL; - const Long INT32_MAX = 0x7fffffffLL; - const Long INT32_MIN = -INT32_MAX - 1LL; + const IceUtil::Int64 INT32MAX = 0x7fffffffLL; + const IceUtil::Int64 INT32MIN = -INT32MAX - 1LL; #else # error "Unsupported operating system or platform!" #endif -const Long INT16_MAX = 0x7fff; -const Long INT16_MIN = -INT16_MAX - 1; -const Long BYTE_MAX = 0xff; -const Long BYTE_MIN = 0x00; +const IceUtil::Int64 INT16MAX = 0x7fff; +const IceUtil::Int64 INT16MIN = -INT16MAX - 1; +const IceUtil::Int64 BYTEMAX = 0xff; +const IceUtil::Int64 BYTEMIN = 0x00; class GrammarBase; class SyntaxTreeBase; diff --git a/cpp/src/Slice/GrammarUtil.h b/cpp/src/Slice/GrammarUtil.h index a3fc29b74d2..e3204a85047 100644 --- a/cpp/src/Slice/GrammarUtil.h +++ b/cpp/src/Slice/GrammarUtil.h @@ -98,7 +98,7 @@ class SLICE_API IntegerTok : public GrammarBase public: IntegerTok() { } - Long v; + IceUtil::Int64 v; }; // ---------------------------------------------------------------------- diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 0b5393ea03d..206a2c0b486 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1594,8 +1594,8 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const { case Builtin::KindByte: { - Long l = STRTOLL(value.c_str(), 0, 0); - if(l < BYTE_MIN || l > BYTE_MAX) + IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); + if(l < BYTEMIN || l > BYTEMAX) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type byte"; _unit->error(msg); @@ -1605,8 +1605,8 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const } case Builtin::KindShort: { - Long l = STRTOLL(value.c_str(), 0, 0); - if(l < INT16_MIN || l > INT16_MAX) + IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); + if(l < INT16MIN || l > INT16MAX) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type short"; _unit->error(msg); @@ -1616,8 +1616,8 @@ Slice::Container::checkRange(const string& name, const TypePtr& constType, const } case Builtin::KindInt: { - Long l = STRTOLL(value.c_str(), 0, 0); - if(l < INT32_MIN || l > INT32_MAX) + IceUtil::Int64 l = IceUtil::strToInt64(value.c_str(), 0, 0); + if(l < INT32MIN || l > INT32MAX) { string msg = "initializer `" + value + "' for constant `" + name + "' out of range for type int"; _unit->error(msg); diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index ea280da5d96..c92ea37b5ec 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -12,6 +12,7 @@ #include // Before Grammer.h, so that YYSTYPE is defined #include +#include #include #include @@ -257,7 +258,7 @@ floating_literal (({fractional_constant}{exponent_part}?)|([[:digit:]]+{exponent } case 'x': { - Long ull = 0; + IceUtil::Int64 ull = 0; while(isxdigit(next = static_cast(yyinput()))) { ull *= 16; @@ -301,30 +302,14 @@ floating_literal (({fractional_constant}{exponent_part}?)|([[:digit:]]+{exponent IntegerTokPtr itp = new IntegerTok; *yylvalp = itp; errno = 0; -#if defined(_WIN32) - itp->v = _atoi64(yytext); - if(itp->v == 0) // Poor error reporting for _atoi64(), so we have to do it the hard way... - { - errno = 0; - long l = strtol(yytext, 0, 0); - if(l != 0 || errno != 0) // _atoi64() returned zero even though yytext wasn't all zeros - { - string msg = "integer constant `"; - msg += yytext; - msg += "' out of range"; - unit->error(msg); - } - } -#else - itp->v = strtoll(yytext, 0, 0); - if(errno == ERANGE && (itp->v == INT64_MIN || itp->v == INT64_MAX)) + itp->v = IceUtil::strToInt64(yytext, 0, 0); + if(errno == ERANGE && (itp->v == IceUtil::INT64MIN || itp->v == IceUtil::INT64MAX)) { string msg = "integer constant `"; msg += yytext; msg += "' out of range"; unit->error(msg); } -#endif return ICE_INTEGER_LITERAL; } -- cgit v1.2.3