diff options
author | Mark Spruiell <mes@zeroc.com> | 2003-01-04 00:45:05 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2003-01-04 00:45:05 +0000 |
commit | 2f9d740c8ba8da86924d0323018f99d1b5644f1d (patch) | |
tree | 9a562a5b7d9d728ac061ebfde9f7f105650d6b07 /cpp/src | |
parent | Fixed Ice.Warn.Dispatch value (diff) | |
download | ice-2f9d740c8ba8da86924d0323018f99d1b5644f1d.tar.bz2 ice-2f9d740c8ba8da86924d0323018f99d1b5644f1d.tar.xz ice-2f9d740c8ba8da86924d0323018f99d1b5644f1d.zip |
add AMD support to generated implementation examples
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 166 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.h | 6 |
2 files changed, 153 insertions, 19 deletions
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 00ce2d64404..e30af60781e 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -3336,6 +3336,78 @@ Slice::Gen::BaseImplVisitor::BaseImplVisitor(const string& dir, const string& pa } void +Slice::Gen::BaseImplVisitor::writeDecl(Output& out, const string& scope, const string& name, const TypePtr& type) +{ + out << nl << typeToString(type, TypeModeIn, scope) << ' ' << name; + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + switch(builtin->kind()) + { + case Builtin::KindBool: + { + out << " = false"; + break; + } + case Builtin::KindByte: + { + out << " = (byte)0"; + break; + } + case Builtin::KindShort: + { + out << " = (short)0"; + break; + } + case Builtin::KindInt: + case Builtin::KindLong: + { + out << " = 0"; + break; + } + case Builtin::KindFloat: + { + out << " = (float)0.0"; + break; + } + case Builtin::KindDouble: + { + out << " = 0.0"; + break; + } + case Builtin::KindString: + { + out << " = \"\""; + break; + } + case Builtin::KindObject: + case Builtin::KindObjectProxy: + case Builtin::KindLocalObject: + { + out << " = null"; + break; + } + } + } + else + { + EnumPtr en = EnumPtr::dynamicCast(type); + if(en) + { + EnumeratorList enumerators = en->getEnumerators(); + out << " = " << getAbsolute(en->scoped()) << '.' << fixKwd(enumerators.front()->name()); + } + else + { + out << " = null"; + } + } + + out << ';'; +} + +void Slice::Gen::BaseImplVisitor::writeReturn(Output& out, const TypePtr& type) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); @@ -3398,33 +3470,89 @@ Slice::Gen::BaseImplVisitor::writeOperation(Output& out, const string& scope, co string retS = typeToString(ret, TypeModeReturn, scope); string params = getParams(op, scope); - out << sp << nl << "public " << retS << nl << opName << '(' << params; - if(!local) + ContainerPtr container = op->container(); + ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + + if(!local && (cl->hasMetaData("amd") || op->hasMetaData("amd"))) { - if(!params.empty()) + ParamDeclList paramList = op->parameters(); + ParamDeclList::const_iterator q; + + out << sp << nl << "public void" << nl << opName << "_async(" << getParamsAsync(op, scope, true) + << ", Ice.Current current)"; + out << sb; + + string result = "r"; + for(q = paramList.begin(); q != paramList.end(); ++q) { - out << ", "; + if((*q)->name() == result) + { + result = "_" + result; + break; + } + } + if(ret) + { + writeDecl(out, scope, result, ret); + } + for(q = paramList.begin(); q != paramList.end(); ++q) + { + if((*q)->isOutParam()) + { + writeDecl(out, scope, fixKwd((*q)->name()), (*q)->type()); + } + } + + out << nl << "__cb.ice_response("; + if(ret) + { + out << result; } - out << "Ice.Current current"; + for(q = paramList.begin(); q != paramList.end(); ++q) + { + if((*q)->isOutParam()) + { + if(ret || q != paramList.begin()) + { + out << ", "; + } + out << fixKwd((*q)->name()); + } + } + out << ");"; + + out << eb; } - out << ')'; + else + { + out << sp << nl << "public " << retS << nl << opName << '(' << params; + if(!local) + { + if(!params.empty()) + { + out << ", "; + } + out << "Ice.Current current"; + } + out << ')'; - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - writeThrowsClause(scope, throws); + ExceptionList throws = op->throws(); + throws.sort(); + throws.unique(); + writeThrowsClause(scope, throws); - out << sb; + out << sb; - // - // Return value - // - if(ret) - { - writeReturn(out, ret); - } + // + // Return value + // + if(ret) + { + writeReturn(out, ret); + } - out << eb; + out << eb; + } } Slice::Gen::ImplVisitor::ImplVisitor(const string& dir, const string& package) : diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h index 33dac340c66..0435e6ee4b4 100644 --- a/cpp/src/slice2java/Gen.h +++ b/cpp/src/slice2java/Gen.h @@ -213,6 +213,12 @@ private: protected: // + // Generate code to emit a local variable declaration and initialize it + // if necessary. + // + void writeDecl(::IceUtil::Output&, const std::string&, const std::string&, const TypePtr&); + + // // Generate code to return a value. // void writeReturn(::IceUtil::Output&, const TypePtr&); |