summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2002-07-05 04:05:42 +0000
committerMichi Henning <michi@zeroc.com>2002-07-05 04:05:42 +0000
commitbb1b84d1436f26eb8c1941eedb97e943e81947bb (patch)
tree0dd48ac1ce692218bcb9e6578e6d7f5bee1ea2ba /cpp/src
parentAdded "i64" suffix for 64-bit integer literals. (diff)
downloadice-bb1b84d1436f26eb8c1941eedb97e943e81947bb.tar.bz2
ice-bb1b84d1436f26eb8c1941eedb97e943e81947bb.tar.xz
ice-bb1b84d1436f26eb8c1941eedb97e943e81947bb.zip
Changed the way 64-bit literals are done in the generated code. The
approach used now (a macro) makes the generated source more readable than the previous one.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp20
-rw-r--r--cpp/src/Slice/Scanner.l2
-rw-r--r--cpp/src/slice2cpp/Gen.cpp18
3 files changed, 34 insertions, 6 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 0c800c87ac4..79725c6f4b4 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -88,6 +88,26 @@ Slice::printVersionCheck(Output& out)
}
void
+Slice::printDefInt64Macro(Output& out)
+{
+ out << "\n";
+ out << "\n#if defined(_WIN32)";
+ out << "\n# define INT64LITERAL(n) n##i64";
+ out << "\n#elif defined(__linux__) && defined(i386)";
+ out << "\n# define INT64LITERAL(n) n##LL";
+ out << "\n#else";
+ out << "\n# error \"Unsupported operating system or platform!\"";
+ out << "\n#endif";
+}
+
+void
+Slice::printUndefInt64Macro(Output& out)
+{
+ out << "\n";
+ out << "\n#undef INT64LITERAL";
+}
+
+void
Slice::printDllExportStuff(Output& out, const string& dllExport)
{
if(dllExport.size())
diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l
index 4cb68b02448..ea280da5d96 100644
--- a/cpp/src/Slice/Scanner.l
+++ b/cpp/src/Slice/Scanner.l
@@ -317,7 +317,7 @@ floating_literal (({fractional_constant}{exponent_part}?)|([[:digit:]]+{exponent
}
#else
itp->v = strtoll(yytext, 0, 0);
- if(errno == ERANGE)
+ if(errno == ERANGE && (itp->v == INT64_MIN || itp->v == INT64_MAX))
{
string msg = "integer constant `";
msg += yytext;
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index db6643bf6ba..06bec36200c 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -214,6 +214,8 @@ Slice::Gen::generate(const UnitPtr& unit)
_dllExport += " ";
}
+ printDefInt64Macro(H);
+
ProxyDeclVisitor proxyDeclVisitor(H, C, _dllExport);
unit->visit(&proxyDeclVisitor);
@@ -263,6 +265,8 @@ Slice::Gen::generate(const UnitPtr& unit)
ImplVisitor implVisitor(implH, implC, _dllExport);
unit->visit(&implVisitor);
}
+
+ printUndefInt64Macro(H);
}
Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) :
@@ -935,11 +939,7 @@ Slice::Gen::TypesVisitor::visitConstDef(const ConstDefPtr& p)
H << nl << "const " << typeToString(p->type()) << " " << p->name() << " = ";
BuiltinPtr bp = BuiltinPtr::dynamicCast(p->type());
- if(bp && bp->kind() != Builtin::KindString)
- {
- H << p->value();
- }
- else
+ if(bp && bp->kind() == Builtin::KindString)
{
//
// Expand strings into the basic source character set. We can't use isalpha() and the like
@@ -981,6 +981,14 @@ Slice::Gen::TypesVisitor::visitConstDef(const ConstDefPtr& p)
H << "\""; // Closing "
}
+ else if(bp && bp->kind() == Builtin::KindLong)
+ {
+ H << "INT64LITERAL(" << p->value() << ")";
+ }
+ else
+ {
+ H << p->value();
+ }
H << ";";
}