summaryrefslogtreecommitdiff
path: root/cpp/src/slice2java/Gen.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2002-07-19 06:50:48 +0000
committerMichi Henning <michi@zeroc.com>2002-07-19 06:50:48 +0000
commit61d3cefa01dcbef2d6ec16e660d9d02767d2c5a8 (patch)
treeff2135e4b1d90c516f31dec237aa368ab41f5f85 /cpp/src/slice2java/Gen.cpp
parentfile ice.xsd was initially added on branch freeze_xml. (diff)
downloadice-61d3cefa01dcbef2d6ec16e660d9d02767d2c5a8.tar.bz2
ice-61d3cefa01dcbef2d6ec16e660d9d02767d2c5a8.tar.xz
ice-61d3cefa01dcbef2d6ec16e660d9d02767d2c5a8.zip
Picked up a few style crimes and fixed them.
Added code generation for Java constants to slice2java. Added missing keyword (strictfp) to lists of keywords that need escaping for Java. Fixed bug in Java code generator: if a type name had a prefix in common with the name of its enclosing scope, the scope mangling code stripped off too much of the scope. For example: enum color { red }; const color c = red; This resulted in the generated type name being "olor" instead of "color" because the constant starts with the same letter as the name of the type. Fixed bug in the keyword escape mechanism -- keywords embedded in scoped names were not escaped. Keywords escaping for both Java and C++ still has bugs. I wrote two Slice torture files full of keywords. Neither the generated C++ code nor the generated Java code work for those files yet. Need to look at this...
Diffstat (limited to 'cpp/src/slice2java/Gen.cpp')
-rw-r--r--cpp/src/slice2java/Gen.cpp103
1 files changed, 97 insertions, 6 deletions
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 6e7772ffd72..975719182e5 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -1753,16 +1753,107 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p)
void
Slice::Gen::TypesVisitor::visitConstDef(const ConstDefPtr& p)
{
-#if 0
string name = fixKwd(p->name());
- string absolute = getAbsolute(p->scoped());
+ string scoped = p->scoped();
+ string absolute = getAbsolute(scoped);
+ TypePtr type = p->type();
- if(open(absolute + "PrxHolder"))
+ if(!open(absolute))
+ {
+ return;
+ }
Output& out = output();
- out << "This is a definition for constant " << p->name() << endl;
- out << eb;
+ out << sp << nl << "public interface " << name;
+ out << sb;
+ out << nl << typeToString(type, TypeModeIn, scoped) << " value = ";
+
+ BuiltinPtr bp;
+ EnumPtr ep;
+ if(bp = BuiltinPtr::dynamicCast(type))
+ {
+ switch(bp->kind())
+ {
+ case Builtin::KindString:
+ {
+ out << "\""; // Opening "
+
+ ios_base::fmtflags originalFlags = out.flags(); // Save stream state
+ streamsize originalWidth = out.width();
+ ostream::char_type originalFill = out.fill();
+
+ const string val = p->value();
+ for(string::const_iterator c = val.begin(); c != val.end(); ++c)
+ {
+ if(isascii(*c) && isprint(*c))
+ {
+ switch(*c)
+ {
+ case '\\': // Take care of \ and "
+ case '"':
+ {
+ out << "\\";
+ break;
+ }
+ }
+ out << *c; // Print normally if printable
+ }
+ else
+ {
+ switch(*c)
+ {
+ case '\r': // CR can't be written as a universal char name in Java
+ {
+ out << "\\r";
+ break;
+ }
+ case '\n': // Ditto for NL
+ {
+ out << "\\n";
+ break;
+ }
+ default:
+ {
+ unsigned char uc = *c; // char may be signed, so make it positive
+ out << "\\u"; // Print as universal character name if non-printable
+ out.flags(ios_base::hex);
+ out.width(4);
+ out.fill('0');
+ out << static_cast<unsigned>(uc);
+ break;
+ }
+ }
+ }
+ }
+
+ out.fill(originalFill); // Restore stream state
+ out.width(originalWidth);
+ out.flags(originalFlags);
+
+ out << "\""; // Closing "
+ break;
+ }
+ case Builtin::KindByte:
+ {
+ out << p->value() << " - 128"; // Slice byte runs from 0-255, Java byte runs from -128 - 127
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ out << p->value() << "L"; // Need to append "L" modifier for long constants
+ }
+ }
+
+ }
+ else if(ep = EnumPtr::dynamicCast(type))
+ {
+ out << fixKwd(p->value());
+ }
+ else
+ {
+ out << p->value();
+ }
+ out << ";" << eb;
close();
-#endif
}
Slice::Gen::HolderVisitor::HolderVisitor(const string& dir, const string& package) :