diff options
Diffstat (limited to 'cpp/src/Slice')
40 files changed, 8168 insertions, 14032 deletions
diff --git a/cpp/src/Slice/.depend.mak b/cpp/src/Slice/.depend.mak deleted file mode 100755 index a4855d54a00..00000000000 --- a/cpp/src/Slice/.depend.mak +++ /dev/null @@ -1,275 +0,0 @@ - -Checksum.obj: \ - Checksum.cpp \ - "$(includedir)\Slice\Checksum.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "MD5.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - -CPlusPlusUtil.obj: \ - CPlusPlusUtil.cpp \ - "$(includedir)\Slice\CPlusPlusUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\Util.h" \ - -CsUtil.obj: \ - CsUtil.cpp \ - "$(includedir)\Slice\CsUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\DotNetNames.h" \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\IceUtil\Functional.h" \ - -DotNetNames.obj: \ - DotNetNames.cpp \ - "$(includedir)\Slice\DotNetNames.h" \ - -FileTracker.obj: \ - FileTracker.cpp \ - "$(includedir)\Slice\FileTracker.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - -JavaUtil.obj: \ - JavaUtil.cpp \ - "$(includedir)\IceUtil\DisableWarnings.h" \ - "$(includedir)\Slice\JavaUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\FileTracker.h" \ - "$(includedir)\Slice\Util.h" \ - "MD5.h" \ - "$(includedir)\IceUtil\Functional.h" \ - -MD5.obj: \ - MD5.cpp \ - "MD5.h" \ - "$(includedir)\IceUtil\Config.h" \ - "MD5I.h" \ - -MD5I.obj: \ - MD5I.cpp \ - "MD5I.h" \ - -Parser.obj: \ - Parser.cpp \ - "$(includedir)\IceUtil\Functional.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\InputUtil.h" \ - "$(includedir)\IceUtil\StringUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "GrammarUtil.h" \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - -PHPUtil.obj: \ - PHPUtil.cpp \ - "$(includedir)\Slice\PHPUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - -Preprocessor.obj: \ - Preprocessor.cpp \ - "$(includedir)\Slice\Preprocessor.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\IceUtil\StringUtil.h" \ - "$(includedir)\IceUtil\StringConverter.h" \ - "..\..\src\IceUtil\FileUtil.h" \ - "$(includedir)\IceUtil\UUID.h" \ - -PythonUtil.obj: \ - PythonUtil.cpp \ - "$(includedir)\Slice\PythonUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\Checksum.h" \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\IceUtil\IceUtil.h" \ - "$(includedir)\IceUtil\PushDisableWarnings.h" \ - "$(includedir)\IceUtil\AbstractMutex.h" \ - "$(includedir)\IceUtil\Lock.h" \ - "$(includedir)\IceUtil\ThreadException.h" \ - "$(includedir)\IceUtil\Time.h" \ - "$(includedir)\IceUtil\Cache.h" \ - "$(includedir)\IceUtil\Mutex.h" \ - "$(includedir)\IceUtil\MutexProtocol.h" \ - "$(includedir)\IceUtil\CountDownLatch.h" \ - "$(includedir)\IceUtil\Cond.h" \ - "$(includedir)\IceUtil\CtrlCHandler.h" \ - "$(includedir)\IceUtil\Functional.h" \ - "$(includedir)\IceUtil\Monitor.h" \ - "$(includedir)\IceUtil\MutexPtrLock.h" \ - "$(includedir)\IceUtil\RecMutex.h" \ - "$(includedir)\IceUtil\ScopedArray.h" \ - "$(includedir)\IceUtil\StringConverter.h" \ - "$(includedir)\IceUtil\Thread.h" \ - "$(includedir)\IceUtil\Timer.h" \ - "$(includedir)\IceUtil\UUID.h" \ - "$(includedir)\IceUtil\UniquePtr.h" \ - "$(includedir)\IceUtil\PopDisableWarnings.h" \ - "$(includedir)\IceUtil\StringUtil.h" \ - "$(includedir)\IceUtil\InputUtil.h" \ - -Python.obj: \ - Python.cpp \ - "$(includedir)\IceUtil\DisableWarnings.h" \ - "$(includedir)\IceUtil\IceUtil.h" \ - "$(includedir)\IceUtil\PushDisableWarnings.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\AbstractMutex.h" \ - "$(includedir)\IceUtil\Lock.h" \ - "$(includedir)\IceUtil\ThreadException.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\Time.h" \ - "$(includedir)\IceUtil\Cache.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Mutex.h" \ - "$(includedir)\IceUtil\MutexProtocol.h" \ - "$(includedir)\IceUtil\CountDownLatch.h" \ - "$(includedir)\IceUtil\Cond.h" \ - "$(includedir)\IceUtil\CtrlCHandler.h" \ - "$(includedir)\IceUtil\Functional.h" \ - "$(includedir)\IceUtil\Monitor.h" \ - "$(includedir)\IceUtil\MutexPtrLock.h" \ - "$(includedir)\IceUtil\RecMutex.h" \ - "$(includedir)\IceUtil\ScopedArray.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\StringConverter.h" \ - "$(includedir)\IceUtil\Thread.h" \ - "$(includedir)\IceUtil\Timer.h" \ - "$(includedir)\IceUtil\UUID.h" \ - "$(includedir)\IceUtil\UniquePtr.h" \ - "$(includedir)\IceUtil\PopDisableWarnings.h" \ - "$(includedir)\IceUtil\Options.h" \ - "$(includedir)\IceUtil\StringUtil.h" \ - "..\..\src\IceUtil\FileUtil.h" \ - "$(includedir)\Slice\Preprocessor.h" \ - "$(includedir)\Slice\FileTracker.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\Slice\PythonUtil.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\Util.h" \ - -RubyUtil.obj: \ - RubyUtil.cpp \ - "$(includedir)\Slice\RubyUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\Checksum.h" \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\IceUtil\Functional.h" \ - "$(includedir)\IceUtil\InputUtil.h" \ - -Util.obj: \ - Util.cpp \ - "$(includedir)\Slice\Util.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "..\..\src\IceUtil\FileUtil.h" \ - "$(includedir)\IceUtil\StringUtil.h" \ - -Ruby.obj: \ - Ruby.cpp \ - "$(includedir)\IceUtil\DisableWarnings.h" \ - "$(includedir)\IceUtil\Options.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\RecMutex.h" \ - "$(includedir)\IceUtil\Lock.h" \ - "$(includedir)\IceUtil\ThreadException.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\Time.h" \ - "$(includedir)\IceUtil\MutexProtocol.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\CtrlCHandler.h" \ - "$(includedir)\IceUtil\Mutex.h" \ - "$(includedir)\IceUtil\MutexPtrLock.h" \ - "$(includedir)\Slice\Preprocessor.h" \ - "$(includedir)\Slice\FileTracker.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\Slice\RubyUtil.h" \ - "$(includedir)\IceUtil\OutputUtil.h" \ - "$(includedir)\Slice\Util.h" \ - -Grammar.obj: \ - Grammar.cpp \ - "GrammarUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Config.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "$(includedir)\IceUtil\InputUtil.h" \ - "$(includedir)\IceUtil\UUID.h" \ - -Scanner.obj: \ - Scanner.cpp \ - "$(includedir)\IceUtil\ScannerConfig.h" \ - "$(includedir)\IceUtil\Config.h" \ - "GrammarUtil.h" \ - "$(includedir)\Slice\Parser.h" \ - "$(includedir)\IceUtil\Shared.h" \ - "$(includedir)\IceUtil\Atomic.h" \ - "$(includedir)\IceUtil\Handle.h" \ - "$(includedir)\IceUtil\Exception.h" \ - "Grammar.h" \ - "$(includedir)\IceUtil\InputUtil.h" \ diff --git a/cpp/src/Slice/.gitignore b/cpp/src/Slice/.gitignore deleted file mode 100644 index 720f44c7047..00000000000 --- a/cpp/src/Slice/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -// Generated by makegitignore.py - -// IMPORTANT: Do not edit this file -- any edits made here will be lost! -.depend -.depend diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 55103f4a395..b65006e6c20 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -24,6 +24,12 @@ using namespace IceUtilInternal; namespace { +string +condString(bool ok, const string& str) +{ + return ok ? str : ""; +} + string toTemplateArg(const string& arg) { if(arg.empty()) @@ -43,19 +49,32 @@ string toTemplateArg(const string& arg) } string +toOptional(const string& s, int typeCtx) +{ + bool cpp11 = (typeCtx & TypeContextCpp11) != 0; + string result = cpp11 ? "Ice::optional" : "IceUtil::Optional"; + result += '<'; + if(cpp11) + { + result += s; + } + else + { + result += toTemplateArg(s); + } + + result += '>'; + return result; +} + + +string stringTypeToString(const TypePtr& type, const StringList& metaData, int typeCtx) { string strType = findMetaData(metaData, typeCtx); if(strType == "wstring" || (typeCtx & TypeContextUseWstring && strType == "")) { - if(featureProfile == IceE) - { - return "::Ice::Wstring"; - } - else - { - return "::std::wstring"; - } + return "::std::wstring"; } else if(strType != "" && strType != "string") { @@ -99,7 +118,7 @@ sequenceTypeToString(const SequencePtr& seq, const StringList& metaData, int typ return "::std::vector<" + s + '>'; } } - string s = typeToString(seq->type(), seq->typeMetaData(), inWstringModule(seq) ? TypeContextUseWstring : 0); + string s = typeToString(seq->type(), seq->typeMetaData(), typeCtx | (inWstringModule(seq) ? TypeContextUseWstring : 0)); return "::std::pair<const " + s + "*, const " + s + "*>"; } else if(seqType.find("%range") == 0) @@ -148,7 +167,6 @@ dictionaryTypeToString(const DictionaryPtr& dict, const StringList& metaData, in } } - void writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const string& fixedName, const StringList& metaData, int typeCtx, bool endArg) @@ -156,11 +174,11 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st string s = typeToString(type, metaData, typeCtx); if(optional) { - s = "IceUtil::Optional<" + toTemplateArg(s) + '>'; + s = toOptional(s, typeCtx); } out << nl << s << ' ' << fixedName << ';'; - if(!(typeCtx & TypeContextInParam) || !endArg) + if((typeCtx & TypeContextCpp11) || !(typeCtx & TypeContextInParam) || !endArg) { return; // We're done. } @@ -190,23 +208,28 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st { md.push_back("cpp:type:" + seqType.substr(strlen("%range:"))); } - s = typeToString(seq, md); + s = typeToString(seq, md, 0); } if(!s.empty()) { if(optional) { - s = "IceUtil::Optional<" + toTemplateArg(s) + '>'; + s = toOptional(s, typeCtx); } - out << nl << s << " ___" << fixedName << ";"; + out << nl << s << ' ' << fixedName << "_tmp_;"; } } } void -writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& fixedName, const StringList& metaData) +writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& fixedName, const StringList& metaData, + const string& obj = "") { + string objPrefix = obj.empty() ? obj : obj + "."; + string paramName = objPrefix + fixedName; + string escapedParamName = objPrefix + fixedName + "_tmp_"; + SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { @@ -227,14 +250,14 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& { if(optional) { - out << nl << "if(___" << fixedName << ")"; + out << nl << "if(" << escapedParamName << ")"; out << sb; - out << nl << fixedName << " = ___" << fixedName << "->second;"; - out << eb; + out << nl << paramName << " = " << escapedParamName << "->second;"; + out << eb; } else { - out << nl << fixedName << " = ___" << fixedName << ".second;"; + out << nl << paramName << " = " << escapedParamName << ".second;"; } } else if(!builtin || @@ -244,32 +267,30 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& { if(optional) { - out << nl << "if(___" << fixedName << ")"; + out << nl << "if(" << escapedParamName << ")"; out << sb; - out << nl << fixedName << ".__setIsSet();"; - out << nl << "if(!___" << fixedName << "->empty())"; + out << nl << paramName << ".__setIsSet();"; + out << nl << "if(!" << escapedParamName << "->empty())"; out << sb; - out << nl << fixedName << "->first" << " = &(*___" << fixedName << ")[0];"; - out << nl << fixedName << "->second" << " = " << fixedName << "->first + " << "___" - << fixedName << "->size();"; + out << nl << paramName << "->first" << " = &(*" << escapedParamName << ")[0];"; + out << nl << paramName << "->second" << " = " << paramName << "->first + " << escapedParamName << "->size();"; out << eb; out << nl << "else"; out << sb; - out << nl << fixedName << "->first" << " = " << fixedName << "->second" << " = 0;"; + out << nl << paramName << "->first" << " = " << paramName << "->second" << " = 0;"; out << eb; out << eb; } else { - out << nl << "if(!___" << fixedName << ".empty())"; + out << nl << "if(!" << escapedParamName << ".empty())"; out << sb; - out << nl << fixedName << ".first" << " = &___" << fixedName << "[0];"; - out << nl << fixedName << ".second" << " = " << fixedName << ".first + " << "___" - << fixedName << ".size();"; + out << nl << paramName << ".first" << " = &" << escapedParamName << "[0];"; + out << nl << paramName << ".second" << " = " << paramName << ".first + " << escapedParamName << ".size();"; out << eb; out << nl << "else"; out << sb; - out << nl << fixedName << ".first" << " = " << fixedName << ".second" << " = 0;"; + out << nl << paramName << ".first" << " = " << paramName << ".second" << " = 0;"; out << eb; } } @@ -278,30 +299,42 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string& { if(optional) { - out << nl << "if(___" << fixedName << ")"; + out << nl << "if(" << escapedParamName << ")"; out << sb; - out << nl << fixedName << ".__setIsSet();"; - out << nl << fixedName << "->first = (*___" << fixedName << ").begin();"; - out << nl << fixedName << "->second = (*___" << fixedName << ").end();"; + out << nl << paramName << ".__setIsSet();"; + out << nl << paramName << "->first = (*" << escapedParamName << ").begin();"; + out << nl << paramName << "->second = (*" << escapedParamName << ").end();"; out << eb; } else { - out << nl << fixedName << ".first = ___" << fixedName << ".begin();"; - out << nl << fixedName << ".second = ___" << fixedName << ".end();"; + out << nl << paramName << ".first = " << escapedParamName << ".begin();"; + out << nl << paramName << ".second = " << escapedParamName << ".end();"; } } } } void -writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal, bool prepend, int typeCtx) +writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal, + bool prepend, int typeCtx, const string& customStream = "", const string& retP = "", const string& obj = "") { string prefix = prepend ? paramPrefix : ""; + string returnValueS = retP.empty() ? string("ret") : retP; + string objPrefix = obj.empty() ? obj : obj + "."; + + string stream = customStream; + if(stream.empty()) + { + stream = marshal ? "ostr" : "istr"; + } + + bool cpp11 = (typeCtx & TypeContextCpp11) != 0; // // Marshal non optional parameters. // + ParamDeclList requiredParams; ParamDeclList optionals; for(ParamDeclList::const_iterator p = params.begin(); p != params.end(); ++p) { @@ -311,57 +344,161 @@ writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const Oper } else { - writeMarshalUnmarshalCode(out, (*p)->type(), false, 0, fixKwd(prefix + (*p)->name()), marshal, (*p)->getMetaData(), - typeCtx); + requiredParams.push_back(*p); } } - if(op && op->returnType()) + + + if(!requiredParams.empty() || (op && op->returnType() && !op->returnIsOptional())) { - if(!op->returnIsOptional()) + if(cpp11) + { + out << nl; + if(marshal) + { + out << stream << "->writeAll"; + } + else + { + out << stream << "->readAll"; + } + out << spar; + for(ParamDeclList::const_iterator p = requiredParams.begin(); p != requiredParams.end(); ++p) + { + out << objPrefix + fixKwd(prefix + (*p)->name()); + } + if(op && op->returnType() && !op->returnIsOptional()) + { + out << objPrefix + returnValueS; + } + out << epar << ";"; + } + else { - writeMarshalUnmarshalCode(out, op->returnType(), false, 0, "__ret", marshal, op->getMetaData(), typeCtx); + for(ParamDeclList::const_iterator p = requiredParams.begin(); p != requiredParams.end(); ++p) + { + writeMarshalUnmarshalCode(out, (*p)->type(), false, 0, fixKwd(prefix + (*p)->name()), marshal, (*p)->getMetaData(), + typeCtx, customStream, true, obj); + } + + if(op && op->returnType()) + { + if(!op->returnIsOptional()) + { + writeMarshalUnmarshalCode(out, op->returnType(), false, 0, returnValueS, marshal, op->getMetaData(), typeCtx, + customStream, true, obj); + } + } } } - // - // Sort optional parameters by tag. - // - class SortFn + if(!optionals.empty() || (op && op->returnType() && op->returnIsOptional())) { - public: - static bool compare(const ParamDeclPtr& lhs, const ParamDeclPtr& rhs) + // + // Sort optional parameters by tag. + // + class SortFn { - return lhs->tag() < rhs->tag(); - } - }; - optionals.sort(SortFn::compare); + public: + static bool compare(const ParamDeclPtr& lhs, const ParamDeclPtr& rhs) + { + return lhs->tag() < rhs->tag(); + } + }; + optionals.sort(SortFn::compare); - // - // Marshal optional parameters. - // - bool checkReturnType = op && op->returnIsOptional(); - for(ParamDeclList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) - { - if(checkReturnType && op->returnTag() < (*p)->tag()) + if(cpp11) + { + out << nl; + if(marshal) + { + out << stream << "->writeAll"; + } + else + { + out << stream << "->readAll"; + } + out << spar; + + { + // + // Tags + // + ostringstream os; + os << '{'; + bool checkReturnType = op && op->returnIsOptional(); + bool insertComma = false; + for(ParamDeclList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) + { + if(checkReturnType && op->returnTag() < (*p)->tag()) + { + os << condString(insertComma, ", ") << op->returnTag(); + checkReturnType = false; + insertComma = true; + } + os << condString(insertComma, ", ") << (*p)->tag(); + insertComma = true; + } + if(checkReturnType) + { + os << condString(insertComma, ", ") << op->returnTag(); + } + os << '}'; + out << os.str(); + } + + { + // + // Parameters + // + bool checkReturnType = op && op->returnIsOptional(); + for(ParamDeclList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) + { + if(checkReturnType && op->returnTag() < (*p)->tag()) + { + out << objPrefix + returnValueS; + checkReturnType = false; + } + out << objPrefix + fixKwd(prefix + (*p)->name()); + } + if(checkReturnType) + { + out << objPrefix + returnValueS; + } + } + out << epar << ";"; + } + else { - writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal, - op->getMetaData(), typeCtx); - checkReturnType = false; + + // + // Marshal optional parameters. + // + + bool checkReturnType = op && op->returnIsOptional(); + for(ParamDeclList::const_iterator p = optionals.begin(); p != optionals.end(); ++p) + { + if(checkReturnType && op->returnTag() < (*p)->tag()) + { + writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), returnValueS, marshal, + op->getMetaData(), typeCtx, customStream, true, obj); + + checkReturnType = false; + } + writeMarshalUnmarshalCode(out, (*p)->type(), true, (*p)->tag(), fixKwd(prefix + (*p)->name()), marshal, + (*p)->getMetaData(), typeCtx, customStream, true, obj); + } + if(checkReturnType) + { + writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), returnValueS, marshal, op->getMetaData(), + typeCtx, customStream, true, obj); + } } - writeMarshalUnmarshalCode(out, (*p)->type(), true, (*p)->tag(), fixKwd(prefix + (*p)->name()), marshal, - (*p)->getMetaData(), typeCtx); - } - if(checkReturnType) - { - writeMarshalUnmarshalCode(out, op->returnType(), true, op->returnTag(), "__ret", marshal, op->getMetaData(), - typeCtx); } } - } -Slice::FeatureProfile Slice::featureProfile = Slice::Ice; -string Slice::paramPrefix = "__p_"; +string Slice::paramPrefix = "iceP_"; char Slice::ToIfdef::operator()(char c) @@ -439,10 +576,10 @@ Slice::printDllExportStuff(Output& out, const string& dllExport) { out << sp; out << "\n#ifndef " << dllExport; - out << "\n# ifdef " << dllExport << "_EXPORTS"; - out << "\n# define " << dllExport << " ICE_DECLSPEC_EXPORT"; - out << "\n# elif defined(ICE_STATIC_LIBS)"; + out << "\n# if defined(ICE_STATIC_LIBS)"; out << "\n# define " << dllExport << " /**/"; + out << "\n# elif defined(" << dllExport << "_EXPORTS)"; + out << "\n# define " << dllExport << " ICE_DECLSPEC_EXPORT"; out << "\n# else"; out << "\n# define " << dllExport << " ICE_DECLSPEC_IMPORT"; out << "\n# endif"; @@ -450,10 +587,36 @@ Slice::printDllExportStuff(Output& out, const string& dllExport) } } +bool +Slice::isMovable(const TypePtr& type) +{ + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + switch(builtin->kind()) + { + case Builtin::KindString: + case Builtin::KindObject: + case Builtin::KindObjectProxy: + case Builtin::KindLocalObject: + case Builtin::KindValue: + { + return true; + } + default: + { + return false; + } + } + } + return !EnumPtr::dynamicCast(type); +} string Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx) { + bool cpp11 = (typeCtx & TypeContextCpp11) != 0; + static const char* builtinTable[] = { "::Ice::Byte", @@ -466,7 +629,24 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx "::std::string", "::Ice::ObjectPtr", "::Ice::ObjectPrx", - "::Ice::LocalObjectPtr" + "::Ice::LocalObjectPtr", + "::Ice::ValuePtr" + }; + + static const char* cpp11BuiltinTable[] = + { + "::Ice::Byte", + "bool", + "short", + "int", + "long long int", + "float", + "double", + "::std::string", + "::std::shared_ptr<::Ice::Object>", + "::std::shared_ptr<::Ice::ObjectPrx>", + "::std::shared_ptr<void>", + "::std::shared_ptr<::Ice::Value>" }; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); @@ -478,20 +658,55 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx } else { - return builtinTable[builtin->kind()]; + if(cpp11) + { + if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal)) + { + return "::std::shared_ptr<::Ice::Value>"; + } + else + { + return cpp11BuiltinTable[builtin->kind()]; + } + } + else + { + return builtinTable[builtin->kind()]; + } } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - return fixKwd(cl->scoped() + "Ptr"); + if(cpp11) + { + if(cl->definition() && cl->definition()->isDelegate()) + { + return classDefToDelegateString(cl->definition()); + } + else if(cl->isInterface() && !cl->isLocal()) + { + return "std::shared_ptr<::Ice::Value>"; + } + else + { + return "::std::shared_ptr<" + cl->scoped() + ">"; + } + } + else + { + return cl->scoped() + "Ptr"; + } } StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "%class") + // + // C++11 mapping doesn't accept cpp:class metadata + // + if(!cpp11 && findMetaData(st->getMetaData()) == "%class") { return fixKwd(st->scoped() + "Ptr"); } @@ -501,7 +716,26 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return fixKwd(proxy->_class()->scoped() + "Prx"); + if(cpp11) + { + ClassDefPtr def = proxy->_class()->definition(); + // + // Non local classes without operations map to the base + // proxy class shared_ptr<Ice::ObjectPrx> + // + if(def && !def->isInterface() && def->allOperations().empty()) + { + return "::std::shared_ptr<::Ice::ObjectPrx>"; + } + else + { + return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">"; + } + } + else + { + return fixKwd(proxy->_class()->scoped() + "Prx"); + } } SequencePtr seq = SequencePtr::dynamicCast(type); @@ -536,7 +770,7 @@ Slice::typeToString(const TypePtr& type, bool optional, const StringList& metaDa { if(optional) { - return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) + ">"; + return toOptional(typeToString(type, metaData, typeCtx), typeCtx); } else { @@ -554,7 +788,7 @@ Slice::returnTypeToString(const TypePtr& type, bool optional, const StringList& if(optional) { - return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) + ">"; + return toOptional(typeToString(type, metaData, typeCtx), typeCtx); } return typeToString(type, metaData, typeCtx); @@ -563,7 +797,9 @@ Slice::returnTypeToString(const TypePtr& type, bool optional, const StringList& string Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx) { - static const char* inputBuiltinTable[] = + bool cpp11 = (typeCtx & TypeContextCpp11) != 0; + + static const char* cpp98InputBuiltinTable[] = { "::Ice::Byte", "bool", @@ -575,14 +811,31 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m "const ::std::string&", "const ::Ice::ObjectPtr&", "const ::Ice::ObjectPrx&", - "const ::Ice::LocalObjectPtr&" + "const ::Ice::LocalObjectPtr&", + "const ::Ice::ValuePtr&" + }; + + static const char* cpp11InputBuiltinTable[] = + { + "::Ice::Byte", + "bool", + "short", + "int", + "long long int", + "float", + "double", + "const ::std::string&", + "const ::std::shared_ptr<::Ice::Object>&", + "const ::std::shared_ptr<::Ice::ObjectPrx>&", + "const ::std::shared_ptr<void>&", + "const ::std::shared_ptr<::Ice::Value>&" }; typeCtx |= TypeContextInParam; if(optional) { - return "const IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&"; + return "const " + toOptional(typeToString(type, metaData, typeCtx), typeCtx) + '&'; } BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); @@ -590,34 +843,91 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m { if(builtin->kind() == Builtin::KindString) { - return string("const ") + stringTypeToString(type, metaData, typeCtx) + "&"; + return string("const ") + stringTypeToString(type, metaData, typeCtx) + '&'; } else { - return inputBuiltinTable[builtin->kind()]; + if(cpp11) + { + if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal)) + { + return "const ::std::shared_ptr<::Ice::Value>&"; + } + else + { + return cpp11InputBuiltinTable[builtin->kind()]; + } + } + else + { + return cpp98InputBuiltinTable[builtin->kind()]; + } } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - return "const " + fixKwd(cl->scoped() + "Ptr&"); + if(cpp11) + { + if(cl->definition() && cl->definition()->isDelegate()) + { + return classDefToDelegateString(cl->definition(), typeCtx); + } + else if(cl->isInterface() && !cl->isLocal()) + { + return "const ::std::shared_ptr<::Ice::Value>&"; + } + else + { + return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&"; + } + } + else + { + return "const " + fixKwd(cl->scoped() + "Ptr&"); + } } StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "%class") + if(cpp11) { - return "const " + fixKwd(st->scoped() + "Ptr&"); + return "const " + fixKwd(st->scoped()) + "&"; + } + else + { + if(findMetaData(st->getMetaData()) == "%class") + { + return "const " + fixKwd(st->scoped() + "Ptr&"); + } + else + { + return "const " + fixKwd(st->scoped()) + "&"; + } } - return "const " + fixKwd(st->scoped()) + "&"; } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return "const " + fixKwd(proxy->_class()->scoped() + "Prx&"); + if(cpp11) + { + ClassDefPtr def = proxy->_class()->definition(); + if(def && !def->isInterface() && def->allOperations().empty()) + { + return "const ::std::shared_ptr<::Ice::ObjectPrx>&"; + } + else + { + return "const ::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&"; + } + } + else + { + return "const " + fixKwd(proxy->_class()->scoped() + "Prx&"); + } } EnumPtr en = EnumPtr::dynamicCast(type); @@ -650,6 +960,8 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m string Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx) { + bool cpp11 = (typeCtx & TypeContextCpp11) != 0; + static const char* outputBuiltinTable[] = { "::Ice::Byte&", @@ -661,13 +973,30 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& "::Ice::Double&", "::std::string&", "::Ice::ObjectPtr&", - "::Ice::ObjectPrx&", - "::Ice::LocalObjectPtr&" + "::Ice::ObjectPrxPtr&", + "::Ice::LocalObjectPtr&", + "::Ice::ValuePtr&" + }; + + static const char* cpp11OutputBuiltinTable[] = + { + "::Ice::Byte&", + "bool&", + "short&", + "int&", + "long long int&", + "float&", + "double&", + "::std::string&", + "::std::shared_ptr<::Ice::Object>&", + "::std::shared_ptr<::Ice::ObjectPrx>&", + "::std::shared_ptr<void>&", + "::std::shared_ptr<::Ice::Value>&" }; if(optional) { - return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&"; + return toOptional(typeToString(type, metaData, typeCtx), typeCtx) + '&'; } BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); @@ -679,30 +1008,84 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& } else { - return outputBuiltinTable[builtin->kind()]; + if(cpp11) + { + if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal)) + { + return "::std::shared_ptr<::Ice::Value>"; + } + else + { + return cpp11OutputBuiltinTable[builtin->kind()]; + } + } + else + { + return outputBuiltinTable[builtin->kind()]; + } } } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if(cl) { - return fixKwd(cl->scoped() + "Ptr&"); + if(cpp11) + { + if(cl->definition() && cl->definition()->isDelegate()) + { + return classDefToDelegateString(cl->definition(), typeCtx) + "&"; + } + else if(cl->isInterface() && !cl->isLocal()) + { + return "::std::shared_ptr<::Ice::Value>&"; + } + else + { + return "::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&"; + } + } + else + { + return fixKwd(cl->scoped() + "Ptr&"); + } } StructPtr st = StructPtr::dynamicCast(type); if(st) { - if(findMetaData(st->getMetaData()) == "%class") + if(!cpp11 && findMetaData(st->getMetaData()) == "%class") { return fixKwd(st->scoped() + "Ptr&"); } - return fixKwd(st->scoped()) + "&"; + else + { + return fixKwd(st->scoped()) + "&"; + } } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return fixKwd(proxy->_class()->scoped() + "Prx&"); + if(cpp11) + { + ClassDefPtr def = proxy->_class()->definition(); + // + // Non local classes without operations map to the base + // proxy class shared_ptr<Ice::ObjectPrx> + // + if(def && !def->isInterface() && def->allOperations().empty()) + { + return "::std::shared_ptr<::Ice::ObjectPrx>"; + } + else + { + return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&"; + } + } + else + { + return fixKwd(proxy->_class()->scoped() + "Prx&"); + } } SequencePtr seq = SequencePtr::dynamicCast(type); @@ -727,25 +1110,25 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& } string -Slice::operationModeToString(Operation::Mode mode) +Slice::operationModeToString(Operation::Mode mode, bool cpp11) { + string prefix = cpp11 ? "::Ice::OperationMode::" : "::Ice::"; switch(mode) { case Operation::Normal: { - return "::Ice::Normal"; + return prefix + "Normal"; } case Operation::Nonmutating: { - return "::Ice::Nonmutating"; + return prefix + "Nonmutating"; } case Operation::Idempotent: { - return "::Ice::Idempotent"; + return prefix + "Idempotent"; } - default: { assert(false); @@ -756,16 +1139,18 @@ Slice::operationModeToString(Operation::Mode mode) } string -Slice::opFormatTypeToString(const OperationPtr& op) +Slice::opFormatTypeToString(const OperationPtr& op, bool cpp11) { + string prefix = cpp11 ? "::Ice::FormatType::" : "::Ice::"; + switch(op->format()) { case DefaultFormat: - return "::Ice::DefaultFormat"; + return prefix + "DefaultFormat"; case CompactFormat: - return "::Ice::CompactFormat"; + return prefix + "CompactFormat"; case SlicedFormat: - return "::Ice::SlicedFormat"; + return prefix + "SlicedFormat"; default: assert(false); @@ -775,7 +1160,7 @@ Slice::opFormatTypeToString(const OperationPtr& op) } // -// If the passed name is a keyword, return the name with a "_cxx_" prefix; +// If the passed name is a keyword, return the name with a "_cpp_" prefix; // otherwise, return the name unchanged. // @@ -792,14 +1177,15 @@ lookupKwd(const string& name) // static const string keywordList[] = { - "and", "and_eq", "asm", "auto", "bit_and", "bit_or", "bool", "break", "case", "catch", "char", - "class", "compl", "const", "const_cast", "continue", "default", "delete", "do", "double", - "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", - "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "not", "not_eq", - "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", - "return", "short", "signed", "sizeof", "static", "static_cast", "struct", "switch", "template", - "this", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", - "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq" + "alignas", "alignof", "and", "and_eq", "asm", "auto", "bit_and", "bit_or", "bool", "break", + "case", "catch", "char", "char16_t", "char32_t", "class", "compl", "const", "const_exptr", "const_cast", "continue", + "decltype", "default", "delete", "do", "double", "dynamic_cast", + "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", + "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", + "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "return", + "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", + "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", + "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq" }; bool found = binary_search(&keywordList[0], &keywordList[sizeof(keywordList) / sizeof(*keywordList)], @@ -845,8 +1231,8 @@ splitScopedName(const string& scoped) // // If the passed name is a scoped name, return the identical scoped name, // but with all components that are C++ keywords replaced by -// their "_cxx_"-prefixed version; otherwise, if the passed name is -// not scoped, but a C++ keyword, return the "_cxx_"-prefixed name; +// their "_cpp_"-prefixed version; otherwise, if the passed name is +// not scoped, but a C++ keyword, return the "_cpp_"-prefixed name; // otherwise, return the name unchanged. // string @@ -868,16 +1254,19 @@ Slice::fixKwd(const string& name) void Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional, int tag, const string& param, - bool marshal, const StringList& metaData, int typeCtx, const string& str, bool pointer) + bool marshal, const StringList& metaData, int typeCtx, const string& customStream, bool pointer, + const string& obj) { + string objPrefix = obj.empty() ? obj : obj + "."; + ostringstream os; - if(str.empty()) + if(customStream.empty()) { - os << (marshal ? "__os" : "__is"); + os << (marshal ? "ostr" : "istr"); } else { - os << str; + os << customStream; } string deref; @@ -916,52 +1305,63 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, bool optional BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); if(builtin && builtin->kind() == Builtin::KindByte) { - out << nl << func << param << ");"; + out << nl << func << objPrefix << param << ");"; return; } - out << nl << func << "___" << param << ");"; - writeParamEndCode(out, seq, optional, param, metaData); + out << nl << func << objPrefix << param << "_tmp_);"; + writeParamEndCode(out, seq, optional, param, metaData, obj); return; } else if(seqType.find("%range") == 0) { - out << nl << func << "___" << param << ");"; - writeParamEndCode(out, seq, optional, param, metaData); + out << nl << func << objPrefix << param << "_tmp_);"; + writeParamEndCode(out, seq, optional, param, metaData, obj); return; } } } - out << nl << func << param << ");"; + out << nl << func << objPrefix << param << ");"; } void -Slice::writeMarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx) +Slice::writeMarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx, + const string& customStream, const string& retP) { - writeMarshalUnmarshalParams(out, params, op, true, prepend, typeCtx); + writeMarshalUnmarshalParams(out, params, op, true, prepend, typeCtx, customStream, retP); } void -Slice::writeUnmarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx) +Slice::writeUnmarshalCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx, + const string& customStream, const string& retP, const string& obj) { - writeMarshalUnmarshalParams(out, params, op, false, prepend, typeCtx); + writeMarshalUnmarshalParams(out, params, op, false, prepend, typeCtx, customStream, retP, obj); } void -Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx) +Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx, + const string& customRet) { string prefix = prepend ? paramPrefix : ""; + string returnValueS = customRet; + if(returnValueS.empty()) + { + returnValueS = "ret"; + } + for(ParamDeclList::const_iterator p = params.begin(); p != params.end(); ++p) { writeParamAllocateCode(out, (*p)->type(), (*p)->optional(), fixKwd(prefix + (*p)->name()), (*p)->getMetaData(), - typeCtx, getEndArg((*p)->type(),(*p)->getMetaData(), (*p)->name()) != (*p)->name()); + typeCtx, getEndArg((*p)->type(), (*p)->getMetaData(), (*p)->name()) != (*p)->name()); } + if(op && op->returnType()) { - writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData(), typeCtx, - getEndArg(op->returnType(), op->getMetaData(), "__ret") != "__ret"); + writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), returnValueS, op->getMetaData(), typeCtx, + getEndArg(op->returnType(), op->getMetaData(), returnValueS) != returnValueS); } + } string @@ -986,11 +1386,11 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string& builtin->kind() != Builtin::KindObject && builtin->kind() != Builtin::KindObjectProxy) { - endArg = "___" + endArg; + endArg += "_tmp_"; } else if(!builtin || builtin->kind() != Builtin::KindByte) { - endArg = "___" + endArg; + endArg += "_tmp_"; } } else if(seqType.find("%range") == 0) @@ -1000,7 +1400,7 @@ Slice::getEndArg(const TypePtr& type, const StringList& metaData, const string& { md.push_back("cpp:type:" + seqType.substr(strlen("%range:"))); } - endArg = "___" + endArg; + endArg += "_tmp_"; } } return endArg; @@ -1016,8 +1416,247 @@ Slice::writeEndCode(Output& out, const ParamDeclList& params, const OperationPtr } if(op && op->returnType()) { - writeParamEndCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData()); + writeParamEndCode(out, op->returnType(), op->returnIsOptional(), "ret", op->getMetaData()); + } +} + +void +Slice::writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output& C, + const string& holder, + const DataMemberPtr& p, + bool marshal) +{ + writeMarshalUnmarshalCode(C, p->type(), p->optional(), p->tag(), holder + fixKwd(p->name()), marshal, + p->getMetaData()); +} + +void +Slice::writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output& out, + const string& holder, + const DataMemberList& dataMembers, + bool optional, + bool marshal) +{ + if(dataMembers.empty()) + { + return; + } + + string stream = marshal ? "ostr" : "istr"; + string streamOp = marshal ? "writeAll" : "readAll"; + + out << nl << stream << "->" << streamOp; + out << spar; + + if(optional) + { + ostringstream os; + os << "{"; + for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + if(q != dataMembers.begin()) + { + os << ", "; + } + os << (*q)->tag(); + } + os << "}"; + out << os.str(); + } + + for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + out << holder + fixKwd((*q)->name()); } + + out << epar << ";"; + +} + +void +Slice::writeStreamHelpers(Output& out, + const ContainedPtr& c, + DataMemberList dataMembers, + bool hasBaseDataMembers, + bool checkClassMetaData, + bool cpp11) +{ + // If c is a C++11 class/exception whose base class contains data members (recursively), then we need to generate + // an StreamWriter even if its implementation is empty. This is becuase our default marsaling uses ice_tuple() which + // contains all of our class/exception's data members as well the base data members, which breaks marshaling. This + // is not an issue for structs. + if(dataMembers.empty() && !(cpp11 && hasBaseDataMembers)) + { + return; + } + + DataMemberList requiredMembers; + DataMemberList optionalMembers; + + for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + if((*q)->optional()) + { + optionalMembers.push_back(*q); + } + else + { + requiredMembers.push_back(*q); + } + } + + // Sort optional data members + class SortFn + { + public: + static bool compare(const DataMemberPtr& lhs, const DataMemberPtr& rhs) + { + return lhs->tag() < rhs->tag(); + } + }; + optionalMembers.sort(SortFn::compare); + + string scoped = c->scoped(); + bool classMetaData = checkClassMetaData ? (findMetaData(c->getMetaData(), false) == "%class") : false; + string fullName = classMetaData ? fixKwd(scoped + "Ptr") : fixKwd(scoped); + string holder = classMetaData ? "v->" : "v."; + + // + // Generate StreamWriter + // + // Only generate StreamWriter specializations if we are generating for C++98 or + // we are generating for C++11 with optional data members and no base class data members + // + if(!cpp11 || !optionalMembers.empty() || hasBaseDataMembers) + { + out << nl << "template<typename S>"; + out << nl << "struct StreamWriter" << (cpp11 ? "<" : "< ") << fullName << ", S>"; + out << sb; + if(requiredMembers.empty() && optionalMembers.empty()) + { + out << nl << "static void write(S*, const " << fullName << "&)"; + } + else + { + out << nl << "static void write(S* ostr, const " << fullName << "& v)"; + } + + out << sb; + + if(cpp11) + { + writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, true); + writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, true); + } + else + { + for(DataMemberList::const_iterator q = requiredMembers.begin(); q != requiredMembers.end(); ++q) + { + writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, true); + } + + for(DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + { + writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, true); + } + } + + out << eb; + out << eb << ";" << nl; + } + + // + // Generate StreamWriter + // + out << nl << "template<typename S>"; + out << nl << "struct StreamReader" << (cpp11 ? "<" : "< ") << fullName << ", S>"; + out << sb; + if (requiredMembers.empty() && optionalMembers.empty()) + { + out << nl << "static void read(S*, " << fullName << "&)"; + } + else + { + out << nl << "static void read(S* istr, " << fullName << "& v)"; + } + + out << sb; + + if(cpp11) + { + writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, false); + writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, false); + } + else + { + for(DataMemberList::const_iterator q = requiredMembers.begin(); q != requiredMembers.end(); ++q) + { + writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, false); + } + + for(DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) + { + writeMarshalUnmarshalDataMemberInHolder(out, holder, *q, false); + } + } + + out << eb; + out << eb << ";" << nl; +} + +void +Slice::writeIceTuple(::IceUtilInternal::Output& out, DataMemberList dataMembers, int typeCtx) +{ + out << sp << nl << "std::tuple<"; + for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + if(q != dataMembers.begin()) + { + out << ", "; + } + out << "const "; + out << typeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx | TypeContextCpp11) << "&"; + } + out << "> ice_tuple() const"; + + out << sb; + out << nl << "return std::tie("; + for(DataMemberList::const_iterator pi = dataMembers.begin(); pi != dataMembers.end(); ++pi) + { + if(pi != dataMembers.begin()) + { + out << ", "; + } + out << fixKwd((*pi)->name()); + } + out << ");" << eb; +} + +bool +Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value) +{ + if(findMetaData(prefix, cl->getMetaData(), value)) + { + return true; + } + + ClassDefPtr def = cl->definition(); + return def ? findMetaData(prefix, def->getMetaData(), value) : false; +} + +bool +Slice::findMetaData(const string& prefix, const StringList& metaData, string& value) +{ + for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); i++) + { + string s = *i; + if(s.find(prefix) == 0) + { + value = s.substr(prefix.size()); + return true; + } + } + return false; } string @@ -1041,28 +1680,23 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) // the return value is % followed by the string after cpp:. // // The priority of the metadata is as follows: - // 1: protobuf - // 2: array, range, view-type for "view" parameters - // 3: class + // 1: array, range (C++98 only), view-type for "view" parameters + // 2: class (C++98 only), scoped (C++98 only), unscoped (C++11 only) + // if(pos != string::npos) { string ss = str.substr(prefix.size()); - if(ss.find("protobuf:") == 0) - { - return str.substr(pos + 1); - } - if(typeCtx & (TypeContextInParam | TypeContextAMIPrivateEnd)) { - if(ss.find("range:") == 0) + if(ss.find("view-type:") == 0) { - return string("%") + str.substr(prefix.size()); + return str.substr(pos + 1); } - else if(ss.find("view-type:") == 0) + else if(ss.find("range:") == 0 && !(typeCtx & TypeContextCpp11)) { - return str.substr(pos + 1); + return string("%") + str.substr(prefix.size()); } } @@ -1078,21 +1712,29 @@ Slice::findMetaData(const StringList& metaData, int typeCtx) { return "%array"; } - else if(ss == "range") + else if(ss == "range" && !(typeCtx & TypeContextCpp11)) { return "%range"; } } // - // Otherwise if the data is "class" it is returned. + // Otherwise if the data is "class", "scoped" or "unscoped" it is returned. // else { string ss = str.substr(prefix.size()); - if(ss == "class") + if(ss == "class" && !(typeCtx & TypeContextCpp11)) { return "%class"; } + else if(ss == "scoped" && !(typeCtx & TypeContextCpp11)) + { + return "%scoped"; + } + else if(ss == "unscoped" && (typeCtx & TypeContextCpp11)) + { + return "%unscoped"; + } } } } @@ -1144,3 +1786,35 @@ Slice::getDataMemberRef(const DataMemberPtr& p) return "(*" + name + ")"; } } + +string +Slice::classDefToDelegateString(const ClassDefPtr& cl, int typeCtx) +{ + assert(cl->isDelegate()); + + // A delegate only has one operation + OperationPtr op = cl->allOperations().front(); + + TypePtr ret = op->returnType(); + string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), typeCtx); + + string t = "::std::function<" + retS + "("; + + ParamDeclList paramList = cl->allOperations().front()->parameters(); + for(ParamDeclList::iterator q = paramList.begin(); q != paramList.end(); ++q) + { + if((*q)->isOutParam()) + { + t += outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx); + } + else + { + t += inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx); + } + + t += distance(q, paramList.end()) == 1 ? "" : ", "; + } + + t += ")>"; + return t; +} diff --git a/cpp/src/Slice/CPlusPlusUtil.h b/cpp/src/Slice/CPlusPlusUtil.h new file mode 100644 index 00000000000..a57b33c9e68 --- /dev/null +++ b/cpp/src/Slice/CPlusPlusUtil.h @@ -0,0 +1,78 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef C_PLUS_PLUS_UTIL_H +#define C_PLUS_PLUS_UTIL_H + +#include <Slice/Parser.h> +#include <IceUtil/OutputUtil.h> + +namespace Slice +{ + +extern std::string paramPrefix; + +struct ToIfdef +{ + char operator()(char); +}; + +void printHeader(::IceUtilInternal::Output&); +void printVersionCheck(::IceUtilInternal::Output&); +void printDllExportStuff(::IceUtilInternal::Output&, const std::string&); + +const int TypeContextInParam = 1; +const int TypeContextAMIEnd = 2; +const int TypeContextAMIPrivateEnd = 4; +const int TypeContextAMICallPrivateEnd = 8; +const int TypeContextUseWstring = 16; +const int TypeContextLocal = 32; +const int TypeContextCpp11 = 64; + +bool isMovable(const TypePtr&); + +std::string typeToString(const TypePtr&, const StringList& = StringList(), int = 0); +std::string typeToString(const TypePtr&, bool, const StringList& = StringList(), int = 0); +std::string returnTypeToString(const TypePtr&, bool, const StringList& = StringList(), int = 0); +std::string inputTypeToString(const TypePtr&, bool, const StringList& = StringList(), int = 0); +std::string outputTypeToString(const TypePtr&, bool, const StringList& = StringList(), int = 0); +std::string operationModeToString(Operation::Mode, bool = false); +std::string opFormatTypeToString(const OperationPtr&, bool); + +std::string fixKwd(const std::string&); + +void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const TypePtr&, bool, int, const std::string&, + bool, const StringList& = StringList(), int = 0, const std::string& = "", + bool = true, const std::string& = ""); + +void writeMarshalCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool, + int = 0, const std::string& = "", const std::string& = ""); +void writeUnmarshalCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool, int = 0, + const std::string& = "", const std::string& = "", const std::string& = ""); +void writeAllocateCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool, + int = 0, const std::string& = ""); + +std::string getEndArg(const TypePtr&, const StringList&, const std::string&); +void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool = false); +void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool); +void writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberList&, bool, bool); +void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool, bool, bool); +void writeIceTuple(::IceUtilInternal::Output&, DataMemberList, int); + +bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&); +bool findMetaData(const std::string&, const StringList&, std::string&); +std::string findMetaData(const StringList&, int = 0); +bool inWstringModule(const SequencePtr&); + +std::string getDataMemberRef(const DataMemberPtr&); + +std::string classDefToDelegateString(const ClassDefPtr&, int = 0); +} + +#endif diff --git a/cpp/src/Slice/Checksum.cpp b/cpp/src/Slice/Checksum.cpp index bc9f95e1fe6..d7bd960bb59 100644 --- a/cpp/src/Slice/Checksum.cpp +++ b/cpp/src/Slice/Checksum.cpp @@ -352,7 +352,7 @@ Slice::ChecksumVisitor::visitEnum(const EnumPtr& p) // const bool explicitValue = p->explicitValue(); - EnumeratorList enums = p->getEnumerators(); + EnumeratorList enums = p->enumerators(); if(explicitValue) { // diff --git a/cpp/src/Slice/Checksum.h b/cpp/src/Slice/Checksum.h new file mode 100644 index 00000000000..3744d8a6ad4 --- /dev/null +++ b/cpp/src/Slice/Checksum.h @@ -0,0 +1,26 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_CHECKSUM_H +#define SLICE_CHECKSUM_H + +#include <Slice/Parser.h> +#include <map> +#include <vector> + +namespace Slice +{ + +typedef std::map<std::string, std::vector<unsigned char> > ChecksumMap; + +ChecksumMap createChecksums(const UnitPtr&); + +} + +#endif diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp deleted file mode 100644 index 0ea61485f56..00000000000 --- a/cpp/src/Slice/CsUtil.cpp +++ /dev/null @@ -1,2660 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Slice/CsUtil.h> -#include <Slice/DotNetNames.h> -#include <Slice/Util.h> -#include <IceUtil/Functional.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#ifdef _WIN32 -#include <direct.h> -#endif - -#ifndef _WIN32 -#include <unistd.h> -#endif - -using namespace std; -using namespace Slice; -using namespace IceUtil; -using namespace IceUtilInternal; - -static string -lookupKwd(const string& name, int baseTypes, bool mangleCasts = false) -{ - // - // Keyword list. *Must* be kept in alphabetical order. - // - static const string keywordList[] = - { - "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", - "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", - "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", - "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", - "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", - "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", - "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while" - }; - bool found = binary_search(&keywordList[0], - &keywordList[sizeof(keywordList) / sizeof(*keywordList)], - name, - Slice::CICompare()); - if(found) - { - return "@" + name; - } - if(mangleCasts && (name == "checkedCast" || name == "uncheckedCast")) - { - return string(DotNet::manglePrefix) + name; - } - return Slice::DotNet::mangleName(name, baseTypes); -} - -// -// Split a scoped name into its components and return the components as a list of (unscoped) identifiers. -// -static StringList -splitScopedName(const string& scoped) -{ - assert(scoped[0] == ':'); - StringList ids; - string::size_type next = 0; - string::size_type pos; - while((pos = scoped.find("::", next)) != string::npos) - { - pos += 2; - if(pos != scoped.size()) - { - string::size_type endpos = scoped.find("::", pos); - if(endpos != string::npos) - { - ids.push_back(scoped.substr(pos, endpos - pos)); - } - } - next = pos; - } - if(next != scoped.size()) - { - ids.push_back(scoped.substr(next)); - } - else - { - ids.push_back(""); - } - - return ids; -} - -// -// If the passed name is a scoped name, return the identical scoped name, -// but with all components that are C# keywords replaced by -// their "@"-prefixed version; otherwise, if the passed name is -// not scoped, but a C# keyword, return the "@"-prefixed name; -// otherwise, check if the name is one of the method names of baseTypes; -// if so, prefix it with _Ice_; otherwise, return the name unchanged. -// -string -Slice::CsGenerator::fixId(const string& name, int baseTypes, bool mangleCasts) -{ - if(name.empty()) - { - return name; - } - if(name[0] != ':') - { - return lookupKwd(name, baseTypes, mangleCasts); - } - StringList ids = splitScopedName(name); - StringList newIds; - for(StringList::const_iterator i = ids.begin(); i != ids.end(); ++i) - { - newIds.push_back(lookupKwd(*i, baseTypes)); - } - stringstream result; - for(StringList::const_iterator j = newIds.begin(); j != newIds.end(); ++j) - { - if(j != newIds.begin()) - { - result << '.'; - } - result << *j; - } - return result.str(); -} - -string -Slice::CsGenerator::fixId(const ContainedPtr& cont, int baseTypes, bool mangleCasts) -{ - ContainerPtr container = cont->container(); - ContainedPtr contained = ContainedPtr::dynamicCast(container); - if(contained && contained->hasMetaData("clr:property") && - (contained->containedType() == Contained::ContainedTypeClass || contained->containedType() == Contained::ContainedTypeStruct)) - { - return cont->name() + "__prop"; - } - else - { - return fixId(cont->name(), baseTypes, mangleCasts); - } -} - -string -Slice::CsGenerator::getOptionalFormat(const TypePtr& type) -{ - BuiltinPtr bp = BuiltinPtr::dynamicCast(type); - if(bp) - { - switch(bp->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - { - return "Ice.OptionalFormat.F1"; - } - case Builtin::KindShort: - { - return "Ice.OptionalFormat.F2"; - } - case Builtin::KindInt: - case Builtin::KindFloat: - { - return "Ice.OptionalFormat.F4"; - } - case Builtin::KindLong: - case Builtin::KindDouble: - { - return "Ice.OptionalFormat.F8"; - } - case Builtin::KindString: - { - return "Ice.OptionalFormat.VSize"; - } - case Builtin::KindObject: - { - return "Ice.OptionalFormat.Class"; - } - case Builtin::KindObjectProxy: - { - return "Ice.OptionalFormat.FSize"; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - - if(EnumPtr::dynamicCast(type)) - { - return "Ice.OptionalFormat.Size"; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - return seq->type()->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ? - "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - return st->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - if(ProxyPtr::dynamicCast(type)) - { - return "Ice.OptionalFormat.FSize"; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - assert(cl); - return "Ice.OptionalFormat.Class"; -} - -string -Slice::CsGenerator::getStaticId(const TypePtr& type) -{ - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - - assert((b && b->kind() == Builtin::KindObject) || cl); - - if(b) - { - return "Ice.ObjectImpl.ice_staticId()"; - } - else if(cl->isInterface()) - { - ContainedPtr cont = ContainedPtr::dynamicCast(cl->container()); - assert(cont); - return fixId(cont->scoped(), DotNet::ICloneable) + "." + cl->name() + "Disp_.ice_staticId()"; - } - else - { - return fixId(cl->scoped(), DotNet::ICloneable) + ".ice_staticId()"; - } -} - -string -Slice::CsGenerator::typeToString(const TypePtr& type, bool optional) -{ - if(!type) - { - return "void"; - } - - if(optional) - { - return "Ice.Optional<" + typeToString(type, false) + ">"; - } - - static const char* builtinTable[] = - { - "byte", - "bool", - "short", - "int", - "long", - "float", - "double", - "string", - "Ice.Object", - "Ice.ObjectPrx", - "_System.Object" - }; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - return builtinTable[builtin->kind()]; - } - - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if(proxy) - { - return fixId(proxy->_class()->scoped() + "Prx"); - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - if(seq->hasMetaData("clr:collection")) - { - return fixId(seq->scoped()); - } - - string prefix = "clr:generic:"; - string meta; - if(seq->findMetaData(prefix, meta)) - { - string type = meta.substr(prefix.size()); - if(type == "List" || type == "LinkedList" || type == "Queue" || type == "Stack") - { - return "_System.Collections.Generic." + type + "<" + typeToString(seq->type()) + ">"; - } - else - { - return "global::" + type + "<" + typeToString(seq->type()) + ">"; - } - } - - prefix = "clr:serializable:"; - if(seq->findMetaData(prefix, meta)) - { - string type = meta.substr(prefix.size()); - return "global::" + type; - } - - return typeToString(seq->type()) + "[]"; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - if(d->hasMetaData("clr:collection")) - { - return fixId(d->scoped()); - } - - string prefix = "clr:generic:"; - string meta; - string typeName; - if(d->findMetaData(prefix, meta)) - { - typeName = meta.substr(prefix.size()); - } - else - { - typeName = "Dictionary"; - } - return "_System.Collections.Generic." + typeName - + "<" + typeToString(d->keyType()) + ", " + typeToString(d->valueType()) + ">"; - } - - ContainedPtr contained = ContainedPtr::dynamicCast(type); - if(contained) - { - return fixId(contained->scoped()); - } - - return "???"; -} - -bool -Slice::CsGenerator::isValueType(const TypePtr& type) -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - return false; - break; - } - default: - { - return true; - break; - } - } - } - StructPtr s = StructPtr::dynamicCast(type); - if(s) - { - if(s->hasMetaData("clr:class")) - { - return false; - } - DataMemberList dm = s->dataMembers(); - for(DataMemberList::const_iterator i = dm.begin(); i != dm.end(); ++i) - { - if(!isValueType((*i)->type()) || (*i)->defaultValueType()) - { - return false; - } - } - return true; - } - if(EnumPtr::dynamicCast(type)) - { - return true; - } - return false; -} - -bool -Slice::CsGenerator::isSerializable(const TypePtr& type) -{ - // - // A proxy cannot be serialized because a communicator is required during deserialization. - // - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObjectProxy) || proxy) - { - return false; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - return isSerializable(seq->type()); - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - return isSerializable(d->keyType()) && isSerializable(d->valueType()); - } - - return true; -} - -void -Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, - const TypePtr& type, - const string& param, - bool marshal, - bool streamingAPI) -{ - string stream; - - if(marshal) - { - stream = streamingAPI ? "outS__" : "os__"; - } - else - { - stream = streamingAPI ? "inS__" : "is__"; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByte(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readByte()" << ';'; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << ".writeBool(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readBool()" << ';'; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShort(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readShort()" << ';'; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeInt(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readInt()" << ';'; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLong(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readLong()" << ';'; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloat(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readFloat()" << ';'; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDouble(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readDouble()" << ';'; - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - out << nl << stream << ".writeString(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readString()" << ';'; - } - break; - } - case Builtin::KindObject: - { - if(marshal) - { - out << nl << stream << ".writeObject(" << param << ");"; - } - else - { - out << nl << stream << ".readObject(" << param << ");"; - } - break; - } - case Builtin::KindObjectProxy: - { - string typeS = typeToString(type); - if(marshal) - { - out << nl << stream << ".writeProxy(" << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readProxy()" << ';'; - } - break; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - string typeS = typeToString(type); - if(marshal) - { - out << nl << typeS << "Helper.write"; - if(!streamingAPI) - { - out << "__"; - } - out << "(" << stream << ", " << param << ");"; - } - else - { - out << nl << param << " = " << typeS << "Helper.read"; - if(!streamingAPI) - { - out << "__"; - } - out << "(" << stream << ");"; - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - out << nl << stream << ".writeObject(" << param << ");"; - } - else - { - out << nl << stream << ".readObject(" << param << ");"; - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - if(marshal) - { - const string write = streamingAPI ? "ice_write" : "write__"; - if(!isValueType(st)) - { - out << nl << typeToString(st) << "." << write << "(" << stream << ", " << param << ");"; - } - else - { - out << nl << param << "." << write << "(" << stream << ");"; - } - } - else - { - if(!isValueType(st)) - { - const string r = streamingAPI ? "ice_read" : "read__"; - out << nl << param << " = " << typeToString(type) << "." << r << "(" << stream << ", " << param << ");"; - } - else - { - const string read = streamingAPI ? "ice_read" : "read__"; - out << nl << param << "." << read << "(" << stream << ");"; - } - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - if(marshal) - { - if(streamingAPI) - { - out << nl << "if((int)" << param << " < " << en->minValue() - << " || (int)" << param << " > " << en->maxValue() << ")"; - out << sb; - out << nl << "throw new Ice.MarshalException(\"enumerator out of range\");"; - out << eb; - } - out << nl << stream << ".writeEnum((int)" << param << ", " << en->maxValue() << ");"; - } - else - { - out << nl << param << " = (" << fixId(en->scoped()) << ')' << stream << ".readEnum(" << en->maxValue() - << ");"; - if(streamingAPI) - { - out << nl << "if((int)" << param << " < " << en->minValue() << " || (int)" << param << " > " - << en->maxValue() << ")"; - out << sb; - out << nl << "throw new Ice.MarshalException(\"enumerator out of range\");"; - out << eb; - } - } - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - writeSequenceMarshalUnmarshalCode(out, seq, param, marshal, streamingAPI, true); - return; - } - - assert(ConstructedPtr::dynamicCast(type)); - string typeS; - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - typeS = fixId(d->scope()) + d->name(); - } - else - { - typeS = typeToString(type); - } - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << param << ");"; - } - else - { - out << nl << param << " = " << typeS << "Helper.read(" << stream << ')' << ';'; - } -} - -void -Slice::CsGenerator::writeOptionalMarshalUnmarshalCode(Output &out, - const TypePtr& type, - const string& param, - int tag, - bool marshal, - bool streamingAPI) -{ - string stream; - - if(marshal) - { - stream = streamingAPI ? "outS__" : "os__"; - } - else - { - stream = streamingAPI ? "inS__" : "is__"; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByte(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readByte(" << tag << ");"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << ".writeBool(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readBool(" << tag << ");"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShort(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readShort(" << tag << ");"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeInt(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readInt(" << tag << ");"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLong(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readLong(" << tag << ");"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloat(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readFloat(" << tag << ");"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDouble(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readDouble(" << tag << ");"; - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - out << nl << stream << ".writeString(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = " << stream << ".readString(" << tag << ");"; - } - break; - } - case Builtin::KindObject: - { - if(marshal) - { - out << nl << stream << ".writeObject(" << tag << ", " << param << ");"; - } - else - { - out << nl << stream << ".readObject(" << tag << ", " << param << ");"; - } - break; - } - case Builtin::KindObjectProxy: - { - string typeS = typeToString(type); - if(marshal) - { - out << nl << stream << ".writeProxy(" << tag << ", " << param << ");"; - } - else - { - out << nl << param << " = new Ice.Optional<Ice.ObjectPrx>(" << stream << ".readProxy(" << tag - << "));"; - } - break; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag - << ", Ice.OptionalFormat.FSize))"; - out << sb; - out << nl << "int pos__ = " << stream << ".startSize();"; - writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); - out << nl << stream << ".endSize(pos__);"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", Ice.OptionalFormat.FSize))"; - out << sb; - out << nl << stream << ".skip(4);"; - string tmp = "tmpVal__"; - string typeS = typeToString(type); - out << nl << typeS << ' ' << tmp << ';'; - writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); - out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << typeS << ">();"; - out << eb; - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - out << nl << stream << ".writeObject(" << tag << ", " << param << ");"; - } - else - { - out << nl << stream << ".readObject(" << tag << ", " << param << ");"; - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " - << getOptionalFormat(st) << "))"; - out << sb; - if(st->isVariableLength()) - { - out << nl << "int pos__ = " << stream << ".startSize();"; - } - else - { - out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; - } - writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); - if(st->isVariableLength()) - { - out << nl << stream << ".endSize(pos__);"; - } - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(st) << "))"; - out << sb; - if(st->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - string typeS = typeToString(type); - string tmp = "tmpVal__"; - if(isValueType(st)) - { - out << nl << typeS << ' ' << tmp << " = new " << typeS << "();"; - } - else - { - out << nl << typeS << ' ' << tmp << " = null;"; - } - writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); - out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << typeS << ">();"; - out << eb; - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - size_t sz = en->getEnumerators().size(); - if(marshal) - { - out << nl << "if(" << param << ".HasValue)"; - out << sb; - out << nl << stream << ".writeEnum(" << tag << ", (int)" << param << ".Value, " << sz << ");"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", Ice.OptionalFormat.Size))"; - out << sb; - string typeS = typeToString(type); - string tmp = "tmpVal__"; - out << nl << typeS << ' ' << tmp << ';'; - writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); - out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << typeS << ">();"; - out << eb; - } - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - writeOptionalSequenceMarshalUnmarshalCode(out, seq, param, tag, marshal, streamingAPI); - return; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - assert(d); - TypePtr keyType = d->keyType(); - TypePtr valueType = d->valueType(); - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " - << getOptionalFormat(d) << "))"; - out << sb; - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << "int pos__ = " << stream << ".startSize();"; - } - else - { - out << nl << stream << ".writeSize(" << param << ".Value == null ? 1 : " << param << ".Value.Count * " - << (keyType->minWireSize() + valueType->minWireSize()) << " + (" << param - << ".Value.Count > 254 ? 5 : 1));"; - } - writeMarshalUnmarshalCode(out, type, param + ".Value", marshal, streamingAPI); - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << stream << ".endSize(pos__);"; - } - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(d) << "))"; - out << sb; - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - string typeS = typeToString(type); - string tmp = "tmpVal__"; - out << nl << typeS << ' ' << tmp << " = new " << typeS << "();"; - writeMarshalUnmarshalCode(out, type, tmp, marshal, streamingAPI); - out << nl << param << " = new Ice.Optional<" << typeS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << typeS << ">();"; - out << eb; - } -} - -void -Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, - const SequencePtr& seq, - const string& param, - bool marshal, - bool streamingAPI, - bool useHelper) -{ - string stream; - if(marshal) - { - stream = streamingAPI ? "outS__" : "os__"; - } - else - { - stream = streamingAPI ? "inS__" : "is__"; - } - - if(useHelper) - { - ContainedPtr cont = ContainedPtr::dynamicCast(seq->container()); - assert(cont); - string helperName = fixId(cont->scoped(), DotNet::ICloneable) + "." + seq->name() + "Helper"; - if(marshal) - { - out << nl << helperName << ".write(" << stream << ", " << param << ");"; - } - else - { - out << nl << param << " = " << helperName << ".read(" << stream << ");"; - } - return; - } - - TypePtr type = seq->type(); - string typeS = typeToString(type); - - const string genericPrefix = "clr:generic:"; - string genericType; - string addMethod = "Add"; - const bool isGeneric = seq->findMetaData(genericPrefix, genericType); - bool isStack = false; - bool isList = false; - bool isLinkedList = false; - bool isCustom = false; - if(isGeneric) - { - genericType = genericType.substr(genericPrefix.size()); - if(genericType == "LinkedList") - { - addMethod = "AddLast"; - isLinkedList = true; - } - else if(genericType == "Queue") - { - addMethod = "Enqueue"; - } - else if(genericType == "Stack") - { - addMethod = "Push"; - isStack = true; - } - else if(genericType == "List") - { - isList = true; - } - else - { - isCustom = true; - } - } - const bool isCollection = seq->hasMetaData("clr:collection"); - const bool isArray = !isGeneric && !isCollection; - const string limitID = isArray ? "Length" : "Count"; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindObject: - case Builtin::KindObjectProxy: - { - if(marshal) - { - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - if(isGeneric && !isList) - { - if(isStack) - { - // - // If the collection is a stack, write in top-to-bottom order. Stacks - // cannot contain Ice.Object. - // - out << nl << "Ice.ObjectPrx[] " << param << "_tmp = " << param << ".ToArray();"; - out << nl << "for(int ix__ = 0; ix__ < " << param << "_tmp.Length; ++ix__)"; - out << sb; - out << nl << stream << ".writeProxy(" << param << "_tmp[ix__]);"; - out << eb; - } - else - { - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - string func = builtin->kind() == Builtin::KindObject ? "writeObject" : "writeProxy"; - out << nl << stream << '.' << func << "(e__.Current);"; - out << eb; - } - } - else - { - out << nl << "for(int ix__ = 0; ix__ < " << param << '.' << limitID << "; ++ix__)"; - out << sb; - string func = builtin->kind() == Builtin::KindObject ? "writeObject" : "writeProxy"; - out << nl << stream << '.' << func << '(' << param << "[ix__]);"; - out << eb; - } - out << eb; - } - else - { - out << nl << "int " << param << "_lenx = " << stream << ".readAndCheckSeqSize(" - << static_cast<unsigned>(builtin->minWireSize()) << ");"; - if(!isStack) - { - out << nl << param << " = new "; - } - if(builtin->kind() == Builtin::KindObject) - { - if(isArray) - { - out << "Ice.Object[" << param << "_lenx];"; - } - else if(isCustom) - { - out << "global::" << genericType << "<Ice.Object>();"; - } - else if(isGeneric) - { - out << "_System.Collections.Generic." << genericType << "<Ice.Object>("; - if(!isLinkedList) - { - out << param << "_lenx"; - } - out << ");"; - } - else - { - out << typeToString(seq) << "(" << param << "_lenx);"; - } - out << nl << "for(int ix__ = 0; ix__ < " << param << "_lenx; ++ix__)"; - out << sb; - out << nl << stream << ".readObject("; - string patcherName; - if(isCustom) - { - patcherName = "CustomSeq"; - } - else if(isList) - { - patcherName = "List"; - } - else if(isArray) - { - patcherName = "Array"; - } - else - { - patcherName = "Sequence"; - } - out << "new IceInternal." << patcherName << "Patcher<Ice.Object>(\"::Ice::Object\", " - << param << ", ix__));"; - } - else - { - if(isStack) - { - out << nl << "Ice.ObjectPrx[] " << param << "_tmp = new Ice.ObjectPrx[" << param << "_lenx];"; - } - else if(isArray) - { - out << "Ice.ObjectPrx[" << param << "_lenx];"; - } - else if(isGeneric) - { - out << "_System.Collections.Generic." << genericType << "<Ice.ObjectPrx>("; - if(!isLinkedList) - { - out << param << "_lenx"; - } - out << ");"; - } - else - { - out << typeToString(seq) << "(" << param << "_lenx);"; - } - out << nl << "for(int ix__ = 0; ix__ < " << param << "_lenx; ++ix__)"; - out << sb; - if(isArray || isStack) - { - string v = isArray ? param : param + "_tmp"; - out << nl << v << "[ix__] = " << stream << ".readProxy();"; - } - else - { - out << nl << "Ice.ObjectPrx val__ = new Ice.ObjectPrxHelperBase();"; - out << nl << "val__ = " << stream << ".readProxy();"; - out << nl << param << "." << addMethod << "(val__);"; - } - } - out << eb; - - if(isStack) - { - out << nl << "_System.Array.Reverse(" << param << "_tmp);"; - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">(" - << param << "_tmp);"; - } - } - break; - } - default: - { - string prefix = "clr:serializable:"; - string meta; - if(seq->findMetaData(prefix, meta)) - { - if(marshal) - { - out << nl << stream << ".writeSerializable(" << param << ");"; - } - else - { - out << nl << param << " = (" << typeToString(seq) << ")" << stream << ".readSerializable();"; - } - break; - } - - string func = typeS; - func[0] = toupper(static_cast<unsigned char>(typeS[0])); - if(marshal) - { - if(isArray) - { - out << nl << stream << ".write" << func << "Seq(" << param << ");"; - } - else if(isCollection) - { - out << nl << stream << ".write" << func << "Seq(" << param << " == null ? null : " - << param << ".ToArray());"; - } - else if(isCustom) - { - if(streamingAPI) - { - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - out << nl << stream << ".write" << func << "(e__.Current);"; - out << eb; - } - else - { - out << nl << stream << ".write" << func << "Seq(" << param << " == null ? 0 : " - << param << ".Count, " << param << ");"; - } - } - else - { - assert(isGeneric); - if(!streamingAPI) - { - out << nl << stream << ".write" << func << "Seq(" << param << " == null ? 0 : " - << param << ".Count, " << param << ");"; - } - else if(isLinkedList) - { - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - out << nl << stream << ".write" << func << "(e__.Current);"; - out << eb; - } - else - { - out << nl << stream << ".write" << func << "Seq(" << param << " == null ? null : " - << param << ".ToArray());"; - } - } - } - else - { - if(isArray) - { - out << nl << param << " = " << stream << ".read" << func << "Seq();"; - } - else if(isCustom) - { - out << sb; - out << nl << param << " = new " << "global::" << genericType << "<" - << typeToString(type) << ">();"; - out << nl << "int szx__ = " << stream << ".readSize();"; - out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)"; - out << sb; - out << nl << param << ".Add(" << stream << ".read" << func << "());"; - out << eb; - out << eb; - } - else if(isCollection) - { - out << nl << param << " = new " << fixId(seq->scoped()) - << '(' << stream << ".read" << func << "Seq());"; - } - else - { - assert(isGeneric); - if(streamingAPI) - { - if(isStack) - { - // - // Stacks are marshaled in top-to-bottom order. The "Stack(type[])" - // constructor assumes the array is in bottom-to-top order, so we - // read the array first, then reverse it. - // - out << nl << typeS << "[] arr__ = " << stream << ".read" << func << "Seq();"; - out << nl << "_System.Array.Reverse(arr__);"; - out << nl << param << " = new " << typeToString(seq) << "(arr__);"; - } - else - { - out << nl << param << " = new " << typeToString(seq) << '(' << stream - << ".read" << func << "Seq());"; - } - } - else - { - out << nl << stream << ".read" << func << "Seq(out " << param << ");"; - } - } - } - break; - } - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - if(isGeneric && !isList) - { - // - // Stacks cannot contain class instances, so there is no need to marshal a - // stack bottom-up here. - // - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - out << nl << stream << ".writeObject(e__.Current);"; - out << eb; - } - else - { - out << nl << "for(int ix__ = 0; ix__ < " << param << '.' << limitID << "; ++ix__)"; - out << sb; - out << nl << stream << ".writeObject(" << param << "[ix__]);"; - out << eb; - } - out << eb; - } - else - { - out << sb; - out << nl << "int szx__ = " << stream << ".readAndCheckSeqSize(" - << static_cast<unsigned>(type->minWireSize()) << ");"; - out << nl << param << " = new "; - if(isArray) - { - out << toArrayAlloc(typeS + "[]", "szx__"); - } - else if(isCustom) - { - out << "global::" << genericType << "<" << typeS << ">()"; - } - else if(isGeneric) - { - out << "_System.Collections.Generic." << genericType << "<" << typeS << ">("; - if(!isLinkedList) - { - out << "szx__"; - } - out << ")"; - } - else - { - out << fixId(seq->scoped()) << "(szx__)"; - } - out << ';'; - out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)"; - out << sb; - - string patcherName; - if(isCustom) - { - patcherName = "CustomSeq"; - } - else if(isList) - { - patcherName = "List"; - } - else if(isArray) - { - patcherName = "Array"; - } - else - { - patcherName = "Sequence"; - } - string scoped = ContainedPtr::dynamicCast(type)->scoped(); - out << nl << "IceInternal." << patcherName << "Patcher<" << typeS << "> spx = new IceInternal." - << patcherName << "Patcher<" << typeS << ">(\"" << scoped << "\", " << param << ", ix__);"; - out << nl << stream << ".readObject("; - out << "spx);"; - out << eb; - out << eb; - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - if(marshal) - { - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - if(isGeneric && !isList) - { - // - // Stacks are marshaled top-down. - // - if(isStack) - { - out << nl << typeS << "[] " << param << "_tmp = " << param << ".ToArray();"; - out << nl << "for(int ix__ = 0; ix__ < " << param << "_tmp.Length; ++ix__)"; - } - else - { - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - } - } - else - { - out << nl << "for(int ix__ = 0; ix__ < " << param << '.' << limitID << "; ++ix__)"; - } - out << sb; - string call; - if(isGeneric && !isList && !isStack) - { - if(isValueType(type)) - { - call = "e__.Current"; - } - else - { - call = "(e__.Current == null ? new "; - call += typeS + "() : e__.Current)"; - } - } - else - { - if(isValueType(type)) - { - call = param; - if(isStack) - { - call += "_tmp"; - } - } - else - { - call = "("; - call += param; - if(isStack) - { - call += "_tmp"; - } - call += "[ix__] == null ? new " + typeS + "() : " + param; - if(isStack) - { - call += "_tmp"; - } - } - call += "[ix__]"; - if(!isValueType(type)) - { - call += ")"; - } - } - call += "."; - call += streamingAPI ? "ice_write" : "write__"; - call += "(" + stream + ");"; - out << nl << call; - out << eb; - out << eb; - } - else - { - out << sb; - out << nl << "int szx__ = " << stream << ".readAndCheckSeqSize(" - << static_cast<unsigned>(type->minWireSize()) << ");"; - if(isArray) - { - out << nl << param << " = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isCustom) - { - out << nl << param << " = new global::" << genericType << "<" << typeS << ">();"; - } - else if(isStack) - { - out << nl << typeS << "[] " << param << "__tmp = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isGeneric) - { - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">("; - if(!isLinkedList) - { - out << "szx__"; - } - out << ");"; - } - else - { - out << nl << param << " = new " << fixId(seq->scoped()) << "(szx__);"; - } - out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)"; - out << sb; - if(isArray || isStack) - { - string v = isArray ? param : param + "__tmp"; - if(!isValueType(st)) - { - out << nl << v << "[ix__] = new " << typeS << "();"; - } - if(streamingAPI) - { - out << nl << v << "[ix__].ice_read(" << stream << ");"; - } - else - { - out << nl << v << "[ix__].read__(" << stream << ");"; - } - } - else - { - out << nl << typeS << " val__ = new " << typeS << "();"; - if(streamingAPI) - { - out << nl << "val__.ice_read(" << stream << ");"; - } - else - { - out << nl << "val__.read__(" << stream << ");"; - } - out << nl << param << "." << addMethod << "(val__);"; - } - out << eb; - if(isStack) - { - out << nl << "_System.Array.Reverse(" << param << "__tmp);"; - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">(" - << param << "__tmp);"; - } - out << eb; - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - if(marshal) - { - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << param << '.'<< limitID << ");"; - if(isGeneric && !isList) - { - // - // Stacks are marshaled top-down. - // - if(isStack) - { - out << nl << typeS << "[] " << param << "_tmp = " << param << ".ToArray();"; - out << nl << "for(int ix__ = 0; ix__ < " << param << "_tmp.Length; ++ix__)"; - out << sb; - out << nl << stream << ".writeEnum((int)" << param << "_tmp[ix__], " << en->maxValue() << ");"; - out << eb; - } - else - { - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - out << nl << stream << ".writeEnum((int)e__.Current, " << en->maxValue() << ");"; - out << eb; - } - } - else - { - out << nl << "for(int ix__ = 0; ix__ < " << param << '.' << limitID << "; ++ix__)"; - out << sb; - out << nl << stream << ".writeEnum((int)" << param << "[ix__], " << en->maxValue() << ");"; - out << eb; - } - out << eb; - } - else - { - out << sb; - out << nl << "int szx__ = " << stream << ".readAndCheckSeqSize(" << - static_cast<unsigned>(type->minWireSize()) << ");"; - if(isArray) - { - out << nl << param << " = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isCustom) - { - out << nl << param << " = new global::" << genericType << "<" << typeS << ">();"; - } - else if(isStack) - { - out << nl << typeS << "[] " << param << "__tmp = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isGeneric) - { - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">("; - if(!isLinkedList) - { - out << "szx__"; - } - out << ");"; - } - else - { - out << nl << param << " = new " << fixId(seq->scoped()) << "(szx__);"; - } - out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)"; - out << sb; - if(isArray || isStack) - { - string v = isArray ? param : param + "__tmp"; - out << nl << v << "[ix__] = (" << typeS << ')' << stream << ".readEnum(" << en->maxValue() << ");"; - } - else - { - out << nl << param << "." << addMethod << "((" << typeS << ')' << stream << ".readEnum(" - << en->maxValue() << "));"; - } - out << eb; - if(isStack) - { - out << nl << "_System.Array.Reverse(" << param << "__tmp);"; - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">(" - << param << "__tmp);"; - } - out << eb; - } - return; - } - - string helperName; - if(ProxyPtr::dynamicCast(type)) - { - helperName = fixId(ProxyPtr::dynamicCast(type)->_class()->scoped() + "PrxHelper"); - } - else - { - helperName = fixId(ContainedPtr::dynamicCast(type)->scoped() + "Helper"); - } - - string func; - if(marshal) - { - func = "write"; - if(!streamingAPI && ProxyPtr::dynamicCast(type)) - { - func += "__"; - } - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; - if(isGeneric && !isList) - { - // - // Stacks are marshaled top-down. - // - if(isStack) - { - out << nl << typeS << "[] " << param << "_tmp = " << param << ".ToArray();"; - out << nl << "for(int ix__ = 0; ix__ < " << param << "_tmp.Length; ++ix__)"; - out << sb; - out << nl << helperName << '.' << func << '(' << stream << ", " << param << "_tmp[ix__]);"; - out << eb; - } - else - { - out << nl << "_System.Collections.Generic.IEnumerator<" << typeS - << "> e__ = " << param << ".GetEnumerator();"; - out << nl << "while(e__.MoveNext())"; - out << sb; - out << nl << helperName << '.' << func << '(' << stream << ", e__.Current);"; - out << eb; - } - } - else - { - out << nl << "for(int ix__ = 0; ix__ < " << param << '.' << limitID << "; ++ix__)"; - out << sb; - out << nl << helperName << '.' << func << '(' << stream << ", " << param << "[ix__]);"; - out << eb; - } - out << eb; - } - else - { - func = "read"; - if(!streamingAPI && ProxyPtr::dynamicCast(type)) - { - func += "__"; - } - out << sb; - out << nl << "int szx__ = " << stream << ".readAndCheckSeqSize(" - << static_cast<unsigned>(type->minWireSize()) << ");"; - if(isArray) - { - out << nl << param << " = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isCustom) - { - out << nl << param << " = new global::" << genericType << "<" << typeS << ">();"; - } - else if(isStack) - { - out << nl << typeS << "[] " << param << "__tmp = new " << toArrayAlloc(typeS + "[]", "szx__") << ";"; - } - else if(isGeneric) - { - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">();"; - } - else - { - out << nl << param << " = new " << fixId(seq->scoped()) << "(szx__);"; - } - out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)"; - out << sb; - if(isArray || isStack) - { - string v = isArray ? param : param + "__tmp"; - out << nl << v << "[ix__] = " << helperName << '.' << func << '(' << stream << ");"; - } - else - { - out << nl << param << "." << addMethod << "(" << helperName << '.' << func << '(' << stream << "));"; - } - out << eb; - if(isStack) - { - out << nl << "_System.Array.Reverse(" << param << "__tmp);"; - out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">(" - << param << "__tmp);"; - } - out << eb; - } - - return; -} - -void -Slice::CsGenerator::writeOptionalSequenceMarshalUnmarshalCode(Output& out, - const SequencePtr& seq, - const string& param, - int tag, - bool marshal, - bool streamingAPI) -{ - string stream; - if(marshal) - { - stream = streamingAPI ? "outS__" : "os__"; - } - else - { - stream = streamingAPI ? "inS__" : "is__"; - } - - const TypePtr type = seq->type(); - const string typeS = typeToString(type); - const string seqS = typeToString(seq); - - string meta; - const bool isArray = !seq->findMetaData("clr:generic:", meta) && !seq->hasMetaData("clr:collection"); - const string length = isArray ? param + ".Value.Length" : param + ".Value.Count"; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindFloat: - case Builtin::KindLong: - case Builtin::KindDouble: - case Builtin::KindString: - { - string func = typeS; - func[0] = toupper(static_cast<unsigned char>(typeS[0])); - const bool isSerializable = seq->findMetaData("clr:serializable:", meta); - - if(marshal) - { - if(isSerializable) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag - << ", Ice.OptionalFormat.VSize))"; - out << sb; - out << nl << stream << ".writeSerializable(" << param << ".Value);"; - out << eb; - } - else if(isArray) - { - out << nl << stream << ".write" << func << "Seq(" << tag << ", " << param << ");"; - } - else - { - out << nl << "if(" << param << ".HasValue)"; - out << sb; - out << nl << stream << ".write" << func << "Seq(" << tag << ", " << param - << ".Value == null ? 0 : " << param << ".Value.Count, " << param << ".Value);"; - out << eb; - } - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(seq) << "))"; - out << sb; - if(builtin->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else if(builtin->kind() != Builtin::KindByte && builtin->kind() != Builtin::KindBool) - { - out << nl << stream << ".skipSize();"; - } - string tmp = "tmpVal__"; - out << nl << seqS << ' ' << tmp << ';'; - writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); - out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << seqS << ">();"; - out << eb; - } - break; - } - - case Builtin::KindObject: - case Builtin::KindObjectProxy: - { - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " - << getOptionalFormat(seq) << "))"; - out << sb; - out << nl << "int pos__ = " << stream << ".startSize();"; - writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); - out << nl << stream << ".endSize(pos__);"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(seq) << "))"; - out << sb; - out << nl << stream << ".skip(4);"; - string tmp = "tmpVal__"; - out << nl << seqS << ' ' << tmp << ';'; - writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); - out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << seqS << ">();"; - out << eb; - } - break; - } - - case Builtin::KindLocalObject: - assert(false); - } - - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " - << getOptionalFormat(seq) << "))"; - out << sb; - if(st->isVariableLength()) - { - out << nl << "int pos__ = " << stream << ".startSize();"; - } - else if(st->minWireSize() > 1) - { - out << nl << stream << ".writeSize(" << param << ".Value == null ? 1 : " << length << " * " - << st->minWireSize() << " + (" << length << " > 254 ? 5 : 1));"; - } - writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); - if(st->isVariableLength()) - { - out << nl << stream << ".endSize(pos__);"; - } - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(seq) << "))"; - out << sb; - if(st->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else if(st->minWireSize() > 1) - { - out << nl << stream << ".skipSize();"; - } - string tmp = "tmpVal__"; - out << nl << seqS << ' ' << tmp << ';'; - writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); - out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << seqS << ">();"; - out << eb; - } - return; - } - - // - // At this point, all remaining element types have variable size. - // - if(marshal) - { - out << nl << "if(" << param << ".HasValue && " << stream << ".writeOpt(" << tag << ", " - << getOptionalFormat(seq) << "))"; - out << sb; - out << nl << "int pos__ = " << stream << ".startSize();"; - writeSequenceMarshalUnmarshalCode(out, seq, param + ".Value", marshal, streamingAPI, true); - out << nl << stream << ".endSize(pos__);"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(seq) << "))"; - out << sb; - out << nl << stream << ".skip(4);"; - string tmp = "tmpVal__"; - out << nl << seqS << ' ' << tmp << ';'; - writeSequenceMarshalUnmarshalCode(out, seq, tmp, marshal, streamingAPI, true); - out << nl << param << " = new Ice.Optional<" << seqS << ">(" << tmp << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new Ice.Optional<" << seqS << ">();"; - out << eb; - } -} - -void -Slice::CsGenerator::writeSerializeDeserializeCode(Output &out, - const TypePtr& type, - const string& param, - bool optional, - int tag, - bool serialize) -{ - if(!isSerializable(type)) - { - return; - } - - if(optional) - { - const string typeName = typeToString(type, true); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } - return; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetByte(\"" << param << "\");"; - } - break; - } - case Builtin::KindBool: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetBoolean(\"" << param << "\");"; - } - break; - } - case Builtin::KindShort: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetInt16(\"" << param << "\");"; - } - break; - } - case Builtin::KindInt: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetInt32(\"" << param << "\");"; - } - break; - } - case Builtin::KindLong: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetInt64(\"" << param << "\");"; - } - break; - } - case Builtin::KindFloat: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetSingle(\"" << param << "\");"; - } - break; - } - case Builtin::KindDouble: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ");"; - } - else - { - out << nl << param << " = " << "info__.GetDouble(\"" << param << "\");"; - } - break; - } - case Builtin::KindString: - { - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << " == null ? \"\" : " << param - << ");"; - } - else - { - out << nl << param << " = " << "info__.GetString(\"" << param << "\");"; - } - break; - } - case Builtin::KindObject: - case Builtin::KindLocalObject: - { - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" - << typeName << "));"; - } - break; - } - case Builtin::KindObjectProxy: - { - // - // Proxies cannot be serialized. - // - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - // - // Proxies cannot be serialized. - // - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } - return; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - assert(d); - const string typeName = typeToString(type, false); - if(serialize) - { - out << nl << "info__.AddValue(\"" << param << "\", " << param << ", typeof(" << typeName << "));"; - } - else - { - out << nl << param << " = (" << typeName << ")info__.GetValue(\"" << param << "\", typeof(" << typeName - << "));"; - } -} - -string -Slice::CsGenerator::toArrayAlloc(const string& decl, const string& sz) -{ - int count = 0; - string::size_type pos = decl.size(); - while(pos > 1 && decl.substr(pos - 2, 2) == "[]") - { - ++count; - pos -= 2; - } - assert(count > 0); - - ostringstream o; - o << decl.substr(0, pos) << '[' << sz << ']' << decl.substr(pos + 2); - return o.str(); -} - -void -Slice::CsGenerator::validateMetaData(const UnitPtr& u) -{ - MetaDataVisitor visitor; - u->visit(&visitor, true); -} - -bool -Slice::CsGenerator::MetaDataVisitor::visitUnitStart(const UnitPtr& p) -{ - // - // Validate global metadata in the top-level file and all included files. - // - StringList files = p->allFiles(); - - for(StringList::iterator q = files.begin(); q != files.end(); ++q) - { - string file = *q; - DefinitionContextPtr dc = p->findDefinitionContext(file); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - StringList newGlobalMetaData; - - static const string csPrefix = "cs:"; - static const string clrPrefix = "clr:"; - for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end(); ++r) - { - string s = *r; - - if(s.find(csPrefix) == 0) - { - static const string csAttributePrefix = csPrefix + "attribute:"; - if(s.find(csAttributePrefix) == 0 && s.size() > csAttributePrefix.size()) - { - newGlobalMetaData.push_back(s); - continue; - } - emitWarning(file, -1, "ignoring invalid global metadata `" + s + "'"); - } - else if(s.find(clrPrefix) == 0) - { - emitWarning(file, -1, "ignoring invalid global metadata `" + s + "'"); - } - else - { - newGlobalMetaData.push_back(s); - } - } - dc->setMetaData(newGlobalMetaData); - } - return true; -} - -bool -Slice::CsGenerator::MetaDataVisitor::visitModuleStart(const ModulePtr& p) -{ - validate(p); - return true; -} - -void -Slice::CsGenerator::MetaDataVisitor::visitModuleEnd(const ModulePtr&) -{ -} - -void -Slice::CsGenerator::MetaDataVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - validate(p); -} - -bool -Slice::CsGenerator::MetaDataVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - validate(p); - return true; -} - -void -Slice::CsGenerator::MetaDataVisitor::visitClassDefEnd(const ClassDefPtr&) -{ -} - -bool -Slice::CsGenerator::MetaDataVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - validate(p); - return true; -} - -void -Slice::CsGenerator::MetaDataVisitor::visitExceptionEnd(const ExceptionPtr&) -{ -} - -bool -Slice::CsGenerator::MetaDataVisitor::visitStructStart(const StructPtr& p) -{ - validate(p); - return true; -} - -void -Slice::CsGenerator::MetaDataVisitor::visitStructEnd(const StructPtr&) -{ -} - -void -Slice::CsGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p) -{ - if(p->hasMetaData("UserException")) - { - ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); - if(!cl->isLocal()) - { - ostringstream os; - os << "ignoring invalid metadata `UserException': directive applies only to local operations " - << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name() - << "' is not local"; - emitWarning(p->file(), p->line(), os.str()); - } - } - validate(p); - - ParamDeclList params = p->parameters(); - for(ParamDeclList::const_iterator i = params.begin(); i != params.end(); ++i) - { - visitParamDecl(*i); - } -} - -void -Slice::CsGenerator::MetaDataVisitor::visitParamDecl(const ParamDeclPtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::visitDataMember(const DataMemberPtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::visitSequence(const SequencePtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::visitDictionary(const DictionaryPtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::visitEnum(const EnumPtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::visitConst(const ConstPtr& p) -{ - validate(p); -} - -void -Slice::CsGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) -{ - static set<string> collectionWarnings; - const string msg = "ignoring invalid metadata"; - - StringList localMetaData = cont->getMetaData(); - StringList newMetaData; - - for(StringList::const_iterator p = localMetaData.begin(); p != localMetaData.end(); ++p) - { - string s = *p; - - string prefix = "clr:"; - - if(s.find(prefix) == 0) - { - SequencePtr seq = SequencePtr::dynamicCast(cont); - if(seq) - { - if(s.substr(prefix.size()) == "collection") - { - if(collectionWarnings.find(cont->file()) == collectionWarnings.end()) - { - emitWarning(cont->file(), cont->line(), "the \"" + s + "\" metadata has been deprecated"); - collectionWarnings.insert(cont->file()); - } - newMetaData.push_back(s); - continue; - } - static const string clrGenericPrefix = prefix + "generic:"; - if(s.find(clrGenericPrefix) == 0) - { - string type = s.substr(clrGenericPrefix.size()); - if(type == "LinkedList" || type == "Queue" || type == "Stack") - { - ClassDeclPtr cd = ClassDeclPtr::dynamicCast(seq->type()); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(!cd && !(builtin && builtin->kind() == Builtin::KindObject)) - { - newMetaData.push_back(s); - continue; - } - } - else if(!type.empty()) - { - newMetaData.push_back(s); - continue; // Custom type or List<T> - } - } - static const string clrSerializablePrefix = prefix + "serializable:"; - if(s.find(clrSerializablePrefix) == 0) - { - string meta; - if(cont->findMetaData(prefix + "collection", meta) || - cont->findMetaData(prefix + "generic:", meta)) - { - emitWarning(cont->file(), cont->line(), msg + " `" + meta + "':\n" + - "serialization can only be used with the array mapping for byte sequences"); - continue; - } - string type = s.substr(clrSerializablePrefix.size()); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(!type.empty() && builtin && builtin->kind() == Builtin::KindByte) - { - newMetaData.push_back(s); - continue; - } - } - } - else if(StructPtr::dynamicCast(cont)) - { - if(s.substr(prefix.size()) == "class") - { - newMetaData.push_back(s); - continue; - } - if(s.substr(prefix.size()) == "property") - { - newMetaData.push_back(s); - continue; - } - static const string clrImplementsPrefix = prefix + "implements:"; - if(s.find(clrImplementsPrefix) == 0) - { - newMetaData.push_back(s); - continue; - } - } - else if(ClassDefPtr::dynamicCast(cont)) - { - if(s.substr(prefix.size()) == "property") - { - newMetaData.push_back(s); - continue; - } - static const string clrImplementsPrefix = prefix + "implements:"; - if(s.find(clrImplementsPrefix) == 0) - { - newMetaData.push_back(s); - continue; - } - } - else if(DictionaryPtr::dynamicCast(cont)) - { - if(s.substr(prefix.size()) == "collection") - { - if(collectionWarnings.find(cont->file()) == collectionWarnings.end()) - { - emitWarning(cont->file(), cont->line(), "the \"" + s + "\" metadata has been deprecated"); - collectionWarnings.insert(cont->file()); - } - newMetaData.push_back(s); - continue; - } - static const string clrGenericPrefix = prefix + "generic:"; - if(s.find(clrGenericPrefix) == 0) - { - string type = s.substr(clrGenericPrefix.size()); - if(type == "SortedDictionary" || type == "SortedList") - { - newMetaData.push_back(s); - continue; - } - } - } - emitWarning(cont->file(), cont->line(), msg + " `" + s + "'"); - continue; - } - - prefix = "cs:"; - if(s.find(prefix) == 0) - { - static const string csAttributePrefix = prefix + "attribute:"; - if(s.find(csAttributePrefix) == 0 && s.size() > csAttributePrefix.size()) - { - newMetaData.push_back(s); - continue; - } - emitWarning(cont->file(), cont->line(), msg + " `" + s + "'"); - continue; - } - newMetaData.push_back(s); - } - cont->setMetaData(newMetaData); -} diff --git a/cpp/src/Slice/DotNetNames.cpp b/cpp/src/Slice/DotNetNames.cpp deleted file mode 100644 index 717996e7b94..00000000000 --- a/cpp/src/Slice/DotNetNames.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Slice/DotNetNames.h> -#include <ctype.h> -#include <cstring> - -using namespace std; - -namespace Slice -{ - -namespace DotNet -{ - -struct Node -{ - const char** names; - const Node** parents; -}; - -static const char* ObjectNames[] = - { - "Equals", "Finalize", "GetHashCode", "GetType", - "MemberwiseClone", "ReferenceEquals", "ToString", 0 - }; -static const Node* ObjectParents[] = - { - 0 - }; -static const Node ObjectNode = - { - ObjectNames, &ObjectParents[0] - }; - -static const char* ICloneableNames[] = - { - "Clone", 0 - }; -static const Node* ICloneableParents[] = - { - &ObjectNode, 0 - }; -static const Node ICloneableNode = - { - ICloneableNames, &ICloneableParents[0] - }; - -static const char* ExceptionNames[] = - { - "Data", "GetBaseException", "GetObjectData", "HelpLink", "HResult", "InnerException", - "Message", "Source", "StackTrace", "TargetSite", 0 - }; -static const Node* ExceptionParents[] = - { - &ObjectNode, 0 - }; -static const Node ExceptionNode = - { - ExceptionNames, &ExceptionParents[0] - }; - -// -// Must be kept in same order as definition of BaseType in header file! -// -static const Node* nodes[] = - { - &ObjectNode, &ICloneableNode, &ExceptionNode - }; - -static bool -ciEquals(const string& s, const char* p) -{ - if(s.size() != strlen(p)) - { - return false; - } - string::const_iterator i = s.begin(); - while(i != s.end()) - { - if(tolower(static_cast<unsigned char>(*i++)) != tolower(static_cast<unsigned char>(*p++))) - { - return false; - } - } - return true; -} - -const char* manglePrefix = "ice_"; -const char* mangleSuffix = "_"; - -static bool -mangle(const string& s, const Node* np, string& newName) -{ - const char** namep = np->names; - while(*namep) - { - if(ciEquals(s, *namep)) - { - newName = manglePrefix + s + mangleSuffix; - return true; - } - ++namep; - } - const Node** parentp = np->parents; - while(*parentp) - { - if(mangle(s, *parentp, newName)) - { - return true; - } - ++parentp; - } - return false; -} - -} - -} - -string -Slice::DotNet::mangleName(const string& s, int baseTypes) -{ - if(baseTypes == 0) - { - return s; - } - string newName; - for(unsigned int mask = 1, i=0; mask < END; mask <<= 1, ++i) - { - if(baseTypes & mask) - { - if(mangle(s, nodes[i], newName)) - { - return newName; - } - } - } - return s; -} diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp index d974b2a8d8d..20dfc7ae93c 100644 --- a/cpp/src/Slice/FileTracker.cpp +++ b/cpp/src/Slice/FileTracker.cpp @@ -7,14 +7,12 @@ // // ********************************************************************** -#include <Slice/FileTracker.h> -#ifdef _WIN32 -# include <direct.h> -#else -# include <unistd.h> -#endif +#include <Slice/FileTracker.h> +#include <IceUtil/ConsoleUtil.h> +#include <IceUtil/FileUtil.h> +using namespace IceUtilInternal; using namespace std; Slice::FileException::FileException(const char* file, int line, const string& r) : @@ -23,16 +21,16 @@ Slice::FileException::FileException(const char* file, int line, const string& r) { } +#ifndef ICE_CPP11_COMPILER Slice::FileException::~FileException() throw() { } - -const char* Slice::FileException::_name = "Slice::FileException"; +#endif string -Slice::FileException::ice_name() const +Slice::FileException::ice_id() const { - return _name; + return "::Slice::FileException"; } void @@ -42,11 +40,13 @@ Slice::FileException::ice_print(ostream& out) const out << ": " << _reason; } +#ifndef ICE_CPP11_MAPPING Slice::FileException* Slice::FileException::ice_clone() const { return new FileException(*this); } +#endif void Slice::FileException::ice_throw() const @@ -93,15 +93,11 @@ Slice::FileTracker::setSource(const string& source) } void -Slice::FileTracker::setOutput(const string& output, bool error) +Slice::FileTracker::error() { - assert(!_source.empty()); - _errors.insert(make_pair(_source, output)); - if(error) - { - _generated.erase(_curr); - _curr = _generated.end(); - } + assert(_curr != _generated.end()); + _generated.erase(_curr); + _curr = _generated.end(); } void @@ -127,19 +123,11 @@ Slice::FileTracker::cleanup() { if(!p->second) { -#ifdef _WIN32 - _unlink(p->first.c_str()); -#else - unlink(p->first.c_str()); -#endif + IceUtilInternal::unlink(p->first); } else { -#ifdef _WIN32 - _rmdir(p->first.c_str()); -#else - rmdir(p->first.c_str()); -#endif + IceUtilInternal::rmdir(p->first); } } } @@ -147,58 +135,19 @@ Slice::FileTracker::cleanup() void Slice::FileTracker::dumpxml() { - cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; - - cout << "<generated>" << endl; - for(map<string, string>::const_iterator p = _errors.begin(); p != _errors.end(); ++p) + consoleOut << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; + consoleOut << "<generated>"; + for(map<string, list<string> >::const_iterator p = _generated.begin(); p != _generated.end(); ++p) { - cout << " <source name=\"" << p->first << "\""; - - map<string, list<string> >::const_iterator q = _generated.find(p->first); - if(q == _generated.end()) + if(!p->second.empty()) { - cout << " error=\"true\">" << endl; - } - else - { - cout << ">" << endl; - for(list<string>::const_iterator r = q->second.begin(); r != q->second.end(); ++r) + consoleOut << endl << " <source name=\"" << p->first << "\">"; + for(list<string>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) { - cout << " <file name=\"" << *r << "\"/>" << endl; + consoleOut << endl << " <file name=\"" << *q << "\"/>"; } - } - cout << " <output>" << escape(p->second) << "</output>" << endl; - cout << " </source>" << endl; - } - cout << "</generated>" << endl; -} - -string -Slice::FileTracker::escape(const string& str) const -{ - ostringstream ostr; - - for(string::const_iterator p = str.begin(); p != str.end(); ++p) - { - switch(*p) - { - case '<': - ostr << "<"; - break; - case '>': - ostr << ">"; - break; - case '&': - ostr << "&"; - break; - case '"': - ostr << """; - break; - default: - ostr << *p; - break; + consoleOut << endl << " </source>"; } } - - return ostr.str(); + consoleOut << endl << "</generated>" << endl; } diff --git a/cpp/src/Slice/FileTracker.h b/cpp/src/Slice/FileTracker.h new file mode 100644 index 00000000000..35151c9d5b3 --- /dev/null +++ b/cpp/src/Slice/FileTracker.h @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef FILE_TRACKER_H +#define FILE_TRACKER_H + +#include <IceUtil/Shared.h> +#include <Slice/Parser.h> + +namespace Slice +{ + +class FileException : public ::IceUtil::Exception +{ +public: + + FileException(const char*, int, const std::string&); +#ifndef ICE_CPP11_COMPILER + ~FileException() throw(); +#endif + virtual std::string ice_id() const; + virtual void ice_print(std::ostream&) const; +#ifndef ICE_CPP11_MAPPING + virtual FileException* ice_clone() const; +#endif + virtual void ice_throw() const; + + std::string reason() const; + +private: + + static const char* _name; + const std::string _reason; +}; + +class FileTracker; +typedef IceUtil::Handle<FileTracker> FileTrackerPtr; + +class FileTracker : public ::IceUtil::SimpleShared +{ +public: + + FileTracker(); + ~FileTracker(); + + static FileTrackerPtr instance(); + + void setSource(const std::string&); + void addFile(const std::string&); + void addDirectory(const std::string&); + void error(); + void cleanup(); + void dumpxml(); + +private: + + std::list<std::pair< std::string, bool> > _files; + std::string _source; + std::map<std::string, std::list<std::string> > _generated; + std::map<std::string, std::list<std::string> >::iterator _curr; +}; + +} + +#endif diff --git a/cpp/src/Slice/Grammar.cpp b/cpp/src/Slice/Grammar.cpp index 45b4fc61250..b94e5582bdf 100644 --- a/cpp/src/Slice/Grammar.cpp +++ b/cpp/src/Slice/Grammar.cpp @@ -1,21 +1,19 @@ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. -/* Skeleton implementation for Bison's Yacc-like parsers in C - - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -28,7 +26,7 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ @@ -46,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.1" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -60,23 +58,17 @@ /* Pull parsers. */ #define YYPULL 1 -/* Using locations. */ -#define YYLSP_NEEDED 0 /* Substitute the variable and function names. */ #define yyparse slice_parse #define yylex slice_lex #define yyerror slice_error -#define yylval slice_lval -#define yychar slice_char #define yydebug slice_debug #define yynerrs slice_nerrs /* Copy the first part of user declarations. */ - -/* Line 189 of yacc.c */ -#line 1 "../Slice/Grammar.y" +#line 1 "src/Slice/Grammar.y" /* yacc.c:339 */ // ********************************************************************** @@ -119,23 +111,24 @@ slice_error(const char* s) if (strcmp(s, "parse error") == 0) { - unit->error("syntax error"); + unit->error("syntax error"); } else { - unit->error(s); + unit->error(s); } } +#line 124 "src/Slice/Grammar.cpp" /* yacc.c:339 */ -/* Line 189 of yacc.c */ -#line 134 "Grammar.tab.c" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif +# ifndef YY_NULLPTR +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -145,78 +138,85 @@ slice_error(const char* s) # define YYERROR_VERBOSE 0 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* In a future release of Bison, this section will be replaced + by #include "Grammar.hpp". */ +#ifndef YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED +# define YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int slice_debug; #endif - -/* Tokens. */ +/* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - ICE_MODULE = 258, - ICE_CLASS = 259, - ICE_INTERFACE = 260, - ICE_EXCEPTION = 261, - ICE_STRUCT = 262, - ICE_SEQUENCE = 263, - ICE_DICTIONARY = 264, - ICE_ENUM = 265, - ICE_OUT = 266, - ICE_EXTENDS = 267, - ICE_IMPLEMENTS = 268, - ICE_THROWS = 269, - ICE_VOID = 270, - ICE_BYTE = 271, - ICE_BOOL = 272, - ICE_SHORT = 273, - ICE_INT = 274, - ICE_LONG = 275, - ICE_FLOAT = 276, - ICE_DOUBLE = 277, - ICE_STRING = 278, - ICE_OBJECT = 279, - ICE_LOCAL_OBJECT = 280, - ICE_LOCAL = 281, - ICE_CONST = 282, - ICE_FALSE = 283, - ICE_TRUE = 284, - ICE_IDEMPOTENT = 285, - ICE_OPTIONAL = 286, - ICE_SCOPE_DELIMITER = 287, - ICE_IDENTIFIER = 288, - ICE_STRING_LITERAL = 289, - ICE_INTEGER_LITERAL = 290, - ICE_FLOATING_POINT_LITERAL = 291, - ICE_IDENT_OP = 292, - ICE_KEYWORD_OP = 293, - ICE_OPTIONAL_OP = 294, - ICE_METADATA_OPEN = 295, - ICE_METADATA_CLOSE = 296, - ICE_GLOBAL_METADATA_OPEN = 297, - ICE_GLOBAL_METADATA_CLOSE = 298, - BAD_CHAR = 299 - }; + enum yytokentype + { + ICE_MODULE = 258, + ICE_CLASS = 259, + ICE_INTERFACE = 260, + ICE_EXCEPTION = 261, + ICE_STRUCT = 262, + ICE_SEQUENCE = 263, + ICE_DICTIONARY = 264, + ICE_ENUM = 265, + ICE_OUT = 266, + ICE_EXTENDS = 267, + ICE_IMPLEMENTS = 268, + ICE_THROWS = 269, + ICE_VOID = 270, + ICE_BYTE = 271, + ICE_BOOL = 272, + ICE_SHORT = 273, + ICE_INT = 274, + ICE_LONG = 275, + ICE_FLOAT = 276, + ICE_DOUBLE = 277, + ICE_STRING = 278, + ICE_OBJECT = 279, + ICE_LOCAL_OBJECT = 280, + ICE_LOCAL = 281, + ICE_CONST = 282, + ICE_FALSE = 283, + ICE_TRUE = 284, + ICE_IDEMPOTENT = 285, + ICE_OPTIONAL = 286, + ICE_VALUE = 287, + ICE_SCOPE_DELIMITER = 288, + ICE_IDENTIFIER = 289, + ICE_STRING_LITERAL = 290, + ICE_INTEGER_LITERAL = 291, + ICE_FLOATING_POINT_LITERAL = 292, + ICE_IDENT_OP = 293, + ICE_KEYWORD_OP = 294, + ICE_OPTIONAL_OP = 295, + ICE_METADATA_OPEN = 296, + ICE_METADATA_CLOSE = 297, + ICE_GLOBAL_METADATA_OPEN = 298, + ICE_GLOBAL_METADATA_CLOSE = 299, + BAD_CHAR = 300 + }; #endif - - +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef int YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif -/* Copy the second part of user declarations. */ +int slice_parse (void); + +#endif /* !YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED */ + +/* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ -#line 220 "Grammar.tab.c" +#line 220 "src/Slice/Grammar.cpp" /* yacc.c:358 */ #ifdef short # undef short @@ -230,11 +230,8 @@ typedef unsigned char yytype_uint8; #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -typedef signed char yytype_int8; #else -typedef short int yytype_int8; +typedef signed char yytype_int8; #endif #ifdef YYTYPE_UINT16 @@ -254,8 +251,7 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# elif ! defined YYSIZE_T # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -266,42 +262,71 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE +# if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +# else +# define YY_ATTRIBUTE(Spec) /* empty */ +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#endif + +#if !defined _Noreturn \ + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +# if defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(n) (n) +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") #else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int yyi) -#else -static int -YYID (yyi) - int yyi; +# define YY_INITIAL_VALUE(Value) Value #endif -{ - return yyi; -} +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif + #if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -319,11 +344,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -331,8 +356,8 @@ YYID (yyi) # endif # ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely @@ -346,25 +371,23 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) + && (defined YYFREE || defined free))) # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined malloc && ! defined EXIT_SUCCESS void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined free && ! defined EXIT_SUCCESS void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif @@ -374,7 +397,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -392,79 +415,85 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 13 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 886 +#define YYLAST 954 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 54 +#define YYNTOKENS 55 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 72 +#define YYNNTS 73 /* YYNRULES -- Number of rules. */ -#define YYNRULES 202 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 301 +#define YYNRULES 206 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 305 -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 299 +#define YYMAXUTOK 300 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, without out-of-bounds checking. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 48, 53, 2, 50, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 45, - 51, 49, 52, 2, 2, 2, 2, 2, 2, 2, + 2, 49, 54, 2, 51, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 46, + 52, 50, 53, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 46, 2, 47, 2, 2, 2, 2, + 2, 2, 2, 47, 2, 48, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -481,129 +510,39 @@ static const yytype_uint8 yytranslate[] = 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45 }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint16 yyprhs[] = -{ - 0, 0, 3, 5, 9, 13, 14, 15, 19, 20, - 26, 27, 32, 35, 36, 38, 40, 42, 44, 46, - 48, 50, 52, 54, 56, 58, 60, 62, 63, 70, - 73, 76, 79, 80, 88, 91, 92, 97, 101, 104, - 105, 108, 112, 116, 119, 121, 124, 126, 128, 131, - 134, 137, 138, 145, 150, 154, 157, 158, 160, 163, - 166, 171, 176, 178, 181, 182, 191, 194, 195, 198, - 199, 204, 208, 211, 212, 214, 218, 221, 223, 225, - 229, 232, 237, 240, 242, 245, 247, 249, 252, 256, - 259, 263, 264, 270, 271, 277, 279, 281, 284, 287, - 290, 291, 299, 303, 305, 307, 310, 311, 316, 320, - 323, 324, 326, 330, 332, 334, 336, 344, 352, 363, - 374, 377, 380, 381, 388, 394, 398, 400, 402, 406, - 408, 409, 411, 413, 415, 416, 417, 421, 427, 432, - 439, 443, 449, 452, 453, 455, 458, 462, 464, 466, - 468, 470, 472, 474, 476, 478, 480, 483, 485, 487, - 490, 493, 495, 499, 501, 503, 504, 506, 508, 510, - 512, 514, 516, 523, 529, 531, 533, 535, 537, 539, - 541, 543, 545, 547, 549, 551, 553, 555, 557, 559, - 561, 563, 565, 567, 569, 571, 573, 575, 577, 579, - 581, 583, 585 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int8 yyrhs[] = -{ - 55, 0, -1, 58, -1, 42, 121, 43, -1, 40, - 121, 41, -1, -1, -1, 56, 59, 58, -1, -1, - 57, 62, 60, 45, 58, -1, -1, 1, 45, 61, - 58, -1, 57, 62, -1, -1, 63, -1, 83, -1, - 84, -1, 98, -1, 99, -1, 66, -1, 67, -1, - 76, -1, 77, -1, 107, -1, 108, -1, 110, -1, - 124, -1, -1, 3, 33, 64, 46, 58, 47, -1, - 6, 33, -1, 6, 125, -1, 122, 65, -1, -1, - 122, 65, 69, 68, 46, 70, 47, -1, 12, 118, - -1, -1, 57, 74, 45, 70, -1, 1, 45, 70, - -1, 57, 74, -1, -1, 119, 33, -1, 39, 35, - 48, -1, 39, 118, 48, -1, 39, 48, -1, 31, - -1, 72, 71, -1, 71, -1, 89, -1, 7, 33, - -1, 7, 125, -1, 122, 75, -1, -1, 122, 75, - 78, 46, 79, 47, -1, 57, 80, 45, 79, -1, - 1, 45, 79, -1, 57, 80, -1, -1, 90, -1, - 4, 33, -1, 4, 125, -1, 4, 37, 35, 48, - -1, 4, 37, 118, 48, -1, 81, -1, 122, 81, - -1, -1, 122, 82, 86, 87, 85, 46, 88, 47, - -1, 12, 118, -1, -1, 13, 101, -1, -1, 57, - 96, 45, 88, -1, 1, 45, 88, -1, 57, 96, - -1, -1, 73, -1, 73, 49, 123, -1, 119, 125, - -1, 119, -1, 71, -1, 71, 49, 123, -1, 72, - 71, -1, 72, 71, 49, 123, -1, 119, 125, -1, - 119, -1, 72, 119, -1, 119, -1, 15, -1, 91, - 37, -1, 30, 91, 37, -1, 91, 38, -1, 30, - 91, 38, -1, -1, 92, 116, 48, 94, 117, -1, - -1, 92, 1, 48, 95, 117, -1, 89, -1, 93, - -1, 5, 33, -1, 5, 125, -1, 122, 97, -1, - -1, 122, 97, 102, 100, 46, 103, 47, -1, 118, - 50, 101, -1, 118, -1, 24, -1, 12, 101, -1, - -1, 57, 104, 45, 103, -1, 1, 45, 103, -1, - 57, 104, -1, -1, 93, -1, 106, 50, 105, -1, - 106, -1, 118, -1, 125, -1, 122, 8, 51, 57, - 119, 52, 33, -1, 122, 8, 51, 57, 119, 52, - 125, -1, 122, 9, 51, 57, 119, 50, 57, 119, - 52, 33, -1, 122, 9, 51, 57, 119, 50, 57, - 119, 52, 125, -1, 10, 33, -1, 10, 125, -1, - -1, 122, 109, 111, 46, 112, 47, -1, 122, 10, - 46, 112, 47, -1, 113, 50, 112, -1, 113, -1, - 33, -1, 33, 49, 114, -1, 125, -1, -1, 35, - -1, 118, -1, 11, -1, -1, -1, 115, 57, 73, - -1, 116, 50, 115, 57, 73, -1, 115, 57, 119, - 125, -1, 116, 50, 115, 57, 119, 125, -1, 115, - 57, 119, -1, 116, 50, 115, 57, 119, -1, 14, - 105, -1, -1, 33, -1, 32, 33, -1, 118, 32, - 33, -1, 16, -1, 17, -1, 18, -1, 19, -1, - 20, -1, 21, -1, 22, -1, 23, -1, 24, -1, - 24, 53, -1, 25, -1, 118, -1, 118, 53, -1, - 34, 120, -1, 34, -1, 121, 50, 120, -1, 120, - -1, 26, -1, -1, 35, -1, 36, -1, 118, -1, - 34, -1, 28, -1, 29, -1, 27, 57, 119, 33, - 49, 123, -1, 27, 57, 119, 49, 123, -1, 3, - -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, - -1, 9, -1, 10, -1, 11, -1, 12, -1, 13, - -1, 14, -1, 15, -1, 16, -1, 17, -1, 18, - -1, 19, -1, 20, -1, 21, -1, 22, -1, 23, - -1, 24, -1, 25, -1, 26, -1, 27, -1, 28, - -1, 29, -1, 30, -1, 31, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 114, 114, 122, 131, 136, 145, 144, 154, 153, - 164, 163, 168, 173, 180, 184, 188, 192, 196, 200, - 204, 208, 212, 216, 220, 224, 228, 238, 237, 271, - 275, 286, 297, 296, 323, 332, 340, 349, 352, 357, - 364, 377, 397, 453, 461, 474, 482, 497, 503, 507, - 518, 529, 528, 570, 579, 582, 587, 594, 600, 604, - 615, 640, 705, 717, 731, 730, 770, 805, 813, 818, - 826, 835, 838, 843, 850, 872, 899, 921, 947, 956, - 967, 976, 985, 995, 1009, 1015, 1023, 1035, 1059, 1084, - 1108, 1139, 1138, 1161, 1160, 1183, 1184, 1190, 1194, 1205, - 1220, 1219, 1254, 1289, 1324, 1334, 1339, 1347, 1356, 1359, - 1364, 1371, 1377, 1384, 1396, 1408, 1419, 1428, 1443, 1454, - 1471, 1475, 1487, 1486, 1510, 1525, 1531, 1539, 1551, 1574, - 1582, 1591, 1595, 1634, 1641, 1652, 1654, 1670, 1686, 1698, - 1710, 1721, 1737, 1742, 1750, 1753, 1759, 1772, 1776, 1780, - 1784, 1788, 1792, 1796, 1800, 1804, 1808, 1812, 1816, 1835, - 1876, 1882, 1890, 1897, 1909, 1916, 1926, 1939, 1952, 1998, - 2009, 2020, 2036, 2045, 2059, 2062, 2065, 2068, 2071, 2074, - 2077, 2080, 2083, 2086, 2089, 2092, 2095, 2098, 2101, 2104, - 2107, 2110, 2113, 2116, 2119, 2122, 2125, 2128, 2131, 2134, - 2137, 2140, 2143 + 0, 115, 115, 123, 132, 137, 146, 145, 155, 154, + 165, 164, 169, 174, 181, 185, 189, 193, 197, 201, + 205, 209, 213, 217, 221, 225, 229, 239, 238, 272, + 276, 287, 298, 297, 324, 333, 341, 350, 353, 358, + 365, 378, 398, 491, 499, 512, 520, 535, 541, 545, + 556, 567, 566, 608, 617, 620, 625, 632, 638, 642, + 653, 678, 780, 792, 806, 805, 845, 880, 888, 893, + 901, 910, 913, 918, 925, 947, 974, 996, 1022, 1031, + 1042, 1051, 1060, 1070, 1084, 1090, 1098, 1110, 1134, 1159, + 1183, 1214, 1213, 1236, 1235, 1258, 1259, 1265, 1269, 1280, + 1295, 1294, 1329, 1364, 1399, 1404, 1414, 1419, 1427, 1436, + 1439, 1444, 1451, 1457, 1464, 1476, 1488, 1499, 1508, 1523, + 1534, 1551, 1555, 1567, 1566, 1599, 1598, 1617, 1623, 1631, + 1643, 1663, 1671, 1680, 1684, 1723, 1730, 1741, 1743, 1759, + 1775, 1787, 1799, 1810, 1826, 1831, 1839, 1842, 1848, 1861, + 1865, 1869, 1873, 1877, 1881, 1885, 1889, 1893, 1897, 1901, + 1905, 1909, 1928, 1969, 1975, 1983, 1990, 2002, 2009, 2019, + 2032, 2045, 2092, 2103, 2114, 2130, 2139, 2153, 2156, 2159, + 2162, 2165, 2168, 2171, 2174, 2177, 2180, 2183, 2186, 2189, + 2192, 2195, 2198, 2201, 2204, 2207, 2210, 2213, 2216, 2219, + 2222, 2225, 2228, 2231, 2234, 2237, 2240 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -614,7 +553,7 @@ static const char *const yytname[] = "ICE_THROWS", "ICE_VOID", "ICE_BYTE", "ICE_BOOL", "ICE_SHORT", "ICE_INT", "ICE_LONG", "ICE_FLOAT", "ICE_DOUBLE", "ICE_STRING", "ICE_OBJECT", "ICE_LOCAL_OBJECT", "ICE_LOCAL", "ICE_CONST", "ICE_FALSE", "ICE_TRUE", - "ICE_IDEMPOTENT", "ICE_OPTIONAL", "ICE_SCOPE_DELIMITER", + "ICE_IDEMPOTENT", "ICE_OPTIONAL", "ICE_VALUE", "ICE_SCOPE_DELIMITER", "ICE_IDENTIFIER", "ICE_STRING_LITERAL", "ICE_INTEGER_LITERAL", "ICE_FLOATING_POINT_LITERAL", "ICE_IDENT_OP", "ICE_KEYWORD_OP", "ICE_OPTIONAL_OP", "ICE_METADATA_OPEN", "ICE_METADATA_CLOSE", @@ -632,498 +571,465 @@ static const char *const yytname[] = "interface_id", "interface_decl", "interface_def", "@10", "interface_list", "interface_extends", "interface_exports", "interface_export", "exception_list", "exception", "sequence_def", - "dictionary_def", "enum_id", "enum_def", "@11", "enumerator_list", + "dictionary_def", "enum_id", "enum_def", "@11", "@12", "enumerator_list", "enumerator", "enumerator_initializer", "out_qualifier", "parameters", "throws", "scoped_name", "type", "string_literal", "string_list", - "local_qualifier", "const_initializer", "const_def", "keyword", 0 + "local_qualifier", "const_initializer", "const_def", "keyword", YY_NULLPTR }; #endif # ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 59, 123, 125, 41, 61, - 44, 60, 62, 42 + 295, 296, 297, 298, 299, 300, 59, 123, 125, 41, + 61, 44, 60, 62, 42 }; # endif -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 54, 55, 56, 57, 57, 59, 58, 60, 58, - 61, 58, 58, 58, 62, 62, 62, 62, 62, 62, - 62, 62, 62, 62, 62, 62, 62, 64, 63, 65, - 65, 66, 68, 67, 69, 69, 70, 70, 70, 70, - 71, 72, 72, 72, 72, 73, 73, 74, 75, 75, - 76, 78, 77, 79, 79, 79, 79, 80, 81, 81, - 82, 82, 82, 83, 85, 84, 86, 86, 87, 87, - 88, 88, 88, 88, 89, 89, 89, 89, 90, 90, - 90, 90, 90, 90, 91, 91, 91, 92, 92, 92, - 92, 94, 93, 95, 93, 96, 96, 97, 97, 98, - 100, 99, 101, 101, 101, 102, 102, 103, 103, 103, - 103, 104, 105, 105, 106, 106, 107, 107, 108, 108, - 109, 109, 111, 110, 110, 112, 112, 113, 113, 113, - 113, 114, 114, 115, 115, 116, 116, 116, 116, 116, - 116, 116, 117, 117, 118, 118, 118, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 120, 120, 121, 121, 122, 122, 123, 123, 123, 123, - 123, 123, 124, 124, 125, 125, 125, 125, 125, 125, - 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, - 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, - 125, 125, 125 -}; +#define YYPACT_NINF -214 -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-214))) + +#define YYTABLE_NINF -138 + +#define yytable_value_is_error(Yytable_value) \ + 0 + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = { - 0, 2, 1, 3, 3, 0, 0, 3, 0, 5, - 0, 4, 2, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 0, 6, 2, - 2, 2, 0, 7, 2, 0, 4, 3, 2, 0, - 2, 3, 3, 2, 1, 2, 1, 1, 2, 2, - 2, 0, 6, 4, 3, 2, 0, 1, 2, 2, - 4, 4, 1, 2, 0, 8, 2, 0, 2, 0, - 4, 3, 2, 0, 1, 3, 2, 1, 1, 3, - 2, 4, 2, 1, 2, 1, 1, 2, 3, 2, - 3, 0, 5, 0, 5, 1, 1, 2, 2, 2, - 0, 7, 3, 1, 1, 2, 0, 4, 3, 2, - 0, 1, 3, 1, 1, 1, 7, 7, 10, 10, - 2, 2, 0, 6, 5, 3, 1, 1, 3, 1, - 0, 1, 1, 1, 0, 0, 3, 5, 4, 6, - 3, 5, 2, 0, 1, 2, 3, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, - 2, 1, 3, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 6, 5, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1 + 454, 23, 44, 44, 83, -214, 19, -214, -214, 44, + -214, -9, 38, -214, 122, 51, -214, 52, 46, -214, + -214, -214, -214, -214, -214, -214, -214, -214, -214, -214, + -214, 129, -214, 122, -214, -214, 44, -214, -214, -214, + 920, 49, 532, 600, 632, 664, 56, 59, 696, 0, + 68, 11, 104, 1, -214, -214, -214, 72, -214, -214, + -214, -214, -214, -214, -214, -214, 66, -214, -214, 87, + -214, 8, 10, 122, -214, -214, -214, -214, -214, -214, + -214, -214, -214, -214, -214, -214, -214, -214, -214, -214, + -214, -214, -214, -214, -214, -214, -214, -214, -214, -214, + -214, -214, -214, -214, -214, -2, -214, -214, -214, -214, + -214, -214, -214, 52, 52, -214, 94, -214, 40, -214, + 96, 40, 131, 43, -214, 98, 443, -214, -214, 116, + -214, 67, 70, -214, 102, 31, 920, 920, 728, 120, + 107, 363, 120, 43, -214, -214, -214, -214, -8, 108, + 728, 110, -214, 70, -214, -214, -214, -214, -214, 120, + -214, -214, -214, 103, 109, 111, 118, 117, -214, 397, + 121, 895, 124, -214, 126, 43, 295, 127, -214, -214, + 760, 52, 54, -214, 728, 123, 895, 134, 363, -214, + 2, 133, 920, 128, -214, 792, -214, 329, -214, 138, + 844, 137, -214, -214, -214, 920, -214, -214, 120, -214, + 397, -214, 920, 136, 142, -214, 792, -214, -214, 130, + -214, 32, 70, 139, 143, 363, -214, -214, 144, 844, + 146, 295, -214, 870, 920, 63, 258, -214, 145, -214, + -214, 147, -214, -214, 70, 397, -214, -214, -214, -214, + 70, -214, 329, 920, -214, -214, 149, 495, -214, -214, + 71, -214, -214, -214, 148, -214, 52, -22, 295, 824, + -214, -214, -214, -214, 143, 329, -214, -214, -214, 895, + -214, 181, -214, -214, -214, -214, 182, -214, 792, 182, + 52, 568, -214, -214, -214, 895, -214, 150, 120, -214, + -214, 792, 568, -214, -214 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ static const yytype_uint8 yydefact[] = { - 0, 0, 0, 0, 0, 6, 165, 2, 10, 161, - 163, 0, 0, 1, 0, 0, 164, 5, 12, 14, + 0, 0, 0, 0, 0, 6, 168, 2, 10, 164, + 166, 0, 0, 1, 0, 0, 167, 5, 12, 14, 19, 20, 21, 22, 15, 16, 17, 18, 23, 24, - 25, 0, 26, 0, 160, 4, 0, 3, 7, 27, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, - 50, 62, 67, 99, 122, 11, 162, 0, 147, 148, - 149, 150, 151, 152, 153, 154, 155, 157, 0, 144, - 158, 0, 0, 174, 175, 176, 177, 178, 179, 180, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, - 201, 202, 58, 0, 59, 97, 98, 29, 30, 48, - 49, 5, 5, 120, 130, 121, 0, 32, 0, 0, - 69, 0, 100, 0, 0, 156, 145, 0, 159, 0, - 0, 9, 0, 0, 0, 0, 127, 0, 126, 129, - 34, 0, 0, 66, 0, 64, 104, 105, 103, 0, - 130, 0, 146, 0, 170, 171, 169, 166, 167, 168, - 173, 60, 61, 0, 0, 0, 124, 130, 0, 0, - 0, 0, 68, 0, 0, 0, 0, 28, 172, 0, - 5, 131, 128, 132, 125, 0, 0, 0, 0, 44, + 25, 0, 26, 0, 163, 4, 0, 3, 7, 27, + 0, 0, 0, 0, 0, 0, 0, 0, 125, 31, + 50, 62, 67, 99, 123, 11, 165, 0, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 159, 160, 0, + 146, 161, 0, 0, 177, 178, 179, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, + 203, 204, 205, 206, 58, 0, 59, 97, 98, 29, + 30, 48, 49, 5, 5, 121, 0, 122, 0, 32, + 0, 0, 69, 0, 100, 0, 0, 158, 147, 0, + 162, 0, 0, 9, 0, 0, 0, 0, 132, 34, + 0, 0, 66, 0, 64, 104, 105, 106, 103, 0, + 132, 0, 148, 0, 173, 174, 172, 169, 170, 171, + 176, 60, 61, 0, 0, 129, 0, 128, 131, 0, + 0, 0, 0, 68, 0, 0, 0, 0, 28, 175, + 0, 5, 0, 126, 132, 0, 0, 0, 0, 44, 0, 78, 0, 55, 57, 83, 52, 0, 102, 0, - 0, 0, 123, 116, 117, 0, 0, 46, 0, 74, - 38, 47, 77, 33, 54, 0, 43, 0, 0, 80, - 0, 0, 40, 82, 0, 0, 0, 0, 86, 0, - 0, 0, 0, 111, 109, 85, 101, 0, 37, 45, - 0, 0, 76, 41, 42, 79, 0, 53, 0, 0, - 95, 96, 72, 77, 65, 108, 0, 84, 87, 89, - 0, 133, 5, 0, 0, 0, 75, 36, 81, 71, - 84, 0, 88, 90, 93, 0, 91, 134, 107, 118, - 119, 70, 143, 136, 140, 143, 5, 0, 94, 138, - 92, 0, 142, 113, 114, 115, 137, 141, 0, 139, - 112 + 0, 0, 124, 117, 118, 0, 133, 130, 134, 127, + 0, 46, 0, 74, 38, 47, 77, 33, 54, 0, + 43, 0, 0, 80, 0, 0, 40, 82, 0, 0, + 0, 0, 86, 0, 0, 0, 0, 112, 110, 85, + 101, 0, 37, 45, 0, 0, 76, 41, 42, 79, + 0, 53, 0, 0, 95, 96, 72, 77, 65, 109, + 0, 84, 87, 89, 0, 135, 5, 0, 0, 0, + 75, 36, 81, 71, 84, 0, 88, 90, 93, 0, + 91, 136, 108, 119, 120, 70, 145, 138, 142, 145, + 5, 0, 94, 140, 92, 0, 144, 114, 115, 116, + 139, 143, 0, 141, 113 }; -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 4, 5, 6, 7, 14, 41, 33, 18, 19, - 57, 49, 20, 21, 141, 117, 187, 207, 208, 209, - 210, 50, 22, 23, 118, 171, 193, 51, 52, 24, - 25, 173, 120, 145, 226, 211, 194, 231, 232, 233, - 285, 282, 252, 53, 26, 27, 149, 147, 122, 201, - 234, 292, 293, 28, 29, 54, 30, 123, 137, 138, - 182, 262, 263, 288, 70, 220, 10, 11, 31, 160, - 32, 139 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -227 -static const yytype_int16 yypact[] = + /* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = { - 126, -16, 4, 4, 65, -227, 21, -227, -227, 4, - -227, -10, -11, -227, 73, 38, -227, 46, 58, -227, - -227, -227, -227, -227, -227, -227, -227, -227, -227, -227, - -227, 291, -227, 73, -227, -227, 4, -227, -227, -227, - 853, 61, 559, 625, 656, 687, 59, 63, 479, 6, - 77, 9, 99, 11, -227, -227, -227, 82, -227, -227, - -227, -227, -227, -227, -227, -227, 84, -227, 106, -227, - 5, 26, 73, -227, -227, -227, -227, -227, -227, -227, - -227, -227, -227, -227, -227, -227, -227, -227, -227, -227, - -227, -227, -227, -227, -227, -227, -227, -227, -227, -227, - -227, -227, -227, 29, -227, -227, -227, -227, -227, -227, - -227, 46, 46, -227, 718, -227, 1, -227, 94, 1, - 129, 3, -227, 100, 434, -227, -227, 112, -227, 98, - 158, -227, 101, 37, 853, 853, 105, 103, 110, -227, - 116, 109, 356, 116, 3, -227, -227, -227, -6, 115, - 718, 117, -227, 158, -227, -227, -227, -227, -227, 116, - -227, -227, -227, 104, 119, 86, -227, 718, 389, 120, - 829, 123, -227, 121, 3, 290, 125, -227, -227, 749, - 46, -227, -227, 116, -227, 130, 829, 132, 356, -227, - 69, 113, 853, 131, -227, 780, -227, 323, -227, 136, - 432, 135, -227, -227, -227, 853, 389, -227, 853, 128, - 138, -227, 780, -227, -227, 140, -227, 57, 158, 146, - 151, 356, -227, -227, 152, 432, 153, 290, -227, 219, - 853, 54, 254, -227, 154, -227, -227, 149, -227, -227, - 158, 389, -227, -227, -227, -227, 158, -227, 323, 853, - -227, -227, 160, 523, -227, -227, 60, -227, -227, -227, - 159, -227, 46, 74, 290, 811, -227, -227, -227, -227, - 151, 323, -227, -227, -227, 829, -227, 195, -227, -227, - -227, -227, 194, -227, 780, 194, 46, 594, -227, -227, - -227, 829, -227, 161, 116, -227, -227, 780, 594, -227, - -227 + -214, -214, -214, -17, -12, -214, -214, -214, -214, -214, + -214, -214, -214, -214, -214, -214, -187, -162, -163, -211, + -214, -214, -214, -214, -214, -173, -214, -214, -214, -214, + -214, -214, -214, -214, -212, -30, -214, -31, -214, -26, + -214, -214, -214, -214, -214, -214, -214, -119, -214, -213, + -214, -98, -214, -214, -214, -214, -214, -214, -214, -130, + -214, -214, -75, -214, -82, -104, -24, 17, 208, -214, + -150, -214, -38 }; -/* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = { - -227, -227, -227, -17, -12, -227, -227, -227, -227, -227, - -227, -227, -227, -227, -227, -227, -191, -162, -159, -182, - -227, -227, -227, -227, -227, -168, -227, -227, -227, -227, - -227, -227, -227, -227, -226, -13, -227, -20, -227, -9, - -227, -227, -227, -227, -227, -227, -227, -119, -227, -215, - -227, -85, -227, -227, -227, -227, -227, -227, -83, -227, - -227, -63, -227, -68, -102, -27, 7, 215, -227, -150, - -227, -38 + -1, 4, 5, 6, 7, 14, 41, 33, 18, 19, + 57, 49, 20, 21, 140, 119, 187, 211, 212, 213, + 214, 50, 22, 23, 120, 172, 193, 51, 52, 24, + 25, 174, 122, 144, 230, 215, 194, 235, 236, 237, + 289, 286, 256, 53, 26, 27, 149, 147, 124, 201, + 238, 296, 297, 28, 29, 54, 30, 125, 116, 166, + 167, 207, 266, 267, 292, 71, 224, 10, 11, 31, + 160, 32, 168 }; -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -136 + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 40, 133, 38, 178, 104, 106, 108, 110, 191, -63, - 115, 192, 255, 71, 140, 238, 34, 143, 116, 148, - 214, 55, 269, 121, 15, 172, 127, 146, 159, 8, - 219, 35, 37, 68, 69, 68, 69, 127, 9, 36, - 36, 230, 148, 56, 174, 281, 239, 16, 17, 278, - 267, 159, -35, 247, -63, 198, -63, -106, 128, 129, - 131, 68, 69, 183, 132, 13, 249, 176, 245, 127, - 230, 39, 148, -13, 1, 130, -5, -5, -5, -5, - -5, -5, -5, -5, 184, 162, 2, 239, 217, 127, - 266, 258, 259, 283, 134, 135, 268, 272, 273, -5, - -5, 68, 69, -8, 215, 244, 72, 163, 164, 296, - 111, 119, 151, 2, 112, 3, 159, 216, 68, 69, - -13, 181, 276, -51, 277, 170, -13, 1, 124, -5, - -5, -5, -5, -5, -5, -5, -5, 125, 159, 126, - 142, 204, 144, 195, 159, 152, 150, 153, 127, 161, - 166, 186, -5, -5, 165, 168, 179, 223, 200, 212, - 167, 175, 218, 205, 177, 188, 2, 197, 3, 180, - 196, 170, 202, 235, 242, 206, 221, 240, 237, 213, - 225, 227, 236, 241, 222, 294, 154, 155, 243, 186, - 68, 69, 156, 157, 158, 246, 294, 248, 253, 264, - 254, 265, 235, 257, 170, 271, 261, 274, 287, 256, - 200, 298, 250, 300, 286, 242, 251, 290, 12, 0, - 0, 0, 270, 0, 186, 0, 0, 280, 0, 0, - 0, 225, 0, 0, 228, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 275, 289, 200, 284, 295, - 189, 68, 69, 0, 225, 260, 0, 0, 190, 299, - 295, 0, 0, 0, 297, 261, 0, 0, 0, 291, - -134, -134, -134, -134, -134, -134, -134, -134, -134, -134, - 0, 0, 0, 0, 0, -134, -134, -134, 0, 0, - 0, 199, 0, -134, -134, 42, 43, 44, 45, 46, - 47, 48, -135, 0, -135, -5, -5, -5, -5, -5, - -5, -5, -5, -5, -5, -5, 0, 0, 0, 0, - -5, -5, -5, -5, 224, 0, 0, 0, 0, -5, - 2, 0, 0, 0, 0, 0, 0, -110, -5, -5, + 40, 135, 38, 179, 106, 108, 110, 112, 192, 191, + 117, -63, 118, 123, 139, 218, 72, 142, 259, 148, + 177, 55, 15, 242, 173, 129, 34, 280, 159, 281, + 223, 69, 70, 35, 134, 69, 70, 234, 219, 148, + 273, 129, 36, 175, 131, 16, 17, -35, -107, 159, + 243, 220, 251, 56, 209, 282, 198, -63, 271, -63, + 132, 133, 130, 285, 129, 129, 253, 145, 287, 8, + 234, 148, 249, 69, 70, 146, 69, 70, 208, 9, + 162, 248, 37, 13, 300, 39, 221, 69, 70, 36, + 206, 243, -8, 2, 270, 73, 136, 137, 154, 155, + 272, 262, 263, 69, 70, 156, 157, 158, 113, 276, + 277, 114, 163, 164, 151, -51, 121, 153, 159, 126, + 127, 128, -13, 1, 171, -5, -5, -5, -5, -5, + -5, -5, -5, 42, 43, 44, 45, 46, 47, 48, + 159, 138, 204, 141, 143, 150, 159, 195, -5, -5, + 152, 161, 186, 129, 169, 176, 180, 227, 178, 200, + 181, 182, 216, 2, 205, 3, 183, 188, 184, 210, + -13, 171, 196, 197, 225, 202, 239, 226, 246, 247, + 229, 241, 217, 222, 231, 240, 244, 298, 245, 250, + 252, 268, 265, 186, 258, 275, 291, 278, 298, 254, + 269, 302, 260, 255, 304, 257, 290, 294, 171, 239, + 261, 12, 0, 0, 200, 0, 0, 0, 0, 246, + 0, 0, 0, 0, 0, 0, 0, 0, 186, 274, + 0, 284, 0, 0, 0, 229, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 279, + 293, 200, 0, 299, 0, 288, 0, 0, 229, 264, + 0, 0, 0, 303, 299, 0, 0, 0, 0, 265, + 0, 301, 0, 295, -136, -136, -136, -136, -136, -136, + -136, -136, -136, -136, 0, 0, 0, 0, 0, -136, + -136, -136, -136, 0, 0, 0, 199, 0, -136, -136, + 0, 0, 0, 0, 0, 0, 0, -137, 0, -137, + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, + -5, 0, 0, 0, 0, -5, -5, -5, -5, -5, + 228, 0, 0, 0, 0, -5, 2, 0, 0, 0, + 0, 0, 0, -111, -5, -5, -5, -5, -5, -5, + -5, -5, -5, -5, -5, 0, 0, 0, 0, -5, + -5, -5, -5, -5, 170, 0, 0, 0, 0, -5, + 2, 0, 0, 0, 0, 0, 0, -73, 0, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, 0, - 0, 0, 0, -5, -5, -5, -5, 169, 0, 0, - 0, 0, -5, 2, 0, 0, 0, 0, 0, 0, - -73, 0, -5, -5, -5, -5, -5, -5, -5, -5, - -5, -5, 0, 0, 0, 0, 0, -5, -5, -5, - 185, 0, 0, 0, 0, -5, 2, 0, 0, 0, - 0, 0, 0, -56, 0, -5, -5, -5, -5, -5, - -5, -5, -5, -5, -5, 0, 0, 0, 0, 0, - -5, -5, -5, 0, 0, 0, 0, 0, -5, 2, - 0, 0, 0, 0, 0, 1, -39, -5, -5, -5, - -5, -5, -5, -5, -5, 0, 0, 228, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 0, 0, - -5, -5, 229, 189, 68, 69, 0, 0, 0, 0, - 0, 190, 0, 0, 2, 0, 3, 0, 0, 0, - 0, -13, 73, 74, 75, 76, 77, 78, 79, 80, + 0, 0, 0, 0, -5, -5, -5, -5, 185, 0, + 0, 0, 0, -5, 2, 0, 0, 0, 0, 0, + 0, -56, 0, -5, -5, -5, -5, -5, -5, -5, + -5, -5, -5, 0, 0, 0, 0, 0, -5, -5, + -5, -5, 0, 0, 0, 0, 0, -5, 2, 0, + 0, 0, 0, 0, 1, -39, -5, -5, -5, -5, + -5, -5, -5, -5, -13, 1, 0, -5, -5, -5, + -5, -5, -5, -5, -5, 0, 0, 0, 0, -5, + -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -5, -5, 0, 0, 2, 0, 3, 0, 0, 0, + 0, -13, 0, 0, 0, 2, 0, 3, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 0, 226, + 0, 0, 0, -85, -85, 74, 75, 76, 77, 78, + 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 0, 104, 0, 0, 0, + 105, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 69, 70, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 0, 113, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 114, 73, 74, 75, 76, + 101, 102, 103, 0, 107, 74, 75, 76, 77, 78, + 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 0, 109, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 0, 222, 0, 0, 0, - -85, -85, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 0, 102, 0, 0, 0, 103, 73, 74, 75, - 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 68, 69, 73, 74, + 97, 98, 99, 100, 101, 102, 103, 0, 111, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - 95, 96, 97, 98, 99, 100, 101, 0, 105, 73, - 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 0, 107, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 0, + 115, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99, 100, 101, 0, - 109, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, - 0, 136, 73, 74, 75, 76, 77, 78, 79, 80, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 0, 165, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 0, 203, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - 100, 101, 0, 222, 73, 74, 75, 76, 77, 78, + 101, 102, 103, 0, 203, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - 99, 100, 101, 0, 279, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 0, 0, 0, 0, 0, - 189, 68, 69, 0, 0, 0, 0, 0, 190, 58, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 0, - 0, 0, 0, 0, 0, 68, 69 + 99, 100, 101, 102, 103, 0, 226, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 0, 283, 232, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 0, 0, 0, 0, 233, 189, 68, 69, 70, 0, + 0, 0, 0, 0, 190, 232, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 0, 0, 0, 0, + 0, 189, 68, 69, 70, 0, 0, 0, 0, 0, + 190, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 0, 0, 0, 0, 0, 189, 68, 69, 70, + 0, 0, 0, 0, 0, 190, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 0, 0, 0, 0, + 0, 0, 68, 69, 70 }; static const yytype_int16 yycheck[] = { - 17, 103, 14, 153, 42, 43, 44, 45, 170, 0, - 48, 170, 227, 40, 116, 206, 9, 119, 12, 121, - 188, 33, 248, 12, 3, 144, 32, 24, 130, 45, - 192, 41, 43, 32, 33, 32, 33, 32, 34, 50, - 50, 200, 144, 36, 50, 271, 208, 26, 27, 264, - 241, 153, 46, 221, 45, 174, 47, 46, 53, 33, - 72, 32, 33, 165, 35, 0, 225, 150, 218, 32, - 229, 33, 174, 0, 1, 49, 3, 4, 5, 6, - 7, 8, 9, 10, 167, 48, 40, 249, 190, 32, - 240, 37, 38, 275, 111, 112, 246, 37, 38, 26, - 27, 32, 33, 45, 35, 48, 45, 134, 135, 291, - 51, 12, 124, 40, 51, 42, 218, 48, 32, 33, - 47, 35, 48, 46, 50, 142, 0, 1, 46, 3, - 4, 5, 6, 7, 8, 9, 10, 53, 240, 33, - 46, 179, 13, 170, 246, 33, 46, 49, 32, 48, - 47, 168, 26, 27, 49, 46, 52, 195, 175, 186, - 50, 46, 49, 180, 47, 45, 40, 46, 42, 50, - 47, 188, 47, 200, 212, 45, 45, 49, 205, 47, - 197, 45, 47, 45, 33, 287, 28, 29, 48, 206, - 32, 33, 34, 35, 36, 49, 298, 45, 225, 45, - 47, 52, 229, 230, 221, 45, 11, 48, 14, 229, - 227, 50, 225, 298, 277, 253, 225, 285, 3, -1, - -1, -1, 249, -1, 241, -1, -1, 265, -1, -1, - -1, 248, -1, -1, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 262, 284, 264, 275, 287, - 31, 32, 33, -1, 271, 1, -1, -1, 39, 297, - 298, -1, -1, -1, 291, 11, -1, -1, -1, 286, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - -1, -1, -1, -1, -1, 31, 32, 33, -1, -1, - -1, 1, -1, 39, 40, 4, 5, 6, 7, 8, - 9, 10, 48, -1, 50, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, - 30, 31, 32, 33, 1, -1, -1, -1, -1, 39, - 40, -1, -1, -1, -1, -1, -1, 47, 15, 16, + 17, 105, 14, 153, 42, 43, 44, 45, 171, 171, + 48, 0, 12, 12, 118, 188, 40, 121, 231, 123, + 150, 33, 3, 210, 143, 33, 9, 49, 132, 51, + 192, 33, 34, 42, 36, 33, 34, 200, 36, 143, + 252, 33, 51, 51, 34, 26, 27, 47, 47, 153, + 212, 49, 225, 36, 184, 268, 175, 46, 245, 48, + 50, 73, 54, 275, 33, 33, 229, 24, 279, 46, + 233, 175, 222, 33, 34, 32, 33, 34, 182, 35, + 49, 49, 44, 0, 295, 34, 190, 33, 34, 51, + 36, 253, 46, 41, 244, 46, 113, 114, 28, 29, + 250, 38, 39, 33, 34, 35, 36, 37, 52, 38, + 39, 52, 136, 137, 126, 47, 12, 50, 222, 47, + 54, 34, 0, 1, 141, 3, 4, 5, 6, 7, + 8, 9, 10, 4, 5, 6, 7, 8, 9, 10, + 244, 47, 180, 47, 13, 47, 250, 171, 26, 27, + 34, 49, 169, 33, 47, 47, 53, 195, 48, 176, + 51, 50, 186, 41, 181, 43, 48, 46, 51, 46, + 48, 188, 48, 47, 46, 48, 200, 34, 216, 49, + 197, 205, 48, 50, 46, 48, 50, 291, 46, 50, + 46, 46, 11, 210, 48, 46, 14, 49, 302, 229, + 53, 51, 233, 229, 302, 229, 281, 289, 225, 233, + 234, 3, -1, -1, 231, -1, -1, -1, -1, 257, + -1, -1, -1, -1, -1, -1, -1, -1, 245, 253, + -1, 269, -1, -1, -1, 252, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 266, + 288, 268, -1, 291, -1, 279, -1, -1, 275, 1, + -1, -1, -1, 301, 302, -1, -1, -1, -1, 11, + -1, 295, -1, 290, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, -1, -1, -1, -1, -1, 31, + 32, 33, 34, -1, -1, -1, 1, -1, 40, 41, + -1, -1, -1, -1, -1, -1, -1, 49, -1, 51, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, -1, -1, -1, -1, 30, 31, 32, 33, 34, + 1, -1, -1, -1, -1, 40, 41, -1, -1, -1, + -1, -1, -1, 48, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, -1, -1, -1, -1, 30, + 31, 32, 33, 34, 1, -1, -1, -1, -1, 40, + 41, -1, -1, -1, -1, -1, -1, 48, -1, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, - -1, -1, -1, 30, 31, 32, 33, 1, -1, -1, - -1, -1, 39, 40, -1, -1, -1, -1, -1, -1, - 47, -1, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, -1, -1, -1, -1, -1, 31, 32, 33, - 1, -1, -1, -1, -1, 39, 40, -1, -1, -1, - -1, -1, -1, 47, -1, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - 31, 32, 33, -1, -1, -1, -1, -1, 39, 40, - -1, -1, -1, -1, -1, 1, 47, 3, 4, 5, - 6, 7, 8, 9, 10, -1, -1, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, - 26, 27, 30, 31, 32, 33, -1, -1, -1, -1, - -1, 39, -1, -1, 40, -1, 42, -1, -1, -1, - -1, 47, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, -1, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 46, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, -1, 33, -1, -1, -1, - 37, 38, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, -1, 33, -1, -1, -1, 37, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 3, 4, + -1, -1, -1, -1, 31, 32, 33, 34, 1, -1, + -1, -1, -1, 40, 41, -1, -1, -1, -1, -1, + -1, 48, -1, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, -1, -1, -1, -1, -1, 31, 32, + 33, 34, -1, -1, -1, -1, -1, 40, 41, -1, + -1, -1, -1, -1, 1, 48, 3, 4, 5, 6, + 7, 8, 9, 10, 0, 1, -1, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, 26, + 27, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 26, 27, -1, -1, 41, -1, 43, -1, -1, -1, + -1, 48, -1, -1, -1, 41, -1, 43, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, -1, 33, 3, + 25, 26, 27, 28, 29, 30, 31, 32, -1, 34, + -1, -1, -1, 38, 39, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, -1, 34, -1, -1, -1, + 38, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, -1, 34, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, -1, 34, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, -1, 34, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, -1, 33, - 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, -1, - 33, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, + 34, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - -1, 33, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, -1, 33, 3, 4, 5, 6, 7, 8, 9, + 32, -1, 34, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, -1, 33, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, -1, 33, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - 31, 32, 33, -1, -1, -1, -1, -1, 39, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, - -1, -1, -1, -1, -1, 32, 33 + 30, 31, 32, -1, 34, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, -1, 34, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, -1, 34, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + -1, -1, -1, -1, 30, 31, 32, 33, 34, -1, + -1, -1, -1, -1, 40, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, + -1, 31, 32, 33, 34, -1, -1, -1, -1, -1, + 40, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, -1, -1, -1, -1, -1, 31, 32, 33, 34, + -1, -1, -1, -1, -1, 40, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, + -1, -1, 32, 33, 34 }; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 1, 40, 42, 55, 56, 57, 58, 45, 34, - 120, 121, 121, 0, 59, 3, 26, 27, 62, 63, - 66, 67, 76, 77, 83, 84, 98, 99, 107, 108, - 110, 122, 124, 61, 120, 41, 50, 43, 58, 33, - 57, 60, 4, 5, 6, 7, 8, 9, 10, 65, - 75, 81, 82, 97, 109, 58, 120, 64, 16, 17, + 0, 1, 41, 43, 56, 57, 58, 59, 46, 35, + 122, 123, 123, 0, 60, 3, 26, 27, 63, 64, + 67, 68, 77, 78, 84, 85, 99, 100, 108, 109, + 111, 124, 126, 62, 122, 42, 51, 44, 59, 34, + 58, 61, 4, 5, 6, 7, 8, 9, 10, 66, + 76, 82, 83, 98, 110, 59, 122, 65, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 32, 33, - 118, 119, 45, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 33, 37, 125, 33, 125, 33, 125, 33, - 125, 51, 51, 33, 46, 125, 12, 69, 78, 12, - 86, 12, 102, 111, 46, 53, 33, 32, 53, 33, - 49, 58, 35, 118, 57, 57, 33, 112, 113, 125, - 118, 68, 46, 118, 13, 87, 24, 101, 118, 100, - 46, 58, 33, 49, 28, 29, 34, 35, 36, 118, - 123, 48, 48, 119, 119, 49, 47, 50, 46, 1, - 57, 79, 101, 85, 50, 46, 112, 47, 123, 52, - 50, 35, 114, 118, 112, 1, 57, 70, 45, 31, - 39, 71, 72, 80, 90, 119, 47, 46, 101, 1, - 57, 103, 47, 33, 125, 57, 45, 71, 72, 73, - 74, 89, 119, 47, 79, 35, 48, 118, 49, 71, - 119, 45, 33, 125, 1, 57, 88, 45, 15, 30, - 72, 91, 92, 93, 104, 119, 47, 119, 70, 71, - 49, 45, 125, 48, 48, 123, 49, 79, 45, 72, - 89, 93, 96, 119, 47, 103, 91, 119, 37, 38, - 1, 11, 115, 116, 45, 52, 123, 70, 123, 88, - 119, 45, 37, 38, 48, 57, 48, 50, 103, 33, - 125, 88, 95, 73, 119, 94, 115, 14, 117, 125, - 117, 57, 105, 106, 118, 125, 73, 119, 50, 125, - 105 + 34, 120, 121, 46, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 34, 38, 127, 34, 127, 34, + 127, 34, 127, 52, 52, 34, 113, 127, 12, 70, + 79, 12, 87, 12, 103, 112, 47, 54, 34, 33, + 54, 34, 50, 59, 36, 120, 58, 58, 47, 120, + 69, 47, 120, 13, 88, 24, 32, 102, 120, 101, + 47, 59, 34, 50, 28, 29, 35, 36, 37, 120, + 125, 49, 49, 121, 121, 34, 114, 115, 127, 47, + 1, 58, 80, 102, 86, 51, 47, 114, 48, 125, + 53, 51, 50, 48, 51, 1, 58, 71, 46, 31, + 40, 72, 73, 81, 91, 121, 48, 47, 102, 1, + 58, 104, 48, 34, 127, 58, 36, 116, 120, 114, + 46, 72, 73, 74, 75, 90, 121, 48, 80, 36, + 49, 120, 50, 72, 121, 46, 34, 127, 1, 58, + 89, 46, 15, 30, 73, 92, 93, 94, 105, 121, + 48, 121, 71, 72, 50, 46, 127, 49, 49, 125, + 50, 80, 46, 73, 90, 94, 97, 121, 48, 104, + 92, 121, 38, 39, 1, 11, 117, 118, 46, 53, + 125, 71, 125, 89, 121, 46, 38, 39, 49, 58, + 49, 51, 104, 34, 127, 89, 96, 74, 121, 95, + 117, 14, 119, 127, 119, 58, 106, 107, 120, 127, + 74, 121, 51, 127, 106 }; -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 55, 56, 57, 58, 58, 60, 59, 61, 59, + 62, 59, 59, 59, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 65, 64, 66, + 66, 67, 69, 68, 70, 70, 71, 71, 71, 71, + 72, 73, 73, 73, 73, 74, 74, 75, 76, 76, + 77, 79, 78, 80, 80, 80, 80, 81, 82, 82, + 83, 83, 83, 84, 86, 85, 87, 87, 88, 88, + 89, 89, 89, 89, 90, 90, 90, 90, 91, 91, + 91, 91, 91, 91, 92, 92, 92, 93, 93, 93, + 93, 95, 94, 96, 94, 97, 97, 98, 98, 99, + 101, 100, 102, 102, 102, 102, 103, 103, 104, 104, + 104, 104, 105, 106, 106, 107, 107, 108, 108, 109, + 109, 110, 110, 112, 111, 113, 111, 114, 114, 115, + 115, 115, 115, 116, 116, 117, 117, 118, 118, 118, + 118, 118, 118, 118, 119, 119, 120, 120, 120, 121, + 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 121, 121, 121, 122, 122, 123, 123, 124, 124, 125, + 125, 125, 125, 125, 125, 126, 126, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 1, 3, 3, 0, 0, 3, 0, 5, + 0, 4, 2, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, 6, 2, + 2, 2, 0, 7, 2, 0, 4, 3, 2, 0, + 2, 3, 3, 2, 1, 2, 1, 1, 2, 2, + 2, 0, 6, 4, 3, 2, 0, 1, 2, 2, + 4, 4, 1, 2, 0, 8, 2, 0, 2, 0, + 4, 3, 2, 0, 1, 3, 2, 1, 1, 3, + 2, 4, 2, 1, 2, 1, 1, 2, 3, 2, + 3, 0, 5, 0, 5, 1, 1, 2, 2, 2, + 0, 7, 3, 1, 1, 1, 2, 0, 4, 3, + 2, 0, 1, 3, 1, 1, 1, 7, 7, 10, + 10, 2, 2, 0, 6, 0, 6, 3, 1, 1, + 3, 1, 0, 1, 1, 1, 0, 0, 3, 5, + 4, 6, 3, 5, 2, 0, 1, 2, 3, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, + 1, 1, 2, 2, 1, 3, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 6, 5, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1 +}; -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab -#define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif - - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ + YYERROR; \ + } \ +while (0) -#ifndef YY_LOCATION_PRINT -# if YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 -/* YYLEX -- calling `yylex' with the right arguments. */ - -#ifdef YYLEX_PARAM -# define YYLEX yylex (&yylval, YYLEX_PARAM) -#else -# define YYLEX yylex (&yylval) -#endif /* Enable debugging if requested. */ #if YYDEBUG @@ -1133,54 +1039,46 @@ while (YYID (0)) # define YYFPRINTF fprintf # endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); # endif - switch (yytype) - { - default: - break; - } + YYUSE (yytype); } @@ -1188,22 +1086,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) | Print this symbol on YYOUTPUT. | `--------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); @@ -1214,16 +1101,8 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) | TOP (included). | `------------------------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -#else -static void -yy_stack_print (yybottom, yytop) - yytype_int16 *yybottom; - yytype_int16 *yytop; -#endif { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1234,49 +1113,42 @@ yy_stack_print (yybottom, yytop) YYFPRINTF (stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else -static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { + unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); + yy_symbol_print (stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); YYFPRINTF (stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -1290,7 +1162,7 @@ int yydebug; /* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH +#ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif @@ -1305,7 +1177,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1314,15 +1185,8 @@ int yydebug; # define yystrlen strlen # else /* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) @@ -1338,16 +1202,8 @@ yystrlen (yystr) # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif { char *yyd = yydest; const char *yys = yysrc; @@ -1377,27 +1233,27 @@ yytnamerr (char *yyres, const char *yystr) char const *yyp = yystr; for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } do_not_strip_quotes: ; } @@ -1408,197 +1264,178 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + } - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif { YYUSE (yyvaluep); - if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { - - default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - +/*----------. +| yyparse. | +`----------*/ -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ - -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) int yyparse (void) -#else -int -yyparse () - -#endif -#endif { /* The lookahead symbol. */ int yychar; + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +YY_INITIAL_VALUE (static YYSTYPE yyval_default;) +YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Number of syntax errors so far. */ int yynerrs; @@ -1608,10 +1445,10 @@ YYSTYPE yylval; int yyerrstatus; /* The stacks and their tools: - `yyss': related to states. - `yyvs': related to semantic values. + 'yyss': related to states. + 'yyvs': related to semantic values. - Refer to the stacks thru separate pointers, to allow yyoverflow + Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1629,7 +1466,7 @@ YYSTYPE yylval; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1647,9 +1484,8 @@ YYSTYPE yylval; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1658,14 +1494,6 @@ YYSTYPE yylval; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - goto yysetstate; /*------------------------------------------------------------. @@ -1686,23 +1514,23 @@ YYSTYPE yylval; #ifdef yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -1710,22 +1538,22 @@ YYSTYPE yylval; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ @@ -1734,10 +1562,10 @@ YYSTYPE yylval; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); @@ -1757,7 +1585,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1766,7 +1594,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = yylex (&yylval); } if (yychar <= YYEOF) @@ -1788,8 +1616,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1806,7 +1634,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; @@ -1829,7 +1659,7 @@ yyreduce: yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. + '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison @@ -1843,391 +1673,353 @@ yyreduce: switch (yyn) { case 2: - -/* Line 1455 of yacc.c */ -#line 115 "../Slice/Grammar.y" +#line 116 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 1680 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 3: - -/* Line 1455 of yacc.c */ -#line 123 "../Slice/Grammar.y" +#line 124 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (3)]); -;} + (yyval) = (yyvsp[-1]); +} +#line 1688 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 4: - -/* Line 1455 of yacc.c */ -#line 132 "../Slice/Grammar.y" +#line 133 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (3)]); -;} + (yyval) = (yyvsp[-1]); +} +#line 1696 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 5: - -/* Line 1455 of yacc.c */ -#line 136 "../Slice/Grammar.y" +#line 137 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = new StringListTok; -;} +} +#line 1704 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 6: - -/* Line 1455 of yacc.c */ -#line 145 "../Slice/Grammar.y" +#line 146 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[0])); if(!metaData->v.empty()) { unit->addGlobalMetaData(metaData->v); } -;} +} +#line 1716 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 8: - -/* Line 1455 of yacc.c */ -#line 154 "../Slice/Grammar.y" +#line 155 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (2)])); - ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (2)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-1])); + ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[0])); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } -;} +} +#line 1729 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 10: - -/* Line 1455 of yacc.c */ -#line 164 "../Slice/Grammar.y" +#line 165 "src/Slice/Grammar.y" /* yacc.c:1661 */ { yyerrok; -;} +} +#line 1737 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 12: - -/* Line 1455 of yacc.c */ -#line 169 "../Slice/Grammar.y" +#line 170 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("`;' missing after definition"); -;} +} +#line 1745 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 13: - -/* Line 1455 of yacc.c */ -#line 173 "../Slice/Grammar.y" +#line 174 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 1752 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 14: - -/* Line 1455 of yacc.c */ -#line 181 "../Slice/Grammar.y" +#line 182 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ModulePtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ModulePtr::dynamicCast((yyvsp[0]))); +} +#line 1760 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 15: - -/* Line 1455 of yacc.c */ -#line 185 "../Slice/Grammar.y" +#line 186 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[0]))); +} +#line 1768 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 16: - -/* Line 1455 of yacc.c */ -#line 189 "../Slice/Grammar.y" +#line 190 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ClassDefPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ClassDefPtr::dynamicCast((yyvsp[0]))); +} +#line 1776 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 17: - -/* Line 1455 of yacc.c */ -#line 193 "../Slice/Grammar.y" +#line 194 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[0]))); +} +#line 1784 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 18: - -/* Line 1455 of yacc.c */ -#line 197 "../Slice/Grammar.y" +#line 198 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ClassDefPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ClassDefPtr::dynamicCast((yyvsp[0]))); +} +#line 1792 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 19: - -/* Line 1455 of yacc.c */ -#line 201 "../Slice/Grammar.y" +#line 202 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0); -;} + assert((yyvsp[0]) == 0); +} +#line 1800 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 20: - -/* Line 1455 of yacc.c */ -#line 205 "../Slice/Grammar.y" +#line 206 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ExceptionPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ExceptionPtr::dynamicCast((yyvsp[0]))); +} +#line 1808 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 21: - -/* Line 1455 of yacc.c */ -#line 209 "../Slice/Grammar.y" +#line 210 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0); -;} + assert((yyvsp[0]) == 0); +} +#line 1816 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 22: - -/* Line 1455 of yacc.c */ -#line 213 "../Slice/Grammar.y" +#line 214 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || StructPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || StructPtr::dynamicCast((yyvsp[0]))); +} +#line 1824 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 23: - -/* Line 1455 of yacc.c */ -#line 217 "../Slice/Grammar.y" +#line 218 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || SequencePtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || SequencePtr::dynamicCast((yyvsp[0]))); +} +#line 1832 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 24: - -/* Line 1455 of yacc.c */ -#line 221 "../Slice/Grammar.y" +#line 222 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || DictionaryPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || DictionaryPtr::dynamicCast((yyvsp[0]))); +} +#line 1840 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 25: - -/* Line 1455 of yacc.c */ -#line 225 "../Slice/Grammar.y" +#line 226 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || EnumPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || EnumPtr::dynamicCast((yyvsp[0]))); +} +#line 1848 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 26: - -/* Line 1455 of yacc.c */ -#line 229 "../Slice/Grammar.y" +#line 230 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - assert((yyvsp[(1) - (1)]) == 0 || ConstPtr::dynamicCast((yyvsp[(1) - (1)]))); -;} + assert((yyvsp[0]) == 0 || ConstPtr::dynamicCast((yyvsp[0]))); +} +#line 1856 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 27: - -/* Line 1455 of yacc.c */ -#line 238 "../Slice/Grammar.y" +#line 239 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->setSeenDefinition(); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ModulePtr module = cont->createModule(ident->v); if(module) { - cont->checkIntroduced(ident->v, module); - unit->pushContainer(module); - (yyval) = module; + cont->checkIntroduced(ident->v, module); + unit->pushContainer(module); + (yyval) = module; } else { (yyval) = 0; } -;} +} +#line 1877 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 28: - -/* Line 1455 of yacc.c */ -#line 255 "../Slice/Grammar.y" +#line 256 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(3) - (6)])) + if((yyvsp[-3])) { - unit->popContainer(); - (yyval) = (yyvsp[(3) - (6)]); + unit->popContainer(); + (yyval) = (yyvsp[-3]); } else { (yyval) = 0; } -;} +} +#line 1893 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 29: - -/* Line 1455 of yacc.c */ -#line 272 "../Slice/Grammar.y" +#line 273 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 1901 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 30: - -/* Line 1455 of yacc.c */ -#line 276 "../Slice/Grammar.y" +#line 277 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as exception name"); - (yyval) = (yyvsp[(2) - (2)]); // Dummy -;} + (yyval) = (yyvsp[0]); // Dummy +} +#line 1911 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 31: - -/* Line 1455 of yacc.c */ -#line 287 "../Slice/Grammar.y" +#line 288 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("exceptions cannot be forward declared"); (yyval) = 0; -;} +} +#line 1920 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 32: - -/* Line 1455 of yacc.c */ -#line 297 "../Slice/Grammar.y" +#line 298 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (3)])); - ExceptionPtr base = ExceptionPtr::dynamicCast((yyvsp[(3) - (3)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-2])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[-1])); + ExceptionPtr base = ExceptionPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ExceptionPtr ex = cont->createException(ident->v, base, local->v); if(ex) { - cont->checkIntroduced(ident->v, ex); - unit->pushContainer(ex); + cont->checkIntroduced(ident->v, ex); + unit->pushContainer(ex); } (yyval) = ex; -;} +} +#line 1938 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 33: - -/* Line 1455 of yacc.c */ -#line 311 "../Slice/Grammar.y" +#line 312 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(4) - (7)])) + if((yyvsp[-3])) { - unit->popContainer(); + unit->popContainer(); } - (yyval) = (yyvsp[(4) - (7)]); -;} + (yyval) = (yyvsp[-3]); +} +#line 1950 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 34: - -/* Line 1455 of yacc.c */ -#line 324 "../Slice/Grammar.y" +#line 325 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ContainedPtr contained = cont->lookupException(scoped->v); cont->checkIntroduced(scoped->v); (yyval) = contained; -;} +} +#line 1962 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 35: - -/* Line 1455 of yacc.c */ -#line 332 "../Slice/Grammar.y" +#line 333 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = 0; -;} +} +#line 1970 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 36: - -/* Line 1455 of yacc.c */ -#line 341 "../Slice/Grammar.y" +#line 342 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); - ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[-2])); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } -;} +} +#line 1983 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 37: - -/* Line 1455 of yacc.c */ -#line 350 "../Slice/Grammar.y" +#line 351 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 1990 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 38: - -/* Line 1455 of yacc.c */ -#line 353 "../Slice/Grammar.y" +#line 354 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("`;' missing after definition"); -;} +} +#line 1998 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 39: - -/* Line 1455 of yacc.c */ -#line 357 "../Slice/Grammar.y" +#line 358 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 2005 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 40: - -/* Line 1455 of yacc.c */ -#line 365 "../Slice/Grammar.y" +#line 366 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); TypeStringTokPtr typestring = new TypeStringTok; typestring->v = make_pair(type, ident->v); (yyval) = typestring; -;} +} +#line 2017 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 41: - -/* Line 1455 of yacc.c */ -#line 378 "../Slice/Grammar.y" +#line 379 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - IntegerTokPtr i = IntegerTokPtr::dynamicCast((yyvsp[(2) - (3)])); + IntegerTokPtr i = IntegerTokPtr::dynamicCast((yyvsp[-1])); int tag; if(i->v < 0 || i->v > Int32Max) @@ -2244,19 +2036,55 @@ yyreduce: m->v.optional = tag >= 0; m->v.tag = tag; (yyval) = m; -;} +} +#line 2041 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 42: - -/* Line 1455 of yacc.c */ -#line 398 "../Slice/Grammar.y" +#line 399 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(2) - (3)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[-1])); ContainerPtr cont = unit->currentContainer(); assert(cont); - ContainedList cl = cont->lookupContained(scoped->v); + ContainedList cl = cont->lookupContained(scoped->v, false); + if(cl.empty()) + { + EnumeratorList enumerators = cont->enumerators(scoped->v); + if(enumerators.size() == 1) + { + // Found + cl.push_back(enumerators.front()); + scoped->v = enumerators.front()->scoped(); + unit->warning(Deprecated, string("referencing enumerator `") + scoped->v + + "' without its enumeration's scope is deprecated"); + } + else if(enumerators.size() > 1) + { + ostringstream os; + os << "enumerator `" << scoped->v << "' could designate"; + bool first = true; + for(EnumeratorList::iterator p = enumerators.begin(); p != enumerators.end(); ++p) + { + if(first) + { + first = false; + } + else + { + os << " or"; + } + + os << " `" << (*p)->scoped() << "'"; + } + unit->error(os.str()); + } + else + { + unit->error(string("`") + scoped->v + "' is not defined"); + } + } + if(cl.empty()) { YYERROR; // Can't continue, jump to next yyerrok @@ -2305,106 +2133,98 @@ yyreduce: m->v.optional = tag >= 0; m->v.tag = tag; (yyval) = m; -;} +} +#line 2138 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 43: - -/* Line 1455 of yacc.c */ -#line 454 "../Slice/Grammar.y" +#line 492 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("missing tag for optional"); OptionalDefTokPtr m = new OptionalDefTok; // Dummy m->v.optional = false; m->v.tag = -1; (yyval) = m; -;} +} +#line 2150 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 44: - -/* Line 1455 of yacc.c */ -#line 462 "../Slice/Grammar.y" +#line 500 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("missing tag for optional"); OptionalDefTokPtr m = new OptionalDefTok; // Dummy m->v.optional = false; m->v.tag = -1; (yyval) = m; -;} +} +#line 2162 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 45: - -/* Line 1455 of yacc.c */ -#line 475 "../Slice/Grammar.y" +#line 513 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr m = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (2)])); - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + OptionalDefTokPtr m = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[0])); m->v.type = ts->v.first; m->v.name = ts->v.second; (yyval) = m; -;} +} +#line 2174 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 46: - -/* Line 1455 of yacc.c */ -#line 483 "../Slice/Grammar.y" +#line 521 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[0])); OptionalDefTokPtr m = new OptionalDefTok; m->v.type = ts->v.first; m->v.name = ts->v.second; m->v.optional = false; m->v.tag = -1; (yyval) = m; -;} +} +#line 2188 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 48: - -/* Line 1455 of yacc.c */ -#line 504 "../Slice/Grammar.y" +#line 542 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 2196 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 49: - -/* Line 1455 of yacc.c */ -#line 508 "../Slice/Grammar.y" +#line 546 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as struct name"); - (yyval) = (yyvsp[(2) - (2)]); // Dummy -;} + (yyval) = (yyvsp[0]); // Dummy +} +#line 2206 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 50: - -/* Line 1455 of yacc.c */ -#line 519 "../Slice/Grammar.y" +#line 557 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("structs cannot be forward declared"); (yyval) = 0; // Dummy -;} +} +#line 2215 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 51: - -/* Line 1455 of yacc.c */ -#line 529 "../Slice/Grammar.y" +#line 567 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); StructPtr st = cont->createStruct(ident->v, local->v); if(st) { - cont->checkIntroduced(ident->v, st); - unit->pushContainer(st); + cont->checkIntroduced(ident->v, st); + unit->pushContainer(st); } else { @@ -2413,19 +2233,18 @@ yyreduce: unit->pushContainer(st); } (yyval) = st; -;} +} +#line 2238 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 52: - -/* Line 1455 of yacc.c */ -#line 548 "../Slice/Grammar.y" +#line 586 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(3) - (6)])) + if((yyvsp[-3])) { - unit->popContainer(); + unit->popContainer(); } - (yyval) = (yyvsp[(3) - (6)]); + (yyval) = (yyvsp[-3]); // // Empty structures are not allowed @@ -2434,76 +2253,69 @@ yyreduce: assert(st); if(st->dataMembers().empty()) { - unit->error("struct `" + st->name() + "' must have at least one member"); // $$ is a dummy + unit->error("struct `" + st->name() + "' must have at least one member"); // $$ is a dummy } -;} +} +#line 2260 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 53: - -/* Line 1455 of yacc.c */ -#line 571 "../Slice/Grammar.y" +#line 609 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); - ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[-2])); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } -;} +} +#line 2273 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 54: - -/* Line 1455 of yacc.c */ -#line 580 "../Slice/Grammar.y" +#line 618 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 2280 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 55: - -/* Line 1455 of yacc.c */ -#line 583 "../Slice/Grammar.y" +#line 621 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("`;' missing after definition"); -;} +} +#line 2288 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 56: - -/* Line 1455 of yacc.c */ -#line 587 "../Slice/Grammar.y" +#line 625 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 2295 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 58: - -/* Line 1455 of yacc.c */ -#line 601 "../Slice/Grammar.y" +#line 639 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 2303 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 59: - -/* Line 1455 of yacc.c */ -#line 605 "../Slice/Grammar.y" +#line 643 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as class name"); - (yyval) = (yyvsp[(2) - (2)]); // Dummy -;} + (yyval) = (yyvsp[0]); // Dummy +} +#line 2313 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 60: - -/* Line 1455 of yacc.c */ -#line 616 "../Slice/Grammar.y" +#line 654 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - IceUtil::Int64 id = IntegerTokPtr::dynamicCast((yyvsp[(3) - (4)]))->v; + IceUtil::Int64 id = IntegerTokPtr::dynamicCast((yyvsp[-1]))->v; if(id < 0) { unit->error("invalid compact id for class: id must be a positive integer"); @@ -2522,22 +2334,58 @@ yyreduce: } ClassIdTokPtr classId = new ClassIdTok(); - classId->v = StringTokPtr::dynamicCast((yyvsp[(2) - (4)]))->v; + classId->v = StringTokPtr::dynamicCast((yyvsp[-2]))->v; classId->t = static_cast<int>(id); (yyval) = classId; -;} +} +#line 2342 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 61: - -/* Line 1455 of yacc.c */ -#line 641 "../Slice/Grammar.y" +#line 679 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(3) - (4)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[-1])); ContainerPtr cont = unit->currentContainer(); assert(cont); - ContainedList cl = cont->lookupContained(scoped->v); + ContainedList cl = cont->lookupContained(scoped->v, false); + if(cl.empty()) + { + EnumeratorList enumerators = cont->enumerators(scoped->v); + if(enumerators.size() == 1) + { + // Found + cl.push_back(enumerators.front()); + scoped->v = enumerators.front()->scoped(); + unit->warning(Deprecated, string("referencing enumerator `") + scoped->v + + "' without its enumeration's scope is deprecated"); + } + else if(enumerators.size() > 1) + { + ostringstream os; + os << "enumerator `" << scoped->v << "' could designate"; + bool first = true; + for(EnumeratorList::iterator p = enumerators.begin(); p != enumerators.end(); ++p) + { + if(first) + { + first = false; + } + else + { + os << " or"; + } + + os << " `" << (*p)->scoped() << "'"; + } + unit->error(os.str()); + } + else + { + unit->error(string("`") + scoped->v + "' is not defined"); + } + } + if(cl.empty()) { YYERROR; // Can't continue, jump to next yyerrok @@ -2591,194 +2439,181 @@ yyreduce: } ClassIdTokPtr classId = new ClassIdTok(); - classId->v = StringTokPtr::dynamicCast((yyvsp[(2) - (4)]))->v; + classId->v = StringTokPtr::dynamicCast((yyvsp[-2]))->v; classId->t = id; (yyval) = classId; -;} +} +#line 2448 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 62: - -/* Line 1455 of yacc.c */ -#line 706 "../Slice/Grammar.y" +#line 781 "src/Slice/Grammar.y" /* yacc.c:1661 */ { ClassIdTokPtr classId = new ClassIdTok(); - classId->v = StringTokPtr::dynamicCast((yyvsp[(1) - (1)]))->v; + classId->v = StringTokPtr::dynamicCast((yyvsp[0]))->v; classId->t = -1; (yyval) = classId; -;} +} +#line 2459 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 63: - -/* Line 1455 of yacc.c */ -#line 718 "../Slice/Grammar.y" +#line 793 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ClassDeclPtr cl = cont->createClassDecl(ident->v, false, local->v); (yyval) = cl; -;} +} +#line 2471 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 64: - -/* Line 1455 of yacc.c */ -#line 731 "../Slice/Grammar.y" +#line 806 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (4)])); - ClassIdTokPtr ident = ClassIdTokPtr::dynamicCast((yyvsp[(2) - (4)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-3])); + ClassIdTokPtr ident = ClassIdTokPtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); - ClassDefPtr base = ClassDefPtr::dynamicCast((yyvsp[(3) - (4)])); - ClassListTokPtr bases = ClassListTokPtr::dynamicCast((yyvsp[(4) - (4)])); + ClassDefPtr base = ClassDefPtr::dynamicCast((yyvsp[-1])); + ClassListTokPtr bases = ClassListTokPtr::dynamicCast((yyvsp[0])); if(base) { - bases->v.push_front(base); + bases->v.push_front(base); } ClassDefPtr cl = cont->createClassDef(ident->v, ident->t, false, bases->v, local->v); if(cl) { - cont->checkIntroduced(ident->v, cl); - unit->pushContainer(cl); - (yyval) = cl; + cont->checkIntroduced(ident->v, cl); + unit->pushContainer(cl); + (yyval) = cl; } else { (yyval) = 0; } -;} +} +#line 2498 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 65: - -/* Line 1455 of yacc.c */ -#line 754 "../Slice/Grammar.y" +#line 829 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(5) - (8)])) + if((yyvsp[-3])) { - unit->popContainer(); - (yyval) = (yyvsp[(5) - (8)]); + unit->popContainer(); + (yyval) = (yyvsp[-3]); } else { (yyval) = 0; } -;} +} +#line 2514 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 66: - -/* Line 1455 of yacc.c */ -#line 771 "../Slice/Grammar.y" +#line 846 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); TypeList types = cont->lookupType(scoped->v); (yyval) = 0; if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not a class"; - unit->error(msg); - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); - } - else - { - cont->checkIntroduced(scoped->v); - (yyval) = def; - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not a class"; + unit->error(msg); + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); + } + else + { + cont->checkIntroduced(scoped->v); + (yyval) = def; + } + } } -;} +} +#line 2552 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 67: - -/* Line 1455 of yacc.c */ -#line 805 "../Slice/Grammar.y" +#line 880 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = 0; -;} +} +#line 2560 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 68: - -/* Line 1455 of yacc.c */ -#line 814 "../Slice/Grammar.y" +#line 889 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 2568 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 69: - -/* Line 1455 of yacc.c */ -#line 818 "../Slice/Grammar.y" +#line 893 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = new ClassListTok; -;} +} +#line 2576 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 70: - -/* Line 1455 of yacc.c */ -#line 827 "../Slice/Grammar.y" +#line 902 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); - ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[-2])); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } -;} +} +#line 2589 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 71: - -/* Line 1455 of yacc.c */ -#line 836 "../Slice/Grammar.y" +#line 911 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 2596 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 72: - -/* Line 1455 of yacc.c */ -#line 839 "../Slice/Grammar.y" +#line 914 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("`;' missing after definition"); -;} +} +#line 2604 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 73: - -/* Line 1455 of yacc.c */ -#line 843 "../Slice/Grammar.y" +#line 918 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 2611 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 74: - -/* Line 1455 of yacc.c */ -#line 851 "../Slice/Grammar.y" +#line 926 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr def = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (1)])); + OptionalDefTokPtr def = OptionalDefTokPtr::dynamicCast((yyvsp[0])); ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); DataMemberPtr dm; if(cl) @@ -2797,16 +2632,15 @@ yyreduce: } unit->currentContainer()->checkIntroduced(def->v.name, dm); (yyval) = dm; -;} +} +#line 2637 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 75: - -/* Line 1455 of yacc.c */ -#line 873 "../Slice/Grammar.y" +#line 948 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr def = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (3)])); - ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(3) - (3)])); + OptionalDefTokPtr def = OptionalDefTokPtr::dynamicCast((yyvsp[-2])); + ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[0])); ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); DataMemberPtr dm; @@ -2829,16 +2663,15 @@ yyreduce: } unit->currentContainer()->checkIntroduced(def->v.name, dm); (yyval) = dm; -;} +} +#line 2668 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 76: - -/* Line 1455 of yacc.c */ -#line 900 "../Slice/Grammar.y" +#line 975 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (2)])); - string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; + TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { @@ -2856,15 +2689,14 @@ yyreduce: } assert((yyval)); unit->error("keyword `" + name + "' cannot be used as data member name"); -;} +} +#line 2694 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 77: - -/* Line 1455 of yacc.c */ -#line 922 "../Slice/Grammar.y" +#line 997 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (1)])); + TypePtr type = TypePtr::dynamicCast((yyvsp[0])); ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { @@ -2882,758 +2714,735 @@ yyreduce: } assert((yyval)); unit->error("missing data member name"); -;} +} +#line 2719 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 78: - -/* Line 1455 of yacc.c */ -#line 948 "../Slice/Grammar.y" +#line 1023 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[0])); StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); DataMemberPtr dm = st->createDataMember(ts->v.second, ts->v.first, false, -1, 0, "", ""); unit->currentContainer()->checkIntroduced(ts->v.second, dm); (yyval) = dm; -;} +} +#line 2732 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 79: - -/* Line 1455 of yacc.c */ -#line 957 "../Slice/Grammar.y" +#line 1032 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (3)])); - ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(3) - (3)])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[-2])); + ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[0])); StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); DataMemberPtr dm = st->createDataMember(ts->v.second, ts->v.first, false, -1, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); unit->currentContainer()->checkIntroduced(ts->v.second, dm); (yyval) = dm; -;} +} +#line 2747 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 80: - -/* Line 1455 of yacc.c */ -#line 968 "../Slice/Grammar.y" +#line 1043 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[0])); StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); (yyval) = st->createDataMember(ts->v.second, ts->v.first, false, 0, 0, "", ""); // Dummy assert((yyval)); unit->error("optional data members not supported in struct"); -;} +} +#line 2760 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 81: - -/* Line 1455 of yacc.c */ -#line 977 "../Slice/Grammar.y" +#line 1052 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[(2) - (4)])); + TypeStringTokPtr ts = TypeStringTokPtr::dynamicCast((yyvsp[-2])); StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); (yyval) = st->createDataMember(ts->v.second, ts->v.first, false, 0, 0, "", ""); // Dummy assert((yyval)); unit->error("optional data members not supported in struct"); -;} +} +#line 2773 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 82: - -/* Line 1455 of yacc.c */ -#line 986 "../Slice/Grammar.y" +#line 1061 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (2)])); - string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; + TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); (yyval) = st->createDataMember(name, type, false, 0, 0, "", ""); // Dummy assert((yyval)); unit->error("keyword `" + name + "' cannot be used as data member name"); -;} +} +#line 2787 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 83: - -/* Line 1455 of yacc.c */ -#line 996 "../Slice/Grammar.y" +#line 1071 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (1)])); + TypePtr type = TypePtr::dynamicCast((yyvsp[0])); StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); assert(st); (yyval) = st->createDataMember(IceUtil::generateUUID(), type, false, 0, 0, "", ""); // Dummy assert((yyval)); unit->error("missing data member name"); -;} +} +#line 2800 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 84: - -/* Line 1455 of yacc.c */ -#line 1010 "../Slice/Grammar.y" +#line 1085 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr m = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (2)])); - m->v.type = TypePtr::dynamicCast((yyvsp[(2) - (2)])); + OptionalDefTokPtr m = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + m->v.type = TypePtr::dynamicCast((yyvsp[0])); (yyval) = m; -;} +} +#line 2810 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 85: - -/* Line 1455 of yacc.c */ -#line 1016 "../Slice/Grammar.y" +#line 1091 "src/Slice/Grammar.y" /* yacc.c:1661 */ { OptionalDefTokPtr m = new OptionalDefTok(); - m->v.type = TypePtr::dynamicCast((yyvsp[(1) - (1)])); + m->v.type = TypePtr::dynamicCast((yyvsp[0])); m->v.optional = false; m->v.tag = -1; (yyval) = m; -;} +} +#line 2822 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 86: - -/* Line 1455 of yacc.c */ -#line 1024 "../Slice/Grammar.y" +#line 1099 "src/Slice/Grammar.y" /* yacc.c:1661 */ { OptionalDefTokPtr m = new OptionalDefTok; m->v.optional = false; m->v.tag = -1; (yyval) = m; -;} +} +#line 2833 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 87: - -/* Line 1455 of yacc.c */ -#line 1036 "../Slice/Grammar.y" +#line 1111 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (2)])); - string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; + OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); - if(op) - { - cl->checkIntroduced(name, op); - unit->pushContainer(op); - (yyval) = op; - } - else - { - (yyval) = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); + if(op) + { + cl->checkIntroduced(name, op); + unit->pushContainer(op); + (yyval) = op; + } + else + { + (yyval) = 0; + } } else { (yyval) = 0; } -;} +} +#line 2861 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 88: - -/* Line 1455 of yacc.c */ -#line 1060 "../Slice/Grammar.y" +#line 1135 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[(2) - (3)])); - string name = StringTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v; + OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, - Operation::Idempotent); - if(op) - { - cl->checkIntroduced(name, op); - unit->pushContainer(op); - (yyval) = op; - } - else - { - (yyval) = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, + Operation::Idempotent); + if(op) + { + cl->checkIntroduced(name, op); + unit->pushContainer(op); + (yyval) = op; + } + else + { + (yyval) = 0; + } } else { (yyval) = 0; } -;} +} +#line 2890 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 89: - -/* Line 1455 of yacc.c */ -#line 1085 "../Slice/Grammar.y" +#line 1160 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[(1) - (2)])); - string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; + OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); - if(op) - { - unit->pushContainer(op); - unit->error("keyword `" + name + "' cannot be used as operation name"); - (yyval) = op; // Dummy - } - else - { - (yyval) = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); + if(op) + { + unit->pushContainer(op); + unit->error("keyword `" + name + "' cannot be used as operation name"); + (yyval) = op; // Dummy + } + else + { + (yyval) = 0; + } } else { (yyval) = 0; } -;} +} +#line 2918 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 90: - -/* Line 1455 of yacc.c */ -#line 1109 "../Slice/Grammar.y" +#line 1184 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[(2) - (3)])); - string name = StringTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v; + OptionalDefTokPtr returnType = OptionalDefTokPtr::dynamicCast((yyvsp[-1])); + string name = StringTokPtr::dynamicCast((yyvsp[0]))->v; ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, - Operation::Idempotent); - if(op) - { - unit->pushContainer(op); - unit->error("keyword `" + name + "' cannot be used as operation name"); - (yyval) = op; // Dummy - } - else - { - return 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, + Operation::Idempotent); + if(op) + { + unit->pushContainer(op); + unit->error("keyword `" + name + "' cannot be used as operation name"); + (yyval) = op; // Dummy + } + else + { + return 0; + } } else { - (yyval) = 0; + (yyval) = 0; } -;} +} +#line 2947 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 91: - -/* Line 1455 of yacc.c */ -#line 1139 "../Slice/Grammar.y" +#line 1214 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(1) - (3)])) + if((yyvsp[-2])) { - unit->popContainer(); - (yyval) = (yyvsp[(1) - (3)]); + unit->popContainer(); + (yyval) = (yyvsp[-2]); } else { (yyval) = 0; } -;} +} +#line 2963 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 92: - -/* Line 1455 of yacc.c */ -#line 1151 "../Slice/Grammar.y" +#line 1226 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OperationPtr op = OperationPtr::dynamicCast((yyvsp[(4) - (5)])); - ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[(5) - (5)])); + OperationPtr op = OperationPtr::dynamicCast((yyvsp[-1])); + ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[0])); assert(el); if(op) { op->setExceptionList(el->v); } -;} +} +#line 2977 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 93: - -/* Line 1455 of yacc.c */ -#line 1161 "../Slice/Grammar.y" +#line 1236 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(1) - (3)])) + if((yyvsp[-2])) { - unit->popContainer(); + unit->popContainer(); } yyerrok; -;} +} +#line 2989 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 94: - -/* Line 1455 of yacc.c */ -#line 1169 "../Slice/Grammar.y" +#line 1244 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - OperationPtr op = OperationPtr::dynamicCast((yyvsp[(4) - (5)])); - ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[(5) - (5)])); + OperationPtr op = OperationPtr::dynamicCast((yyvsp[-1])); + ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[0])); assert(el); if(op) { op->setExceptionList(el->v); // Dummy } -;} +} +#line 3003 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 97: - -/* Line 1455 of yacc.c */ -#line 1191 "../Slice/Grammar.y" +#line 1266 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 3011 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 98: - -/* Line 1455 of yacc.c */ -#line 1195 "../Slice/Grammar.y" +#line 1270 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as interface name"); - (yyval) = (yyvsp[(2) - (2)]); // Dummy -;} + (yyval) = (yyvsp[0]); // Dummy +} +#line 3021 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 99: - -/* Line 1455 of yacc.c */ -#line 1206 "../Slice/Grammar.y" +#line 1281 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ClassDeclPtr cl = cont->createClassDecl(ident->v, true, local->v); cont->checkIntroduced(ident->v, cl); (yyval) = cl; -;} +} +#line 3034 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 100: - -/* Line 1455 of yacc.c */ -#line 1220 "../Slice/Grammar.y" +#line 1295 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (3)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-2])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[-1])); ContainerPtr cont = unit->currentContainer(); - ClassListTokPtr bases = ClassListTokPtr::dynamicCast((yyvsp[(3) - (3)])); + ClassListTokPtr bases = ClassListTokPtr::dynamicCast((yyvsp[0])); ClassDefPtr cl = cont->createClassDef(ident->v, -1, true, bases->v, local->v); if(cl) { - cont->checkIntroduced(ident->v, cl); - unit->pushContainer(cl); - (yyval) = cl; + cont->checkIntroduced(ident->v, cl); + unit->pushContainer(cl); + (yyval) = cl; } else { (yyval) = 0; } -;} +} +#line 3056 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 101: - -/* Line 1455 of yacc.c */ -#line 1238 "../Slice/Grammar.y" +#line 1313 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - if((yyvsp[(4) - (7)])) + if((yyvsp[-3])) { - unit->popContainer(); - (yyval) = (yyvsp[(4) - (7)]); + unit->popContainer(); + (yyval) = (yyvsp[-3]); } else { - (yyval) = 0; + (yyval) = 0; } -;} +} +#line 3072 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 102: - -/* Line 1455 of yacc.c */ -#line 1255 "../Slice/Grammar.y" +#line 1330 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - ClassListTokPtr intfs = ClassListTokPtr::dynamicCast((yyvsp[(3) - (3)])); - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (3)])); + ClassListTokPtr intfs = ClassListTokPtr::dynamicCast((yyvsp[0])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); TypeList types = cont->lookupType(scoped->v); if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || !cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not an interface"; - unit->error(msg); - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); - } - else - { - cont->checkIntroduced(scoped->v); - intfs->v.push_front(def); - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || !cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not an interface"; + unit->error(msg); + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); + } + else + { + cont->checkIntroduced(scoped->v); + intfs->v.push_front(def); + } + } } (yyval) = intfs; -;} +} +#line 3111 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 103: - -/* Line 1455 of yacc.c */ -#line 1290 "../Slice/Grammar.y" +#line 1365 "src/Slice/Grammar.y" /* yacc.c:1661 */ { ClassListTokPtr intfs = new ClassListTok; - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); TypeList types = cont->lookupType(scoped->v); if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || !cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not an interface"; - unit->error(msg); // $$ is a dummy - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); // $$ is a dummy - } - else - { - cont->checkIntroduced(scoped->v); - intfs->v.push_front(def); - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || !cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not an interface"; + unit->error(msg); // $$ is a dummy + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); // $$ is a dummy + } + else + { + cont->checkIntroduced(scoped->v); + intfs->v.push_front(def); + } + } } (yyval) = intfs; -;} +} +#line 3150 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 104: - -/* Line 1455 of yacc.c */ -#line 1325 "../Slice/Grammar.y" +#line 1400 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("illegal inheritance from type Object"); (yyval) = new ClassListTok; // Dummy -;} +} +#line 3159 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 105: - -/* Line 1455 of yacc.c */ -#line 1335 "../Slice/Grammar.y" +#line 1405 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + unit->error("illegal inheritance from type Value"); + (yyval) = new ClassListTok; // Dummy +} +#line 3168 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 106: - -/* Line 1455 of yacc.c */ -#line 1339 "../Slice/Grammar.y" +#line 1415 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = new ClassListTok; -;} + (yyval) = (yyvsp[0]); +} +#line 3176 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 107: +#line 1419 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { + (yyval) = new ClassListTok; +} +#line 3184 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; -/* Line 1455 of yacc.c */ -#line 1348 "../Slice/Grammar.y" + case 108: +#line 1428 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); - ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[-2])); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } -;} +} +#line 3197 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 108: - -/* Line 1455 of yacc.c */ -#line 1357 "../Slice/Grammar.y" + case 109: +#line 1437 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3204 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 109: - -/* Line 1455 of yacc.c */ -#line 1360 "../Slice/Grammar.y" + case 110: +#line 1440 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("`;' missing after definition"); -;} +} +#line 3212 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 110: - -/* Line 1455 of yacc.c */ -#line 1364 "../Slice/Grammar.y" + case 111: +#line 1444 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3219 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 112: - -/* Line 1455 of yacc.c */ -#line 1378 "../Slice/Grammar.y" + case 113: +#line 1458 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[(1) - (3)])); - ExceptionListTokPtr exceptionList = ExceptionListTokPtr::dynamicCast((yyvsp[(3) - (3)])); + ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[-2])); + ExceptionListTokPtr exceptionList = ExceptionListTokPtr::dynamicCast((yyvsp[0])); exceptionList->v.push_front(exception); (yyval) = exceptionList; -;} +} +#line 3230 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 113: - -/* Line 1455 of yacc.c */ -#line 1385 "../Slice/Grammar.y" + case 114: +#line 1465 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[(1) - (1)])); + ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[0])); ExceptionListTokPtr exceptionList = new ExceptionListTok; exceptionList->v.push_front(exception); (yyval) = exceptionList; -;} +} +#line 3241 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 114: - -/* Line 1455 of yacc.c */ -#line 1397 "../Slice/Grammar.y" + case 115: +#line 1477 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); ExceptionPtr exception = cont->lookupException(scoped->v); if(!exception) { - exception = cont->createException(IceUtil::generateUUID(), 0, false, Dummy); // Dummy + exception = cont->createException(IceUtil::generateUUID(), 0, false, Dummy); // Dummy } cont->checkIntroduced(scoped->v, exception); (yyval) = exception; -;} +} +#line 3257 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 115: - -/* Line 1455 of yacc.c */ -#line 1409 "../Slice/Grammar.y" + case 116: +#line 1489 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as exception name"); (yyval) = unit->currentContainer()->createException(IceUtil::generateUUID(), 0, false, Dummy); // Dummy -;} +} +#line 3267 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 116: - -/* Line 1455 of yacc.c */ -#line 1420 "../Slice/Grammar.y" + case 117: +#line 1500 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (7)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(7) - (7)])); - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(4) - (7)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (7)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-6])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + TypePtr type = TypePtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); (yyval) = cont->createSequence(ident->v, type, metaData->v, local->v); -;} +} +#line 3280 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 117: - -/* Line 1455 of yacc.c */ -#line 1429 "../Slice/Grammar.y" + case 118: +#line 1509 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (7)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(7) - (7)])); - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(4) - (7)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (7)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-6])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + TypePtr type = TypePtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); (yyval) = cont->createSequence(ident->v, type, metaData->v, local->v); // Dummy unit->error("keyword `" + ident->v + "' cannot be used as sequence name"); -;} +} +#line 3294 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 118: - -/* Line 1455 of yacc.c */ -#line 1444 "../Slice/Grammar.y" - { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (10)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(10) - (10)])); - StringListTokPtr keyMetaData = StringListTokPtr::dynamicCast((yyvsp[(4) - (10)])); - TypePtr keyType = TypePtr::dynamicCast((yyvsp[(5) - (10)])); - StringListTokPtr valueMetaData = StringListTokPtr::dynamicCast((yyvsp[(7) - (10)])); - TypePtr valueType = TypePtr::dynamicCast((yyvsp[(8) - (10)])); + case 119: +#line 1524 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-9])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); + StringListTokPtr keyMetaData = StringListTokPtr::dynamicCast((yyvsp[-6])); + TypePtr keyType = TypePtr::dynamicCast((yyvsp[-5])); + StringListTokPtr valueMetaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + TypePtr valueType = TypePtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); (yyval) = cont->createDictionary(ident->v, keyType, keyMetaData->v, valueType, valueMetaData->v, local->v); -;} +} +#line 3309 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 119: - -/* Line 1455 of yacc.c */ -#line 1455 "../Slice/Grammar.y" - { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (10)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(10) - (10)])); - StringListTokPtr keyMetaData = StringListTokPtr::dynamicCast((yyvsp[(4) - (10)])); - TypePtr keyType = TypePtr::dynamicCast((yyvsp[(5) - (10)])); - StringListTokPtr valueMetaData = StringListTokPtr::dynamicCast((yyvsp[(7) - (10)])); - TypePtr valueType = TypePtr::dynamicCast((yyvsp[(8) - (10)])); + case 120: +#line 1535 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-9])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); + StringListTokPtr keyMetaData = StringListTokPtr::dynamicCast((yyvsp[-6])); + TypePtr keyType = TypePtr::dynamicCast((yyvsp[-5])); + StringListTokPtr valueMetaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + TypePtr valueType = TypePtr::dynamicCast((yyvsp[-2])); ContainerPtr cont = unit->currentContainer(); (yyval) = cont->createDictionary(ident->v, keyType, keyMetaData->v, valueType, valueMetaData->v, local->v); // Dummy unit->error("keyword `" + ident->v + "' cannot be used as dictionary name"); -;} +} +#line 3325 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 120: - -/* Line 1455 of yacc.c */ -#line 1472 "../Slice/Grammar.y" + case 121: +#line 1552 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 3333 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 121: - -/* Line 1455 of yacc.c */ -#line 1476 "../Slice/Grammar.y" + case 122: +#line 1556 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as enumeration name"); - (yyval) = (yyvsp[(2) - (2)]); // Dummy -;} + (yyval) = (yyvsp[0]); // Dummy +} +#line 3343 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 122: - -/* Line 1455 of yacc.c */ -#line 1487 "../Slice/Grammar.y" + case 123: +#line 1567 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); EnumPtr en = cont->createEnum(ident->v, local->v); - cont->checkIntroduced(ident->v, en); + if(en) + { + cont->checkIntroduced(ident->v, en); + } + else + { + en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); + } + unit->pushContainer(en); (yyval) = en; -;} +} +#line 3364 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 123: - -/* Line 1455 of yacc.c */ -#line 1496 "../Slice/Grammar.y" + case 124: +#line 1584 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - EnumPtr en = EnumPtr::dynamicCast((yyvsp[(3) - (6)])); + EnumPtr en = EnumPtr::dynamicCast((yyvsp[-3])); if(en) { - EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast((yyvsp[(5) - (6)])); - if(enumerators->v.empty()) - { - unit->error("enum `" + en->name() + "' must have at least one enumerator"); - } - en->setEnumerators(enumerators->v); // Dummy + EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast((yyvsp[-1])); + if(enumerators->v.empty()) + { + unit->error("enum `" + en->name() + "' must have at least one enumerator"); + } + unit->popContainer(); } - (yyval) = (yyvsp[(3) - (6)]); -;} + (yyval) = (yyvsp[-3]); +} +#line 3382 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 124: - -/* Line 1455 of yacc.c */ -#line 1511 "../Slice/Grammar.y" + case 125: +#line 1599 "src/Slice/Grammar.y" /* yacc.c:1661 */ { unit->error("missing enumeration name"); - BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (5)])); + BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[-1])); ContainerPtr cont = unit->currentContainer(); - EnumPtr en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); // Dummy - EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast((yyvsp[(4) - (5)])); - en->setEnumerators(enumerators->v); // Dummy + EnumPtr en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); + unit->pushContainer(en); (yyval) = en; -;} +} +#line 3395 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 125: + case 126: +#line 1608 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { + unit->popContainer(); + (yyval) = (yyvsp[-4]); +} +#line 3404 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; -/* Line 1455 of yacc.c */ -#line 1526 "../Slice/Grammar.y" + case 127: +#line 1618 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - EnumeratorListTokPtr ens = EnumeratorListTokPtr::dynamicCast((yyvsp[(1) - (3)])); - ens->v.splice(ens->v.end(), EnumeratorListTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v); + EnumeratorListTokPtr ens = EnumeratorListTokPtr::dynamicCast((yyvsp[-2])); + ens->v.splice(ens->v.end(), EnumeratorListTokPtr::dynamicCast((yyvsp[0]))->v); (yyval) = ens; -;} +} +#line 3414 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 126: - -/* Line 1455 of yacc.c */ -#line 1532 "../Slice/Grammar.y" + case 128: +#line 1624 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3421 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 127: - -/* Line 1455 of yacc.c */ -#line 1540 "../Slice/Grammar.y" + case 129: +#line 1632 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); EnumeratorListTokPtr ens = new EnumeratorListTok; ContainerPtr cont = unit->currentContainer(); EnumeratorPtr en = cont->createEnumerator(ident->v); if(en) { - ens->v.push_front(en); + ens->v.push_front(en); } (yyval) = ens; -;} +} +#line 3437 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 128: - -/* Line 1455 of yacc.c */ -#line 1552 "../Slice/Grammar.y" + case 130: +#line 1644 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (3)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[-2])); EnumeratorListTokPtr ens = new EnumeratorListTok; ContainerPtr cont = unit->currentContainer(); - IntegerTokPtr intVal = IntegerTokPtr::dynamicCast((yyvsp[(3) - (3)])); + IntegerTokPtr intVal = IntegerTokPtr::dynamicCast((yyvsp[0])); if(intVal) { if(intVal->v < 0 || intVal->v > Int32Max) @@ -3643,53 +3452,46 @@ yyreduce: else { EnumeratorPtr en = cont->createEnumerator(ident->v, static_cast<int>(intVal->v)); - if(en) - { - ens->v.push_front(en); - } + ens->v.push_front(en); } } (yyval) = ens; -;} +} +#line 3461 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 129: - -/* Line 1455 of yacc.c */ -#line 1575 "../Slice/Grammar.y" + case 131: +#line 1664 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); unit->error("keyword `" + ident->v + "' cannot be used as enumerator"); EnumeratorListTokPtr ens = new EnumeratorListTok; // Dummy (yyval) = ens; -;} +} +#line 3472 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 130: - -/* Line 1455 of yacc.c */ -#line 1582 "../Slice/Grammar.y" + case 132: +#line 1671 "src/Slice/Grammar.y" /* yacc.c:1661 */ { EnumeratorListTokPtr ens = new EnumeratorListTok; (yyval) = ens; // Dummy -;} +} +#line 3481 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 131: - -/* Line 1455 of yacc.c */ -#line 1592 "../Slice/Grammar.y" + case 133: +#line 1681 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(1) - (1)]); -;} + (yyval) = (yyvsp[0]); +} +#line 3489 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 132: - -/* Line 1455 of yacc.c */ -#line 1596 "../Slice/Grammar.y" + case 134: +#line 1685 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainedList cl = unit->currentContainer()->lookupContained(scoped->v); IntegerTokPtr tok; if(!cl.empty()) @@ -3720,433 +3522,407 @@ yyreduce: } (yyval) = tok; -;} +} +#line 3527 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 133: - -/* Line 1455 of yacc.c */ -#line 1635 "../Slice/Grammar.y" + case 135: +#line 1724 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BoolTokPtr out = new BoolTok; out->v = true; (yyval) = out; -;} +} +#line 3537 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 134: - -/* Line 1455 of yacc.c */ -#line 1641 "../Slice/Grammar.y" + case 136: +#line 1730 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BoolTokPtr out = new BoolTok; out->v = false; (yyval) = out; -;} +} +#line 3547 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 135: - -/* Line 1455 of yacc.c */ -#line 1652 "../Slice/Grammar.y" + case 137: +#line 1741 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3554 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 136: - -/* Line 1455 of yacc.c */ -#line 1655 "../Slice/Grammar.y" + case 138: +#line 1744 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); - OptionalDefTokPtr tsp = OptionalDefTokPtr::dynamicCast((yyvsp[(3) - (3)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-2])); + OptionalDefTokPtr tsp = OptionalDefTokPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); - unit->currentContainer()->checkIntroduced(tsp->v.name, pd); - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(2) - (3)])); + ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); + unit->currentContainer()->checkIntroduced(tsp->v.name, pd); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-1])); if(!metaData->v.empty()) { pd->setMetaData(metaData->v); } } -;} +} +#line 3574 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 137: - -/* Line 1455 of yacc.c */ -#line 1671 "../Slice/Grammar.y" + case 139: +#line 1760 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (5)])); - OptionalDefTokPtr tsp = OptionalDefTokPtr::dynamicCast((yyvsp[(5) - (5)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-2])); + OptionalDefTokPtr tsp = OptionalDefTokPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); - unit->currentContainer()->checkIntroduced(tsp->v.name, pd); - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(4) - (5)])); + ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); + unit->currentContainer()->checkIntroduced(tsp->v.name, pd); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-1])); if(!metaData->v.empty()) { pd->setMetaData(metaData->v); } } -;} +} +#line 3594 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 138: - -/* Line 1455 of yacc.c */ -#line 1687 "../Slice/Grammar.y" + case 140: +#line 1776 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (4)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(3) - (4)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(4) - (4)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-3])); + TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy - unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); + op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy + unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); } -;} +} +#line 3610 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 139: - -/* Line 1455 of yacc.c */ -#line 1699 "../Slice/Grammar.y" + case 141: +#line 1788 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (6)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (6)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(6) - (6)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-3])); + TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy - unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); + op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy + unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); } -;} +} +#line 3626 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 140: - -/* Line 1455 of yacc.c */ -#line 1711 "../Slice/Grammar.y" + case 142: +#line 1800 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(3) - (3)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-2])); + TypePtr type = TypePtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy - unit->error("missing parameter name"); + op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy + unit->error("missing parameter name"); } -;} +} +#line 3641 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 141: - -/* Line 1455 of yacc.c */ -#line 1722 "../Slice/Grammar.y" + case 143: +#line 1811 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (5)])); - TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (5)])); + BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[-2])); + TypePtr type = TypePtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy - unit->error("missing parameter name"); + op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy + unit->error("missing parameter name"); } -;} +} +#line 3656 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 142: - -/* Line 1455 of yacc.c */ -#line 1738 "../Slice/Grammar.y" + case 144: +#line 1827 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - (yyval) = (yyvsp[(2) - (2)]); -;} + (yyval) = (yyvsp[0]); +} +#line 3664 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 143: - -/* Line 1455 of yacc.c */ -#line 1742 "../Slice/Grammar.y" + case 145: +#line 1831 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = new ExceptionListTok; -;} +} +#line 3672 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 144: - -/* Line 1455 of yacc.c */ -#line 1751 "../Slice/Grammar.y" + case 146: +#line 1840 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3679 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 145: - -/* Line 1455 of yacc.c */ -#line 1754 "../Slice/Grammar.y" + case 147: +#line 1843 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); ident->v = "::" + ident->v; (yyval) = ident; -;} +} +#line 3689 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 146: - -/* Line 1455 of yacc.c */ -#line 1760 "../Slice/Grammar.y" + case 148: +#line 1849 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (3)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(3) - (3)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[-2])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[0])); scoped->v += "::"; scoped->v += ident->v; (yyval) = scoped; -;} +} +#line 3701 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 147: - -/* Line 1455 of yacc.c */ -#line 1773 "../Slice/Grammar.y" + case 149: +#line 1862 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindByte); -;} +} +#line 3709 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 148: - -/* Line 1455 of yacc.c */ -#line 1777 "../Slice/Grammar.y" + case 150: +#line 1866 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindBool); -;} +} +#line 3717 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 149: - -/* Line 1455 of yacc.c */ -#line 1781 "../Slice/Grammar.y" + case 151: +#line 1870 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindShort); -;} +} +#line 3725 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 150: - -/* Line 1455 of yacc.c */ -#line 1785 "../Slice/Grammar.y" + case 152: +#line 1874 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindInt); -;} +} +#line 3733 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 151: - -/* Line 1455 of yacc.c */ -#line 1789 "../Slice/Grammar.y" + case 153: +#line 1878 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindLong); -;} +} +#line 3741 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 152: - -/* Line 1455 of yacc.c */ -#line 1793 "../Slice/Grammar.y" + case 154: +#line 1882 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindFloat); -;} +} +#line 3749 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 153: - -/* Line 1455 of yacc.c */ -#line 1797 "../Slice/Grammar.y" + case 155: +#line 1886 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindDouble); -;} +} +#line 3757 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 154: - -/* Line 1455 of yacc.c */ -#line 1801 "../Slice/Grammar.y" + case 156: +#line 1890 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindString); -;} +} +#line 3765 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 155: - -/* Line 1455 of yacc.c */ -#line 1805 "../Slice/Grammar.y" + case 157: +#line 1894 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindObject); -;} +} +#line 3773 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 156: - -/* Line 1455 of yacc.c */ -#line 1809 "../Slice/Grammar.y" + case 158: +#line 1898 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindObjectProxy); -;} +} +#line 3781 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 157: - -/* Line 1455 of yacc.c */ -#line 1813 "../Slice/Grammar.y" + case 159: +#line 1902 "src/Slice/Grammar.y" /* yacc.c:1661 */ { (yyval) = unit->builtin(Builtin::KindLocalObject); -;} +} +#line 3789 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 158: + case 160: +#line 1906 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { + (yyval) = unit->builtin(Builtin::KindValue); +} +#line 3797 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; -/* Line 1455 of yacc.c */ -#line 1817 "../Slice/Grammar.y" + case 161: +#line 1910 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ContainerPtr cont = unit->currentContainer(); if(cont) { - TypeList types = cont->lookupType(scoped->v); - if(types.empty()) - { - YYERROR; // Can't continue, jump to next yyerrok - } - cont->checkIntroduced(scoped->v); - (yyval) = types.front(); + TypeList types = cont->lookupType(scoped->v); + if(types.empty()) + { + YYERROR; // Can't continue, jump to next yyerrok + } + cont->checkIntroduced(scoped->v); + (yyval) = types.front(); } else { (yyval) = 0; } -;} +} +#line 3820 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 159: - -/* Line 1455 of yacc.c */ -#line 1836 "../Slice/Grammar.y" + case 162: +#line 1929 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (2)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[-1])); ContainerPtr cont = unit->currentContainer(); if(cont) { - TypeList types = cont->lookupType(scoped->v); - if(types.empty()) - { - YYERROR; // Can't continue, jump to next yyerrok - } - for(TypeList::iterator p = types.begin(); p != types.end(); ++p) - { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); - if(!cl) - { - string msg = "`"; - msg += scoped->v; - msg += "' must be class or interface"; - unit->error(msg); - YYERROR; // Can't continue, jump to next yyerrok - } - cont->checkIntroduced(scoped->v); - if(cl->isLocal()) - { - unit->error("cannot create proxy for " + cl->kindOf() + " `" + cl->name() + "'"); // $$ is dummy - } - *p = new Proxy(cl); - } - (yyval) = types.front(); + TypeList types = cont->lookupType(scoped->v); + if(types.empty()) + { + YYERROR; // Can't continue, jump to next yyerrok + } + for(TypeList::iterator p = types.begin(); p != types.end(); ++p) + { + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); + if(!cl) + { + string msg = "`"; + msg += scoped->v; + msg += "' must be class or interface"; + unit->error(msg); + YYERROR; // Can't continue, jump to next yyerrok + } + cont->checkIntroduced(scoped->v); + if(cl->isLocal()) + { + unit->error("cannot create proxy for " + cl->kindOf() + " `" + cl->name() + "'"); // $$ is dummy + } + *p = new Proxy(cl); + } + (yyval) = types.front(); } else { (yyval) = 0; } -;} +} +#line 3860 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 160: - -/* Line 1455 of yacc.c */ -#line 1877 "../Slice/Grammar.y" + case 163: +#line 1970 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr str1 = StringTokPtr::dynamicCast((yyvsp[(1) - (2)])); - StringTokPtr str2 = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); + StringTokPtr str1 = StringTokPtr::dynamicCast((yyvsp[-1])); + StringTokPtr str2 = StringTokPtr::dynamicCast((yyvsp[0])); str1->v += str2->v; -;} +} +#line 3870 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 161: - -/* Line 1455 of yacc.c */ -#line 1883 "../Slice/Grammar.y" + case 164: +#line 1976 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 3877 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 162: - -/* Line 1455 of yacc.c */ -#line 1891 "../Slice/Grammar.y" + case 165: +#line 1984 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[(3) - (3)])); - StringListTokPtr stringList = StringListTokPtr::dynamicCast((yyvsp[(1) - (3)])); + StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[0])); + StringListTokPtr stringList = StringListTokPtr::dynamicCast((yyvsp[-2])); stringList->v.push_back(str->v); (yyval) = stringList; -;} +} +#line 3888 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 163: - -/* Line 1455 of yacc.c */ -#line 1898 "../Slice/Grammar.y" + case 166: +#line 1991 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[0])); StringListTokPtr stringList = new StringListTok; stringList->v.push_back(str->v); (yyval) = stringList; -;} +} +#line 3899 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 164: - -/* Line 1455 of yacc.c */ -#line 1910 "../Slice/Grammar.y" + case 167: +#line 2003 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BoolTokPtr local = new BoolTok; local->v = true; (yyval) = local; -;} +} +#line 3909 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 165: - -/* Line 1455 of yacc.c */ -#line 1916 "../Slice/Grammar.y" + case 168: +#line 2009 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BoolTokPtr local = new BoolTok; local->v = false; (yyval) = local; -;} +} +#line 3919 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 166: - -/* Line 1455 of yacc.c */ -#line 1927 "../Slice/Grammar.y" + case 169: +#line 2020 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BuiltinPtr type = unit->builtin(Builtin::KindLong); - IntegerTokPtr intVal = IntegerTokPtr::dynamicCast((yyvsp[(1) - (1)])); + IntegerTokPtr intVal = IntegerTokPtr::dynamicCast((yyvsp[0])); ostringstream sstr; sstr << intVal->v; ConstDefTokPtr def = new ConstDefTok; @@ -4155,16 +3931,15 @@ yyreduce: def->v.valueAsString = sstr.str(); def->v.valueAsLiteral = intVal->literal; (yyval) = def; -;} +} +#line 3936 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 167: - -/* Line 1455 of yacc.c */ -#line 1940 "../Slice/Grammar.y" + case 170: +#line 2033 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BuiltinPtr type = unit->builtin(Builtin::KindDouble); - FloatingTokPtr floatVal = FloatingTokPtr::dynamicCast((yyvsp[(1) - (1)])); + FloatingTokPtr floatVal = FloatingTokPtr::dynamicCast((yyvsp[0])); ostringstream sstr; sstr << floatVal->v; ConstDefTokPtr def = new ConstDefTok; @@ -4173,19 +3948,19 @@ yyreduce: def->v.valueAsString = sstr.str(); def->v.valueAsLiteral = floatVal->literal; (yyval) = def; -;} +} +#line 3953 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 168: - -/* Line 1455 of yacc.c */ -#line 1953 "../Slice/Grammar.y" + case 171: +#line 2046 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[0])); ConstDefTokPtr def = new ConstDefTok; - ContainedList cl = unit->currentContainer()->lookupContained(scoped->v); + ContainedList cl = unit->currentContainer()->lookupContained(scoped->v, false); if(cl.empty()) { + // Could be an enumerator def->v.type = TypePtr(0); def->v.value = SyntaxTreeBasePtr(0); def->v.valueAsString = scoped->v; @@ -4193,9 +3968,9 @@ yyreduce: } else { - EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); + EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); ConstPtr constant = ConstPtr::dynamicCast(cl.front()); - if(enumerator) + if(enumerator) { unit->currentContainer()->checkIntroduced(scoped->v, enumerator); def->v.type = enumerator->type(); @@ -4211,336 +3986,319 @@ yyreduce: def->v.valueAsLiteral = constant->value(); } else - { - string msg = "illegal initializer: `" + scoped->v + "' is a"; - static const string vowels = "aeiou"; - string kindOf = cl.front()->kindOf(); - if(vowels.find_first_of(kindOf[0]) != string::npos) - { - msg += "n"; - } - msg += " " + kindOf; - unit->error(msg); // $$ is dummy - } + { + string msg = "illegal initializer: `" + scoped->v + "' is a"; + static const string vowels = "aeiou"; + string kindOf = cl.front()->kindOf(); + if(vowels.find_first_of(kindOf[0]) != string::npos) + { + msg += "n"; + } + msg += " " + kindOf; + unit->error(msg); // $$ is dummy + } } (yyval) = def; -;} +} +#line 4004 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 169: - -/* Line 1455 of yacc.c */ -#line 1999 "../Slice/Grammar.y" + case 172: +#line 2093 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BuiltinPtr type = unit->builtin(Builtin::KindString); - StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[0])); ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; def->v.valueAsString = literal->v; def->v.valueAsLiteral = literal->literal; (yyval) = def; -;} +} +#line 4019 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 170: - -/* Line 1455 of yacc.c */ -#line 2010 "../Slice/Grammar.y" + case 173: +#line 2104 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BuiltinPtr type = unit->builtin(Builtin::KindBool); - StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[0])); ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; def->v.valueAsString = "false"; def->v.valueAsLiteral = "false"; (yyval) = def; -;} +} +#line 4034 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 171: - -/* Line 1455 of yacc.c */ -#line 2021 "../Slice/Grammar.y" + case 174: +#line 2115 "src/Slice/Grammar.y" /* yacc.c:1661 */ { BuiltinPtr type = unit->builtin(Builtin::KindBool); - StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); + StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[0])); ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; def->v.valueAsString = "true"; def->v.valueAsLiteral = "true"; (yyval) = def; -;} +} +#line 4049 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 172: - -/* Line 1455 of yacc.c */ -#line 2037 "../Slice/Grammar.y" + case 175: +#line 2131 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(2) - (6)])); - TypePtr const_type = TypePtr::dynamicCast((yyvsp[(3) - (6)])); - StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(4) - (6)])); - ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(6) - (6)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-4])); + TypePtr const_type = TypePtr::dynamicCast((yyvsp[-3])); + StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[-2])); + ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[0])); (yyval) = unit->currentContainer()->createConst(ident->v, const_type, metaData->v, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); -;} +} +#line 4062 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; - case 173: - -/* Line 1455 of yacc.c */ -#line 2046 "../Slice/Grammar.y" + case 176: +#line 2140 "src/Slice/Grammar.y" /* yacc.c:1661 */ { - StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(2) - (5)])); - TypePtr const_type = TypePtr::dynamicCast((yyvsp[(3) - (5)])); - ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(5) - (5)])); + StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[-3])); + TypePtr const_type = TypePtr::dynamicCast((yyvsp[-2])); + ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[0])); unit->error("missing constant name"); (yyval) = unit->currentContainer()->createConst(IceUtil::generateUUID(), const_type, metaData->v, value->v.value, value->v.valueAsString, value->v.valueAsLiteral, Dummy); // Dummy -;} - break; - - case 174: - -/* Line 1455 of yacc.c */ -#line 2060 "../Slice/Grammar.y" - { -;} - break; - - case 175: - -/* Line 1455 of yacc.c */ -#line 2063 "../Slice/Grammar.y" - { -;} - break; - - case 176: - -/* Line 1455 of yacc.c */ -#line 2066 "../Slice/Grammar.y" - { -;} +} +#line 4075 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 177: - -/* Line 1455 of yacc.c */ -#line 2069 "../Slice/Grammar.y" +#line 2154 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4082 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 178: - -/* Line 1455 of yacc.c */ -#line 2072 "../Slice/Grammar.y" +#line 2157 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4089 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 179: - -/* Line 1455 of yacc.c */ -#line 2075 "../Slice/Grammar.y" +#line 2160 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4096 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 180: - -/* Line 1455 of yacc.c */ -#line 2078 "../Slice/Grammar.y" +#line 2163 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4103 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 181: - -/* Line 1455 of yacc.c */ -#line 2081 "../Slice/Grammar.y" +#line 2166 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4110 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 182: - -/* Line 1455 of yacc.c */ -#line 2084 "../Slice/Grammar.y" +#line 2169 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4117 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 183: - -/* Line 1455 of yacc.c */ -#line 2087 "../Slice/Grammar.y" +#line 2172 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4124 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 184: - -/* Line 1455 of yacc.c */ -#line 2090 "../Slice/Grammar.y" +#line 2175 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4131 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 185: - -/* Line 1455 of yacc.c */ -#line 2093 "../Slice/Grammar.y" +#line 2178 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4138 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 186: - -/* Line 1455 of yacc.c */ -#line 2096 "../Slice/Grammar.y" +#line 2181 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4145 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 187: - -/* Line 1455 of yacc.c */ -#line 2099 "../Slice/Grammar.y" +#line 2184 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4152 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 188: - -/* Line 1455 of yacc.c */ -#line 2102 "../Slice/Grammar.y" +#line 2187 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4159 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 189: - -/* Line 1455 of yacc.c */ -#line 2105 "../Slice/Grammar.y" +#line 2190 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4166 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 190: - -/* Line 1455 of yacc.c */ -#line 2108 "../Slice/Grammar.y" +#line 2193 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4173 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 191: - -/* Line 1455 of yacc.c */ -#line 2111 "../Slice/Grammar.y" +#line 2196 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4180 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 192: - -/* Line 1455 of yacc.c */ -#line 2114 "../Slice/Grammar.y" +#line 2199 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4187 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 193: - -/* Line 1455 of yacc.c */ -#line 2117 "../Slice/Grammar.y" +#line 2202 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4194 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 194: - -/* Line 1455 of yacc.c */ -#line 2120 "../Slice/Grammar.y" +#line 2205 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4201 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 195: - -/* Line 1455 of yacc.c */ -#line 2123 "../Slice/Grammar.y" +#line 2208 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4208 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 196: - -/* Line 1455 of yacc.c */ -#line 2126 "../Slice/Grammar.y" +#line 2211 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4215 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 197: - -/* Line 1455 of yacc.c */ -#line 2129 "../Slice/Grammar.y" +#line 2214 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4222 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 198: - -/* Line 1455 of yacc.c */ -#line 2132 "../Slice/Grammar.y" +#line 2217 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4229 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 199: - -/* Line 1455 of yacc.c */ -#line 2135 "../Slice/Grammar.y" +#line 2220 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4236 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 200: - -/* Line 1455 of yacc.c */ -#line 2138 "../Slice/Grammar.y" +#line 2223 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4243 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 201: - -/* Line 1455 of yacc.c */ -#line 2141 "../Slice/Grammar.y" +#line 2226 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4250 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; case 202: +#line 2229 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { +} +#line 4257 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; -/* Line 1455 of yacc.c */ -#line 2144 "../Slice/Grammar.y" + case 203: +#line 2232 "src/Slice/Grammar.y" /* yacc.c:1661 */ { -;} +} +#line 4264 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ break; + case 204: +#line 2235 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { +} +#line 4271 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; + + case 205: +#line 2238 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { +} +#line 4278 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; + + case 206: +#line 2241 "src/Slice/Grammar.y" /* yacc.c:1661 */ + { +} +#line 4285 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ + break; -/* Line 1455 of yacc.c */ -#line 4542 "Grammar.tab.c" +#line 4289 "src/Slice/Grammar.cpp" /* yacc.c:1661 */ default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -4549,7 +4307,7 @@ yyreduce: *++yyvsp = yyval; - /* Now `shift' the result of the reduction. Determine what state + /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ @@ -4564,10 +4322,14 @@ yyreduce: goto yynewstate; -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -4575,37 +4337,36 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); - } - else - { - yyerror (YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -4614,20 +4375,20 @@ yyerrlab: if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an - error, discard it. */ + error, discard it. */ if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } } /* Else will try to reuse lookahead token after shifting the error @@ -4646,7 +4407,7 @@ yyerrorlab: if (/*CONSTCOND*/ 0) goto yyerrorlab; - /* Do not reclaim the symbols of the rule which action triggered + /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; @@ -4659,35 +4420,37 @@ yyerrorlab: | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) - YYABORT; + YYABORT; yydestruct ("Error: popping", - yystos[yystate], yyvsp); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ @@ -4711,7 +4474,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined(yyoverflow) || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -4723,16 +4486,21 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - /* Do not reclaim the symbols of the rule which action triggered + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -4743,13 +4511,7 @@ yyreturn: if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif - /* Make sure YYID is used. */ - return YYID (yyresult); + return yyresult; } - - - -/* Line 1675 of yacc.c */ -#line 2148 "../Slice/Grammar.y" - +#line 2245 "src/Slice/Grammar.y" /* yacc.c:1906 */ diff --git a/cpp/src/Slice/Grammar.h b/cpp/src/Slice/Grammar.h index 0ee3d141315..86819102570 100644 --- a/cpp/src/Slice/Grammar.h +++ b/cpp/src/Slice/Grammar.h @@ -1,21 +1,19 @@ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. -/* Skeleton interface for Bison's Yacc-like parsers in C - - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -28,71 +26,80 @@ special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. - + This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +#ifndef YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED +# define YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int slice_debug; +#endif -/* Tokens. */ +/* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - ICE_MODULE = 258, - ICE_CLASS = 259, - ICE_INTERFACE = 260, - ICE_EXCEPTION = 261, - ICE_STRUCT = 262, - ICE_SEQUENCE = 263, - ICE_DICTIONARY = 264, - ICE_ENUM = 265, - ICE_OUT = 266, - ICE_EXTENDS = 267, - ICE_IMPLEMENTS = 268, - ICE_THROWS = 269, - ICE_VOID = 270, - ICE_BYTE = 271, - ICE_BOOL = 272, - ICE_SHORT = 273, - ICE_INT = 274, - ICE_LONG = 275, - ICE_FLOAT = 276, - ICE_DOUBLE = 277, - ICE_STRING = 278, - ICE_OBJECT = 279, - ICE_LOCAL_OBJECT = 280, - ICE_LOCAL = 281, - ICE_CONST = 282, - ICE_FALSE = 283, - ICE_TRUE = 284, - ICE_IDEMPOTENT = 285, - ICE_OPTIONAL = 286, - ICE_SCOPE_DELIMITER = 287, - ICE_IDENTIFIER = 288, - ICE_STRING_LITERAL = 289, - ICE_INTEGER_LITERAL = 290, - ICE_FLOATING_POINT_LITERAL = 291, - ICE_IDENT_OP = 292, - ICE_KEYWORD_OP = 293, - ICE_OPTIONAL_OP = 294, - ICE_METADATA_OPEN = 295, - ICE_METADATA_CLOSE = 296, - ICE_GLOBAL_METADATA_OPEN = 297, - ICE_GLOBAL_METADATA_CLOSE = 298, - BAD_CHAR = 299 - }; + enum yytokentype + { + ICE_MODULE = 258, + ICE_CLASS = 259, + ICE_INTERFACE = 260, + ICE_EXCEPTION = 261, + ICE_STRUCT = 262, + ICE_SEQUENCE = 263, + ICE_DICTIONARY = 264, + ICE_ENUM = 265, + ICE_OUT = 266, + ICE_EXTENDS = 267, + ICE_IMPLEMENTS = 268, + ICE_THROWS = 269, + ICE_VOID = 270, + ICE_BYTE = 271, + ICE_BOOL = 272, + ICE_SHORT = 273, + ICE_INT = 274, + ICE_LONG = 275, + ICE_FLOAT = 276, + ICE_DOUBLE = 277, + ICE_STRING = 278, + ICE_OBJECT = 279, + ICE_LOCAL_OBJECT = 280, + ICE_LOCAL = 281, + ICE_CONST = 282, + ICE_FALSE = 283, + ICE_TRUE = 284, + ICE_IDEMPOTENT = 285, + ICE_OPTIONAL = 286, + ICE_VALUE = 287, + ICE_SCOPE_DELIMITER = 288, + ICE_IDENTIFIER = 289, + ICE_STRING_LITERAL = 290, + ICE_INTEGER_LITERAL = 291, + ICE_FLOATING_POINT_LITERAL = 292, + ICE_IDENT_OP = 293, + ICE_KEYWORD_OP = 294, + ICE_OPTIONAL_OP = 295, + ICE_METADATA_OPEN = 296, + ICE_METADATA_CLOSE = 297, + ICE_GLOBAL_METADATA_OPEN = 298, + ICE_GLOBAL_METADATA_CLOSE = 299, + BAD_CHAR = 300 + }; #endif - - +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef int YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif +int slice_parse (void); +#endif /* !YY_SLICE_SRC_SLICE_GRAMMAR_HPP_INCLUDED */ diff --git a/cpp/src/Slice/Grammar.y b/cpp/src/Slice/Grammar.y index 2867ef96cf9..0ff52066500 100644 --- a/cpp/src/Slice/Grammar.y +++ b/cpp/src/Slice/Grammar.y @@ -40,17 +40,17 @@ slice_error(const char* s) if (strcmp(s, "parse error") == 0) { - unit->error("syntax error"); + unit->error("syntax error"); } else { - unit->error(s); + unit->error(s); } } %} -%pure_parser +%pure-parser // // All keyword tokens. Make sure to modify the "keyword" rule in this @@ -86,6 +86,7 @@ slice_error(const char* s) %token ICE_TRUE %token ICE_IDEMPOTENT %token ICE_OPTIONAL +%token ICE_VALUE // // Other tokens. @@ -156,7 +157,7 @@ definitions ContainedPtr contained = ContainedPtr::dynamicCast($2); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } } ';' definitions @@ -242,9 +243,9 @@ module_def ModulePtr module = cont->createModule(ident->v); if(module) { - cont->checkIntroduced(ident->v, module); - unit->pushContainer(module); - $$ = module; + cont->checkIntroduced(ident->v, module); + unit->pushContainer(module); + $$ = module; } else { @@ -255,8 +256,8 @@ module_def { if($3) { - unit->popContainer(); - $$ = $3; + unit->popContainer(); + $$ = $3; } else { @@ -302,8 +303,8 @@ exception_def ExceptionPtr ex = cont->createException(ident->v, base, local->v); if(ex) { - cont->checkIntroduced(ident->v, ex); - unit->pushContainer(ex); + cont->checkIntroduced(ident->v, ex); + unit->pushContainer(ex); } $$ = ex; } @@ -311,7 +312,7 @@ exception_def { if($4) { - unit->popContainer(); + unit->popContainer(); } $$ = $4; } @@ -343,7 +344,7 @@ exception_exports ContainedPtr contained = ContainedPtr::dynamicCast($2); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } } | error ';' exception_exports @@ -400,7 +401,44 @@ optional ContainerPtr cont = unit->currentContainer(); assert(cont); - ContainedList cl = cont->lookupContained(scoped->v); + ContainedList cl = cont->lookupContained(scoped->v, false); + if(cl.empty()) + { + EnumeratorList enumerators = cont->enumerators(scoped->v); + if(enumerators.size() == 1) + { + // Found + cl.push_back(enumerators.front()); + scoped->v = enumerators.front()->scoped(); + unit->warning(Deprecated, string("referencing enumerator `") + scoped->v + + "' without its enumeration's scope is deprecated"); + } + else if(enumerators.size() > 1) + { + ostringstream os; + os << "enumerator `" << scoped->v << "' could designate"; + bool first = true; + for(EnumeratorList::iterator p = enumerators.begin(); p != enumerators.end(); ++p) + { + if(first) + { + first = false; + } + else + { + os << " or"; + } + + os << " `" << (*p)->scoped() << "'"; + } + unit->error(os.str()); + } + else + { + unit->error(string("`") + scoped->v + "' is not defined"); + } + } + if(cl.empty()) { YYERROR; // Can't continue, jump to next yyerrok @@ -533,8 +571,8 @@ struct_def StructPtr st = cont->createStruct(ident->v, local->v); if(st) { - cont->checkIntroduced(ident->v, st); - unit->pushContainer(st); + cont->checkIntroduced(ident->v, st); + unit->pushContainer(st); } else { @@ -548,7 +586,7 @@ struct_def { if($3) { - unit->popContainer(); + unit->popContainer(); } $$ = $3; @@ -559,7 +597,7 @@ struct_def assert(st); if(st->dataMembers().empty()) { - unit->error("struct `" + st->name() + "' must have at least one member"); // $$ is a dummy + unit->error("struct `" + st->name() + "' must have at least one member"); // $$ is a dummy } } ; @@ -573,7 +611,7 @@ struct_exports ContainedPtr contained = ContainedPtr::dynamicCast($2); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } } | error ';' struct_exports @@ -643,7 +681,44 @@ class_id ContainerPtr cont = unit->currentContainer(); assert(cont); - ContainedList cl = cont->lookupContained(scoped->v); + ContainedList cl = cont->lookupContained(scoped->v, false); + if(cl.empty()) + { + EnumeratorList enumerators = cont->enumerators(scoped->v); + if(enumerators.size() == 1) + { + // Found + cl.push_back(enumerators.front()); + scoped->v = enumerators.front()->scoped(); + unit->warning(Deprecated, string("referencing enumerator `") + scoped->v + + "' without its enumeration's scope is deprecated"); + } + else if(enumerators.size() > 1) + { + ostringstream os; + os << "enumerator `" << scoped->v << "' could designate"; + bool first = true; + for(EnumeratorList::iterator p = enumerators.begin(); p != enumerators.end(); ++p) + { + if(first) + { + first = false; + } + else + { + os << " or"; + } + + os << " `" << (*p)->scoped() << "'"; + } + unit->error(os.str()); + } + else + { + unit->error(string("`") + scoped->v + "' is not defined"); + } + } + if(cl.empty()) { YYERROR; // Can't continue, jump to next yyerrok @@ -736,14 +811,14 @@ class_def ClassListTokPtr bases = ClassListTokPtr::dynamicCast($4); if(base) { - bases->v.push_front(base); + bases->v.push_front(base); } ClassDefPtr cl = cont->createClassDef(ident->v, ident->t, false, bases->v, local->v); if(cl) { - cont->checkIntroduced(ident->v, cl); - unit->pushContainer(cl); - $$ = cl; + cont->checkIntroduced(ident->v, cl); + unit->pushContainer(cl); + $$ = cl; } else { @@ -754,8 +829,8 @@ class_def { if($5) { - unit->popContainer(); - $$ = $5; + unit->popContainer(); + $$ = $5; } else { @@ -775,30 +850,30 @@ class_extends $$ = 0; if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not a class"; - unit->error(msg); - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); - } - else - { - cont->checkIntroduced(scoped->v); - $$ = def; - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not a class"; + unit->error(msg); + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); + } + else + { + cont->checkIntroduced(scoped->v); + $$ = def; + } + } } } | @@ -829,7 +904,7 @@ class_exports ContainedPtr contained = ContainedPtr::dynamicCast($2); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } } | error ';' class_exports @@ -1039,17 +1114,17 @@ operation_preamble ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); - if(op) - { - cl->checkIntroduced(name, op); - unit->pushContainer(op); - $$ = op; - } - else - { - $$ = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); + if(op) + { + cl->checkIntroduced(name, op); + unit->pushContainer(op); + $$ = op; + } + else + { + $$ = 0; + } } else { @@ -1063,18 +1138,18 @@ operation_preamble ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, - Operation::Idempotent); - if(op) - { - cl->checkIntroduced(name, op); - unit->pushContainer(op); - $$ = op; - } - else - { - $$ = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, + Operation::Idempotent); + if(op) + { + cl->checkIntroduced(name, op); + unit->pushContainer(op); + $$ = op; + } + else + { + $$ = 0; + } } else { @@ -1088,17 +1163,17 @@ operation_preamble ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); - if(op) - { - unit->pushContainer(op); - unit->error("keyword `" + name + "' cannot be used as operation name"); - $$ = op; // Dummy - } - else - { - $$ = 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag); + if(op) + { + unit->pushContainer(op); + unit->error("keyword `" + name + "' cannot be used as operation name"); + $$ = op; // Dummy + } + else + { + $$ = 0; + } } else { @@ -1112,22 +1187,22 @@ operation_preamble ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); if(cl) { - OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, - Operation::Idempotent); - if(op) - { - unit->pushContainer(op); - unit->error("keyword `" + name + "' cannot be used as operation name"); - $$ = op; // Dummy - } - else - { - return 0; - } + OperationPtr op = cl->createOperation(name, returnType->v.type, returnType->v.optional, returnType->v.tag, + Operation::Idempotent); + if(op) + { + unit->pushContainer(op); + unit->error("keyword `" + name + "' cannot be used as operation name"); + $$ = op; // Dummy + } + else + { + return 0; + } } else { - $$ = 0; + $$ = 0; } } ; @@ -1139,8 +1214,8 @@ operation { if($1) { - unit->popContainer(); - $$ = $1; + unit->popContainer(); + $$ = $1; } else { @@ -1161,7 +1236,7 @@ throws { if($1) { - unit->popContainer(); + unit->popContainer(); } yyerrok; } @@ -1225,9 +1300,9 @@ interface_def ClassDefPtr cl = cont->createClassDef(ident->v, -1, true, bases->v, local->v); if(cl) { - cont->checkIntroduced(ident->v, cl); - unit->pushContainer(cl); - $$ = cl; + cont->checkIntroduced(ident->v, cl); + unit->pushContainer(cl); + $$ = cl; } else { @@ -1238,12 +1313,12 @@ interface_def { if($4) { - unit->popContainer(); - $$ = $4; + unit->popContainer(); + $$ = $4; } else { - $$ = 0; + $$ = 0; } } ; @@ -1259,30 +1334,30 @@ interface_list TypeList types = cont->lookupType(scoped->v); if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || !cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not an interface"; - unit->error(msg); - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); - } - else - { - cont->checkIntroduced(scoped->v); - intfs->v.push_front(def); - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || !cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not an interface"; + unit->error(msg); + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); + } + else + { + cont->checkIntroduced(scoped->v); + intfs->v.push_front(def); + } + } } $$ = intfs; } @@ -1294,30 +1369,30 @@ interface_list TypeList types = cont->lookupType(scoped->v); if(!types.empty()) { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); - if(!cl || !cl->isInterface()) - { - string msg = "`"; - msg += scoped->v; - msg += "' is not an interface"; - unit->error(msg); // $$ is a dummy - } - else - { - ClassDefPtr def = cl->definition(); - if(!def) - { - string msg = "`"; - msg += scoped->v; - msg += "' has been declared but not defined"; - unit->error(msg); // $$ is a dummy - } - else - { - cont->checkIntroduced(scoped->v); - intfs->v.push_front(def); - } - } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(types.front()); + if(!cl || !cl->isInterface()) + { + string msg = "`"; + msg += scoped->v; + msg += "' is not an interface"; + unit->error(msg); // $$ is a dummy + } + else + { + ClassDefPtr def = cl->definition(); + if(!def) + { + string msg = "`"; + msg += scoped->v; + msg += "' has been declared but not defined"; + unit->error(msg); // $$ is a dummy + } + else + { + cont->checkIntroduced(scoped->v); + intfs->v.push_front(def); + } + } } $$ = intfs; } @@ -1326,6 +1401,11 @@ interface_list unit->error("illegal inheritance from type Object"); $$ = new ClassListTok; // Dummy } +| ICE_VALUE +{ + unit->error("illegal inheritance from type Value"); + $$ = new ClassListTok; // Dummy +} ; // ---------------------------------------------------------------------- @@ -1350,7 +1430,7 @@ interface_exports ContainedPtr contained = ContainedPtr::dynamicCast($2); if(contained && !metaData->v.empty()) { - contained->setMetaData(metaData->v); + contained->setMetaData(metaData->v); } } | error ';' interface_exports @@ -1400,7 +1480,7 @@ exception ExceptionPtr exception = cont->lookupException(scoped->v); if(!exception) { - exception = cont->createException(IceUtil::generateUUID(), 0, false, Dummy); // Dummy + exception = cont->createException(IceUtil::generateUUID(), 0, false, Dummy); // Dummy } cont->checkIntroduced(scoped->v, exception); $$ = exception; @@ -1489,7 +1569,15 @@ enum_def StringTokPtr ident = StringTokPtr::dynamicCast($2); ContainerPtr cont = unit->currentContainer(); EnumPtr en = cont->createEnum(ident->v, local->v); - cont->checkIntroduced(ident->v, en); + if(en) + { + cont->checkIntroduced(ident->v, en); + } + else + { + en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); + } + unit->pushContainer(en); $$ = en; } '{' enumerator_list '}' @@ -1497,26 +1585,30 @@ enum_def EnumPtr en = EnumPtr::dynamicCast($3); if(en) { - EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast($5); - if(enumerators->v.empty()) - { - unit->error("enum `" + en->name() + "' must have at least one enumerator"); - } - en->setEnumerators(enumerators->v); // Dummy + EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast($5); + if(enumerators->v.empty()) + { + unit->error("enum `" + en->name() + "' must have at least one enumerator"); + } + unit->popContainer(); } $$ = $3; } | -local_qualifier ICE_ENUM '{' enumerator_list '}' +local_qualifier ICE_ENUM { unit->error("missing enumeration name"); BoolTokPtr local = BoolTokPtr::dynamicCast($1); ContainerPtr cont = unit->currentContainer(); - EnumPtr en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); // Dummy - EnumeratorListTokPtr enumerators = EnumeratorListTokPtr::dynamicCast($4); - en->setEnumerators(enumerators->v); // Dummy + EnumPtr en = cont->createEnum(IceUtil::generateUUID(), local->v, Dummy); + unit->pushContainer(en); $$ = en; } +'{' enumerator_list '}' +{ + unit->popContainer(); + $$ = $2; +} ; // ---------------------------------------------------------------------- @@ -1544,7 +1636,7 @@ enumerator EnumeratorPtr en = cont->createEnumerator(ident->v); if(en) { - ens->v.push_front(en); + ens->v.push_front(en); } $$ = ens; } @@ -1563,10 +1655,7 @@ enumerator else { EnumeratorPtr en = cont->createEnumerator(ident->v, static_cast<int>(intVal->v)); - if(en) - { - ens->v.push_front(en); - } + ens->v.push_front(en); } } $$ = ens; @@ -1658,8 +1747,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); - unit->currentContainer()->checkIntroduced(tsp->v.name, pd); + ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); + unit->currentContainer()->checkIntroduced(tsp->v.name, pd); StringListTokPtr metaData = StringListTokPtr::dynamicCast($2); if(!metaData->v.empty()) { @@ -1674,8 +1763,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); - unit->currentContainer()->checkIntroduced(tsp->v.name, pd); + ParamDeclPtr pd = op->createParamDecl(tsp->v.name, tsp->v.type, isOutParam->v, tsp->v.optional, tsp->v.tag); + unit->currentContainer()->checkIntroduced(tsp->v.name, pd); StringListTokPtr metaData = StringListTokPtr::dynamicCast($4); if(!metaData->v.empty()) { @@ -1691,8 +1780,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy - unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); + op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy + unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); } } | parameters ',' out_qualifier meta_data type keyword @@ -1703,8 +1792,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy - unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); + op->createParamDecl(ident->v, type, isOutParam->v, false, 0); // Dummy + unit->error("keyword `" + ident->v + "' cannot be used as parameter name"); } } | out_qualifier meta_data type @@ -1714,8 +1803,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy - unit->error("missing parameter name"); + op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy + unit->error("missing parameter name"); } } | parameters ',' out_qualifier meta_data type @@ -1725,8 +1814,8 @@ parameters OperationPtr op = OperationPtr::dynamicCast(unit->currentContainer()); if(op) { - op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy - unit->error("missing parameter name"); + op->createParamDecl(IceUtil::generateUUID(), type, isOutParam->v, false, 0); // Dummy + unit->error("missing parameter name"); } } ; @@ -1813,19 +1902,23 @@ type { $$ = unit->builtin(Builtin::KindLocalObject); } +| ICE_VALUE +{ + $$ = unit->builtin(Builtin::KindValue); +} | scoped_name { StringTokPtr scoped = StringTokPtr::dynamicCast($1); ContainerPtr cont = unit->currentContainer(); if(cont) { - TypeList types = cont->lookupType(scoped->v); - if(types.empty()) - { - YYERROR; // Can't continue, jump to next yyerrok - } - cont->checkIntroduced(scoped->v); - $$ = types.front(); + TypeList types = cont->lookupType(scoped->v); + if(types.empty()) + { + YYERROR; // Can't continue, jump to next yyerrok + } + cont->checkIntroduced(scoped->v); + $$ = types.front(); } else { @@ -1838,30 +1931,30 @@ type ContainerPtr cont = unit->currentContainer(); if(cont) { - TypeList types = cont->lookupType(scoped->v); - if(types.empty()) - { - YYERROR; // Can't continue, jump to next yyerrok - } - for(TypeList::iterator p = types.begin(); p != types.end(); ++p) - { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); - if(!cl) - { - string msg = "`"; - msg += scoped->v; - msg += "' must be class or interface"; - unit->error(msg); - YYERROR; // Can't continue, jump to next yyerrok - } - cont->checkIntroduced(scoped->v); - if(cl->isLocal()) - { - unit->error("cannot create proxy for " + cl->kindOf() + " `" + cl->name() + "'"); // $$ is dummy - } - *p = new Proxy(cl); - } - $$ = types.front(); + TypeList types = cont->lookupType(scoped->v); + if(types.empty()) + { + YYERROR; // Can't continue, jump to next yyerrok + } + for(TypeList::iterator p = types.begin(); p != types.end(); ++p) + { + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); + if(!cl) + { + string msg = "`"; + msg += scoped->v; + msg += "' must be class or interface"; + unit->error(msg); + YYERROR; // Can't continue, jump to next yyerrok + } + cont->checkIntroduced(scoped->v); + if(cl->isLocal()) + { + unit->error("cannot create proxy for " + cl->kindOf() + " `" + cl->name() + "'"); // $$ is dummy + } + *p = new Proxy(cl); + } + $$ = types.front(); } else { @@ -1953,9 +2046,10 @@ const_initializer { StringTokPtr scoped = StringTokPtr::dynamicCast($1); ConstDefTokPtr def = new ConstDefTok; - ContainedList cl = unit->currentContainer()->lookupContained(scoped->v); + ContainedList cl = unit->currentContainer()->lookupContained(scoped->v, false); if(cl.empty()) { + // Could be an enumerator def->v.type = TypePtr(0); def->v.value = SyntaxTreeBasePtr(0); def->v.valueAsString = scoped->v; @@ -1963,9 +2057,9 @@ const_initializer } else { - EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); + EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); ConstPtr constant = ConstPtr::dynamicCast(cl.front()); - if(enumerator) + if(enumerator) { unit->currentContainer()->checkIntroduced(scoped->v, enumerator); def->v.type = enumerator->type(); @@ -1981,17 +2075,17 @@ const_initializer def->v.valueAsLiteral = constant->value(); } else - { - string msg = "illegal initializer: `" + scoped->v + "' is a"; - static const string vowels = "aeiou"; - string kindOf = cl.front()->kindOf(); - if(vowels.find_first_of(kindOf[0]) != string::npos) - { - msg += "n"; - } - msg += " " + kindOf; - unit->error(msg); // $$ is dummy - } + { + string msg = "illegal initializer: `" + scoped->v + "' is a"; + static const string vowels = "aeiou"; + string kindOf = cl.front()->kindOf(); + if(vowels.find_first_of(kindOf[0]) != string::npos) + { + msg += "n"; + } + msg += " " + kindOf; + unit->error(msg); // $$ is dummy + } } $$ = def; } @@ -2143,6 +2237,9 @@ keyword | ICE_OPTIONAL { } +| ICE_VALUE +{ +} ; %% diff --git a/cpp/src/Slice/GrammarUtil.h b/cpp/src/Slice/GrammarUtil.h index dfccbe3f6db..ef155dd38dc 100644 --- a/cpp/src/Slice/GrammarUtil.h +++ b/cpp/src/Slice/GrammarUtil.h @@ -48,7 +48,7 @@ typedef ::IceUtil::Handle<ClassIdTok> ClassIdTokPtr; // StringTok // ---------------------------------------------------------------------- -class SLICE_API StringTok : public GrammarBase +class StringTok : public GrammarBase { public: @@ -61,7 +61,7 @@ public: // StringListTok // ---------------------------------------------------------------------- -class SLICE_API StringListTok : public GrammarBase +class StringListTok : public GrammarBase { public: @@ -73,7 +73,7 @@ public: // TypeStringTok // ---------------------------------------------------------------------- -class SLICE_API TypeStringTok : public GrammarBase +class TypeStringTok : public GrammarBase { public: @@ -85,7 +85,7 @@ public: // TypeStringListTok // ---------------------------------------------------------------------- -class SLICE_API TypeStringListTok : public GrammarBase +class TypeStringListTok : public GrammarBase { public: @@ -97,7 +97,7 @@ public: // IntegerTok // ---------------------------------------------------------------------- -class SLICE_API IntegerTok : public GrammarBase +class IntegerTok : public GrammarBase { public: @@ -110,7 +110,7 @@ public: // FloatingTok // ---------------------------------------------------------------------- -class SLICE_API FloatingTok : public GrammarBase +class FloatingTok : public GrammarBase { public: @@ -123,7 +123,7 @@ public: // BoolTok // ---------------------------------------------------------------------- -class SLICE_API BoolTok : public GrammarBase +class BoolTok : public GrammarBase { public: @@ -135,7 +135,7 @@ public: // ExceptionListTok // ---------------------------------------------------------------------- -class SLICE_API ExceptionListTok : public GrammarBase +class ExceptionListTok : public GrammarBase { public: @@ -147,7 +147,7 @@ public: // ClassListTok // ---------------------------------------------------------------------- -class SLICE_API ClassListTok : public GrammarBase +class ClassListTok : public GrammarBase { public: @@ -159,7 +159,7 @@ public: // EnumeratorListTok // ---------------------------------------------------------------------- -class SLICE_API EnumeratorListTok : public GrammarBase +class EnumeratorListTok : public GrammarBase { public: @@ -171,7 +171,7 @@ public: // ConstDefTok // ---------------------------------------------------------------------- -class SLICE_API ConstDefTok : public GrammarBase +class ConstDefTok : public GrammarBase { public: @@ -183,7 +183,7 @@ public: // OptionalDefTok // ---------------------------------------------------------------------- -class SLICE_API OptionalDefTok : public GrammarBase +class OptionalDefTok : public GrammarBase { public: @@ -195,7 +195,7 @@ public: // ClassIdTok // ---------------------------------------------------------------------- -class SLICE_API ClassIdTok : public GrammarBase +class ClassIdTok : public GrammarBase { public: diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp deleted file mode 100644 index fe2d701cc39..00000000000 --- a/cpp/src/Slice/JavaUtil.cpp +++ /dev/null @@ -1,4342 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <IceUtil/DisableWarnings.h> -#include <Slice/JavaUtil.h> -#include <Slice/FileTracker.h> -#include <Slice/Util.h> -#include <Slice/MD5.h> -#include <IceUtil/Functional.h> -#include <IceUtil/FileUtil.h> - -#include <sys/types.h> -#include <string.h> - -#ifdef _WIN32 -#include <direct.h> -#endif - -#ifndef _WIN32 -#include <unistd.h> -#endif - -using namespace std; -using namespace Slice; -using namespace IceUtil; -using namespace IceUtilInternal; - -namespace -{ - -void -hashAdd(long& hashCode, const std::string& value) -{ - for(std::string::const_iterator p = value.begin(); p != value.end(); ++p) - { - hashCode = ((hashCode << 5) + hashCode) ^ *p; - } -} - -string -typeToBufferString(const TypePtr& type) -{ - static const char* builtinBufferTable[] = - { - "java.nio.ByteBuffer", - "???", - "java.nio.ShortBuffer", - "java.nio.IntBuffer", - "java.nio.LongBuffer", - "java.nio.FloatBuffer", - "java.nio.DoubleBuffer", - "???", - "???", - "???", - "???" - }; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(!builtin) - { - return "???"; - } - else - { - return builtinBufferTable[builtin->kind()]; - } -} -} - -long -Slice::computeSerialVersionUUID(const ClassDefPtr& p) -{ - ostringstream os; - - ClassList bases = p->bases(); - os << "Name: " << p->scoped(); - - os << " Bases: ["; - for(ClassList::const_iterator i = bases.begin(); i != bases.end();) - { - os << (*i)->scoped(); - i++; - if(i != bases.end()) - { - os << ", "; - } - } - os << "]"; - - os << " Members: ["; - DataMemberList members = p->dataMembers(); - for(DataMemberList::const_iterator i = members.begin(); i != members.end();) - { - os << (*i)->name() << ":" << (*i)->type(); - i++; - if(i != members.end()) - { - os << ", "; - } - } - os << "]"; - - const string data = os.str(); - long hashCode = 5381; - hashAdd(hashCode, data); - return hashCode; -} - -long -Slice::computeSerialVersionUUID(const StructPtr& p) -{ - ostringstream os; - - os << "Name: " << p->scoped(); - os << " Members: ["; - DataMemberList members = p->dataMembers(); - for(DataMemberList::const_iterator i = members.begin(); i != members.end();) - { - os << (*i)->name() << ":" << (*i)->type(); - i++; - if(i != members.end()) - { - os << ", "; - } - } - os << "]"; - - const string data = os.str(); - long hashCode = 5381; - hashAdd(hashCode, data); - return hashCode; -} - -long -Slice::computeSerialVersionUUID(const ExceptionPtr& p) -{ - ostringstream os; - - os << "Name: " << p->scoped(); - os << " Members: ["; - DataMemberList members = p->dataMembers(); - for(DataMemberList::const_iterator i = members.begin(); i != members.end();) - { - os << (*i)->name() << ":" << (*i)->type(); - i++; - if(i != members.end()) - { - os << ", "; - } - } - os << "]"; - - const string data = os.str(); - long hashCode = 5381; - hashAdd(hashCode, data); - return hashCode; -} - - - -Slice::JavaOutput::JavaOutput() -{ -} - -Slice::JavaOutput::JavaOutput(ostream& os) : - Output(os) -{ -} - -Slice::JavaOutput::JavaOutput(const char* s) : - Output(s) -{ -} - -void -Slice::JavaOutput::openClass(const string& cls, const string& prefix, const string& sliceFile) -{ - string package; - string file; - string path = prefix; - - string::size_type pos = cls.rfind('.'); - if(pos != string::npos) - { - package = cls.substr(0, pos); - file = cls.substr(pos + 1); - string dir = package; - - // - // Create package directories if necessary. - // - pos = 0; - string::size_type start = 0; - do - { - if(!path.empty()) - { - path += "/"; - } - pos = dir.find('.', start); - if(pos != string::npos) - { - path += dir.substr(start, pos - start); - start = pos + 1; - } - else - { - path += dir.substr(start); - } - - IceUtilInternal::structstat st; - if(!IceUtilInternal::stat(path, &st)) - { - if(!(st.st_mode & S_IFDIR)) - { - ostringstream os; - os << "failed to create package directory `" << path - << "': file already exists and is not a directory"; - throw FileException(__FILE__, __LINE__, os.str()); - } - continue; - } - - if(IceUtilInternal::mkdir(path, 0777) != 0) - { - ostringstream os; - os << "cannot create directory `" << path << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); - } - FileTracker::instance()->addDirectory(path); - } - while(pos != string::npos); - } - else - { - file = cls; - } - file += ".java"; - - // - // Open class file. - // - if(!path.empty()) - { - path += "/"; - } - path += file; - - open(path.c_str()); - if(isOpen()) - { - FileTracker::instance()->addFile(path); - printHeader(); - printGeneratedHeader(*this, sliceFile); - if(!package.empty()) - { - separator(); - print("package "); - print(package.c_str()); - print(";"); - } - } - else - { - ostringstream os; - os << "cannot open file `" << path << "': " << strerror(errno); - throw FileException(__FILE__, __LINE__, os.str()); - } -} - -void -Slice::JavaOutput::printHeader() -{ - static const char* header = -"// **********************************************************************\n" -"//\n" -"// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.\n" -"//\n" -"// This copy of Ice is licensed to you under the terms described in the\n" -"// ICE_LICENSE file included in this distribution.\n" -"//\n" -"// **********************************************************************\n" - ; - - print(header); - print("//\n"); - print("// Ice version "); - print(ICE_STRING_VERSION); - print("\n"); - print("//\n"); -} - -const string Slice::JavaGenerator::_getSetMetaData = "java:getset"; - -Slice::JavaGenerator::JavaGenerator(const string& dir) : - _dir(dir), - _out(0) -{ -} - -Slice::JavaGenerator::~JavaGenerator() -{ - // If open throws an exception other generators could be left open - // during the stack unwind. - if(_out != 0) - { - close(); - } - assert(_out == 0); -} - -void -Slice::JavaGenerator::open(const string& absolute, const string& file) -{ - assert(_out == 0); - - JavaOutput* out = createOutput(); - try - { - out->openClass(absolute, _dir, file); - } - catch(const FileException&) - { - delete out; - throw; - } - _out = out; -} - -void -Slice::JavaGenerator::close() -{ - assert(_out != 0); - *_out << nl; - delete _out; - _out = 0; -} - -Output& -Slice::JavaGenerator::output() const -{ - assert(_out != 0); - return *_out; -} - -static string -lookupKwd(const string& name) -{ - // - // Keyword list. *Must* be kept in alphabetical order. Note that checkedCast and uncheckedCast - // are not Java keywords, but are in this list to prevent illegal code being generated if - // someone defines Slice operations with that name. - // - // NOTE: Any changes made to this list must also be made in BasicStream.java. - // - static const string keywordList[] = - { - "abstract", "assert", "boolean", "break", "byte", "case", "catch", - "char", "checkedCast", "class", "clone", "const", "continue", "default", "do", - "double", "else", "enum", "equals", "extends", "false", "final", "finalize", - "finally", "float", "for", "getClass", "goto", "hashCode", "if", - "implements", "import", "instanceof", "int", "interface", "long", - "native", "new", "notify", "notifyAll", "null", "package", "private", - "protected", "public", "return", "short", "static", "strictfp", "super", "switch", - "synchronized", "this", "throw", "throws", "toString", "transient", - "true", "try", "uncheckedCast", "void", "volatile", "wait", "while" - }; - bool found = binary_search(&keywordList[0], - &keywordList[sizeof(keywordList) / sizeof(*keywordList)], - name); - return found ? "_" + name : name; -} - -// -// Split a scoped name into its components and return the components as a list of (unscoped) identifiers. -// -static StringList -splitScopedName(const string& scoped) -{ - assert(scoped[0] == ':'); - StringList ids; - string::size_type next = 0; - string::size_type pos; - while((pos = scoped.find("::", next)) != string::npos) - { - pos += 2; - if(pos != scoped.size()) - { - string::size_type endpos = scoped.find("::", pos); - if(endpos != string::npos) - { - ids.push_back(scoped.substr(pos, endpos - pos)); - } - } - next = pos; - } - if(next != scoped.size()) - { - ids.push_back(scoped.substr(next)); - } - else - { - ids.push_back(""); - } - - return ids; -} - -// -// If the passed name is a scoped name, return the identical scoped name, -// but with all components that are Java keywords replaced by -// their "_"-prefixed version; otherwise, if the passed name is -// not scoped, but a Java keyword, return the "_"-prefixed name; -// otherwise, return the name unchanged. -// -string -Slice::JavaGenerator::fixKwd(const string& name) const -{ - if(name.empty()) - { - return name; - } - if(name[0] != ':') - { - return lookupKwd(name); - } - StringList ids = splitScopedName(name); - transform(ids.begin(), ids.end(), ids.begin(), ptr_fun(lookupKwd)); - stringstream result; - for(StringList::const_iterator i = ids.begin(); i != ids.end(); ++i) - { - result << "::" + *i; - } - return result.str(); -} - -string -Slice::JavaGenerator::convertScopedName(const string& scoped, const string& prefix, const string& suffix) const -{ - string result; - string::size_type start = 0; - string fscoped = fixKwd(scoped); - - // - // Skip leading "::" - // - if(fscoped[start] == ':') - { - assert(fscoped[start + 1] == ':'); - start += 2; - } - - // - // Convert all occurrences of "::" to "." - // - string::size_type pos; - do - { - pos = fscoped.find(':', start); - string fix; - if(pos == string::npos) - { - string s = fscoped.substr(start); - if(!s.empty()) - { - fix = prefix + fixKwd(s) + suffix; - } - } - else - { - assert(fscoped[pos + 1] == ':'); - fix = fixKwd(fscoped.substr(start, pos - start)); - start = pos + 2; - } - - if(!result.empty() && !fix.empty()) - { - result += "."; - } - result += fix; - } - while(pos != string::npos); - - return result; -} - -string -Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const -{ - UnitPtr unit = cont->container()->unit(); - string file = cont->file(); - assert(!file.empty()); - - map<string, string>::const_iterator p = _filePackagePrefix.find(file); - if(p != _filePackagePrefix.end()) - { - return p->second; - } - - static const string prefix = "java:package:"; - DefinitionContextPtr dc = unit->findDefinitionContext(file); - assert(dc); - string q = dc->findMetaData(prefix); - if(!q.empty()) - { - q = q.substr(prefix.size()); - } - _filePackagePrefix[file] = q; - return q; -} - -string -Slice::JavaGenerator::getPackage(const ContainedPtr& cont) const -{ - string scope = convertScopedName(cont->scope()); - string prefix = getPackagePrefix(cont); - if(!prefix.empty()) - { - if(!scope.empty()) - { - return prefix + "." + scope; - } - else - { - return prefix; - } - } - - return scope; -} - -string -Slice::JavaGenerator::getAbsolute(const ContainedPtr& cont, - const string& package, - const string& prefix, - const string& suffix) const -{ - string name = cont->name(); - if(prefix == "" && suffix == "") - { - name = fixKwd(name); - } - string contPkg = getPackage(cont); - if(contPkg == package) - { - return prefix + name + suffix; - } - else if(!contPkg.empty()) - { - return contPkg + "." + prefix + name + suffix; - } - else - { - return prefix + name + suffix; - } -} - -string -Slice::JavaGenerator::getStaticId(const TypePtr& type, const string& package) const -{ - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - - assert((b && b->kind() == Builtin::KindObject) || cl); - - if(b) - { - return "Ice.ObjectImpl.ice_staticId()"; - } - else if(cl->isInterface()) - { - return getAbsolute(cl, package, "_", "Disp") + ".ice_staticId()"; - } - else - { - return getAbsolute(cl, package) + ".ice_staticId()"; - } -} - -bool -Slice::JavaGenerator::useOptionalMapping(const OperationPtr& p) -{ - // - // The "java:optional" metadata can be applied to an operation or its - // interface to force the mapping to use the Ice.Optional types. - // - // Without the tag, parameters use the normal (non-optional) mapping. - // - static const string tag = "java:optional"; - - ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); - assert(cl); - - return p->hasMetaData(tag) || cl->hasMetaData(tag); -} - -string -Slice::JavaGenerator::getOptionalFormat(const TypePtr& type) -{ - BuiltinPtr bp = BuiltinPtr::dynamicCast(type); - if(bp) - { - switch(bp->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - { - return "Ice.OptionalFormat.F1"; - } - case Builtin::KindShort: - { - return "Ice.OptionalFormat.F2"; - } - case Builtin::KindInt: - case Builtin::KindFloat: - { - return "Ice.OptionalFormat.F4"; - } - case Builtin::KindLong: - case Builtin::KindDouble: - { - return "Ice.OptionalFormat.F8"; - } - case Builtin::KindString: - { - return "Ice.OptionalFormat.VSize"; - } - case Builtin::KindObject: - { - return "Ice.OptionalFormat.Class"; - } - case Builtin::KindObjectProxy: - { - return "Ice.OptionalFormat.FSize"; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - - if(EnumPtr::dynamicCast(type)) - { - return "Ice.OptionalFormat.Size"; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - return seq->type()->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ? - "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - return st->isVariableLength() ? "Ice.OptionalFormat.FSize" : "Ice.OptionalFormat.VSize"; - } - - if(ProxyPtr::dynamicCast(type)) - { - return "Ice.OptionalFormat.FSize"; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - assert(cl); - return "Ice.OptionalFormat.Class"; -} - -string -Slice::JavaGenerator::typeToString(const TypePtr& type, - TypeMode mode, - const string& package, - const StringList& metaData, - bool formal, - bool optional) const -{ - static const char* builtinTable[] = - { - "byte", - "boolean", - "short", - "int", - "long", - "float", - "double", - "String", - "Ice.Object", - "Ice.ObjectPrx", - "java.lang.Object" - }; - static const char* builtinHolderTable[] = - { - "Ice.ByteHolder", - "Ice.BooleanHolder", - "Ice.ShortHolder", - "Ice.IntHolder", - "Ice.LongHolder", - "Ice.FloatHolder", - "Ice.DoubleHolder", - "Ice.StringHolder", - "Ice.ObjectHolder", - "Ice.ObjectPrxHolder", - "Ice.LocalObjectHolder" - }; - static const char* builtinOptionalTable[] = - { - "Ice.ByteOptional", - "Ice.BooleanOptional", - "Ice.ShortOptional", - "Ice.IntOptional", - "Ice.LongOptional", - "Ice.FloatOptional", - "Ice.DoubleOptional", - "???", - "???", - "???", - "???" - }; - - if(!type) - { - assert(mode == TypeModeReturn); - return "void"; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - if(optional) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindLong: - case Builtin::KindFloat: - case Builtin::KindDouble: - { - return builtinOptionalTable[builtin->kind()]; - } - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - break; - } - } - } - else - { - if(mode == TypeModeOut) - { - return builtinHolderTable[builtin->kind()]; - } - else - { - return builtinTable[builtin->kind()]; - } - } - } - - if(optional) - { - return "Ice.Optional<" + typeToString(type, TypeModeIn, package, metaData, formal) + ">"; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - return getAbsolute(cl, package, "", mode == TypeModeOut ? "Holder" : ""); - } - - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if(proxy) - { - return getAbsolute(proxy->_class(), package, "", mode == TypeModeOut ? "PrxHolder" : "Prx"); - } - - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - if(dict) - { - if(mode == TypeModeOut) - { - // - // Only use the type's generated holder if the instance and - // formal types match. - // - string instanceType, formalType; - getDictionaryTypes(dict, "", metaData, instanceType, formalType); - string origInstanceType, origFormalType; - getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType); - if(formalType == origFormalType && instanceType == origInstanceType) - { - return getAbsolute(dict, package, "", "Holder"); - } - - // - // The custom type may or may not be compatible with the type used - // in the generated holder. We use a generic holder that holds a value of the - // formal custom type. - // - return string("Ice.Holder<") + formalType + " >"; - } - else - { - string instanceType, formalType; - getDictionaryTypes(dict, package, metaData, instanceType, formalType); - return formal ? formalType : instanceType; - } - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - if(mode == TypeModeOut) - { - string instanceType, formalType; - getSequenceTypes(seq, "", metaData, instanceType, formalType); - if(sequenceHasHolder(seq)) - { - // - // Only use the type's generated holder if the instance and - // formal types match. - // - string origInstanceType, origFormalType; - getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType); - if(formalType == origFormalType && instanceType == origInstanceType) - { - return getAbsolute(seq, package, "", "Holder"); - } - } - - // - // The custom type may or may not be compatible with the type used - // in the generated holder. We use a generic holder that holds a value of the - // formal custom type. - // - return string("Ice.Holder<") + formalType + " >"; - } - else - { - string instanceType, formalType; - getSequenceTypes(seq, package, metaData, instanceType, formalType); - return formal ? formalType : instanceType; - } - } - - ContainedPtr contained = ContainedPtr::dynamicCast(type); - if(contained) - { - if(mode == TypeModeOut) - { - return getAbsolute(contained, package, "", "Holder"); - } - else - { - return getAbsolute(contained, package); - } - } - - return "???"; -} - -string -Slice::JavaGenerator::typeToObjectString(const TypePtr& type, - TypeMode mode, - const string& package, - const StringList& metaData, - bool formal) const -{ - static const char* builtinTable[] = - { - "java.lang.Byte", - "java.lang.Boolean", - "java.lang.Short", - "java.lang.Integer", - "java.lang.Long", - "java.lang.Float", - "java.lang.Double", - "java.lang.String", - "Ice.Object", - "Ice.ObjectPrx", - "java.lang.Object" - }; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin && mode != TypeModeOut) - { - return builtinTable[builtin->kind()]; - } - - return typeToString(type, mode, package, metaData, formal); -} - -void -Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, - const string& package, - const TypePtr& type, - OptionalMode mode, - bool optionalMapping, - int tag, - const string& param, - bool marshal, - int& iter, - bool holder, - const StringList& metaData, - const string& patchParams) -{ - string stream = marshal ? "__os" : "__is"; - string v; - if(holder) - { - v = param + ".value"; - } - else - { - v = param; - } - - const bool optionalParam = mode == OptionalInParam || mode == OptionalOutParam || mode == OptionalReturnParam; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeByte(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeByte(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readByte(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByte();"; - } - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeBool(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeBool(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readBool(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readBool();"; - } - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeShort(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeShort(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readShort(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShort();"; - } - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeInt(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeInt(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readInt(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readInt();"; - } - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeLong(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeLong(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readLong(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLong();"; - } - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeFloat(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeFloat(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readFloat(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloat();"; - } - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeDouble(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeDouble(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readDouble(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDouble();"; - } - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeString(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeString(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readString(" << tag << ", " << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readString();"; - } - } - break; - } - case Builtin::KindObject: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeObject(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeObject(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readObject(" << tag << ", " << param << ");"; - } - else if(holder && mode == OptionalNone) - { - out << nl << stream << ".readObject(" << param << ");"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - break; - } - case Builtin::KindObjectProxy: - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeProxy(" << tag << ", " << v << ");"; - } - else if(mode == OptionalMember) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << stream << ".writeProxy(" << v << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << stream << ".writeProxy(" << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << stream << ".readProxy(" << tag << ", " << v << ");"; - } - else if(mode == OptionalMember) - { - out << nl << stream << ".skip(4);"; - out << nl << v << " = " << stream << ".readProxy();"; - } - else - { - out << nl << v << " = " << stream << ".readProxy();"; - } - } - break; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - string typeS = typeToString(type, TypeModeIn, package); - if(marshal) - { - if(optionalParam) - { - if(optionalMapping) - { - out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag - << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << "Helper.__write(" << stream << ", " << v << ".get());"; - out << nl << stream << ".endSize(__pos);"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");"; - out << nl << stream << ".endSize(__pos);"; - out << eb; - } - } - else if(mode == OptionalMember) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << stream << ".skip(4);"; - out << nl << v << ".set(" << typeS << "Helper.__read(" << stream << "));"; - out << eb; - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - else if(mode == OptionalMember) - { - out << nl << stream << ".skip(4);"; - out << nl << v << " = " << typeS << "Helper.__read(" << stream << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.__read(" << stream << ");"; - } - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - if(optionalParam) - { - out << nl << stream << ".writeObject(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".writeObject(" << v << ");"; - } - } - else - { - if(optionalParam) - { - string typeS = typeToString(type, TypeModeIn, package); - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << stream << ".readObject(new Ice.OptionalObject(" << v << ", " << typeS << ".class, " - << getStaticId(type, package) << "));"; - out << eb; - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - else - { - if(holder && mode == OptionalNone) - { - out << nl << stream << ".readObject(" << param << ");"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - if(marshal) - { - if(optionalParam || mode == OptionalMember) - { - string val; - if(optionalParam) - { - if(optionalMapping) - { - out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" - << tag << ", " << getOptionalFormat(type) << "))"; - val = v + ".get()"; - } - else - { - out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - val = v; - } - out << sb; - } - else - { - val = v; - } - - if(st->isVariableLength()) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << ".__write(" << stream << ", " << val << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; - out << nl << typeS << ".__write(" << stream << ", " << val << ");"; - } - if(optionalParam) - { - out << eb; - } - } - else - { - out << nl << typeS << ".__write(" << stream << ", " << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - - if(st->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - - out << nl << typeS << " __tmpOpt = new " << typeS << "();"; - out << nl << "__tmpOpt.__read(" << stream << ");"; - out << nl << v << ".set(__tmpOpt);"; - - out << eb; - - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - else if(mode == OptionalMember) - { - if(st->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - out << nl << v << " = " << typeS << ".__read(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << ".__read(" << stream << ", " << v << ");"; - } - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - if(marshal) - { - if(optionalParam) - { - if(optionalMapping) - { - out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag - << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << typeS << ".__write(" << stream << ", " << v << ".get());"; - out << eb; - } - else - { - out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << typeS << ".__write(" << stream << ", " << v << ");"; - out << eb; - } - } - else - { - out << nl << typeS << ".__write(" << stream << ", " << v << ");"; - } - } - else - { - if(optionalParam) - { - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << v << ".set(" << typeS << ".__read(" << stream << "));"; - out << eb; - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - else - { - out << nl << v << " = " << typeS << ".__read(" << stream << ");"; - } - } - return; - } - - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - if(dict) - { - if(optionalParam || mode == OptionalMember) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - TypePtr keyType = dict->keyType(); - TypePtr valueType = dict->valueType(); - - if(marshal) - { - if(optionalParam) - { - if(optionalMapping) - { - out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" - << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - } - else - { - out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - } - } - - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - string d = optionalParam && optionalMapping ? v + ".get()" : v; - out << nl << "int __pos = " << stream << ".startSize();"; - writeDictionaryMarshalUnmarshalCode(out, package, dict, d, marshal, iter, true, metaData); - out << nl << stream << ".endSize(__pos);"; - } - else - { - const size_t wireSize = keyType->minWireSize() + valueType->minWireSize(); - string tmpName; - if(optionalParam && optionalMapping) - { - tmpName = "__optDict"; - out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();"; - } - else - { - tmpName = v; - } - out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".size();"; - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData); - } - - if(optionalParam) - { - out << eb; - } - } - else - { - string tmpName; - - if(optionalParam) - { - tmpName = "__optDict"; - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << typeS << ' ' << tmpName << ';'; - } - else - { - tmpName = v; - } - - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - - writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData); - - if(optionalParam) - { - out << nl << v << ".set(" << tmpName << ");"; - out << eb; - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - } - } - else - { - writeDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData); - } - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - if(optionalParam || mode == OptionalMember) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - TypePtr elemType = seq->type(); - BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType); - - if(optionalParam && elemBuiltin && elemBuiltin->kind() != Builtin::KindObject && - elemBuiltin->kind() != Builtin::KindObjectProxy && !hasTypeMetaData(seq, metaData)) - { - static const char* builtinTable[] = - { - "Byte", - "Bool", - "Short", - "Int", - "Long", - "Float", - "Double", - "String", - "???", - "???", - "???" - }; - - switch(elemBuiltin->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindLong: - case Builtin::KindFloat: - case Builtin::KindDouble: - case Builtin::KindString: - { - string bs = builtinTable[elemBuiltin->kind()]; - - if(marshal) - { - out << nl << stream << ".write" << bs << "Seq(" << tag << ", " << v << ");"; - } - else - { - out << nl << stream << ".read" << bs << "Seq(" << tag << ", " << v << ");"; - } - return; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - - string ignore; - const size_t wireSize = elemType->minWireSize(); - - if(marshal) - { - if(optionalParam) - { - if(optionalMapping) - { - out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" - << tag << ", " << getOptionalFormat(type) << "))"; - } - else - { - out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - } - - out << sb; - } - - if(elemType->isVariableLength()) - { - string s = optionalParam && optionalMapping ? v + ".get()" : v; - out << nl << "int __pos = " << stream << ".startSize();"; - writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData); - out << nl << stream << ".endSize(__pos);"; - } - else if(findMetaData("java:type:", metaData, ignore) || - findMetaData("java:type:", seq->getMetaData(), ignore)) - { - // - // The sequence is an instance of java.util.List<E>, where E is a fixed-size type. - // If the element type is bool or byte, we do NOT write an extra size. - // - - string tmpName; - if(optionalParam && optionalMapping) - { - tmpName = "__optSeq"; - out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();"; - } - else - { - tmpName = v; - } - - if(wireSize > 1) - { - out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".size();"; - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - } - writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData); - } - else if(findMetaData("java:protobuf:", seq->getMetaData(), ignore) || - findMetaData("java:serializable:", seq->getMetaData(), ignore)) - { - // - // This just writes a byte sequence. - // - string s = optionalParam && optionalMapping ? v + ".get()" : v; - writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData); - } - else - { - // - // At this point we have a regular Java array of a fixed-size type. - // - - string tmpName; - if(optionalParam && optionalMapping) - { - tmpName = "__optSeq"; - out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();"; - } - else - { - tmpName = v; - } - - if(wireSize > 1) - { - out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".length;"; - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - } - - writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData); - } - - if(optionalParam) - { - out << eb; - } - } - else - { - string tmpName; - if(optionalParam) - { - tmpName = "__optSeq"; - out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; - out << sb; - out << nl << typeS << ' ' << tmpName << ';'; - } - else - { - tmpName = v; - } - - if(elemType->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else if(wireSize > 1) - { - if(findMetaData("java:type:", metaData, ignore) || - findMetaData("java:type:", seq->getMetaData(), ignore)) - { - // - // The sequence is an instance of java.util.List<E>, where E is a fixed-size type. - // - - out << nl << stream << ".skipSize();"; - } - else if(!findMetaData("java:protobuf:", seq->getMetaData(), ignore) && - !findMetaData("java:serializable:", seq->getMetaData(), ignore)) - { - out << nl << stream << ".skipSize();"; - } - } - - writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData); - - if(optionalParam) - { - out << nl << v << ".set(" << tmpName << ");"; - out << eb; - if(mode == OptionalOutParam) - { - out << nl << "else"; - out << sb; - out << nl << v << ".clear();"; - out << eb; - } - } - } - } - else - { - writeSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - return; - } - - ConstructedPtr constructed = ConstructedPtr::dynamicCast(type); - assert(constructed); - string typeS = getAbsolute(constructed, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } -} - -void -Slice::JavaGenerator::writeDictionaryMarshalUnmarshalCode(Output& out, - const string& package, - const DictionaryPtr& dict, - const string& param, - bool marshal, - int& iter, - bool useHelper, - const StringList& metaData) -{ - string stream = marshal ? "__os" : "__is"; - string v = param; - - string instanceType; - - // - // We have to determine whether it's possible to use the - // type's generated helper class for this marshal/unmarshal - // task. Since the user may have specified a custom type in - // metadata, it's possible that the helper class is not - // compatible and therefore we'll need to generate the code - // in-line instead. - // - // Specifically, there may be "local" metadata (i.e., from - // a data member or parameter definition) that overrides the - // original type. We'll compare the mapped types with and - // without local metadata to determine whether we can use - // the helper. - // - string formalType; - getDictionaryTypes(dict, "", metaData, instanceType, formalType); - string origInstanceType, origFormalType; - getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType); - if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType)) - { - useHelper = false; - } - - // - // If we can use the helper, it's easy. - // - if(useHelper) - { - string typeS = getAbsolute(dict, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - TypePtr key = dict->keyType(); - TypePtr value = dict->valueType(); - - string keyS = typeToString(key, TypeModeIn, package); - string valueS = typeToString(value, TypeModeIn, package); - - ostringstream o; - o << iter; - string iterS = o.str(); - iter++; - - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << "__os.writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << "__os.writeSize(" << v << ".size());"; - string keyObjectS = typeToObjectString(key, TypeModeIn, package); - string valueObjectS = typeToObjectString(value, TypeModeIn, package); - out << nl << "for(java.util.Map.Entry<" << keyObjectS << ", " << valueObjectS << "> __e : " << v - << ".entrySet())"; - out << sb; - for(int i = 0; i < 2; i++) - { - string arg; - TypePtr type; - if(i == 0) - { - arg = "__e.getKey()"; - type = key; - } - else - { - arg = "__e.getValue()"; - type = value; - } - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, true, iter, false); - } - out << eb; - out << eb; - } - else - { - out << nl << v << " = new " << instanceType << "();"; - out << nl << "int __sz" << iterS << " = __is.readSize();"; - out << nl << "for(int __i" << iterS << " = 0; __i" << iterS << " < __sz" << iterS << "; __i" << iterS << "++)"; - out << sb; - for(int i = 0; i < 2; i++) - { - string arg; - TypePtr type; - string typeS; - if(i == 0) - { - arg = "__key"; - type = key; - typeS = keyS; - } - else - { - arg = "__value"; - type = value; - typeS = valueS; - } - - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - if(ClassDeclPtr::dynamicCast(type) || (b && b->kind() == Builtin::KindObject)) - { - string keyTypeStr = typeToObjectString(key, TypeModeIn, package); - string valueTypeStr = typeToObjectString(value, TypeModeIn, package); - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false, - StringList(), - "new IceInternal.DictionaryPatcher<" + keyTypeStr + ", " + valueTypeStr + - ">(" + v + ", " + typeS + ".class, \"" + type->typeId() + "\", __key)"); - } - else - { - if(StructPtr::dynamicCast(type)) - { - out << nl << typeS << ' ' << arg << " = null;"; - } - else - { - out << nl << typeS << ' ' << arg << ';'; - } - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false); - } - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(value); - if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value)) - { - out << nl << "" << v << ".put(__key, __value);"; - } - out << eb; - } -} - -void -Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, - const string& package, - const SequencePtr& seq, - const string& param, - bool marshal, - int& iter, - bool useHelper, - const StringList& metaData) -{ - string stream = marshal ? "__os" : "__is"; - string v = param; - - // - // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to - // get rid of these two easy cases first. - // - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin && builtin->kind() == Builtin::KindByte) - { - string meta; - static const string protobuf = "java:protobuf:"; - static const string serializable = "java:serializable:"; - if(seq->findMetaData(serializable, meta)) - { - if(marshal) - { - out << nl << stream << ".writeSerializable(" << v << ");"; - } - else - { - string type = typeToString(seq, TypeModeIn, package); - out << nl << v << " = (" << type << ")" << stream << ".readSerializable();"; - } - return; - } - else if(seq->findMetaData(protobuf, meta)) - { - if(marshal) - { - out << nl << "if(!" << v << ".isInitialized())"; - out << sb; - out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");"; - out << eb; - out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());"; - } - else - { - string type = typeToString(seq, TypeModeIn, package); - out << nl << "try"; - out << sb; - out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());"; - out << eb; - out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)"; - out << sb; - out << nl << "throw new Ice.MarshalException(__ex);"; - out << eb; - } - return; - } - } - - if(builtin && - (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - string meta; - static const string bytebuffer = "java:buffer"; - if(seq->findMetaData(bytebuffer, meta) || findMetaData(bytebuffer, metaData, meta)) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByteBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByteBuffer();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShortBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShortBuffer();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeIntBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readIntBuffer();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLongBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLongBuffer();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloatBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloatBuffer();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDoubleBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDoubleBuffer();"; - } - break; - } - case Builtin::KindBool: - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - } - - bool customType = false; - string instanceType; - - // - // We have to determine whether it's possible to use the - // type's generated helper class for this marshal/unmarshal - // task. Since the user may have specified a custom type in - // metadata, it's possible that the helper class is not - // compatible and therefore we'll need to generate the code - // in-line instead. - // - // Specifically, there may be "local" metadata (i.e., from - // a data member or parameter definition) that overrides the - // original type. We'll compare the mapped types with and - // without local metadata to determine whether we can use - // the helper. - // - string formalType; - customType = getSequenceTypes(seq, "", metaData, instanceType, formalType); - string origInstanceType, origFormalType; - getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType); - if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType)) - { - useHelper = false; - } - - // - // If we can use the helper, it's easy. - // - if(useHelper) - { - string typeS = getAbsolute(seq, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - // - // Determine sequence depth. - // - int depth = 0; - TypePtr origContent = seq->type(); - SequencePtr s = SequencePtr::dynamicCast(origContent); - while(s) - { - // - // Stop if the inner sequence type has a custom, serializable or protobuf type. - // - if(hasTypeMetaData(s)) - { - break; - } - depth++; - origContent = s->type(); - s = SequencePtr::dynamicCast(origContent); - } - string origContentS = typeToString(origContent, TypeModeIn, package); - - TypePtr type = seq->type(); - - if(customType) - { - // - // Marshal/unmarshal a custom sequence type. - // - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - string typeS = getAbsolute(seq, package); - ostringstream o; - o << origContentS; - int d = depth; - while(d--) - { - o << "[]"; - } - string cont = o.str(); - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".size());"; - string typeS = typeToString(type, TypeModeIn, package); - out << nl << "for(" << typeS << " __elem : " << v << ')'; - out << sb; - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", true, iter, false); - out << eb; - out << eb; // else - } - else - { - bool isObject = false; - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if((b && b->kind() == Builtin::KindObject) || cl) - { - isObject = true; - } - out << nl << v << " = new " << instanceType << "();"; - out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize() - << ");"; - if(isObject) - { - if(b) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - assert(cl); - if(cl->isInterface()) - { - out << nl << "final String __type" << iter << " = " - << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - } - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - if(isObject) - { - // - // Add a null value to the list as a placeholder for the element. - // - out << nl << v << ".add(null);"; - ostringstream patchParams; - patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS - << ".class, __type" << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter, - false, StringList(), patchParams.str()); - } - else - { - if(StructPtr::dynamicCast(type)) - { - out << nl << cont << " __elem = null;"; - } - else - { - out << nl << cont << " __elem;"; - } - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter, false); - } - if(!isObject) - { - out << nl << v << ".add(__elem);"; - } - out << eb; - iter++; - } - } - else - { - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) - { - switch(b->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByteSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByteSeq();"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << ".writeBoolSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readBoolSeq();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShortSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShortSeq();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeIntSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readIntSeq();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLongSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLongSeq();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloatSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloatSeq();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDoubleSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDoubleSeq();"; - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - out << nl << stream << ".writeStringSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readStringSeq();"; - } - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - else - { - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".length);"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << v << ".length; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - iter++; - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), true, iter, false); - out << eb; - out << eb; - } - else - { - bool isObject = false; - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(origContent); - if((b && b->kind() == Builtin::KindObject) || cl) - { - isObject = true; - } - out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" - << type->minWireSize() << ");"; - if(isObject) - { - if(b) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - assert(cl); - if(cl->isInterface()) - { - out << nl << "final String __type" << iter << " = " - << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - } - // - // We cannot allocate an array of a generic type, such as - // - // arr = new Map<String, String>[sz]; - // - // Attempting to compile this code results in a "generic array creation" error - // message. This problem can occur when the sequence's element type is a - // dictionary, or when the element type is a nested sequence that uses a custom - // mapping. - // - // The solution is to rewrite the code as follows: - // - // arr = (Map<String, String>[])new Map[sz]; - // - // Unfortunately, this produces an unchecked warning during compilation. - // - // A simple test is to look for a "<" character in the content type, which - // indicates the use of a generic type. - // - string::size_type pos = origContentS.find('<'); - if(pos != string::npos) - { - string nonGenericType = origContentS.substr(0, pos); - out << nl << v << " = (" << origContentS << "[]"; - int d = depth; - while(d--) - { - out << "[]"; - } - out << ")new " << nonGenericType << "[__len" << iter << "]"; - } - else - { - out << nl << v << " = new " << origContentS << "[__len" << iter << "]"; - } - int d = depth; - while(d--) - { - out << "[]"; - } - out << ';'; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - ostringstream patchParams; - if(isObject) - { - patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS - << ".class, __type" << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter, - false, StringList(), patchParams.str()); - } - else - { - writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter, false); - } - out << eb; - iter++; - } - } - } -} - -void -Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, - const string& package, - const TypePtr& type, - bool optional, - int /*tag*/, - const string& param, - bool marshal, - int& iter, - bool holder, - const StringList& metaData, - const string& patchParams) -{ - string stream = marshal ? "__outS" : "__inS"; - string v; - if(holder && !optional) - { - v = param + ".value"; - } - else - { - v = param; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByte(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByte();"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << ".writeBool(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readBool();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShort(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShort();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeInt(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readInt();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLong(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLong();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloat(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloat();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDouble(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDouble();"; - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - out << nl << stream << ".writeString(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readString();"; - } - break; - } - case Builtin::KindObject: - { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - if(holder && !optional) - { - out << nl << stream << ".readObject(" << param << ");"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - break; - } - case Builtin::KindObjectProxy: - { - if(marshal) - { - if(optional) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << stream << ".writeProxy(" << v << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << stream << ".writeProxy(" << v << ");"; - } - } - else - { - if(optional) - { - out << nl << stream << ".skip(4);"; - } - out << nl << v << " = " << stream << ".readProxy();"; - } - break; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - string typeS = typeToString(type, TypeModeIn, package); - if(marshal) - { - if(optional) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - } - else - { - if(optional) - { - out << nl << stream << ".skip(4);"; - } - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - out << nl << stream << ".writeObject(" << v << ");"; - } - else - { - if(holder && !optional) - { - out << nl << stream << ".readObject(" << param << ");"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - return; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - string typeS = typeToString(type, TypeModeIn, package); - if(marshal) - { - if(optional) - { - if(st->isVariableLength()) - { - out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; - out << nl << stream << ".endSize(__pos);"; - } - else - { - out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; - out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; - } - } - else - { - out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; - } - } - else - { - if(optional) - { - if(st->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - } - out << nl << v << " = " << typeS << ".ice_read(" << stream << ", " << v << ");"; - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - string typeS = typeToString(type, TypeModeIn, package); - if(marshal) - { - out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << ".ice_read(" << stream << ");"; - } - return; - } - - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - if(dict) - { - if(optional) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - TypePtr keyType = dict->keyType(); - TypePtr valueType = dict->valueType(); - - if(marshal) - { - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << "int __pos = " << stream << ".startSize();"; - writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData); - out << nl << stream << ".endSize(__pos);"; - } - else - { - const size_t wireSize = keyType->minWireSize() + valueType->minWireSize(); - out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".size();"; - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData); - } - } - else - { - if(keyType->isVariableLength() || valueType->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else - { - out << nl << stream << ".skipSize();"; - } - - writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData); - } - } - else - { - writeStreamDictionaryMarshalUnmarshalCode(out, package, dict, v, marshal, iter, true, metaData); - } - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - if(optional) - { - string typeS = typeToString(type, TypeModeIn, package, metaData); - TypePtr elemType = seq->type(); - BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType); - - string ignore; - - if(marshal) - { - if(elemType->isVariableLength()) - { - out << nl << "int __pos = " << stream << ".startSize();"; - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - out << nl << stream << ".endSize(__pos);"; - } - else if(findMetaData("java:type:", metaData, ignore) || - findMetaData("java:type:", seq->getMetaData(), ignore)) - { - // - // The sequence is an instance of java.util.List<E>, where E is a fixed-size type. - // If the element type is bool or byte, we do NOT write an extra size. - // - - if(!elemBuiltin || - (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool)) - { - out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".size();"; - const size_t wireSize = elemType->minWireSize(); - - if(wireSize > 1) - { - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - } - else - { - // - // The element type could be a struct with a wire size of 1. - // - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize + 5 : __optSize + 1);"; - } - } - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - else if(findMetaData("java:protobuf:", seq->getMetaData(), ignore) || - findMetaData("java:serializable:", seq->getMetaData(), ignore)) - { - // - // This just writes a byte sequence. - // - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - else - { - // - // At this point we have a regular Java array of a fixed-size type. - // - - if(!elemBuiltin || (elemBuiltin->kind() != Builtin::KindByte && - elemBuiltin->kind() != Builtin::KindBool)) - { - out << nl << "final int __optSize = " << v << " == null ? 0 : " << v << ".length;"; - const size_t wireSize = elemType->minWireSize(); - - if(wireSize > 1) - { - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize - << " + 5 : __optSize * " << wireSize << " + 1);"; - } - else - { - // - // The element type could be a struct with a wire size of 1. - // - out << nl << stream << ".writeSize(__optSize > 254 ? __optSize + 5 : __optSize + 1);"; - } - } - - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - } - else - { - if(elemType->isVariableLength()) - { - out << nl << stream << ".skip(4);"; - } - else if(findMetaData("java:type:", metaData, ignore) || - findMetaData("java:type:", seq->getMetaData(), ignore)) - { - // - // The sequence is an instance of java.util.List<E>, where E is a fixed-size type. - // If the element type is bool or byte, we do NOT write an extra size. - // - - if(!elemBuiltin || - (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool)) - { - out << nl << stream << ".skipSize();"; - } - } - else if(!findMetaData("java:protobuf:", seq->getMetaData(), ignore) && - !findMetaData("java:serializable:", seq->getMetaData(), ignore)) - { - if(!elemBuiltin || - (elemBuiltin->kind() != Builtin::KindByte && elemBuiltin->kind() != Builtin::KindBool)) - { - out << nl << stream << ".skipSize();"; - } - } - - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - } - else - { - writeStreamSequenceMarshalUnmarshalCode(out, package, seq, v, marshal, iter, true, metaData); - } - return; - } - - ConstructedPtr constructed = ConstructedPtr::dynamicCast(type); - assert(constructed); - string typeS = getAbsolute(constructed, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } -} - -void -Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out, - const string& package, - const DictionaryPtr& dict, - const string& param, - bool marshal, - int& iter, - bool useHelper, - const StringList& metaData) -{ - string stream = marshal ? "__outS" : "__inS"; - string v = param; - - // - // We have to determine whether it's possible to use the - // type's generated helper class for this marshal/unmarshal - // task. Since the user may have specified a custom type in - // metadata, it's possible that the helper class is not - // compatible and therefore we'll need to generate the code - // in-line instead. - // - // Specifically, there may be "local" metadata (i.e., from - // a data member or parameter definition) that overrides the - // original type. We'll compare the mapped types with and - // without local metadata to determine whether we can use - // the helper. - // - string instanceType, formalType; - getDictionaryTypes(dict, "", metaData, instanceType, formalType); - string origInstanceType, origFormalType; - getDictionaryTypes(dict, "", StringList(), origInstanceType, origFormalType); - if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType)) - { - useHelper = false; - } - - // - // If we can use the helper, it's easy. - // - if(useHelper) - { - string typeS = getAbsolute(dict, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - TypePtr key = dict->keyType(); - TypePtr value = dict->valueType(); - - string keyS = typeToString(key, TypeModeIn, package); - string valueS = typeToString(value, TypeModeIn, package); - - ostringstream o; - o << iter; - string iterS = o.str(); - iter++; - - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << "__outS.writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << "__outS.writeSize(" << v << ".size());"; - string keyObjectS = typeToObjectString(key, TypeModeIn, package); - string valueObjectS = typeToObjectString(value, TypeModeIn, package); - out << nl << "for(java.util.Map.Entry<" << keyObjectS << ", " << valueObjectS << "> __e : " << v - << ".entrySet())"; - out << sb; - for(int i = 0; i < 2; i++) - { - string arg; - TypePtr type; - if(i == 0) - { - arg = "__e.getKey()"; - type = key; - } - else - { - arg = "__e.getValue()"; - type = value; - } - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, true, iter, false); - } - out << eb; - out << eb; - } - else - { - out << nl << v << " = new " << instanceType << "();"; - out << nl << "int __sz" << iterS << " = __inS.readSize();"; - out << nl << "for(int __i" << iterS << " = 0; __i" << iterS << " < __sz" << iterS << "; __i" << iterS << "++)"; - out << sb; - for(int i = 0; i < 2; i++) - { - string arg; - TypePtr type; - string typeS; - if(i == 0) - { - arg = "__key"; - type = key; - typeS = keyS; - } - else - { - arg = "__value"; - type = value; - typeS = valueS; - } - - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - string s = typeToString(type, TypeModeIn, package); - if(ClassDeclPtr::dynamicCast(type) || (b && b->kind() == Builtin::KindObject)) - { - string keyTypeStr = typeToObjectString(key, TypeModeIn, package); - string valueTypeStr = typeToObjectString(value, TypeModeIn, package); - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false, - StringList(), "new IceInternal.DictionaryPatcher<" + keyTypeStr + - ", " + valueTypeStr + ">(" + v + ", " + s + ".class, \"" + - type->typeId() + "\", __key)"); - } - else - { - if(StructPtr::dynamicCast(type)) - { - out << nl << s << ' ' << arg << " = null;"; - } - else - { - out << nl << s << ' ' << arg << ';'; - } - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false); - } - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(value); - if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value)) - { - out << nl << "" << v << ".put(__key, __value);"; - } - out << eb; - } -} - -void -Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out, - const string& package, - const SequencePtr& seq, - const string& param, - bool marshal, - int& iter, - bool useHelper, - const StringList& metaData) -{ - string stream = marshal ? "__outS" : "__inS"; - string v = param; - - // - // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to - // get rid of these two easy cases first. - // - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin && builtin->kind() == Builtin::KindByte) - { - string meta; - static const string protobuf = "java:protobuf:"; - static const string serializable = "java:serializable:"; - if(seq->findMetaData(serializable, meta)) - { - if(marshal) - { - out << nl << stream << ".writeSerializable(" << v << ");"; - } - else - { - string type = typeToString(seq, TypeModeIn, package); - out << nl << v << " = (" << type << ")" << stream << ".readSerializable();"; - } - return; - } - else if(seq->findMetaData(protobuf, meta)) - { - if(marshal) - { - out << nl << "if(!" << v << ".isInitialized())"; - out << sb; - out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");"; - out << eb; - out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());"; - } - else - { - string type = meta.substr(protobuf.size()); - out << nl << "try"; - out << sb; - out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());"; - out << eb; - out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)"; - out << sb; - out << nl << "Ice.MarshalException __mex = new Ice.MarshalException();"; - out << nl << "__mex.initCause(__ex);"; - out << nl << "throw __mex;"; - out << eb; - } - return; - } - } - - if(builtin && - (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - string meta; - static const string bytebuffer = "java:buffer"; - if(seq->findMetaData(bytebuffer, meta) || findMetaData(bytebuffer, metaData, meta)) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByteBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByteBuffer();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShortBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShortBuffer();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeIntBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readIntBuffer();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLongBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLongBuffer();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloatBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloatBuffer();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDoubleBuffer(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDoubleBuffer();"; - } - break; - } - case Builtin::KindBool: - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - return; - } - } - - // - // We have to determine whether it's possible to use the - // type's generated helper class for this marshal/unmarshal - // task. Since the user may have specified a custom type in - // metadata, it's possible that the helper class is not - // compatible and therefore we'll need to generate the code - // in-line instead. - // - // Specifically, there may be "local" metadata (i.e., from - // a data member or parameter definition) that overrides the - // original type. We'll compare the mapped types with and - // without local metadata to determine whether we can use - // the helper. - // - string instanceType, formalType; - bool customType = getSequenceTypes(seq, "", metaData, instanceType, formalType); - string origInstanceType, origFormalType; - getSequenceTypes(seq, "", StringList(), origInstanceType, origFormalType); - if((formalType != origFormalType) || (!marshal && instanceType != origInstanceType)) - { - useHelper = false; - } - - // - // If we can use the helper, it's easy. - // - if(useHelper) - { - string typeS = getAbsolute(seq, package); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - // - // Determine sequence depth - // - int depth = 0; - TypePtr origContent = seq->type(); - SequencePtr s = SequencePtr::dynamicCast(origContent); - while(s) - { - // - // Stop if the inner sequence type has a custom, serializable or protobuf type. - // - if(hasTypeMetaData(s)) - { - break; - } - depth++; - origContent = s->type(); - s = SequencePtr::dynamicCast(origContent); - } - string origContentS = typeToString(origContent, TypeModeIn, package); - - TypePtr type = seq->type(); - - if(customType) - { - // - // Marshal/unmarshal a custom sequence type. - // - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - string typeS = getAbsolute(seq, package); - ostringstream o; - o << origContentS; - int d = depth; - while(d--) - { - o << "[]"; - } - string cont = o.str(); - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".size());"; - string typeS = typeToString(type, TypeModeIn, package); - out << nl << "for(" << typeS << " __elem : " << v << ')'; - out << sb; - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", true, iter, false); - out << eb; - out << eb; // else - } - else - { - bool isObject = false; - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if((b && b->kind() == Builtin::KindObject) || cl) - { - isObject = true; - } - out << nl << v << " = new " << instanceType << "();"; - out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize() - << ");"; - if(isObject) - { - if(b) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - assert(cl); - if(cl->isInterface()) - { - out << nl << "final String __type" << iter << " = " - << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - } - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - if(isObject) - { - // - // Add a null value to the list as a placeholder for the element. - // - out << nl << v << ".add(null);"; - ostringstream patchParams; - patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS - << ".class, __type" << iter << ", __i" << iter << ')'; - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false, - StringList(), patchParams.str()); - } - else - { - if(StructPtr::dynamicCast(type)) - { - out << nl << cont << " __elem = null;"; - } - else - { - out << nl << cont << " __elem;"; - } - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false); - } - if(!isObject) - { - out << nl << v << ".add(__elem);"; - } - out << eb; - iter++; - } - } - else - { - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) - { - switch(b->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << ".writeByteSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readByteSeq();"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << ".writeBoolSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readBoolSeq();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << ".writeShortSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readShortSeq();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << ".writeIntSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readIntSeq();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << ".writeLongSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readLongSeq();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << ".writeFloatSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readFloatSeq();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << ".writeDoubleSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readDoubleSeq();"; - } - break; - } - case Builtin::KindString: - { - if(marshal) - { - out << nl << stream << ".writeStringSeq(" << v << ");"; - } - else - { - out << nl << v << " = " << stream << ".readStringSeq();"; - } - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - else - { - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".length);"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << v << ".length; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - iter++; - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), true, iter, false); - out << eb; - out << eb; - } - else - { - bool isObject = false; - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(origContent); - if((b && b->kind() == Builtin::KindObject) || cl) - { - isObject = true; - } - out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" - << type->minWireSize() << ");"; - if(isObject) - { - if(b) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - assert(cl); - if(cl->isInterface()) - { - out << nl << "final String __type" << iter << " = " - << getAbsolute(cl, package, "_", "Disp") << ".ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - } - // - // We cannot allocate an array of a generic type, such as - // - // arr = new Map<String, String>[sz]; - // - // Attempting to compile this code results in a "generic array creation" error - // message. This problem can occur when the sequence's element type is a - // dictionary, or when the element type is a nested sequence that uses a custom - // mapping. - // - // The solution is to rewrite the code as follows: - // - // arr = (Map<String, String>[])new Map[sz]; - // - // Unfortunately, this produces an unchecked warning during compilation. - // - // A simple test is to look for a "<" character in the content type, which - // indicates the use of a generic type. - // - string::size_type pos = origContentS.find('<'); - if(pos != string::npos) - { - string nonGenericType = origContentS.substr(0, pos); - out << nl << v << " = (" << origContentS << "[]"; - int d = depth; - while(d--) - { - out << "[]"; - } - out << ")new " << nonGenericType << "[__len" << iter << "]"; - } - else - { - out << nl << v << " = new " << origContentS << "[__len" << iter << "]"; - } - int d = depth; - while(d--) - { - out << "[]"; - } - out << ';'; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - ostringstream patchParams; - if(isObject) - { - patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS - << ".class, __type" << iter << ", __i" << iter << ')'; - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false, - StringList(), patchParams.str()); - } - else - { - writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false); - } - out << eb; - iter++; - } - } - } -} - -bool -Slice::JavaGenerator::findMetaData(const string& prefix, const StringList& metaData, string& value) -{ - for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) - { - if(q->find(prefix) == 0) - { - value = *q; - return true; - } - } - - return false; -} - -bool -Slice::JavaGenerator::getTypeMetaData(const StringList& metaData, string& instanceType, string& formalType) -{ - // - // Extract the instance type and an optional formal type. - // The correct syntax is "java:type:instance-type[:formal-type]". - // - static const string prefix = "java:type:"; - string directive; - if(findMetaData(prefix, metaData, directive)) - { - string::size_type pos = directive.find(':', prefix.size()); - if(pos != string::npos) - { - instanceType = directive.substr(prefix.size(), pos - prefix.size()); - formalType = directive.substr(pos + 1); - } - else - { - instanceType = directive.substr(prefix.size()); - formalType.clear(); - } - return true; - } - - return false; -} - -bool -Slice::JavaGenerator::hasTypeMetaData(const TypePtr& type, const StringList& localMetaData) -{ - ContainedPtr cont = ContainedPtr::dynamicCast(type); - if(cont) - { - static const string prefix = "java:type:"; - string directive; - - if(findMetaData(prefix, localMetaData, directive)) - { - return true; - } - - StringList metaData = cont->getMetaData(); - - if(findMetaData(prefix, metaData, directive)) - { - return true; - } - - if(findMetaData("java:protobuf:", metaData, directive) || - findMetaData("java:serializable:", metaData, directive)) - { - SequencePtr seq = SequencePtr::dynamicCast(cont); - if(seq) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin && builtin->kind() == Builtin::KindByte) - { - return true; - } - } - } - - if(findMetaData("java:buffer", localMetaData, directive)) - { - SequencePtr seq = SequencePtr::dynamicCast(cont); - if(seq) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin && - (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - return true; - } - } - } - } - - return false; -} - -bool -Slice::JavaGenerator::getDictionaryTypes(const DictionaryPtr& dict, - const string& package, - const StringList& metaData, - string& instanceType, - string& formalType) const -{ - // - // Get the types of the key and value. - // - string keyTypeStr = typeToObjectString(dict->keyType(), TypeModeIn, package); - string valueTypeStr = typeToObjectString(dict->valueType(), TypeModeIn, package); - - // - // Collect metadata for a custom type. - // - if(getTypeMetaData(metaData, instanceType, formalType) || - getTypeMetaData(dict->getMetaData(), instanceType, formalType)) - { - assert(!instanceType.empty()); - if(formalType.empty()) - { - formalType = "java.util.Map<" + keyTypeStr + ", " + valueTypeStr + ">"; - } - return true; - } - - // - // Return a default type for the platform. - // - instanceType = "java.util.HashMap<" + keyTypeStr + ", " + valueTypeStr + ">"; - formalType = "java.util.Map<" + keyTypeStr + ", " + valueTypeStr + ">"; - return false; -} - -bool -Slice::JavaGenerator::getSequenceTypes(const SequencePtr& seq, - const string& package, - const StringList& metaData, - string& instanceType, - string& formalType) const -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin) - { - if(builtin->kind() == Builtin::KindByte) - { - string prefix = "java:serializable:"; - string meta; - if(seq->findMetaData(prefix, meta)) - { - instanceType = formalType = meta.substr(prefix.size()); - return true; - } - prefix = "java:protobuf:"; - if(seq->findMetaData(prefix, meta)) - { - instanceType = formalType = meta.substr(prefix.size()); - return true; - } - } - - if((builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - string prefix = "java:buffer"; - string meta; - string ignore; - if(seq->findMetaData(prefix, meta) || findMetaData(prefix, metaData, ignore)) - { - instanceType = formalType = typeToBufferString(seq->type()); - return true; - } - } - } - - // - // Collect metadata for a custom type. - // - if(getTypeMetaData(metaData, instanceType, formalType) || - getTypeMetaData(seq->getMetaData(), instanceType, formalType)) - { - assert(!instanceType.empty()); - if(formalType.empty()) - { - formalType = "java.util.List<" + typeToObjectString(seq->type(), TypeModeIn, package) + ">"; - } - return true; - } - - // - // The default mapping is a native array. - // - instanceType = formalType = typeToString(seq->type(), TypeModeIn, package, metaData) + "[]"; - return false; -} - -bool -Slice::JavaGenerator::sequenceHasHolder(const SequencePtr& p) const -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type()); - if(builtin && builtin->kind() == Builtin::KindByte) - { - string prefix = "java:serializable:"; - string meta; - if(p->findMetaData(prefix, meta)) - { - return false; - } - prefix = "java:protobuf:"; - if(p->findMetaData(prefix, meta)) - { - return false; - } - } - - if(builtin && - (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - string meta; - string prefix = "java:buffer"; - if(p->findMetaData(prefix, meta)) - { - return false; - } - } - - return true; -} - - -JavaOutput* -Slice::JavaGenerator::createOutput() -{ - return new JavaOutput; -} - -void -Slice::JavaGenerator::validateMetaData(const UnitPtr& u) -{ - MetaDataVisitor visitor; - u->visit(&visitor, true); -} - -bool -Slice::JavaGenerator::MetaDataVisitor::visitUnitStart(const UnitPtr& p) -{ - static const string prefix = "java:"; - - // - // Validate global metadata in the top-level file and all included files. - // - StringList files = p->allFiles(); - - for(StringList::iterator q = files.begin(); q != files.end(); ++q) - { - string file = *q; - DefinitionContextPtr dc = p->findDefinitionContext(file); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end(); ++r) - { - string s = *r; - if(_history.count(s) == 0) - { - if(s.find(prefix) == 0) - { - bool ok = false; - - static const string packagePrefix = "java:package:"; - if(s.find(packagePrefix) == 0 && s.size() > packagePrefix.size()) - { - ok = true; - } - - if(!ok) - { - emitWarning(file, "", "ignoring invalid global metadata `" + s + "'"); - } - } - _history.insert(s); - } - } - } - return true; -} - -bool -Slice::JavaGenerator::MetaDataVisitor::visitModuleStart(const ModulePtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); - return true; -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); -} - -bool -Slice::JavaGenerator::MetaDataVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); - return true; -} - -bool -Slice::JavaGenerator::MetaDataVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); - return true; -} - -bool -Slice::JavaGenerator::MetaDataVisitor::visitStructStart(const StructPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); - return true; -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p) -{ - if(p->hasMetaData("UserException")) - { - ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); - if(!cl->isLocal()) - { - ostringstream os; - os << "ignoring invalid metadata `UserException': directive applies only to local operations " - << "but enclosing " << (cl->isInterface() ? "interface" : "class") << " `" << cl->name() - << "' is not local"; - emitWarning(p->file(), p->line(), os.str()); - } - } - StringList metaData = getMetaData(p); - TypePtr returnType = p->returnType(); - if(!metaData.empty()) - { - if(!returnType) - { - for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) - { - if(q->find("java:type:", 0) == 0) - { - emitWarning(p->file(), p->line(), "ignoring invalid metadata `" + *q + - "' for operation with void return type"); - break; - } - } - } - else - { - validateType(returnType, metaData, p->file(), p->line()); - } - } - - ParamDeclList params = p->parameters(); - for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q) - { - metaData = getMetaData(*q); - validateType((*q)->type(), metaData, p->file(), (*q)->line()); - } - - validateGetSet(p, metaData, p->file(), p->line()); -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitDataMember(const DataMemberPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p->type(), metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitSequence(const SequencePtr& p) -{ - static const string protobuf = "java:protobuf:"; - static const string serializable = "java:serializable:"; - static const string bytebuffer = "java:buffer"; - StringList metaData = getMetaData(p); - const string file = p->file(); - const string line = p->line(); - for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ) - { - string s = *q++; - if(_history.count(s) == 0) // Don't complain about the same metadata more than once. - { - if(s.find(protobuf) == 0 || s.find(serializable) == 0) - { - // - // Remove from list so validateType does not try to handle as well. - // - metaData.remove(s); - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type()); - if(!builtin || builtin->kind() != Builtin::KindByte) - { - _history.insert(s); - emitWarning(file, line, "ignoring invalid metadata `" + s + "': " + - "this metadata can only be used with a byte sequence"); - } - } - else if(s.find(bytebuffer) == 0) - { - metaData.remove(s); - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type()); - if(!builtin || - (builtin->kind() != Builtin::KindByte && builtin->kind() != Builtin::KindShort && - builtin->kind() != Builtin::KindInt && builtin->kind() != Builtin::KindLong && - builtin->kind() != Builtin::KindFloat && builtin->kind() != Builtin::KindDouble)) - { - _history.insert(s); - emitWarning(file, line, "ignoring invalid metadata `" + s + "': " + - "this metadata can not be used with this type"); - } - } - } - } - - validateType(p, metaData, file, line); - validateGetSet(p, metaData, file, line); -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitDictionary(const DictionaryPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitEnum(const EnumPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); -} - -void -Slice::JavaGenerator::MetaDataVisitor::visitConst(const ConstPtr& p) -{ - StringList metaData = getMetaData(p); - validateType(p, metaData, p->file(), p->line()); - validateGetSet(p, metaData, p->file(), p->line()); -} - -StringList -Slice::JavaGenerator::MetaDataVisitor::getMetaData(const ContainedPtr& cont) -{ - static const string prefix = "java:"; - - StringList metaData = cont->getMetaData(); - StringList result; - - for(StringList::const_iterator p = metaData.begin(); p != metaData.end(); ++p) - { - string s = *p; - if(_history.count(s) == 0) // Don't complain about the same metadata more than once. - { - if(s.find(prefix) == 0) - { - string::size_type pos = s.find(':', prefix.size()); - if(pos == string::npos) - { - if(s.size() > prefix.size()) - { - string rest = s.substr(prefix.size()); - if(rest == "getset") - { - result.push_back(s); - } - else if(rest == "buffer") - { - result.push_back(s); - } - continue; - } - } - else if(s.substr(prefix.size(), pos - prefix.size()) == "type") - { - result.push_back(s); - continue; - } - else if(s.substr(prefix.size(), pos - prefix.size()) == "serializable") - { - result.push_back(s); - continue; - } - else if(s.substr(prefix.size(), pos - prefix.size()) == "protobuf") - { - result.push_back(s); - continue; - } - else if(s.substr(prefix.size(), pos - prefix.size()) == "serialVersionUID") - { - result.push_back(s); - continue; - } - - emitWarning(cont->file(), cont->line(), "ignoring invalid metadata `" + s + "'"); - } - - _history.insert(s); - } - } - - return result; -} - -void -Slice::JavaGenerator::MetaDataVisitor::validateType(const SyntaxTreeBasePtr& p, const StringList& metaData, - const string& file, const string& line) -{ - for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); ++i) - { - // - // Type metadata ("java:type:Foo") is only supported by sequences and dictionaries. - // - if(i->find("java:type:", 0) == 0 && (!SequencePtr::dynamicCast(p) && !DictionaryPtr::dynamicCast(p))) - { - string str; - ContainedPtr cont = ContainedPtr::dynamicCast(p); - if(cont) - { - str = cont->kindOf(); - } - else - { - BuiltinPtr b = BuiltinPtr::dynamicCast(p); - assert(b); - str = b->typeId(); - } - emitWarning(file, line, "invalid metadata for " + str); - } - else if(i->find("java:buffer") == 0) - { - SequencePtr seq = SequencePtr::dynamicCast(p); - if(seq) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); - if(builtin && - (builtin->kind() == Builtin::KindByte || builtin->kind() == Builtin::KindShort || - builtin->kind() == Builtin::KindInt || builtin->kind() == Builtin::KindLong || - builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) - { - continue; - } - - } - emitWarning(file, line, "ignoring invalid metadata `" + *i + "'"); - } - else if(i->find("java:protobuf:") == 0 || i->find("java:serializable:") == 0) - { - // - // Only valid in sequence defintion which is checked in visitSequence - // - emitWarning(file, line, "ignoring invalid metadata `" + *i + "'"); - } - } -} - -void -Slice::JavaGenerator::MetaDataVisitor::validateGetSet(const SyntaxTreeBasePtr& p, const StringList& metaData, - const string& file, const string& line) -{ - for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); ++i) - { - // - // The "getset" metadata can only be specified on a class, struct, exception or data member. - // - if((*i) == "java:getset" && - (!ClassDefPtr::dynamicCast(p) && !StructPtr::dynamicCast(p) && !ExceptionPtr::dynamicCast(p) && - !DataMemberPtr::dynamicCast(p))) - { - string str; - ContainedPtr cont = ContainedPtr::dynamicCast(p); - if(cont) - { - str = cont->kindOf(); - } - else - { - BuiltinPtr b = BuiltinPtr::dynamicCast(p); - assert(b); - str = b->typeId(); - } - emitWarning(file, line, "invalid metadata for " + str); - } - } -} diff --git a/cpp/src/Slice/JavaUtil.h b/cpp/src/Slice/JavaUtil.h new file mode 100644 index 00000000000..776c8169321 --- /dev/null +++ b/cpp/src/Slice/JavaUtil.h @@ -0,0 +1,400 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef JAVA_UTIL_H +#define JAVA_UTIL_H + +#include <Slice/Parser.h> +#include <IceUtil/OutputUtil.h> + +namespace Slice +{ + +// +// Compute Java serialVersionUID for a Slice class +// +long +computeSerialVersionUUID(const ClassDefPtr&); + +// +// Compute Java serialVersionUID for a Slice class +// +long +computeSerialVersionUUID(const ExceptionPtr&); + +// +// Compute Java serialVersionUID for a Slice struct +// +long +computeSerialVersionUUID(const StructPtr&); + +class JavaOutput : public ::IceUtilInternal::Output +{ +public: + + JavaOutput(); + JavaOutput(std::ostream&); + JavaOutput(const char*); + + // + // Open a file to hold the source for a Java class. The first + // argument is the class name (including an optional leading + // package). Intermediate directories will be created as + // necessary to open the file in the package. The second + // argument specifies a directory prefix in which to locate + // the class. + // + // After successfully opening the file, the function invokes + // printHeader() and then emits a "package" statement if + // necessary. + // + void openClass(const std::string&, const std::string&, const std::string& = std::string()); + + virtual void printHeader(); +}; + +class JavaCompatGenerator : private ::IceUtil::noncopyable +{ +public: + + virtual ~JavaCompatGenerator(); + + // + // Validate all metadata in the unit with a "java:" prefix. + // + static void validateMetaData(const UnitPtr&); + + void close(); + +protected: + + JavaCompatGenerator(const std::string&); + + // + // Given the fully-scoped Java class name, create any intermediate + // package directories and open the class file, + // + void open(const std::string&, const std::string&); + + ::IceUtilInternal::Output& output() const; + + // + // Check a symbol against any of the Java keywords. If a + // match is found, return the symbol with a leading underscore. + // + std::string fixKwd(const std::string&) const; + + // + // Convert a Slice scoped name into a Java name. + // + std::string convertScopedName(const std::string&, + const std::string& = std::string(), + const std::string& = std::string()) const; + + + // + // Returns the package prefix for a give Slice file. + // + std::string getPackagePrefix(const ContainedPtr&) const; + + // + // Returns the Java package of a Contained entity. + // + std::string getPackage(const ContainedPtr&) const; + + // + // Returns the Java name for a Contained entity. If the optional + // package argument matches the entity's package name, then the + // package is removed from the result. + // + std::string getAbsolute(const ContainedPtr&, + const std::string& = std::string(), + const std::string& = std::string(), + const std::string& = std::string()) const; + + // + // Return the method call necessary to obtain the static type ID for an object type. + // + std::string getStaticId(const TypePtr&, const std::string&) const; + + // + // Determines whether an operation should use the optional mapping. + // + bool useOptionalMapping(const OperationPtr&); + + // + // Returns the optional type corresponding to the given Slice type. + // + std::string getOptionalFormat(const TypePtr&); + + // + // Get the Java name for a type. If an optional scope is provided, + // the scope will be removed from the result if possible. + // + enum TypeMode + { + TypeModeIn, + TypeModeOut, + TypeModeMember, + TypeModeReturn + }; + std::string typeToString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true, bool = false) const; + + // + // Get the Java object name for a type. For primitive types, this returns the + // Java class type (e.g., Integer). For all other types, this function delegates + // to typeToString. + // + std::string typeToObjectString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true) const; + + // + // Generate code to marshal or unmarshal a type. + // + enum OptionalMode + { + OptionalNone, + OptionalInParam, + OptionalOutParam, + OptionalReturnParam, + OptionalMember + }; + + void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const TypePtr&, OptionalMode, + bool, int, const std::string&, bool, int&, bool = false, const std::string& = "", + const StringList& = StringList(), const std::string& = ""); + + // + // Generate code to marshal or unmarshal a dictionary type. + // + void writeDictionaryMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const DictionaryPtr&, + const std::string&, bool, int&, bool, + const std::string& = "", const StringList& = StringList()); + + // + // Generate code to marshal or unmarshal a sequence type. + // + void writeSequenceMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const SequencePtr&, + const std::string&, bool, int&, bool, + const std::string& = "", const StringList& = StringList()); + + // + // Search metadata for an entry with the given prefix and return the entire string. + // + static bool findMetaData(const std::string&, const StringList&, std::string&); + + // + // Get custom type metadata. If metadata is found, the abstract and + // concrete types are extracted and the function returns true. If an + // abstract type is not specified, it is set to an empty string. + // + static bool getTypeMetaData(const StringList&, std::string&, std::string&); + + // + // Determine whether a custom type is defined. The function checks the + // metadata of the type's original definition, as well as any optional + // metadata that typically represents a data member or parameter. + // + static bool hasTypeMetaData(const TypePtr&, const StringList& = StringList()); + + // + // Obtain the concrete and abstract types for a dictionary or sequence type. + // The functions return true if a custom type was defined and false to indicate + // the default mapping was used. + // + bool getDictionaryTypes(const DictionaryPtr&, const std::string&, const StringList&, + std::string&, std::string&) const; + bool getSequenceTypes(const SequencePtr&, const std::string&, const StringList&, std::string&, std::string&) const; + + bool sequenceHasHolder(const SequencePtr&) const; + + virtual JavaOutput* createOutput(); + + static const std::string _getSetMetaData; + +private: + + std::string _dir; + ::IceUtilInternal::Output* _out; + mutable std::map<std::string, std::string> _filePackagePrefix; +}; + +class JavaGenerator : private ::IceUtil::noncopyable +{ +public: + + virtual ~JavaGenerator(); + + // + // Validate all metadata in the unit with a "java:" prefix. + // + static void validateMetaData(const UnitPtr&); + + void close(); + +protected: + + JavaGenerator(const std::string&); + + // + // Given the fully-scoped Java class name, create any intermediate + // package directories and open the class file, + // + void open(const std::string&, const std::string&); + + ::IceUtilInternal::Output& output() const; + + // + // Check a symbol against any of the Java keywords. If a + // match is found, return the symbol with a leading underscore. + // + std::string fixKwd(const std::string&) const; + + // + // Convert a Slice scoped name into a Java name. + // + std::string convertScopedName(const std::string&, + const std::string& = std::string(), + const std::string& = std::string()) const; + + + // + // Returns the package prefix for a give Slice file. + // + std::string getPackagePrefix(const ContainedPtr&) const; + + // + // Returns the Java package of a Contained entity. + // + std::string getPackage(const ContainedPtr&) const; + + // + // Returns the Java name for a Contained entity. If the optional + // package argument matches the entity's package name, then the + // package is removed from the result. + // + std::string getAbsolute(const ContainedPtr&, + const std::string& = std::string(), + const std::string& = std::string(), + const std::string& = std::string()) const; + + // + // Return the method call necessary to obtain the static type ID for an object type. + // + std::string getStaticId(const TypePtr&, const std::string&) const; + + // + // Determines whether an operation should use the optional mapping. + // + bool useOptionalMapping(const OperationPtr&); + + // + // Returns the optional type corresponding to the given Slice type. + // + std::string getOptionalFormat(const TypePtr&); + + // + // Get the Java name for a type. If an optional scope is provided, + // the scope will be removed from the result if possible. + // + enum TypeMode + { + TypeModeIn, + TypeModeOut, + TypeModeMember, + TypeModeReturn + }; + std::string typeToString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true, bool = false, bool = false) const; + + // + // Get the Java object name for a type. For primitive types, this returns the + // Java class type (e.g., Integer). For all other types, this function delegates + // to typeToString. + // + std::string typeToObjectString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true, bool = false) const; + + // + // Generate code to marshal or unmarshal a type. + // + enum OptionalMode + { + OptionalNone, + OptionalInParam, + OptionalOutParam, + OptionalReturnParam, + OptionalMember + }; + + std::string getWriteFunction(const std::string&, const TypePtr&); + std::string getReadFunction(const std::string&, const TypePtr&); + + void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const TypePtr&, OptionalMode, + bool, int, const std::string&, bool, int&, const std::string& = "", + const StringList& = StringList(), const std::string& = ""); + + // + // Generate code to marshal or unmarshal a dictionary type. + // + void writeDictionaryMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const DictionaryPtr&, + const std::string&, bool, int&, bool, + const std::string& = "", const StringList& = StringList()); + + // + // Generate code to marshal or unmarshal a sequence type. + // + void writeSequenceMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const SequencePtr&, + const std::string&, bool, int&, bool, + const std::string& = "", const StringList& = StringList()); + + // + // Search metadata for an entry with the given prefix and return the entire string. + // + static bool findMetaData(const std::string&, const StringList&, std::string&); + + // + // Get custom type metadata. If metadata is found, the abstract and + // concrete types are extracted and the function returns true. If an + // abstract type is not specified, it is set to an empty string. + // + static bool getTypeMetaData(const StringList&, std::string&, std::string&); + + // + // Determine whether a custom type is defined. The function checks the + // metadata of the type's original definition, as well as any optional + // metadata that typically represents a data member or parameter. + // + static bool hasTypeMetaData(const TypePtr&, const StringList& = StringList()); + + // + // Obtain the concrete and abstract types for a dictionary or sequence type. + // The functions return true if a custom type was defined and false to indicate + // the default mapping was used. + // + bool getDictionaryTypes(const DictionaryPtr&, const std::string&, const StringList&, + std::string&, std::string&, bool) const; + bool getSequenceTypes(const SequencePtr&, const std::string&, const StringList&, std::string&, std::string&, + bool) const; + + virtual JavaOutput* createOutput(); + + static const std::string _getSetMetaData; + +private: + + std::string _dir; + ::IceUtilInternal::Output* _out; + mutable std::map<std::string, std::string> _filePackagePrefix; +}; + +} + +#endif diff --git a/cpp/src/Slice/Makefile b/cpp/src/Slice/Makefile deleted file mode 100644 index a9ca7316f40..00000000000 --- a/cpp/src/Slice/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ../.. - -LIBFILENAME = $(call mklibfilename,Slice,$(VERSION)) -SONAME = $(call mksoname,Slice,$(SOVERSION)) -LIBNAME = $(call mklibname,Slice) -TARGETS = $(call mklibtargets,$(libdir)/$(LIBFILENAME),$(libdir)/$(SONAME),$(libdir)$(cpp11libdirsuffix)/$(LIBNAME)) - -OBJS = Checksum.o \ - CPlusPlusUtil.o \ - CsUtil.o \ - DotNetNames.o \ - FileTracker.o \ - JavaUtil.o \ - MD5.o \ - MD5I.o \ - ObjCUtil.o \ - Parser.o \ - PHPUtil.o \ - Preprocessor.o \ - PythonUtil.o \ - Python.o \ - RubyUtil.o \ - Ruby.o \ - Scanner.o \ - Util.o \ - ../Slice/Grammar.o - -include $(top_srcdir)/config/Make.rules - - -CPPFLAGS := -I.. $(CPPFLAGS) -DSLICE_API_EXPORTS -BISONFLAGS := --name-prefix "slice_" $(BISONFLAGS) - -LINKWITH := $(BASELIBS) $(MCPP_LIBS) -ifeq ($(STATICLIBS),yes) -$(libdir)/$(LIBNAME): $(OBJS) - @mkdir -p $(dir $@) - rm -f $@ - $(call mklib,$@,$(OBJS)) -else -$(libdir)/$(LIBFILENAME): $(OBJS) $(MCPP_NUPKG) - @mkdir -p $(dir $@) - rm -f $@ - $(call mkshlib,$@,$(SONAME),$(OBJS),$(LINKWITH)) - -$(libdir)/$(SONAME): $(libdir)/$(LIBFILENAME) - rm -f $@ - ln -s $(LIBFILENAME) $@ - -$(libdir)$(cpp11libdirsuffix)/$(LIBNAME): $(libdir)/$(SONAME) - @mkdir -p $(libdir)$(cpp11libdirsuffix) - rm -f $@ - ln -s $(cpp11sonamedir)$(SONAME) $@ - -install:: all - $(call installlib,$(DESTDIR)$(install_libdir),$(libdir),$(LIBFILENAME),$(SONAME),$(LIBNAME)) -endif - diff --git a/cpp/src/Slice/Makefile.mak b/cpp/src/Slice/Makefile.mak deleted file mode 100644 index 074a4eab47e..00000000000 --- a/cpp/src/Slice/Makefile.mak +++ /dev/null @@ -1,87 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ..\.. - -LIBNAME = $(top_srcdir)\lib\slice$(LIBSUFFIX).lib -DLLNAME = $(top_srcdir)\bin\slice$(SOVERSION)$(LIBSUFFIX)$(COMPSUFFIX).dll - -TARGETS = $(LIBNAME) $(DLLNAME) - -BISON_FLEX_OBJS = .\Grammar.obj \ - .\Scanner.obj - -OBJS = .\Checksum.obj \ - .\CPlusPlusUtil.obj \ - .\CsUtil.obj \ - .\DotNetNames.obj \ - .\FileTracker.obj \ - .\JavaUtil.obj \ - .\MD5.obj \ - .\MD5I.obj \ - .\Parser.obj \ - .\PHPUtil.obj \ - .\Preprocessor.obj \ - .\PythonUtil.obj \ - .\Python.obj \ - .\RubyUtil.obj \ - .\Util.obj \ - .\Ruby.obj \ - $(BISON_FLEX_OBJS) - -!include $(top_srcdir)/config/Make.rules.mak - -$(OBJS) : $(MCPP_NUPKG) - -CPPFLAGS = -I.. $(CPPFLAGS) -DSLICE_API_EXPORTS -DWIN32_LEAN_AND_MEAN -BISONFLAGS = --name-prefix "slice_" $(BISONFLAGS) - -!if "$(GENERATE_PDB)" == "yes" -PDBFLAGS = /pdb:$(DLLNAME:.dll=.pdb) -!endif - -RES_FILE = Slice.res - -!if "$(STATICLIBS)" == "yes" - -$(DLLNAME): - -$(LIBNAME): $(OBJS) - $(AR) $(ARFLAGS) $(PDBFLAGS) $(OBJS) $(PREOUT)$@ - -!else - -$(LIBNAME): $(DLLNAME) - -$(DLLNAME): $(OBJS) Slice.res - $(LINK) $(BASE):0x21000000 $(LD_DLLFLAGS) $(MCPP_LDFLAGS) $(PDBFLAGS) $(OBJS) $(PREOUT)$@ $(PRELIBS)$(BASELIBS) $(MCPP_LIBS) \ - $(RES_FILE) - move $(DLLNAME:.dll=.lib) $(LIBNAME) - @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ - $(MT) -nologo -manifest $@.manifest -outputresource:$@;#2 && del /q $@.manifest - @if exist $(DLLNAME:.dll=.exp) del /q $(DLLNAME:.dll=.exp) - @if defined SIGN_CERTIFICATE echo ^ ^ ^ Signing $@ && \ - signtool sign /f "$(SIGN_CERTIFICATE)" /p $(SIGN_PASSWORD) /t $(SIGN_TIMESTAMPSERVER) $@ - -!endif - -clean:: - -del /q Slice.res - -install:: all - copy $(LIBNAME) "$(install_libdir)" - copy $(DLLNAME) "$(install_bindir)" - - -!if "$(GENERATE_PDB)" == "yes" - -install:: all - copy $(DLLNAME:.dll=.pdb) "$(install_bindir)" - -!endif diff --git a/cpp/src/Slice/Makefile.mk b/cpp/src/Slice/Makefile.mk new file mode 100644 index 00000000000..eaa997af989 --- /dev/null +++ b/cpp/src/Slice/Makefile.mk @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +$(project)_libraries := Slice + +Slice_targetdir := $(libdir) +Slice_libs := mcpp + +# Always enable the static configuration for the Slice library and never +# install it +Slice_always_enable_configs := static +Slice_always_enable_platforms := $(build-platform) +Slice_install_configs := none +Slice_bisonflags := --name-prefix "slice_" + +projects += $(project) diff --git a/cpp/src/Slice/ObjCUtil.cpp b/cpp/src/Slice/ObjCUtil.cpp deleted file mode 100644 index e9001855f06..00000000000 --- a/cpp/src/Slice/ObjCUtil.cpp +++ /dev/null @@ -1,1310 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Slice/ObjCUtil.h> -#include <Slice/Util.h> -#include <IceUtil/Functional.h> -#include <IceUtil/StringUtil.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#ifdef _WIN32 -#include <direct.h> -#endif - -#ifndef _WIN32 -#include <unistd.h> -#endif - -using namespace std; -using namespace Slice; -using namespace IceUtil; -using namespace IceUtilInternal; - -Slice::ObjCGenerator::ModuleMap Slice::ObjCGenerator::_modules; - -static string -lookupKwd(const string& name, int baseType, bool mangleCasts = false) -{ - // - // All lists in this method *must* be kept in case-insensitive - // alphabetical order. - // - static string keywordList[] = - { - "auto", "BOOL", "break", "bycopy", "byref", "case", "char", "const", "continue", - "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", - "id", "if", "IMP", "in", "inline", "inout", "int", "long", "nil", "NO", "oneway", "out", - "register", "return", "SEL", "self", "short", "signed", "sizeof", "static", "struct", "super", "switch", - "typedef", "union", "unsigned", "void", "volatile", "while", "YES" - }; - - static string nsObjectList[] = - { - "autorelease", "class", "classForCoder", "copy", "dealloc", "description", "hash", "init", "isa", - "isProxy", "mutableCopy", "release", "retain", "retainCount", "superclass", "zone" - }; - static string nsExceptionList[] = - { - "callStackReturnAddresses", "name", "raise", "reason", "reserved", "userInfo", - }; - - bool found = binary_search(&keywordList[0], - &keywordList[sizeof(keywordList) / sizeof(*keywordList)], - name, - Slice::CICompare()); - if(!found) - { - switch(baseType) - { - case BaseTypeNone: - break; - - case BaseTypeException: - found = binary_search(&nsExceptionList[0], - &nsExceptionList[sizeof(nsExceptionList) / sizeof(*nsExceptionList)], - name, - Slice::CICompare()); - if(found) - { - break; - } - - case BaseTypeObject: - found = binary_search(&nsObjectList[0], - &nsObjectList[sizeof(nsObjectList) / sizeof(*nsObjectList)], - name, - Slice::CICompare()); - break; - } - } - if(found || (mangleCasts && (name == "checkedCast" || name == "uncheckedCast"))) - { - return name + "_"; - } - return name; -} - -static string -lookupParamIdKwd(const string& name) -{ - // - // All lists in this method *must* be kept in case-insensitive - // alphabetical order. - // - static string keywordList[] = - { - "nil", "NO", "YES" - }; - if(binary_search(&keywordList[0], - &keywordList[sizeof(keywordList) / sizeof(*keywordList)], - name, - Slice::CICompare())) - { - return name + "_"; - } - return name; -} - -bool -Slice::ObjCGenerator::addModule(const ModulePtr& m, const string& name) -{ - string scoped = m->scoped(); - ModuleMap::const_iterator i = _modules.find(scoped); - if(i != _modules.end()) - { - if(i->second.name != name) - { - return false; - } - } - else - { - ModulePrefix mp; - mp.m = m; - mp.name = name; - _modules[scoped] = mp; - } - return true; -} - -Slice::ObjCGenerator::ModulePrefix -Slice::ObjCGenerator::modulePrefix(const ModulePtr& m) -{ - return _modules[m->scoped()]; -} - -string -Slice::ObjCGenerator::moduleName(const ModulePtr& m) -{ - return _modules[m->scoped()].name; -} - -ModulePtr -Slice::ObjCGenerator::findModule(const ContainedPtr& cont, int baseTypes, bool mangleCasts) -{ - ModulePtr m = ModulePtr::dynamicCast(cont); - ContainerPtr container = cont->container(); - while(container && !m) - { - ContainedPtr contained = ContainedPtr::dynamicCast(container); - container = contained->container(); - m = ModulePtr::dynamicCast(contained); - } - assert(m); - return m; -} - -// -// If the passed name is a scoped name, return the identical scoped -// name, but with all components that are Objective-C keywords -// replaced by their prefixed version; otherwise, if the passed name -// is not scoped, but an Objective-C keyword, return the prefixed -// name; otherwise, check if the name is one of the method names of -// baseTypes; if so, returned the prefixed name; otherwise, return the -// name unchanged. -// -string -Slice::ObjCGenerator::fixId(const string& name, int baseTypes, bool mangleCasts) -{ - if(name.empty()) - { - return name; - } - return lookupKwd(name, baseTypes, mangleCasts); -} - -string -Slice::ObjCGenerator::fixId(const ContainedPtr& cont, int baseTypes, bool mangleCasts) -{ - return fixId(cont->name(), baseTypes, mangleCasts); -} - -string -Slice::ObjCGenerator::fixName(const ContainedPtr& cont, int baseTypes, bool mangleCasts) -{ - return moduleName(findModule(cont, baseTypes, mangleCasts)) + cont->name(); -} - -string -Slice::ObjCGenerator::getParamId(const ContainedPtr& param) -{ - string n; - if(ParamDeclPtr::dynamicCast(param) && param->findMetaData("objc:param:", n)) - { - return lookupParamIdKwd(n.substr(11)); - } - else - { - return lookupParamIdKwd(param->name()); - } -} - -string -Slice::ObjCGenerator::getFactoryMethod(const ContainedPtr& p, bool deprecated) -{ - ClassDefPtr def = ClassDefPtr::dynamicCast(p); - if(def && def->declaration()->isLocal()) - { - deprecated = false; // Local classes don't have this issue since they were added after this fix. - } - - // - // If deprecated is true, we return uDPConnectionInfo for a class - // named UDPConnectionInfo, return udpConnectionInfo otherwise. - // - string name = fixId(p->name()); - if(name.empty()) - { - return name; - } - else if(deprecated || name.size() < 2 || !isupper(*(name.begin() + 1))) - { - *name.begin() = tolower(*name.begin()); - } - else - { - for(string::iterator p = name.begin(); p != name.end() && isalpha(*p); ++p) - { - if(p != name.end() - 1 && isalpha(*(p + 1)) && !isupper(*(p + 1))) - { - break; - } - *p = tolower(*p); - } - } - return name; -} - -string -Slice::ObjCGenerator::typeToString(const TypePtr& type) -{ - if(!type) - { - return "void"; - } - - static const char* builtinTable[] = - { - "ICEByte", - "BOOL", - "ICEShort", - "ICEInt", - "ICELong", - "ICEFloat", - "ICEDouble", - "NSString", - "ICEObject", - "id<ICEObjectPrx>", - "id" // Dummy--we don't support Slice local Object - }; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - return builtinTable[builtin->kind()]; - } - - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if(proxy) - { - string mName = moduleName(findModule(proxy->_class())); - return "id<" + mName + (proxy->_class()->name()) + "Prx>"; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - return fixName(seq); - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - return fixName(d); - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(cl->isInterface()) - { - if(cl->isLocal()) - { - return "id<" + fixName(cl) + ">"; - } - else - { - return "ICEObject"; - } - } - else if(cl->isLocal()) - { - string name = fixName(cl); - return name + "<" + name + ">"; - } - } - - ContainedPtr contained = ContainedPtr::dynamicCast(type); - if(contained) - { - return fixName(contained); - } - - return "???"; -} - -string -Slice::ObjCGenerator::inTypeToString(const TypePtr& type, bool optional, bool autoreleasing, bool reference) -{ - string s; - if(optional) - { - s = "id"; - } - else - { - s = typeToString(type); - if(mapsToPointerType(type)) - { - s += "*"; - } - } - if(autoreleasing && !isValueType(type)) - { - s += " ICE_AUTORELEASING_QUALIFIER"; - } - if(reference) - { - s += "*"; - } - return s; -} - -string -Slice::ObjCGenerator::outTypeToString(const TypePtr& type, bool optional, bool autoreleasing, bool reference) -{ - if(!type) - { - return "void"; - } - - string s; - if(optional) - { - s = "id"; - } - else - { - SequencePtr seq = SequencePtr::dynamicCast(type); - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(isString(type)) - { - s = "NSMutableString"; - } - else if(seq) - { - string prefix = moduleName(findModule(seq)); - s = prefix + "Mutable" + seq->name(); - } - else if(d) - { - string prefix = moduleName(findModule(d)); - s = prefix + "Mutable" + d->name(); - } - else - { - s = typeToString(type); - } - if(mapsToPointerType(type)) - { - s += "*"; - } - } - if(autoreleasing && !isValueType(type)) - { - s += " ICE_AUTORELEASING_QUALIFIER"; - } - if(reference) - { - s += "*"; - } - return s; -} - -string -Slice::ObjCGenerator::typeToObjCTypeString(const TypePtr& type) -{ - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if(proxy) - { - return moduleName(findModule(proxy->_class())) + (proxy->_class()->name()) + "Prx"; - } - else - { - return typeToString(type); - } -} - -bool -Slice::ObjCGenerator::isValueType(const TypePtr& type) -{ - if(!type) - { - return true; - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - return false; - break; - } - default: - { - return true; - break; - } - } - } - if(EnumPtr::dynamicCast(type)) - { - return true; - } - return false; -} - -bool -Slice::ObjCGenerator::isString(const TypePtr& type) -{ - if(!type) - { - return false; - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - return builtin && builtin->kind() == Builtin::KindString; -} -bool -Slice::ObjCGenerator::isClass(const TypePtr& type) -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - return builtin->kind() == Builtin::KindObject; - } - return ClassDeclPtr::dynamicCast(type); -} - -bool -Slice::ObjCGenerator::mapsToPointerType(const TypePtr& type) -{ - if(isValueType(type)) - { - return false; - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - return builtin->kind() != Builtin::KindObjectProxy && builtin->kind() != Builtin::KindLocalObject; - } - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl && cl->isInterface()) - { - if(cl->isLocal()) - { - return false; - } - else - { - return true; - } - } - return !ProxyPtr::dynamicCast(type); -} - -string -Slice::ObjCGenerator::getBuiltinName(const BuiltinPtr& builtin) -{ - switch(builtin->kind()) - { - case Builtin::KindByte: - { - return "Byte"; - } - case Builtin::KindBool: - { - return "Bool"; - } - case Builtin::KindShort: - { - return "Short"; - } - case Builtin::KindInt: - { - return "Int"; - } - case Builtin::KindLong: - { - return "Long"; - } - case Builtin::KindFloat: - { - return "Float"; - } - case Builtin::KindDouble: - { - return "Double"; - } - case Builtin::KindString: - { - return "String"; - } - case Builtin::KindObject: - { - return "Object"; - } - case Builtin::KindObjectProxy: - { - return "Proxy"; - } - default: - { - assert(false); - } - } - return "NO__SUCH__TYPE"; -} - -string -Slice::ObjCGenerator::getOptionalHelperGetter(const TypePtr& type) -{ - if(isValueType(type)) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - return "get" + getBuiltinName(builtin); - } - if(EnumPtr::dynamicCast(type)) - { - return "getInt"; - } - } - return "get"; -} - -// -// Split a scoped name into its components and return the components as a list of (unscoped) identifiers. -// -StringList -Slice::ObjCGenerator::splitScopedName(const string& scoped) -{ - assert(scoped[0] == ':'); - StringList ids; - string::size_type next = 0; - string::size_type pos; - while((pos = scoped.find("::", next)) != string::npos) - { - pos += 2; - if(pos != scoped.size()) - { - string::size_type endpos = scoped.find("::", pos); - if(endpos != string::npos) - { - ids.push_back(scoped.substr(pos, endpos - pos)); - } - } - next = pos; - } - if(next != scoped.size()) - { - ids.push_back(scoped.substr(next)); - } - else - { - ids.push_back(""); - } - - return ids; -} - -string -Slice::ObjCGenerator::getOptionalFormat(const TypePtr& type) -{ - BuiltinPtr bp = BuiltinPtr::dynamicCast(type); - if(bp) - { - switch(bp->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - { - return "ICEOptionalFormatF1"; - } - case Builtin::KindShort: - { - return "ICEOptionalFormatF2"; - } - case Builtin::KindInt: - case Builtin::KindFloat: - { - return "ICEOptionalFormatF4"; - } - case Builtin::KindLong: - case Builtin::KindDouble: - { - return "ICEOptionalFormatF8"; - } - case Builtin::KindString: - { - return "ICEOptionalFormatVSize"; - } - case Builtin::KindObject: - { - return "ICEOptionalFormatClass"; - } - case Builtin::KindObjectProxy: - { - return "ICEOptionalFormatFSize"; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - - if(EnumPtr::dynamicCast(type)) - { - return "ICEOptionalFormatSize"; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - return seq->type()->isVariableLength() ? "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - return (d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) ? - "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - return st->isVariableLength() ? "ICEOptionalFormatFSize" : "ICEOptionalFormatVSize"; - } - - if(ProxyPtr::dynamicCast(type)) - { - return "ICEOptionalFormatFSize"; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - assert(cl); - return "ICEOptionalFormatClass"; -} - -void -Slice::ObjCGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, - bool marshal, bool autoreleased) const -{ - string stream = marshal ? "os_" : "is_"; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - - if(builtin) - { - string name; - if(builtin->kind() == Builtin::KindObject) - { - if(marshal) - { - out << nl << "[" << stream << " writeObject:" << param << "];"; - } - else - { - if(autoreleased) - { - out << nl << "[" << stream << " readObject:&" << param << "];"; - } - else - { - out << nl << "[" << stream << " newObject:&" << param << "];"; - } - } - } - else if(builtin->kind() == Builtin::KindObjectProxy) - { - if(marshal) - { - out << nl << "[" << stream << " writeProxy:" << param << "];"; - } - else - { - if(autoreleased) - { - out << nl << param << " = [" << stream << " readProxy:[ICEObjectPrx class]];"; - } - else - { - out << nl << param << " = [" << stream << " newProxy:[ICEObjectPrx class]];"; - } - } - } - else - { - if(marshal) - { - out << nl << "[" << stream << " write" << getBuiltinName(builtin) << ":" << param << "];"; - } - else - { - if(autoreleased || isValueType(builtin)) - { - out << nl << param << " = [" << stream << " read" << getBuiltinName(builtin) << "];"; - } - else - { - out << nl << param << " = [" << stream << " new" << getBuiltinName(builtin) << "];"; - } - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - if(marshal) - { - out << nl << "[" << stream << " writeProxy:(id<ICEObjectPrx>)" << param << "];"; - } - else - { - string name = moduleName(findModule(prx->_class())) + prx->_class()->name() + "Prx"; - out << nl << param << " = (id<" << name << ">)[" << stream; - if(autoreleased) - { - out << " readProxy:"; - } - else - { - out << " newProxy:"; - } - // - // We use objc_getClass to get the proxy class instead of [name class]. This is to avoid - // a warning if the proxy is forward declared. - // - if(prx->_class()->definition()) - { - out << "[" << name << " class]];"; - } - else - { - out << "objc_getClass(\"" << name << "\")];"; - } - } - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - if(marshal) - { - // Cast avoids warning for forward-declared classes. - out << nl << "[" << stream << " writeObject:(ICEObject*)" << param << "];"; - } - else - { - if(autoreleased) - { - out << nl << "[" << stream << " " << "readObject:(ICEObject**)&" << param; - } - else - { - out << nl << "[" << stream << " " << "newObject:(ICEObject**)&" << param; - } - - if(cl->isInterface()) - { - out << "];"; - } - else - { - string name = moduleName(findModule(cl)) + cl->name(); - if(cl->definition()) - { - out << " expectedType:[" << name << " class]];"; - } - else - { - out << " expectedType:objc_getClass(\"" << name << "\")];"; - } - } - } - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - if(marshal) - { - out << nl << "[" << stream << " writeEnumerator:" << param << " min:" << en->minValue() - << " max:" << en->maxValue() << "];"; - } - else - { - out << nl << param << " = " << "[" << stream << " readEnumerator:" << en->minValue() - << " max:" << en->maxValue() << "];"; - } - return; - } - - ContainedPtr c = ContainedPtr::dynamicCast(type); - assert(c); - string name = moduleName(findModule(c)) + c->name() + "Helper"; - if(marshal) - { - out << nl << "[" + name << " write:" << param << " stream:" << stream << "];"; - } - else - { - if(StructPtr::dynamicCast(type)) - { - if(autoreleased) - { - out << nl << param << " = [" << name << " read:" << stream << " value:" << param << "];"; - } - else - { - out << nl << param << " = [" << name << " readRetained:" << stream << " value:" << param << "];"; - } - } - else - { - if(autoreleased) - { - out << nl << param << " = [" << name << " read:" << stream << "];"; - } - else - { - out << nl << param << " = [" << name << " readRetained:" << stream << "];"; - } - } - } -} - -void -Slice::ObjCGenerator::writeOptMemberMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, - bool marshal) const -{ - string stream = marshal ? "os_" : "is_"; - string optionalHelper; - string helper; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - if(builtin->kind() == Builtin::KindObjectProxy) - { - optionalHelper = "ICEVarLengthOptionalHelper"; - helper = "[ICEProxyHelper class]"; - } - else - { - writeMarshalUnmarshalCode(out, type, param, marshal, false); - return; - } - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - writeMarshalUnmarshalCode(out, type, param, marshal, false); - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - writeMarshalUnmarshalCode(out, type, param, marshal, false); - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - optionalHelper = "ICEVarLengthOptionalHelper"; - helper = "objc_getClass(\"" + moduleName(findModule(prx->_class())) + prx->_class()->name() + "PrxHelper\")"; - } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - if(st->isVariableLength()) - { - optionalHelper = "ICEVarLengthOptionalHelper"; - } - else - { - optionalHelper = "ICEFixedLengthOptionalHelper"; - } - helper = "[" + typeToString(st) + "Helper class]"; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - TypePtr element = seq->type(); - if(element->isVariableLength()) - { - optionalHelper = "ICEVarLengthOptionalHelper"; - } - else if(element->minWireSize() == 1) - { - writeMarshalUnmarshalCode(out, type, param, marshal, false); - return; - } - else - { - optionalHelper = "ICEFixedSequenceOptionalHelper"; - } - helper = "[" + moduleName(findModule(seq)) + seq->name() + "Helper class]"; - } - - DictionaryPtr d = DictionaryPtr::dynamicCast(type); - if(d) - { - if(d->keyType()->isVariableLength() || d->valueType()->isVariableLength()) - { - optionalHelper = "ICEVarLengthOptionalHelper"; - } - else - { - optionalHelper = "ICEFixedDictionaryOptionalHelper"; - } - helper = "[" + moduleName(findModule(d)) + d->name() + "Helper class]"; - } - - out << nl; - if(marshal) - { - out << "[" << optionalHelper << " write:" << param << " stream:" << stream << " helper:" << helper << "];"; - } - else - { - out << param << " = [" << optionalHelper << " readRetained:" << stream << " helper:" << helper << "];"; - } - -} - -void -Slice::ObjCGenerator::writeOptParamMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, - int tag, bool marshal) const -{ - string helper; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - ProxyPtr proxy = ProxyPtr::dynamicCast(type); - if(builtin) - { - helper = "ICE" + getBuiltinName(builtin) + "Helper"; - } - else if(proxy) - { - helper = moduleName(findModule(proxy->_class())) + (proxy->_class()->name()) + "PrxHelper"; - } - else - { - helper = typeToString(type) + "Helper"; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - out << nl; - if(marshal) - { - out << "[" << helper << " writeOpt:" << param << " stream:os_ tag:" << tag << "];"; - } - else - { - out << "[" << helper << " readOpt:&" << param << " stream:is_ tag:" << tag << "];"; - } - return; - } - - out << nl; - if(marshal) - { - out << "[" << helper << " writeOpt:" << param << " stream:os_ tag:" << tag << "];"; - } - else - { - out << param << " = [" << helper << " readOpt:is_ tag:" << tag << "];"; - } -} - -void -Slice::ObjCGenerator::validateMetaData(const UnitPtr& u) -{ - MetaDataVisitor visitor; - u->visit(&visitor, true); -} - -const string Slice::ObjCGenerator::MetaDataVisitor::_objcPrefix = "objc:"; -const string Slice::ObjCGenerator::MetaDataVisitor::_msg = "ignoring invalid metadata"; - -Slice::ObjCGenerator::MetaDataVisitor::MetaDataVisitor() -{ -} - -bool -Slice::ObjCGenerator::MetaDataVisitor::visitUnitStart(const UnitPtr& p) -{ - // - // Validate global metadata in the top-level file and all included files. - // - StringList files = p->allFiles(); - - for(StringList::iterator q = files.begin(); q != files.end(); ++q) - { - string file = *q; - DefinitionContextPtr dc = p->findDefinitionContext(file); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - int headerDir = 0; - for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end(); ++r) - { - string s = *r; - if(_history.count(s) == 0) - { - if(s.find(_objcPrefix) == 0) - { - static const string objcHeaderDirPrefix = "objc:header-dir:"; - if(s.find(objcHeaderDirPrefix) == 0 && s.size() > objcHeaderDirPrefix.size()) - { - headerDir++; - if(headerDir > 1) - { - ostringstream ostr; - ostr << "ignoring invalid global metadata `" << s - << "': directive can appear only once per file"; - emitWarning(file, -1, ostr.str()); - _history.insert(s); - } - continue; - } - ostringstream ostr; - ostr << "ignoring invalid global metadata `" << s << "'"; - emitWarning(file, -1, ostr.str()); - } - _history.insert(s); - } - } - } - - return true; -} - -bool -Slice::ObjCGenerator::MetaDataVisitor::visitModuleStart(const ModulePtr& p) -{ - validate(p); - return true; -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitModuleEnd(const ModulePtr&) -{ -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - validate(p); -} - -bool -Slice::ObjCGenerator::MetaDataVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - validate(p); - return true; -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitClassDefEnd(const ClassDefPtr&) -{ -} - -bool -Slice::ObjCGenerator::MetaDataVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - validate(p); - return true; -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitExceptionEnd(const ExceptionPtr&) -{ -} - -bool -Slice::ObjCGenerator::MetaDataVisitor::visitStructStart(const StructPtr& p) -{ - validate(p); - return true; -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitStructEnd(const StructPtr&) -{ -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p) -{ - if(p->hasMetaData("UserException")) - { - ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container()); - if(!cl->isLocal()) - { - ostringstream os; - os << "ignoring invalid metadata `UserException': directive applies only to local operations " - << ": warning: metadata directive `UserException' applies only to local operations " - << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name() - << "' is not local"; - emitWarning(p->file(), p->line(), os.str()); - } - } - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitParamDecl(const ParamDeclPtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitDataMember(const DataMemberPtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitSequence(const SequencePtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitDictionary(const DictionaryPtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitEnum(const EnumPtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::visitConst(const ConstPtr& p) -{ - validate(p); -} - -void -Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) -{ - ModulePtr m = ModulePtr::dynamicCast(cont); - if(m) - { - bool error = false; - bool foundPrefix = false; - - StringList meta = getMetaData(m); - StringList::const_iterator p; - - for(p = meta.begin(); p != meta.end(); ++p) - { - const string prefix = "prefix:"; - string name; - if(p->substr(_objcPrefix.size(), prefix.size()) == prefix) - { - foundPrefix = true; - name = trim(p->substr(_objcPrefix.size() + prefix.size())); - if(name.empty()) - { - if(_history.count(*p) == 0) - { - string file = m->definitionContext()->filename(); - ostringstream os; - os << _msg << " `" << *p << "'" << endl; - emitWarning(file, m->line(), os.str()); - _history.insert(*p); - } - error = true; - } - else - { - if(!addModule(m, name)) - { - modulePrefixError(m, *p); - } - } - } - else - { - if(_history.count(*p) == 0) - { - string file = m->definitionContext()->filename(); - ostringstream os; - os << _msg << " `" << *p << "'" << endl; - emitWarning(file, m->line(), os.str()); - _history.insert(*p); - } - error = true; - } - } - - if(!error && !foundPrefix) - { - StringList names = splitScopedName(m->scoped()); - string name; - for(StringList::const_iterator i = names.begin(); i != names.end(); ++i) - { - name += *i; - } - if(!addModule(m, name)) - { - modulePrefixError(m, ""); - } - } - } -} - -StringList -Slice::ObjCGenerator::MetaDataVisitor::getMetaData(const ContainedPtr& cont) -{ - StringList ret; - StringList localMetaData = cont->getMetaData(); - StringList::const_iterator p; - - for(p = localMetaData.begin(); p != localMetaData.end(); ++p) - { - if(p->find(_objcPrefix) != string::npos) - { - ret.push_back(*p); - } - } - - return ret; -} - -void -Slice::ObjCGenerator::MetaDataVisitor::modulePrefixError(const ModulePtr& m, const string& metadata) -{ - string file = m->definitionContext()->filename(); - string line = m->line(); - ModulePrefix mp = modulePrefix(m); - string old_file = mp.m->definitionContext()->filename(); - string old_line = mp.m->line(); - ostringstream os; - if(!metadata.empty()) - { - os << _msg << " `" << metadata << "': "; - } - os << "inconsistent module prefix previously defined "; - if(old_file != file) - { - os << "in " << old_file << ":"; - } - else - { - os << "at line "; - } - os << line; - os << " as `" << mp.name << "'" << endl; - emitWarning(file, line, os.str()); -} diff --git a/cpp/src/Slice/PHPUtil.cpp b/cpp/src/Slice/PHPUtil.cpp index 08251339a1a..09114294b32 100644 --- a/cpp/src/Slice/PHPUtil.cpp +++ b/cpp/src/Slice/PHPUtil.cpp @@ -9,6 +9,8 @@ #include <Slice/PHPUtil.h> #include <functional> +#include <algorithm> +#include <vector> using namespace std; using namespace Slice; @@ -29,8 +31,8 @@ lookupKwd(const string& name) // // Keyword list. *Must* be kept in alphabetical order. // - static const string keywordList[] = - { + static const string keywordList[] = + { "abstract", "and", "array", "as", "break", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "if", @@ -135,12 +137,6 @@ Slice::PHP::fixIdent(const string& ident) } string -Slice::PHP::getAbsolute(const ContainedPtr& cont, bool ns, const string& prefix, const string& suffix) -{ - return scopedToName(cont->scope() + prefix + cont->name() + suffix, ns); -} - -string Slice::PHP::escapeName(const string& name) { string result = name; diff --git a/cpp/src/Slice/PHPUtil.h b/cpp/src/Slice/PHPUtil.h new file mode 100644 index 00000000000..f5558f655f9 --- /dev/null +++ b/cpp/src/Slice/PHPUtil.h @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_PHP_UTIL_H +#define SLICE_PHP_UTIL_H + +#include <IceUtil/Config.h> +#include <string> + +namespace Slice +{ +namespace PHP +{ + +// +// Convert a scoped name into a PHP name. +// +std::string scopedToName(const std::string&, bool); + +// +// Check the given identifier against PHP's list of reserved words. If it matches +// a reserved word, then an escaped version is returned with a leading underscore. +// +std::string fixIdent(const std::string&); + +// +// Since PHP uses the backslash character as the namespace separator, we have +// to escape backslash characters when they appear in a string literal. +// +std::string escapeName(const std::string&); + +} +} + +#endif diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index af0b0f2bb73..00fb1d42047 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -63,6 +63,56 @@ filterOrderedOptionalDataMembers(const DataMemberList& members) return result; } +void +sortOptionalParameters(ParamDeclList& params) +{ + // + // Sort optional parameters by tag. + // + class SortFn + { + public: + static bool compare(const ParamDeclPtr& lhs, const ParamDeclPtr& rhs) + { + return lhs->tag() < rhs->tag(); + } + }; + params.sort(SortFn::compare); +} + +bool +isMutableAfterReturnType(const TypePtr& type) +{ + // + // Returns true if the type contains data types which can be referenced by user code + // and mutated after a dispatch returns. + // + + if(ClassDeclPtr::dynamicCast(type)) + { + return true; + } + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin && (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindValue)) + { + return true; + } + + if(SequencePtr::dynamicCast(type) || DictionaryPtr::dynamicCast(type)) + { + return true; + } + + StructPtr s = StructPtr::dynamicCast(type); + if(s) + { + return true; + } + + return false; +} + } namespace Slice @@ -79,6 +129,7 @@ Unit* unit; Slice::DefinitionContext::DefinitionContext(int includeLevel, const StringList& metaData) : _includeLevel(includeLevel), _metaData(metaData), _seenDefinition(false) { + initSuppressedWarnings(); } string @@ -121,6 +172,7 @@ void Slice::DefinitionContext::setMetaData(const StringList& metaData) { _metaData = metaData; + initSuppressedWarnings(); } string @@ -143,6 +195,74 @@ Slice::DefinitionContext::getMetaData() const return _metaData; } +void +Slice::DefinitionContext::warning(WarningCategory category, const string& file, int line, const string& msg) const +{ + if(!suppressWarning(category)) + { + emitWarning(file, line, msg); + } +} + +void +Slice::DefinitionContext::warning(WarningCategory category, const string& file, const string& line, const string& msg) const +{ + if(!suppressWarning(category)) + { + emitWarning(file, line, msg); + } +} + +bool +Slice::DefinitionContext::suppressWarning(WarningCategory category) const +{ + return _suppressedWarnings.find(category) != _suppressedWarnings.end() || + _suppressedWarnings.find(All) != _suppressedWarnings.end(); +} + +void +Slice::DefinitionContext::initSuppressedWarnings() +{ + _suppressedWarnings.clear(); + const string prefix = "suppress-warning"; + string value = findMetaData(prefix); + if(value == prefix) + { + _suppressedWarnings.insert(All); + } + else if(!value.empty()) + { + assert(value.length() > prefix.length()); + if(value[prefix.length()] == ':') + { + value = value.substr(prefix.length() + 1); + vector<string> result; + IceUtilInternal::splitString(value, ",", result); + for(vector<string>::iterator p = result.begin(); p != result.end(); ++p) + { + string s = IceUtilInternal::trim(*p); + if(s == "all") + { + _suppressedWarnings.insert(All); + } + else if(s == "deprecated") + { + _suppressedWarnings.insert(Deprecated); + } + else if(s == "invalid-metadata") + { + _suppressedWarnings.insert(InvalidMetaData); + } + else + { + warning(InvalidMetaData, "", "", string("invalid category `") + s + + "' in global metadata suppress-warning"); + } + } + } + } +} + // ---------------------------------------------------------------------- // SyntaxTreeBase // ---------------------------------------------------------------------- @@ -258,6 +378,11 @@ Slice::Builtin::typeId() const return "::Ice::LocalObject"; break; } + case KindValue: + { + return "::Ice::Value"; + break; + } } assert(false); return ""; // Keep the compiler happy. @@ -266,7 +391,7 @@ Slice::Builtin::typeId() const bool Slice::Builtin::usesClasses() const { - return _kind == KindObject; + return _kind == KindObject || _kind == KindValue; } size_t @@ -283,7 +408,8 @@ Slice::Builtin::minWireSize() const 8, // KindDouble 1, // KindString: at least one byte for an empty string. 1, // KindObject: at least one byte (to marshal an index instead of an instance). - 2 // KindObjectProxy: at least an empty identity for a nil proxy, that is, 2 bytes. + 2, // KindObjectProxy: at least an empty identity for a nil proxy, that is, 2 bytes. + 1 // KindValue: at least one byte (to marshal an index instead of an instance). }; assert(_kind != KindLocalObject); @@ -293,7 +419,7 @@ Slice::Builtin::minWireSize() const bool Slice::Builtin::isVariableLength() const { - return _kind == KindString || _kind == KindObject || _kind == KindObjectProxy; + return _kind == KindString || _kind == KindObject || _kind == KindObjectProxy || _kind == KindValue; } Builtin::Kind @@ -320,7 +446,8 @@ const char* Slice::Builtin::builtinTable[] = "string", "Object", "Object*", - "LocalObject" + "LocalObject", + "Value" }; Slice::Builtin::Builtin(const UnitPtr& unit, Kind kind) : @@ -368,12 +495,13 @@ string Slice::Contained::flattenedScope() const { string s = scope(); - string flattenedScope; - for(string::const_iterator r = s.begin(); r != s.end(); ++r) + string::size_type pos = 0; + while((pos = s.find("::", pos)) != string::npos) { - flattenedScope += ((*r) == ':') ? '_' : *r; + s.replace(pos, 2, "_"); + } - return flattenedScope; + return s; } string @@ -496,12 +624,6 @@ Slice::Contained::operator==(const Contained& rhs) const return _scoped == rhs._scoped; } -bool -Slice::Contained::operator!=(const Contained& rhs) const -{ - return _scoped != rhs._scoped; -} - Slice::Contained::Contained(const ContainerPtr& container, const string& name) : SyntaxTreeBase(container->unit()), _container(container), @@ -876,17 +998,6 @@ Slice::Container::createSequence(const string& name, const TypePtr& type, const { checkIdentifier(name); - if(_unit->profile() == IceE && !local) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type)) - { - string msg = "Sequence `" + name + "' cannot contain object values."; - _unit->error(msg); - return 0; - } - } - ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -942,17 +1053,6 @@ Slice::Container::createDictionary(const string& name, const TypePtr& keyType, c { checkIdentifier(name); - if(_unit->profile() == IceE && !local) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(valueType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(valueType)) - { - string msg = "Dictionary `" + name + "' cannot contain object values."; - _unit->error(msg); - return 0; - } - } - ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -997,7 +1097,7 @@ Slice::Container::createDictionary(const string& name, const TypePtr& keyType, c } if(containsSequence) { - _unit->warning("use of sequences in dictionary keys has been deprecated"); + _unit->warning(Deprecated, "use of sequences in dictionary keys has been deprecated"); } } @@ -1067,13 +1167,8 @@ Slice::Container::createEnum(const string& name, bool local, NodeType nt) EnumeratorPtr Slice::Container::createEnumerator(const string& name) { - EnumeratorPtr p = validateEnumerator(name); - if(p) - { - return p; - } - - p = new Enumerator(this, name); + validateEnumerator(name); + EnumeratorPtr p = new Enumerator(this, name); _contents.push_back(p); return p; } @@ -1081,13 +1176,8 @@ Slice::Container::createEnumerator(const string& name) EnumeratorPtr Slice::Container::createEnumerator(const string& name, int value) { - EnumeratorPtr p = validateEnumerator(name); - if(p) - { - return p; - } - - p = new Enumerator(this, name, value); + validateEnumerator(name); + EnumeratorPtr p = new Enumerator(this, name, value); _contents.push_back(p); return p; } @@ -1133,15 +1223,17 @@ Slice::Container::createConst(const string name, const TypePtr& constType, const checkForGlobalDef(name, "constant"); // Don't return here -- we create the constant anyway. } + SyntaxTreeBasePtr resolvedValueType = valueType; + // - // Validate the constant and its value. + // Validate the constant and its value; for enums, find enumerator // - if(nt == Real && !validateConstant(name, constType, valueType, value, true)) + if(nt == Real && !validateConstant(name, constType, resolvedValueType, value, true)) { return 0; } - ConstPtr p = new Const(this, name, constType, metaData, valueType, value, literal); + ConstPtr p = new Const(this, name, constType, metaData, resolvedValueType, value, literal); _contents.push_back(p); return p; } @@ -1178,16 +1270,8 @@ Slice::Container::lookupType(const string& scoped, bool printError) return lookupTypeNoBuiltin(scoped, printError); } -// -// TODO: Hack to keep binary compatibility with Ice 3.6.0, fix properly in Ice 3.7 -// -namespace -{ -bool ignoreUndefined = false; -} - TypeList -Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) +Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError, bool ignoreUndefined) { // // Remove whitespace. @@ -1304,12 +1388,7 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) ContainedPtr contained = ContainedPtr::dynamicCast(this); if(contained) { - if(typeError) - { - ignoreUndefined = true; - } - results = contained->container()->lookupTypeNoBuiltin(sc, printError); - ignoreUndefined = false; + results = contained->container()->lookupTypeNoBuiltin(sc, printError, typeError || ignoreUndefined); } else if(!typeError) { @@ -1539,6 +1618,86 @@ Slice::Container::enums() const return result; } +EnumeratorList +Slice::Container::enumerators() const +{ + EnumeratorList result; + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + EnumeratorPtr q = EnumeratorPtr::dynamicCast(*p); + if(q) + { + result.push_back(q); + } + } + return result; +} + +// +// Find enumerators using the old unscoped enumerators lookup +// +EnumeratorList +Slice::Container::enumerators(const string& scoped) const +{ + EnumeratorList result; + string::size_type lastColon = scoped.rfind(':'); + + if(lastColon == string::npos) + { + // check all enclosing scopes + ContainerPtr container = const_cast<Container*>(this); + do + { + EnumList enums = container->enums(); + for(EnumList::iterator p = enums.begin(); p != enums.end(); ++p) + { + ContainedList cl = (*p)->lookupContained(scoped, false); + if(!cl.empty()) + { + result.push_back(EnumeratorPtr::dynamicCast(cl.front())); + } + } + + ContainedPtr contained = ContainedPtr::dynamicCast(container); + if(contained) + { + container = contained->container(); + } + else + { + container = 0; + } + } + while(result.empty() && container); + } + else + { + // Find the referenced scope + ContainerPtr container = const_cast<Container*>(this); + string scope = scoped.substr(0, scoped.rfind("::")); + ContainedList cl = container->lookupContained(scope, false); + if(!cl.empty()) + { + container = ContainerPtr::dynamicCast(cl.front()); + if(container) + { + EnumList enums = container->enums(); + string name = scoped.substr(lastColon + 1); + for(EnumList::iterator p = enums.begin(); p != enums.end(); ++p) + { + ContainedList cl = (*p)->lookupContained(name, false); + if(!cl.empty()) + { + result.push_back(EnumeratorPtr::dynamicCast(cl.front())); + } + } + } + } + } + + return result; +} + ConstList Slice::Container::consts() const { @@ -1610,7 +1769,7 @@ Slice::Container::hasLocalClassDefsWithAsync() const ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); if(cl && cl->isLocal()) { - if(cl->hasMetaData("async")) + if(cl->hasMetaData("async-oneway")) { return true; } @@ -1618,7 +1777,7 @@ Slice::Container::hasLocalClassDefsWithAsync() const OperationList ol = cl->operations(); for(OperationList::const_iterator q = ol.begin(); q != ol.end(); ++q) { - if((*q)->hasMetaData("async")) + if((*q)->hasMetaData("async-oneway")) { return true; } @@ -1677,7 +1836,47 @@ Slice::Container::hasNonLocalExceptions() const return false; } +bool +Slice::Container::hasStructs() const +{ + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + StructPtr q = StructPtr::dynamicCast(*p); + if(q) + { + return true; + } + + ContainerPtr container = ContainerPtr::dynamicCast(*p); + if(container && container->hasStructs()) + { + return true; + } + } + return false; +} + +bool +Slice::Container::hasExceptions() const +{ + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ExceptionPtr q = ExceptionPtr::dynamicCast(*p); + if(q) + { + return true; + } + + ContainerPtr container = ContainerPtr::dynamicCast(*p); + if(container && container->hasExceptions()) + { + return true; + } + } + + return false; +} bool Slice::Container::hasClassDecls() const @@ -1775,6 +1974,66 @@ Slice::Container::hasClassDefs() const } bool +Slice::Container::hasLocalClassDefs() const +{ + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); + if(cl && cl->isLocal()) + { + return true; + } + + ContainerPtr container = ContainerPtr::dynamicCast(*p); + if(container && container->hasLocalClassDefs()) + { + return true; + } + } + return false; +} + +bool +Slice::Container::hasNonLocalInterfaceDefs() const +{ + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); + if(cl && !cl->isLocal() && (cl->isInterface() || !cl->allOperations().empty())) + { + return true; + } + + ContainerPtr container = ContainerPtr::dynamicCast(*p); + if(container && container->hasNonLocalInterfaceDefs()) + { + return true; + } + } + return false; +} + +bool +Slice::Container::hasValueDefs() const +{ + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); + if(cl && !cl->isLocal() && !cl->isInterface()) + { + return true; + } + + ContainerPtr container = ContainerPtr::dynamicCast(*p); + if(container && container->hasValueDefs()) + { + return true; + } + } + return false; +} + +bool Slice::Container::hasOnlyClassDecls() const { for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) @@ -2001,7 +2260,7 @@ Slice::Container::mergeModules() metaData2.unique(); if(!checkGlobalMetaData(metaData1, metaData2)) { - unit()->warning("global metadata mismatch for module `" + mod1->name() + "' in files " + + unit()->warning(All, "global metadata mismatch for module `" + mod1->name() + "' in files " + dc1->filename() + " and " + dc2->filename()); } @@ -2310,23 +2569,34 @@ Slice::Container::checkIdentifier(const string& name) const // // For rules controlled by a translator option, we don't complain about included files. // - _unit->error("illegal underscore in identifier `" + name + "'"); + + DefinitionContextPtr dc = _unit->currentDefinitionContext(); + assert(dc); + if(dc->findMetaData("underscore") != "underscore") // no "underscore" global metadata + { + _unit->error("illegal underscore in identifier `" + name + "'"); + } } + // + // For rules controlled by a translator option, we don't complain about included files. + // if(_unit->currentIncludeLevel() == 0 && !_unit->allowIcePrefix()) { - // - // For rules controlled by a translator option, we don't complain about included files. - // - if(name.size() >= 3) + DefinitionContextPtr dc = _unit->currentDefinitionContext(); + assert(dc); + if(dc->findMetaData("ice-prefix") != "ice-prefix") // no "ice-prefix" global metadata { - string prefix3; - prefix3 += ::tolower(static_cast<unsigned char>(name[0])); - prefix3 += ::tolower(static_cast<unsigned char>(name[1])); - prefix3 += ::tolower(static_cast<unsigned char>(name[2])); - if(prefix3 == "ice") + if(name.size() >= 3) { - _unit->error("illegal identifier `" + name + "': `" + name.substr(0, 3) + "' prefix is reserved"); + string prefix3; + prefix3 += ::tolower(static_cast<unsigned char>(name[0])); + prefix3 += ::tolower(static_cast<unsigned char>(name[1])); + prefix3 += ::tolower(static_cast<unsigned char>(name[2])); + if(prefix3 == "ice") + { + _unit->error("illegal identifier `" + name + "': `" + name.substr(0, 3) + "' prefix is reserved"); + } } } } @@ -2429,7 +2699,7 @@ Slice::Container::checkGlobalMetaData(const StringList& m1, const StringList& m2 } bool -Slice::Container::validateConstant(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& valueType, +Slice::Container::validateConstant(const string& name, const TypePtr& type, SyntaxTreeBasePtr& valueType, const string& value, bool isConstant) { // @@ -2575,6 +2845,7 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: + case Builtin::KindValue: { assert(false); break; @@ -2657,20 +2928,57 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons } else { - EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); - - if(!lte) + if(valueType) { - string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; - _unit->error(msg); - return false; + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); + + if(!lte) + { + string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; + _unit->error(msg); + return false; + } + EnumeratorList elist = e->enumerators(); + if(find(elist.begin(), elist.end(), lte) == elist.end()) + { + string msg = "enumerator `" + value + "' is not defined in enumeration `" + e->scoped() + "'"; + _unit->error(msg); + return false; + } } - EnumeratorList elist = e->getEnumerators(); - if(find(elist.begin(), elist.end(), lte) == elist.end()) + else { - string msg = "enumerator `" + value + "' is not defined in enumeration `" + e->scoped() + "'"; - _unit->error(msg); - return false; + // Check if value designates an enumerator of e + string newVal = value; + string::size_type lastColon = value.rfind(':'); + if(lastColon != string::npos && lastColon + 1 < value.length()) + { + newVal = value.substr(0, lastColon + 1) + e->name() + "::" + value.substr(lastColon + 1); + } + + ContainedList clist = e->lookupContained(newVal, false); + if(clist.empty()) + { + string msg = "`" + value + "' does not designate an enumerator of `" + e->scoped() + "'"; + _unit->error(msg); + return false; + } + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(clist.front()); + if(lte) + { + valueType = lte; + if(lastColon != string::npos) + { + _unit->warning(Deprecated, string("referencing enumerator `") + lte->name() + + "' in its enumeration's enclosing scope is deprecated"); + } + } + else + { + string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; + _unit->error(msg); + return false; + } } } } @@ -2678,7 +2986,7 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons return true; } -EnumeratorPtr +void Slice::Container::validateEnumerator(const string& name) { checkIdentifier(name); @@ -2686,32 +2994,19 @@ Slice::Container::validateEnumerator(const string& name) ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { - EnumeratorPtr p = EnumeratorPtr::dynamicCast(matches.front()); - if(p) - { - if(_unit->ignRedefs()) - { - p->updateIncludeLevel(); - return p; - } - } if(matches.front()->name() == name) { - string msg = "redefinition of " + matches.front()->kindOf() + " `" + matches.front()->name(); - msg += "' as enumerator"; - _unit->error(msg); + _unit->error(string("redefinition of enumerator `") + name + "'"); } else { string msg = "enumerator `" + name + "' differs only in capitalization from "; - msg += matches.front()->kindOf() + " `" + matches.front()->name() + "'"; + msg += "`" + matches.front()->name() + "'"; _unit->error(msg); } } nameIsLegal(name, "enumerator"); // Don't return here -- we create the enumerator anyway. - - return 0; } // ---------------------------------------------------------------------- @@ -3186,6 +3481,12 @@ Slice::ClassDef::createOperation(const string& name, _unit->error(msg); } + if(!isInterface() && !isLocal() && !_hasOperations) + { + // Only warn for the first operation + _unit->warning(Deprecated, "classes with operations are deprecated"); + } + _hasOperations = true; OperationPtr op = new Operation(this, name, returnType, optional, tag, mode); _contents.push_back(op); @@ -3199,28 +3500,6 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, bool { checkIdentifier(name); - if(_unit->profile() == IceE) - { - if(!isLocal()) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObject)) - { - string msg = "Class data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - - ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); - if(classDecl != 0 && !classDecl->isLocal()) - { - string msg = "Class data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - } - } - assert(!isInterface()); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -3303,7 +3582,7 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, bool string dv = defaultValue; string dl = defaultLiteral; - if(dlt) + if(dlt || (EnumPtr::dynamicCast(type) && !dv.empty())) { // // Validate the default value. @@ -3456,7 +3735,9 @@ Slice::ClassDef::classDataMembers() const if(q) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->type())) + if((builtin && builtin->kind() == Builtin::KindObject) || + (builtin && builtin->kind() == Builtin::KindValue) || + ClassDeclPtr::dynamicCast(q->type())) { result.push_back(q); } @@ -3603,6 +3884,17 @@ Slice::ClassDef::inheritsMetaData(const string& meta) const return false; } +bool +Slice::ClassDef::hasBaseDataMembers() const +{ + if(!_bases.empty() && !_bases.front()->isInterface()) + { + return !_bases.front()->allDataMembers().empty(); + } + + return false; +} + Contained::ContainedType Slice::ClassDef::containedType() const { @@ -3645,6 +3937,11 @@ Slice::ClassDef::compactId() const return _compactId; } +bool +Slice::ClassDef::isDelegate() const +{ + return isLocal() && isInterface() && hasMetaData("delegate") && allOperations().size() == 1; +} Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, int id, bool intf, const ClassList& bases, bool local) : SyntaxTreeBase(container->unit()), @@ -3657,6 +3954,17 @@ Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, int _local(local), _compactId(id) { + if(!local && !intf) + { + for(ClassList::const_iterator p = _bases.begin(); p != _bases.end(); ++p) + { + if((*p)->isInterface()) + { + _unit->warning(Deprecated, "classes implementing interfaces are deprecated"); + break; + } + } + } // // First element of bases may be a class, all others must be // interfaces. @@ -3681,13 +3989,13 @@ Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, int bool Slice::Proxy::isLocal() const { - return __class->isLocal(); + return _classDecl->isLocal(); } string Slice::Proxy::typeId() const { - return __class->scoped(); + return _classDecl->scoped(); } bool @@ -3711,13 +4019,13 @@ Slice::Proxy::isVariableLength() const ClassDeclPtr Slice::Proxy::_class() const { - return __class; + return _classDecl; } Slice::Proxy::Proxy(const ClassDeclPtr& cl) : SyntaxTreeBase(cl->unit()), Type(cl->unit()), - __class(cl) + _classDecl(cl) { } @@ -3739,28 +4047,6 @@ Slice::Exception::createDataMember(const string& name, const TypePtr& type, bool { checkIdentifier(name); - if(_unit->profile() == IceE) - { - if(!isLocal()) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObject)) - { - string msg = "Exception data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - - ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); - if(classDecl != 0 && !classDecl->isLocal()) - { - string msg = "Exception data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - } - } - ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -3830,7 +4116,7 @@ Slice::Exception::createDataMember(const string& name, const TypePtr& type, bool string dv = defaultValue; string dl = defaultLiteral; - if(dlt) + if(dlt || (EnumPtr::dynamicCast(type) && !dv.empty())) { // // Validate the default value. @@ -3925,7 +4211,9 @@ Slice::Exception::classDataMembers() const if(q) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->type())) + if((builtin && builtin->kind() == Builtin::KindObject) || + (builtin && builtin->kind() == Builtin::KindValue) || + ClassDeclPtr::dynamicCast(q->type())) { result.push_back(q); } @@ -4059,6 +4347,12 @@ Slice::Exception::inheritsMetaData(const string& meta) const return false; } +bool +Slice::Exception::hasBaseDataMembers() const +{ + return _base && !_base->allDataMembers().empty(); +} + string Slice::Exception::kindOf() const { @@ -4093,29 +4387,6 @@ Slice::Struct::createDataMember(const string& name, const TypePtr& type, bool op const SyntaxTreeBasePtr& defaultValueType, const string& defaultValue, const string& defaultLiteral) { - checkIdentifier(name); - - if(_unit->profile() == IceE) - { - if(!isLocal()) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObject)) - { - string msg = "Struct data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); - if(classDecl != 0 && !classDecl->isLocal()) - { - string msg = "Struct data member `" + name + "' cannot be a value object."; - _unit->error(msg); - return 0; - } - } - } - ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) { @@ -4167,7 +4438,7 @@ Slice::Struct::createDataMember(const string& name, const TypePtr& type, bool op string dv = defaultValue; string dl = defaultLiteral; - if(dlt) + if(dlt || (EnumPtr::dynamicCast(type) && !dv.empty())) { // // Validate the default value. @@ -4230,7 +4501,9 @@ Slice::Struct::classDataMembers() const if(q) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->type())) + if((builtin && builtin->kind() == Builtin::KindObject) || + (builtin && builtin->kind() == Builtin::KindValue) || + ClassDeclPtr::dynamicCast(q->type())) { result.push_back(q); } @@ -4569,6 +4842,7 @@ Slice::Dictionary::legalKeyType(const TypePtr& type, bool& containsSequence) case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: + case Builtin::KindValue: { return false; break; @@ -4630,71 +4904,9 @@ Slice::Dictionary::Dictionary(const ContainerPtr& container, const string& name, void Slice::Enum::destroy() { - _enumerators.clear(); SyntaxTreeBase::destroy(); } -EnumeratorList -Slice::Enum::getEnumerators() -{ - return _enumerators; -} - -void -Slice::Enum::setEnumerators(const EnumeratorList& ens) -{ - _enumerators = ens; - int lastValue = -1; - set<int> values; - for(EnumeratorList::iterator p = _enumerators.begin(); p != _enumerators.end(); ++p) - { - (*p)->_type = this; - - if((*p)->_explicitValue) - { - _explicitValue = true; - - if((*p)->_value < 0) - { - string msg = "value for enumerator `" + (*p)->name() + "' is out of range"; - _unit->error(msg); - } - } - else - { - if(lastValue == Int32Max) - { - string msg = "value for enumerator `" + (*p)->name() + "' is out of range"; - _unit->error(msg); - } - - // - // If the enumerator was not assigned an explicit value, we automatically assign - // it one more than the previous enumerator. - // - (*p)->_value = lastValue + 1; - } - - if(values.count((*p)->_value) != 0) - { - string msg = "enumerator `" + (*p)->name() + "' has a duplicate value"; - _unit->error(msg); - } - values.insert((*p)->_value); - - lastValue = (*p)->_value; - - if(lastValue > _maxValue) - { - _maxValue = lastValue; - } - if(lastValue < _minValue) - { - _minValue = lastValue; - } - } -} - bool Slice::Enum::explicitValue() const { @@ -4763,15 +4975,77 @@ Slice::Enum::recDependencies(set<ConstructedPtr>&) Slice::Enum::Enum(const ContainerPtr& container, const string& name, bool local) : SyntaxTreeBase(container->unit()), + Container(container->unit()), Type(container->unit()), Contained(container, name), Constructed(container, name, local), _explicitValue(false), _minValue(Int32Max), - _maxValue(0) + _maxValue(0), + _lastValue(-1) { } +int +Slice::Enum::newEnumerator(const EnumeratorPtr& p) +{ + if(p->explicitValue()) + { + _explicitValue = true; + _lastValue = p->value(); + + if(_lastValue < 0) + { + string msg = "value for enumerator `" + p->name() + "' is out of range"; + _unit->error(msg); + } + } + else + { + if(_lastValue == Int32Max) + { + string msg = "value for enumerator `" + p->name() + "' is out of range"; + _unit->error(msg); + } + else + { + // + // If the enumerator was not assigned an explicit value, we automatically assign + // it one more than the previous enumerator. + // + ++_lastValue; + } + } + + bool checkForDuplicates = true; + if(_lastValue > _maxValue) + { + _maxValue = _lastValue; + checkForDuplicates = false; + } + if(_lastValue < _minValue) + { + _minValue = _lastValue; + checkForDuplicates = false; + } + + if(checkForDuplicates) + { + EnumeratorList enl = enumerators(); + for(EnumeratorList::iterator q = enl.begin(); q != enl.end(); ++q) + { + EnumeratorPtr& r = *q; + if(r != p && r->value() == _lastValue) + { + _unit->error(string("enumerator `") + p->name() + "' has the same value as enumerator `" + + r->name() + "'"); + } + } + } + + return _lastValue; +} + // ---------------------------------------------------------------------- // Enumerator // ---------------------------------------------------------------------- @@ -4779,7 +5053,7 @@ Slice::Enum::Enum(const ContainerPtr& container, const string& name, bool local) EnumPtr Slice::Enumerator::type() const { - return _type; + return EnumPtr::dynamicCast(container()); } Contained::ContainedType @@ -4818,6 +5092,7 @@ Slice::Enumerator::Enumerator(const ContainerPtr& container, const string& name) _explicitValue(false), _value(-1) { + _value = EnumPtr::dynamicCast(container)->newEnumerator(this); } Slice::Enumerator::Enumerator(const ContainerPtr& container, const string& name, int value) : @@ -4826,6 +5101,7 @@ Slice::Enumerator::Enumerator(const ContainerPtr& container, const string& name, _explicitValue(true), _value(value) { + EnumPtr::dynamicCast(container)->newEnumerator(this); } // ---------------------------------------------------------------------- @@ -4898,6 +5174,11 @@ Slice::Const::Const(const ContainerPtr& container, const string& name, const Typ _value(value), _literal(literal) { + if(valueType == 0) + { + cerr << "const " << name << " created with null valueType" << endl; + } + } // ---------------------------------------------------------------------- @@ -4941,33 +5222,33 @@ Slice::Operation::sendMode() const } } -ParamDeclPtr -Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam, bool optional, int tag) +bool +Slice::Operation::hasMarshaledResult() const { - checkIdentifier(name); - - if(_unit->profile() == IceE) + ClassDefPtr cl = ClassDefPtr::dynamicCast(container()); + assert(cl); + if(cl->hasMetaData("marshaled-result") || hasMetaData("marshaled-result")) { - ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container()); - assert(cl); - if(!cl->isLocal()) + if(returnType() && isMutableAfterReturnType(returnType())) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if((builtin && builtin->kind() == Builtin::KindObject)) - { - string msg = "Object `" + name + "' cannot be passed by value."; - _unit->error(msg); - return 0; - } - ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(type); - if(classDecl != 0 && !classDecl->isLocal()) + return true; + } + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ParamDeclPtr q = ParamDeclPtr::dynamicCast(*p); + if(q->isOutParam() && isMutableAfterReturnType(q->type())) { - string msg = "Object `" + name + "' cannot be passed by value."; - _unit->error(msg); - return 0; + return true; } } } + return false; +} + +ParamDeclPtr +Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam, bool optional, int tag) +{ + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -5067,6 +5348,74 @@ Slice::Operation::parameters() const return result; } +ParamDeclList +Slice::Operation::inParameters() const +{ + ParamDeclList result; + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ParamDeclPtr q = ParamDeclPtr::dynamicCast(*p); + if(q && !q->isOutParam()) + { + result.push_back(q); + } + } + return result; +} + +void +Slice::Operation::inParameters(ParamDeclList& required, ParamDeclList& optional) const +{ + const ParamDeclList params = inParameters(); + for(ParamDeclList::const_iterator pli = params.begin(); pli != params.end(); ++pli) + { + if((*pli)->optional()) + { + optional.push_back(*pli); + } + else + { + required.push_back(*pli); + } + } + + sortOptionalParameters(optional); +} + +ParamDeclList +Slice::Operation::outParameters() const +{ + ParamDeclList result; + for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) + { + ParamDeclPtr q = ParamDeclPtr::dynamicCast(*p); + if(q && q->isOutParam()) + { + result.push_back(q); + } + } + return result; +} + +void +Slice::Operation::outParameters(ParamDeclList& required, ParamDeclList& optional) const +{ + const ParamDeclList params = outParameters(); + for(ParamDeclList::const_iterator pli = params.begin(); pli != params.end(); ++pli) + { + if((*pli)->optional()) + { + optional.push_back(*pli); + } + else + { + required.push_back(*pli); + } + } + + sortOptionalParameters(optional); +} + ExceptionList Slice::Operation::throws() const { @@ -5219,12 +5568,25 @@ Slice::Operation::returnsData() const } bool +Slice::Operation::returnsMultipleValues() const +{ + size_t count = outParameters().size(); + + if(returnType()) + { + ++count; + } + + return count > 1; +} + +bool Slice::Operation::sendsOptionals() const { - ParamDeclList pdl = parameters(); + ParamDeclList pdl = inParameters(); for(ParamDeclList::const_iterator i = pdl.begin(); i != pdl.end(); ++i) { - if(!(*i)->isOutParam() && (*i)->optional()) + if((*i)->optional()) { return true; } @@ -5263,7 +5625,7 @@ Slice::Operation::attributes() const } if(i == 2) { - emitWarning(definitionContext()->filename(), line(), "invalid freeze metadata for operation"); + _unit->warning(InvalidMetaData, "invalid freeze metadata for operation"); } else { @@ -5284,7 +5646,7 @@ Slice::Operation::attributes() const { if(result != 0 && (i == int(Supports) || i == int(Never))) { - emitWarning(definitionContext()->filename(), line(), "invalid freeze metadata for operation"); + _unit->warning(InvalidMetaData, "invalid freeze metadata for operation"); } else { @@ -5298,7 +5660,7 @@ Slice::Operation::attributes() const if(i == 4) { - emitWarning(definitionContext()->filename(), line(), "invalid freeze metadata for operation"); + _unit->warning(InvalidMetaData, "invalid freeze metadata for operation"); // // Set default @@ -5356,26 +5718,6 @@ Slice::Operation::Operation(const ContainerPtr& container, _returnTag(returnTag), _mode(mode) { - if(_unit->profile() == IceE) - { - ClassDefPtr cl = ClassDefPtr::dynamicCast(this->container()); - assert(cl); - if(!cl->isLocal()) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(returnType); - if((builtin && builtin->kind() == Builtin::KindObject)) - { - string msg = "Method `" + name + "' cannot return an object by value."; - _unit->error(msg); - } - ClassDeclPtr classDecl = ClassDeclPtr::dynamicCast(returnType); - if(classDecl != 0 && !classDecl->isLocal()) - { - string msg = "Method `" + name + "' cannot return an object by value."; - _unit->error(msg); - } - } - } } // ---------------------------------------------------------------------- @@ -5801,13 +6143,6 @@ Slice::Unit::setSeenDefinition() } void -Slice::Unit::error(const char* s) -{ - emitError(currentFile(), _currentLine, s); - _errors++; -} - -void Slice::Unit::error(const string& s) { emitError(currentFile(), _currentLine, s); @@ -5815,15 +6150,16 @@ Slice::Unit::error(const string& s) } void -Slice::Unit::warning(const char* s) const -{ - emitWarning(currentFile(), _currentLine, s); -} - -void -Slice::Unit::warning(const string& s) const +Slice::Unit::warning(WarningCategory category, const string& msg) const { - emitWarning(currentFile(), _currentLine, s); + if(_definitionContextStack.empty()) + { + emitWarning(currentFile(), _currentLine, msg); + } + else + { + _definitionContextStack.top()->warning(category, currentFile(), _currentLine, msg); + } } ContainerPtr @@ -6038,6 +6374,11 @@ Slice::Unit::usesNonLocals() const return true; } + if(_builtins.find(Builtin::KindValue) != _builtins.end()) + { + return true; + } + return false; } @@ -6059,12 +6400,6 @@ Slice::Unit::usesConsts() const return false; } -FeatureProfile -Slice::Unit::profile() const -{ - return _featureProfile; -} - StringList Slice::Unit::includeFiles() const { @@ -6084,7 +6419,7 @@ Slice::Unit::allFiles() const } int -Slice::Unit::parse(const string& filename, FILE* file, bool debug, Slice::FeatureProfile profile) +Slice::Unit::parse(const string& filename, FILE* file, bool debug) { slice_debug = debug ? 1 : 0; @@ -6094,7 +6429,6 @@ Slice::Unit::parse(const string& filename, FILE* file, bool debug, Slice::Featur _currentComment = ""; _currentLine = 1; _currentIncludeLevel = 0; - _featureProfile = profile; _topLevelFile = fullPath(filename); pushContainer(this); pushDefinitionContext(); @@ -6130,6 +6464,11 @@ Slice::Unit::parse(const string& filename, FILE* file, bool debug, Slice::Featur popContainer(); assert(_definitionContextStack.size() == 1); popDefinitionContext(); + + if(!checkUndefinedTypes()) + { + status = EXIT_FAILURE; + } } Slice::unit = 0; @@ -6228,6 +6567,113 @@ Slice::Unit::eraseWhiteSpace(string& s) } } +bool +Slice::Unit::checkUndefinedTypes() +{ + class Visitor : public ParserVisitor + { + public: + + Visitor(int& errors) : + _errors(errors), + _local(false) + { + } + + virtual bool visitClassDefStart(const ClassDefPtr& p) + { + _local = p->isLocal(); + return true; + } + + virtual bool visitExceptionStart(const ExceptionPtr& p) + { + _local = p->isLocal(); + return true; + } + + virtual bool visitStructStart(const StructPtr& p) + { + _local = p->isLocal(); + return true; + } + + virtual void visitOperation(const OperationPtr& p) + { + if(p->returnType()) + { + checkUndefined(p->returnType(), "return type", p->file(), p->line()); + } + ParamDeclList params = p->parameters(); + for(ParamDeclList::const_iterator q = params.begin(); q != params.end(); ++q) + { + checkUndefined((*q)->type(), "parameter " + (*q)->name(), (*q)->file(), (*q)->line()); + } + } + + virtual void visitParamDecl(const ParamDeclPtr& p) + { + checkUndefined(p->type(), "parameter " + p->name(), p->file(), p->line()); + } + + virtual void visitDataMember(const DataMemberPtr& p) + { + checkUndefined(p->type(), "member " + p->name(), p->file(), p->line()); + } + + virtual void visitSequence(const SequencePtr& p) + { + _local = p->isLocal(); + checkUndefined(p->type(), "element type", p->file(), p->line()); + } + + virtual void visitDictionary(const DictionaryPtr& p) + { + _local = p->isLocal(); + checkUndefined(p->keyType(), "key type", p->file(), p->line()); + checkUndefined(p->valueType(), "value type", p->file(), p->line()); + } + + private: + + void checkUndefined(const TypePtr& type, const string& desc, const string& file, const string& line) + { + // + // See ICE-6867. Any use of a proxy requires the full type definition, as does any + // use of a class in a non-local context. + // + ProxyPtr p = ProxyPtr::dynamicCast(type); + if(p) + { + const ClassDeclPtr cl = p->_class(); + if(!cl->definition()) + { + ostringstream ostr; + ostr << desc << " uses a proxy for undefined type `" << cl->scoped() << "'"; + emitError(file, line, ostr.str()); + _errors++; + } + } + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + if(cl && !cl->definition() && !_local) + { + ostringstream ostr; + ostr << desc << " refers to undefined type `" << cl->scoped() << "'"; + emitError(file, line, ostr.str()); + _errors++; + } + } + + int& _errors; + bool _local; + }; + + Visitor v(_errors); + visit(&v, true); + return _errors == 0; +} + // ---------------------------------------------------------------------- // CICompare // ---------------------------------------------------------------------- diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h new file mode 100644 index 00000000000..b5afc987e75 --- /dev/null +++ b/cpp/src/Slice/Parser.h @@ -0,0 +1,1116 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_PARSER_H +#define SLICE_PARSER_H + +#include <IceUtil/Shared.h> +#include <IceUtil/Handle.h> +#include <string> +#include <vector> +#include <list> +#include <stack> +#include <map> +#include <set> +#include <stdio.h> + + +namespace Slice +{ + +#if defined(_WIN32) && !defined(__MINGW32__) + +const IceUtil::Int64 Int32Max = 0x7fffffffi64; +const IceUtil::Int64 Int32Min = -Int32Max - 1i64; + +#else + +# if defined(INT32_MIN) && defined(INT32_MAX) + +const IceUtil::Int64 Int32Max = INT32_MAX; +const IceUtil::Int64 Int32Min = INT32_MIN; + +# else + +const IceUtil::Int64 Int32Max = 0x7fffffffLL; +const IceUtil::Int64 Int32Min = -Int32Max - 1LL; + +# endif + +#endif + +const IceUtil::Int64 Int16Max = 0x7fff; +const IceUtil::Int64 Int16Min = -Int16Max - 1; +const IceUtil::Int64 ByteMax = 0xff; +const IceUtil::Int64 ByteMin = 0x00; + +enum NodeType +{ + Dummy, + Real +}; + +// +// Format preference for classes and exceptions. +// +enum FormatType +{ + DefaultFormat, // No preference was specified. + CompactFormat, // Minimal format. + SlicedFormat // Full format. +}; + +enum WarningCategory +{ + All, + Deprecated, + InvalidMetaData +}; + +class GrammarBase; +class SyntaxTreeBase; +class Type; +class Builtin; +class Contained; +class Container; +class Module; +class Constructed; +class ClassDecl; +class ClassDef; +class Proxy; +class Exception; +class Struct; +class Operation; +class ParamDecl; +class DataMember; +class Sequence; +class Dictionary; +class Enum; +class Enumerator; +class Const; +class Unit; +class CICompare; +class DerivedToBaseCompare; +class ModulePartialCompare; + +typedef ::IceUtil::Handle<GrammarBase> GrammarBasePtr; +typedef ::IceUtil::Handle<SyntaxTreeBase> SyntaxTreeBasePtr; +typedef ::IceUtil::Handle<Type> TypePtr; +typedef ::IceUtil::Handle<Builtin> BuiltinPtr; +typedef ::IceUtil::Handle<Contained> ContainedPtr; +typedef ::IceUtil::Handle<Container> ContainerPtr; +typedef ::IceUtil::Handle<Module> ModulePtr; +typedef ::IceUtil::Handle<Constructed> ConstructedPtr; +typedef ::IceUtil::Handle<ClassDecl> ClassDeclPtr; +typedef ::IceUtil::Handle<ClassDef> ClassDefPtr; +typedef ::IceUtil::Handle<Proxy> ProxyPtr; +typedef ::IceUtil::Handle<Exception> ExceptionPtr; +typedef ::IceUtil::Handle<Struct> StructPtr; +typedef ::IceUtil::Handle<Operation> OperationPtr; +typedef ::IceUtil::Handle<ParamDecl> ParamDeclPtr; +typedef ::IceUtil::Handle<DataMember> DataMemberPtr; +typedef ::IceUtil::Handle<Sequence> SequencePtr; +typedef ::IceUtil::Handle<Dictionary> DictionaryPtr; +typedef ::IceUtil::Handle<Enum> EnumPtr; +typedef ::IceUtil::Handle<Enumerator> EnumeratorPtr; +typedef ::IceUtil::Handle<Const> ConstPtr; +typedef ::IceUtil::Handle<Unit> UnitPtr; + +typedef std::list<TypePtr> TypeList; +typedef std::list<ExceptionPtr> ExceptionList; +typedef std::set<std::string> StringSet; +typedef std::list<std::string> StringList; +typedef std::pair<TypePtr, std::string> TypeString; +typedef std::list<TypeString> TypeStringList; +typedef std::list<ContainedPtr> ContainedList; +typedef std::list<ModulePtr> ModuleList; +typedef std::list<ConstructedPtr> ConstructedList; +typedef std::list<ClassDefPtr> ClassList; +typedef std::list<ExceptionPtr> ExceptionList; +typedef std::list<StructPtr> StructList; +typedef std::list<SequencePtr> SequenceList; +typedef std::list<DictionaryPtr> DictionaryList; +typedef std::list<EnumPtr> EnumList; +typedef std::list<ConstPtr> ConstList; +typedef std::list<OperationPtr> OperationList; +typedef std::list<DataMemberPtr> DataMemberList; +typedef std::list<ParamDeclPtr> ParamDeclList; +typedef std::list<EnumeratorPtr> EnumeratorList; + +struct ConstDef +{ + TypePtr type; + SyntaxTreeBasePtr value; + std::string valueAsString; + std::string valueAsLiteral; +}; + +struct OptionalDef +{ + TypePtr type; + std::string name; + bool optional; + int tag; +}; + +// ---------------------------------------------------------------------- +// CICompare -- function object to do case-insensitive string comparison. +// ---------------------------------------------------------------------- + +class CICompare : public std::binary_function<std::string, std::string, bool> +{ +public: + + bool operator()(const std::string&, const std::string&) const; +}; + +#if defined(__SUNPRO_CC) +bool cICompare(const std::string&, const std::string&); +#endif + +// ---------------------------------------------------------------------- +// DerivedToBaseCompare -- function object to do sort exceptions into +// most-derived to least-derived order. +// ---------------------------------------------------------------------- + +class DerivedToBaseCompare : public std::binary_function<std::string, std::string, bool> +{ +public: + + bool operator()(const ExceptionPtr&, const ExceptionPtr&) const; +}; + +#if defined(__SUNPRO_CC) +bool derivedToBaseCompare(const ExceptionPtr&, const ExceptionPtr&); +#endif + +// ---------------------------------------------------------------------- +// ParserVisitor +// ---------------------------------------------------------------------- + +class ParserVisitor +{ +public: + + virtual ~ParserVisitor() { } + virtual bool visitUnitStart(const UnitPtr&) { return true; } + virtual void visitUnitEnd(const UnitPtr&) { } + virtual bool visitModuleStart(const ModulePtr&) { return true; } + virtual void visitModuleEnd(const ModulePtr&) { } + virtual void visitClassDecl(const ClassDeclPtr&) { } + virtual bool visitClassDefStart(const ClassDefPtr&) { return true; } + virtual void visitClassDefEnd(const ClassDefPtr&) { } + virtual bool visitExceptionStart(const ExceptionPtr&) { return true; } + virtual void visitExceptionEnd(const ExceptionPtr&) { } + virtual bool visitStructStart(const StructPtr&) { return true; } + virtual void visitStructEnd(const StructPtr&) { } + virtual void visitOperation(const OperationPtr&) { } + virtual void visitParamDecl(const ParamDeclPtr&) { } + virtual void visitDataMember(const DataMemberPtr&) { } + virtual void visitSequence(const SequencePtr&) { } + virtual void visitDictionary(const DictionaryPtr&) { } + virtual void visitEnum(const EnumPtr&) { } + virtual void visitConst(const ConstPtr&) { } +}; + +// ---------------------------------------------------------------------- +// DefinitionContext +// ---------------------------------------------------------------------- + +class DefinitionContext : public ::IceUtil::SimpleShared +{ +public: + + DefinitionContext(int, const StringList&); + + std::string filename() const; + int includeLevel() const; + bool seenDefinition() const; + + void setFilename(const std::string&); + void setSeenDefinition(); + + bool hasMetaData() const; + void setMetaData(const StringList&); + std::string findMetaData(const std::string&) const; + StringList getMetaData() const; + + // + // Emit warning unless filtered out by [["suppress-warning"]] + // + void warning(WarningCategory, const std::string&, int, const std::string&) const; + void warning(WarningCategory, const std::string&, const std::string&, const std::string&) const; + +private: + + bool suppressWarning(WarningCategory) const; + void initSuppressedWarnings(); + + int _includeLevel; + StringList _metaData; + std::string _filename; + bool _seenDefinition; + std::set<WarningCategory> _suppressedWarnings; +}; +typedef ::IceUtil::Handle<DefinitionContext> DefinitionContextPtr; + +// ---------------------------------------------------------------------- +// GrammarBase +// ---------------------------------------------------------------------- + +class GrammarBase : public ::IceUtil::SimpleShared +{ +}; + +// ---------------------------------------------------------------------- +// SyntaxTreeBase +// ---------------------------------------------------------------------- + +class SyntaxTreeBase : public GrammarBase +{ +public: + + virtual void destroy(); + UnitPtr unit() const; + DefinitionContextPtr definitionContext() const; // May be nil + virtual void visit(ParserVisitor*, bool); + +protected: + + SyntaxTreeBase(const UnitPtr&); + + UnitPtr _unit; + DefinitionContextPtr _definitionContext; +}; + +// ---------------------------------------------------------------------- +// Type +// ---------------------------------------------------------------------- + +class Type : public virtual SyntaxTreeBase +{ +public: + + virtual bool isLocal() const = 0; + virtual std::string typeId() const = 0; + virtual bool usesClasses() const = 0; + virtual size_t minWireSize() const = 0; + virtual bool isVariableLength() const = 0; + +protected: + + Type(const UnitPtr&); +}; + +// ---------------------------------------------------------------------- +// Builtin +// ---------------------------------------------------------------------- + +class Builtin : public virtual Type +{ +public: + + enum Kind + { + KindByte, + KindBool, + KindShort, + KindInt, + KindLong, + KindFloat, + KindDouble, + KindString, + KindObject, + KindObjectProxy, + KindLocalObject, + KindValue + }; + + virtual bool isLocal() const; + virtual std::string typeId() const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + + Kind kind() const; + std::string kindAsString() const; + + static const char* builtinTable[]; + +protected: + + Builtin(const UnitPtr&, Kind); + friend class Unit; + + Kind _kind; +}; + +// ---------------------------------------------------------------------- +// Contained +// ---------------------------------------------------------------------- + +class Contained : public virtual SyntaxTreeBase +{ +public: + + ContainerPtr container() const; + std::string name() const; + std::string scoped() const; + std::string scope() const; + std::string flattenedScope() const; + std::string file() const; + std::string line() const; + std::string comment() const; + + int includeLevel() const; + void updateIncludeLevel(); + + bool hasMetaData(const std::string&) const; + bool findMetaData(const std::string&, std::string&) const; + std::list<std::string> getMetaData() const; + void setMetaData(const std::list<std::string>&); + void addMetaData(const std::string&); // TODO: remove this method once "cs:" and "vb:" are hard errors. + + static FormatType parseFormatMetaData(const std::list<std::string>&); + + enum ContainedType + { + ContainedTypeSequence, + ContainedTypeDictionary, + ContainedTypeEnum, + ContainedTypeEnumerator, + ContainedTypeModule, + ContainedTypeClass, + ContainedTypeException, + ContainedTypeStruct, + ContainedTypeOperation, + ContainedTypeParamDecl, + ContainedTypeDataMember, + ContainedTypeConstant + }; + virtual ContainedType containedType() const = 0; + + virtual bool uses(const ContainedPtr&) const = 0; + virtual std::string kindOf() const = 0; + + bool operator<(const Contained&) const; + bool operator==(const Contained&) const; + +protected: + + Contained(const ContainerPtr&, const std::string&); + friend class Container; + + ContainerPtr _container; + std::string _name; + std::string _scoped; + std::string _file; + std::string _line; + std::string _comment; + int _includeLevel; + std::list<std::string> _metaData; +}; + +// ---------------------------------------------------------------------- +// Container +// ---------------------------------------------------------------------- + +class Container : public virtual SyntaxTreeBase +{ +public: + + virtual void destroy(); + ModulePtr createModule(const std::string&); + ClassDefPtr createClassDef(const std::string&, int, bool, const ClassList&, bool); + ClassDeclPtr createClassDecl(const std::string&, bool, bool, bool = true); + ExceptionPtr createException(const std::string&, const ExceptionPtr&, bool, NodeType = Real); + StructPtr createStruct(const std::string&, bool, NodeType = Real); + SequencePtr createSequence(const std::string&, const TypePtr&, const StringList&, bool, NodeType = Real); + DictionaryPtr createDictionary(const std::string&, const TypePtr&, const StringList&, const TypePtr&, + const StringList&, bool, NodeType = Real); + EnumPtr createEnum(const std::string&, bool, NodeType = Real); + EnumeratorPtr createEnumerator(const std::string&); + EnumeratorPtr createEnumerator(const std::string&, int); + ConstPtr createConst(const std::string, const TypePtr&, const StringList&, const SyntaxTreeBasePtr&, + const std::string&, const std::string&, NodeType = Real); + TypeList lookupType(const std::string&, bool = true); + TypeList lookupTypeNoBuiltin(const std::string&, bool = true, bool = false); + ContainedList lookupContained(const std::string&, bool = true); + ExceptionPtr lookupException(const std::string&, bool = true); + UnitPtr unit() const; + ModuleList modules() const; + ClassList classes() const; + ExceptionList exceptions() const; + StructList structs() const; + SequenceList sequences() const; + DictionaryList dictionaries() const; + EnumList enums() const; + EnumeratorList enumerators() const; + EnumeratorList enumerators(const std::string&) const; + ConstList consts() const; + ContainedList contents() const; + bool hasNonLocalClassDecls() const; + bool hasNonLocalClassDefs() const; + bool hasLocalClassDefsWithAsync() const; + bool hasNonLocalSequences() const; + bool hasNonLocalExceptions() const; + bool hasStructs() const; + bool hasExceptions() const; + bool hasDictionaries() const; + bool hasOnlyDictionaries(DictionaryList&) const; + bool hasClassDecls() const; + bool hasClassDefs() const; + bool hasLocalClassDefs() const; + bool hasNonLocalInterfaceDefs() const; + bool hasValueDefs() const; + bool hasOnlyClassDecls() const; + bool hasAbstractClassDefs() const; + bool hasNonLocalDataOnlyClasses() const; + bool hasOtherConstructedOrExceptions() const; // Exceptions or constructed types other than classes. + bool hasContentsWithMetaData(const std::string&) const; + bool hasAsyncOps() const; + bool hasNonLocalContained(Contained::ContainedType) const; + std::string thisScope() const; + void mergeModules(); + void sort(); + void sortContents(bool); + virtual void visit(ParserVisitor*, bool); + void containerRecDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + + bool checkIntroduced(const std::string&, ContainedPtr = 0); + bool nameIsLegal(const std::string&, const char *); + bool checkForGlobalDef(const std::string&, const char *); + +protected: + + Container(const UnitPtr&); + + void checkIdentifier(const std::string&) const; + bool checkInterfaceAndLocal(const std::string&, bool, bool, bool, bool, bool); + bool checkGlobalMetaData(const StringList&, const StringList&); + bool validateConstant(const std::string&, const TypePtr&, SyntaxTreeBasePtr&, const std::string&, bool); + void validateEnumerator(const std::string&); + + ContainedList _contents; + std::map<std::string, ContainedPtr, CICompare> _introducedMap; +}; + +// ---------------------------------------------------------------------- +// Module +// ---------------------------------------------------------------------- + +class Module : public virtual Container, public virtual Contained +{ +public: + + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + +protected: + + Module(const ContainerPtr&, const std::string&); + friend class Container; +}; + +// ---------------------------------------------------------------------- +// Constructed +// ---------------------------------------------------------------------- + +class Constructed : public virtual Type, public virtual Contained +{ +public: + + virtual bool isLocal() const; + virtual std::string typeId() const; + virtual bool isVariableLength() const = 0; + ConstructedList dependencies(); + virtual void recDependencies(std::set<ConstructedPtr>&) = 0; // Internal operation, don't use directly. + +protected: + + Constructed(const ContainerPtr&, const std::string&, bool); + + bool _local; +}; + +// ---------------------------------------------------------------------- +// ClassDecl +// ---------------------------------------------------------------------- + +class ClassDecl : public virtual Constructed +{ +public: + + virtual void destroy(); + ClassDefPtr definition() const; + bool isInterface() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + virtual void visit(ParserVisitor*, bool); + virtual std::string kindOf() const; + virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + + static void checkBasesAreLegal(const std::string&, bool, bool, const ClassList&, const UnitPtr&); + +protected: + + ClassDecl(const ContainerPtr&, const std::string&, bool, bool); + friend class Container; + friend class ClassDef; + + ClassDefPtr _definition; + bool _interface; + +private: + + typedef std::list<ClassList> GraphPartitionList; + typedef std::list<StringList> StringPartitionList; + + static bool isInList(const GraphPartitionList&, const ClassDefPtr); + static void addPartition(GraphPartitionList&, GraphPartitionList::reverse_iterator, const ClassDefPtr); + static StringPartitionList toStringPartitionList(const GraphPartitionList&); + static void checkPairIntersections(const StringPartitionList&, const std::string&, const UnitPtr&); +}; + +// ---------------------------------------------------------------------- +// Operation +// ---------------------------------------------------------------------- + +class Operation : public virtual Contained, public virtual Container +{ +public: + + // + // Note: The order of definitions here *must* match the order of + // definitions of ::Ice::OperationMode in slice/Ice/Current.ice! + // + enum Mode + { + Normal, + Nonmutating, + Idempotent + }; + + TypePtr returnType() const; + bool returnIsOptional() const; + int returnTag() const; + Mode mode() const; + Mode sendMode() const; + bool hasMarshaledResult() const; + ParamDeclPtr createParamDecl(const std::string&, const TypePtr&, bool, bool, int); + ParamDeclList parameters() const; + ParamDeclList inParameters() const; + void inParameters(ParamDeclList&, ParamDeclList&) const; + ParamDeclList outParameters() const; + void outParameters(ParamDeclList&, ParamDeclList&) const; + ExceptionList throws() const; + void setExceptionList(const ExceptionList&); + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + bool sendsClasses(bool) const; + bool returnsClasses(bool) const; + bool returnsData() const; + bool returnsMultipleValues() const; + bool sendsOptionals() const; + int attributes() const; + FormatType format() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + +protected: + + Operation(const ContainerPtr&, const std::string&, const TypePtr&, bool, int, Mode); + friend class ClassDef; + + TypePtr _returnType; + bool _returnIsOptional; + int _returnTag; + ExceptionList _throws; + Mode _mode; +}; + +// ---------------------------------------------------------------------- +// ClassDef +// ---------------------------------------------------------------------- + +// +// Note: For the purpose of this parser, a class definition is not +// considered to be a type, but a class declaration is. And each class +// definition has at least one class declaration (but not vice versa), +// so if you need the class as a "constructed type", use the +// declaration() operation to navigate to the class declaration. +// +class ClassDef : public virtual Container, public virtual Contained +{ +public: + + virtual void destroy(); + OperationPtr createOperation(const std::string&, const TypePtr&, bool, int, Operation::Mode = Operation::Normal); + DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); + ClassDeclPtr declaration() const; + ClassList bases() const; + ClassList allBases() const; + OperationList operations() const; + OperationList allOperations() const; + DataMemberList dataMembers() const; + DataMemberList orderedOptionalDataMembers() const; + DataMemberList allDataMembers() const; + DataMemberList classDataMembers() const; + DataMemberList allClassDataMembers() const; + bool canBeCyclic() const; + bool isAbstract() const; + bool isInterface() const; + bool isA(const std::string&) const; + virtual bool isLocal() const; + bool hasDataMembers() const; + bool hasOperations() const; + bool hasDefaultValues() const; + bool inheritsMetaData(const std::string&) const; + bool hasBaseDataMembers() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + int compactId() const; + bool isDelegate() const; + +protected: + + ClassDef(const ContainerPtr&, const std::string&, int, bool, const ClassList&, bool); + friend class Container; + + ClassDeclPtr _declaration; + bool _interface; + bool _hasDataMembers; + bool _hasOperations; + ClassList _bases; + bool _local; + int _compactId; +}; + +// ---------------------------------------------------------------------- +// Proxy +// ---------------------------------------------------------------------- + +class Proxy : public virtual Type +{ +public: + + virtual bool isLocal() const; + virtual std::string typeId() const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + + ClassDeclPtr _class() const; + + Proxy(const ClassDeclPtr&); + +protected: + + ClassDeclPtr _classDecl; +}; + +// ---------------------------------------------------------------------- +// Exception +// ---------------------------------------------------------------------- + +// No inheritance from Constructed, as this is not a Type +class Exception : public virtual Container, public virtual Contained +{ +public: + + virtual void destroy(); + DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); + DataMemberList dataMembers() const; + DataMemberList orderedOptionalDataMembers() const; + DataMemberList allDataMembers() const; + DataMemberList classDataMembers() const; + DataMemberList allClassDataMembers() const; + ExceptionPtr base() const; + ExceptionList allBases() const; + virtual bool isBaseOf(const ExceptionPtr&) const; + virtual bool isLocal() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + bool usesClasses(bool) const; + bool hasDefaultValues() const; + bool inheritsMetaData(const std::string&) const; + bool hasBaseDataMembers() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + +protected: + + Exception(const ContainerPtr&, const std::string&, const ExceptionPtr&, bool); + friend class Container; + + ExceptionPtr _base; + bool _local; +}; + +// ---------------------------------------------------------------------- +// Struct +// ---------------------------------------------------------------------- + +class Struct : public virtual Container, public virtual Constructed +{ +public: + + DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); + DataMemberList dataMembers() const; + DataMemberList classDataMembers() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + bool hasDefaultValues() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + +protected: + + Struct(const ContainerPtr&, const std::string&, bool); + friend class Container; +}; + +// ---------------------------------------------------------------------- +// Sequence +// ---------------------------------------------------------------------- + +class Sequence : public virtual Constructed +{ +public: + + TypePtr type() const; + StringList typeMetaData() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + +protected: + + Sequence(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, bool); + friend class Container; + + TypePtr _type; + StringList _typeMetaData; +}; + +// ---------------------------------------------------------------------- +// Dictionary +// ---------------------------------------------------------------------- + +class Dictionary : public virtual Constructed +{ +public: + + TypePtr keyType() const; + TypePtr valueType() const; + StringList keyMetaData() const; + StringList valueMetaData() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + + static bool legalKeyType(const TypePtr&, bool&); + +protected: + + Dictionary(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const TypePtr&, + const StringList&, bool); + friend class Container; + + TypePtr _keyType; + TypePtr _valueType; + StringList _keyMetaData; + StringList _valueMetaData; +}; + +// ---------------------------------------------------------------------- +// Enum +// ---------------------------------------------------------------------- + +class Enum : public virtual Container, public virtual Constructed +{ +public: + + virtual void destroy(); + bool explicitValue() const; + int minValue() const; + int maxValue() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual bool usesClasses() const; + virtual size_t minWireSize() const; + virtual bool isVariableLength() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. + +protected: + + Enum(const ContainerPtr&, const std::string&, bool); + int newEnumerator(const EnumeratorPtr&); + + friend class Container; + friend class Enumerator; + + bool _explicitValue; + IceUtil::Int64 _minValue; + IceUtil::Int64 _maxValue; + int _lastValue; +}; + +// ---------------------------------------------------------------------- +// Enumerator +// ---------------------------------------------------------------------- + +class Enumerator : public virtual Contained +{ +public: + + EnumPtr type() const; + virtual bool uses(const ContainedPtr&) const; + virtual ContainedType containedType() const; + virtual std::string kindOf() const; + + bool explicitValue() const; + int value() const; + +protected: + + Enumerator(const ContainerPtr&, const std::string&); + Enumerator(const ContainerPtr&, const std::string&, int); + friend class Container; + + bool _explicitValue; + int _value; +}; + +// ---------------------------------------------------------------------- +// Const +// ---------------------------------------------------------------------- + +class Const : public virtual Contained +{ +public: + + TypePtr type() const; + StringList typeMetaData() const; + SyntaxTreeBasePtr valueType() const; + std::string value() const; + std::string literal() const; + virtual bool uses(const ContainedPtr&) const; + virtual ContainedType containedType() const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + +protected: + + Const(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); + friend class Container; + + TypePtr _type; + StringList _typeMetaData; + SyntaxTreeBasePtr _valueType; + std::string _value; + std::string _literal; +}; + +// ---------------------------------------------------------------------- +// ParamDecl +// ---------------------------------------------------------------------- + +class ParamDecl : public virtual Contained +{ +public: + + TypePtr type() const; + bool isOutParam() const; + bool optional() const; + int tag() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + +protected: + + ParamDecl(const ContainerPtr&, const std::string&, const TypePtr&, bool, bool, int); + friend class Operation; + + TypePtr _type; + bool _isOutParam; + bool _optional; + int _tag; +}; + +// ---------------------------------------------------------------------- +// DataMember +// ---------------------------------------------------------------------- + +class DataMember : public virtual Contained +{ +public: + + TypePtr type() const; + bool optional() const; + int tag() const; + std::string defaultValue() const; + std::string defaultLiteral() const; + SyntaxTreeBasePtr defaultValueType() const; + virtual ContainedType containedType() const; + virtual bool uses(const ContainedPtr&) const; + virtual std::string kindOf() const; + virtual void visit(ParserVisitor*, bool); + + +protected: + + DataMember(const ContainerPtr&, const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); + friend class ClassDef; + friend class Struct; + friend class Exception; + + TypePtr _type; + bool _optional; + int _tag; + SyntaxTreeBasePtr _defaultValueType; + std::string _defaultValue; + std::string _defaultLiteral; +}; + +// ---------------------------------------------------------------------- +// Unit +// ---------------------------------------------------------------------- + +class Unit : public virtual Container +{ +public: + + static UnitPtr createUnit(bool, bool, bool, bool, const StringList& = StringList()); + + bool ignRedefs() const; + bool allowIcePrefix() const; + bool allowUnderscore() const; + + void setComment(const std::string&); + std::string currentComment(); // Not const, as this function removes the current comment. + std::string currentFile() const; + std::string topLevelFile() const; + int currentLine() const; + + void nextLine(); + bool scanPosition(const char*); + int currentIncludeLevel() const; + + void addGlobalMetaData(const StringList&); + + void setSeenDefinition(); + + void error(const std::string&); // Not const because error count is increased + void warning(WarningCategory, const std::string&) const; + + ContainerPtr currentContainer() const; + void pushContainer(const ContainerPtr&); + void popContainer(); + + DefinitionContextPtr currentDefinitionContext() const; + void pushDefinitionContext(); + void popDefinitionContext(); + DefinitionContextPtr findDefinitionContext(const std::string&) const; + + void addContent(const ContainedPtr&); + void removeContent(const ContainedPtr&); + ContainedList findContents(const std::string&) const; + ClassList findDerivedClasses(const ClassDefPtr&) const; + ExceptionList findDerivedExceptions(const ExceptionPtr&) const; + ContainedList findUsedBy(const ContainedPtr&) const; + + void addTypeId(int, const std::string&); + std::string getTypeId(int); + + bool usesNonLocals() const; + bool usesConsts() const; + + // + // Returns the path names of the files included directly by the top-level file. + // + StringList includeFiles() const; + + // + // Returns the path names of all files parsed by this unit. + // + StringList allFiles() const; + + int parse(const std::string&, FILE*, bool); + + virtual void destroy(); + virtual void visit(ParserVisitor*, bool); + + BuiltinPtr builtin(Builtin::Kind); // Not const, as builtins are created on the fly. (Lazy initialization.) + + void addTopLevelModule(const std::string&, const std::string&); + std::set<std::string> getTopLevelModules(const std::string&) const; + +private: + + Unit(bool, bool, bool, bool, const StringList&); + static void eraseWhiteSpace(::std::string&); + bool checkUndefinedTypes(); + + bool _ignRedefs; + bool _all; + bool _allowIcePrefix; + bool _allowUnderscore; + StringList _defaultGlobalMetaData; + int _errors; + std::string _currentComment; + int _currentLine; + int _currentIncludeLevel; + std::string _currentFile; + std::string _topLevelFile; + std::stack<DefinitionContextPtr> _definitionContextStack; + StringList _includeFiles; + std::stack<ContainerPtr> _containerStack; + std::map<Builtin::Kind, BuiltinPtr> _builtins; + std::map<std::string, ContainedList> _contentMap; + std::map<std::string, DefinitionContextPtr> _definitionContextMap; + std::map<int, std::string> _typeIds; + std::map< std::string, std::set<std::string> > _fileTopLevelModules; +}; + +extern Unit* unit; // The current parser for bison/flex + +} + +#endif diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 73b6222aa1b..9ed4eee10ab 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -13,7 +13,9 @@ #include <IceUtil/StringConverter.h> #include <IceUtil/FileUtil.h> #include <IceUtil/UUID.h> +#include <IceUtil/ConsoleUtil.h> #include <algorithm> +#include <iterator> #include <vector> #include <fstream> #include <sys/types.h> @@ -26,6 +28,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; // // mcpp defines @@ -82,11 +85,9 @@ Slice::Preprocessor::addQuotes(const string& arg) { // // Add quotes around the given argument to ensure that arguments - // with spaces will be preserved as a single argument. We also - // escape the "\" character to ensure that we don't end up with a - // \" at the end of the string. + // with spaces will be preserved as a single argument // - return "\"" + IceUtilInternal::escapeString(arg, "\\") + "\""; + return "\"" + escapeString(arg, "", IceUtilInternal::Unicode) + "\""; } string @@ -140,7 +141,7 @@ namespace { vector<string> -baseArgs(vector<string> args, bool keepComments, const string& extraArgs, const string& fileName) +baseArgs(vector<string> args, bool keepComments, const vector<string>& extraArgs, const string& fileName) { if(keepComments) { @@ -161,10 +162,7 @@ baseArgs(vector<string> args, bool keepComments, const string& extraArgs, const args.push_back(os.str()); } - if(!extraArgs.empty()) - { - args.push_back(extraArgs); - } + copy(extraArgs.begin(), extraArgs.end(), back_inserter(args)); args.push_back(fileName); return args; } @@ -172,7 +170,15 @@ baseArgs(vector<string> args, bool keepComments, const string& extraArgs, const } FILE* -Slice::Preprocessor::preprocess(bool keepComments, const string& extraArgs) +Slice::Preprocessor::preprocess(bool keepComments, const string& extraArg) +{ + vector<string> args; + args.push_back(extraArg); + return preprocess(keepComments, args); +} + +FILE* +Slice::Preprocessor::preprocess(bool keepComments, const vector<string>& extraArgs) { if(!checkInputFile()) { @@ -270,10 +276,7 @@ Slice::Preprocessor::preprocess(bool keepComments, const string& extraArgs) } else { - ostream& os = getErrorStream(); - os << _path << ": error: could not open temporary file: "; - os << _cppFile; - os << endl; + consoleErr << _path << ": error: could not open temporary file: " << _cppFile << endl; } } @@ -287,7 +290,17 @@ Slice::Preprocessor::preprocess(bool keepComments, const string& extraArgs) bool Slice::Preprocessor::printMakefileDependencies(ostream& out, Language lang, const vector<string>& includePaths, - const string& extraArgs, const string& cppSourceExt, + const string& extraArg, const string& cppSourceExt, + const string& optValue) +{ + vector<string> extraArgs; + extraArgs.push_back(extraArg); + return printMakefileDependencies(out, lang, includePaths, extraArgs, cppSourceExt, optValue); +} + +bool +Slice::Preprocessor::printMakefileDependencies(ostream& out, Language lang, const vector<string>& includePaths, + const vector<string>& extraArgs, const string& cppSourceExt, const string& optValue) { if(!checkInputFile()) @@ -379,7 +392,7 @@ Slice::Preprocessor::printMakefileDependencies(ostream& out, Language lang, cons // /foo/A.ice /foo/B.ice becomes // /foo/A.ice // /foo/B.ice - // + // // C:\foo\A.ice C:\foo\B.ice becomes // C:\foo\A.ice // C:\foo\B.ice @@ -704,7 +717,7 @@ Slice::Preprocessor::printMakefileDependencies(ostream& out, Language lang, cons } default: { - abort(); + assert(false); break; } } @@ -750,14 +763,14 @@ Slice::Preprocessor::checkInputFile() } if(suffix != ".ice") { - getErrorStream() << _path << ": error: input files must end with `.ice'" << endl; + consoleErr << _path << ": error: input files must end with `.ice'" << endl; return false; } - IceUtilInternal::ifstream test(_fileName); + ifstream test(IceUtilInternal::streamFilename(_fileName).c_str()); if(!test) { - getErrorStream() << _path << ": error: cannot open `" << _fileName << "' for reading" << endl; + consoleErr << _path << ": error: cannot open `" << _fileName << "' for reading" << endl; return false; } test.close(); diff --git a/cpp/src/Slice/Preprocessor.h b/cpp/src/Slice/Preprocessor.h new file mode 100644 index 00000000000..f237a41b3f1 --- /dev/null +++ b/cpp/src/Slice/Preprocessor.h @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef PREPROCESSOR_H +#define PREPROCESSOR_H + +#include <IceUtil/Shared.h> +#include <IceUtil/Handle.h> +#include <vector> + +namespace Slice +{ + +class Preprocessor; +typedef IceUtil::Handle<Preprocessor> PreprocessorPtr; + +class Preprocessor : public IceUtil::SimpleShared +{ +public: + + static PreprocessorPtr create(const std::string&, const std::string&, const std::vector<std::string>&); + + ~Preprocessor(); + + FILE* preprocess(bool, const std::string& = ""); + FILE* preprocess(bool, const std::vector<std::string>&); + bool close(); + + enum Language { CPlusPlus, Java, CSharp, Python, Ruby, PHP, JavaScript, JavaScriptJSON, ObjC, SliceXML }; + + bool printMakefileDependencies(std::ostream&, Language, const std::vector<std::string>&, const std::string& = "", + const std::string& = "cpp", const std::string& = ""); + bool printMakefileDependencies(std::ostream&, Language, const std::vector<std::string>&, + const std::vector<std::string>&, const std::string& = "cpp", + const std::string& = ""); + + std::string getBaseName(); + + static std::string addQuotes(const std::string&); + static std::string normalizeIncludePath(const std::string&); + +private: + + Preprocessor(const std::string&, const std::string&, const std::vector<std::string>&); + + bool checkInputFile(); + + const std::string _path; + const std::string _fileName; + const std::string _shortFileName; + const std::vector<std::string> _args; + std::string _cppFile; + FILE* _cppHandle; +}; + +} + +#endif diff --git a/cpp/src/Slice/Python.cpp b/cpp/src/Slice/Python.cpp index f5908ba1a2f..a866992af48 100644 --- a/cpp/src/Slice/Python.cpp +++ b/cpp/src/Slice/Python.cpp @@ -14,6 +14,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> // BUGFIX: With MSVC2013 if this isn't included you get strange linker errors. #include <IceUtil/FileUtil.h> #include <Slice/Preprocessor.h> @@ -38,6 +39,7 @@ using namespace std; using namespace Slice; using namespace Slice::Python; +using namespace IceUtilInternal; namespace { @@ -250,7 +252,7 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub IceUtilInternal::structstat st; if(!IceUtilInternal::stat(initPath, &st)) { - IceUtilInternal::ifstream in(initPath); + ifstream in(IceUtilInternal::streamFilename(initPath).c_str()); if(!in) { ostringstream os; @@ -351,7 +353,7 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis { string initPath = dir + "/__init__.py"; - IceUtilInternal::ofstream os(initPath); + ofstream os(IceUtilInternal::streamFilename(initPath).c_str()); if(!os) { ostringstream os; @@ -383,8 +385,8 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -398,8 +400,6 @@ usage(const string& n) "--depend-xml Generate dependencies in XML format.\n" "--depend-file FILE Write dependencies to FILE instead of standard output.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only).\n" - "--underscore Permit underscores in Slice identifiers.\n" "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" "--prefix PREFIX Prepend filenames of Python modules with PREFIX.\n" @@ -438,7 +438,7 @@ Slice::Python::compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -451,7 +451,7 @@ Slice::Python::compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -502,21 +502,21 @@ Slice::Python::compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; usage(argv[0]); return EXIT_FAILURE; } if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; usage(argv[0]); return EXIT_FAILURE; } if(noPackage && buildPackage) { - getErrorStream() << argv[0] << ": error: cannot specify both --no-package and --build-package" << endl; + consoleErr << argv[0] << ": error: cannot specify both --no-package and --build-package" << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -528,10 +528,10 @@ Slice::Python::compile(const vector<string>& argv) bool keepComments = true; - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -552,7 +552,6 @@ Slice::Python::compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -562,20 +561,17 @@ Slice::Python::compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Python : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Python : Preprocessor::SliceXML, includePaths, "-D__SLICE2PY__", "", prefix)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -592,7 +588,7 @@ Slice::Python::compile(const vector<string>& argv) if(preprocess) { char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != ICE_NULLPTR) { if(fputs(buf, stdout) == EOF) { @@ -659,13 +655,15 @@ Slice::Python::compile(const vector<string>& argv) FileTracker::instance()->addFile(file); // - // Python magic comment to set the file encoding, it must be first or second line + // Emit a Python magic comment to set the file encoding. + // It must be the first or second line. // out << "# -*- coding: utf-8 -*-\n"; printHeader(out); printGeneratedHeader(out, base + ".ice", "#"); + // - // Generate the Python mapping. + // Generate Python code. // generate(u, all, checksum, includePaths, out); @@ -687,13 +685,13 @@ Slice::Python::compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } catch(const string& err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } } @@ -707,7 +705,6 @@ Slice::Python::compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -716,7 +713,12 @@ Slice::Python::compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index 8fe29955ed6..05c928c0e7d 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -12,8 +12,6 @@ #include <Slice/Util.h> #include <IceUtil/IceUtil.h> #include <IceUtil/StringUtil.h> -#include <IceUtil/InputUtil.h> -#include <IceUtil/Unicode.h> #include <climits> #include <iterator> @@ -22,6 +20,27 @@ using namespace Slice; using namespace IceUtil; using namespace IceUtilInternal; +namespace +{ + +string +getEscapedParamName(const OperationPtr& p, const string& name) +{ + ParamDeclList params = p->parameters(); + + for(ParamDeclList::const_iterator i = params.begin(); i != params.end(); ++i) + { + if((*i)->name() == name) + { + return name + "_"; + } + } + return name; +} + +} + + namespace Slice { namespace Python @@ -49,7 +68,7 @@ private: // // Validates sequence metadata. // - void validateSequence(const string&, const string&, const TypePtr&, const StringList&); + StringList validateSequence(const string&, const string&, const TypePtr&, const StringList&); // // Checks a definition that doesn't currently support Python metadata. @@ -105,9 +124,14 @@ public: private: // + // Emit Python code for the class operations + // + void writeOperations(const ClassDefPtr&); + + // // Return a Python symbol for the given parser element. // - string getSymbol(const ContainedPtr&, const string& = string()); + string getSymbol(const ContainedPtr&, const string& = "", const string& = ""); // // Emit Python code to assign the given symbol in the current module. @@ -183,7 +207,7 @@ private: }; bool parseOpComment(const string&, OpComment&); - enum DocstringMode { DocSync, DocAsyncBegin, DocAsyncEnd, DocDispatch, DocAsyncDispatch }; + enum DocstringMode { DocSync, DocAsync, DocAsyncBegin, DocAsyncEnd, DocDispatch, DocAsyncDispatch }; void writeDocstring(const OperationPtr&, DocstringMode, bool); @@ -196,44 +220,6 @@ private: } } -string -u32CodePoint(unsigned int value) -{ - ostringstream s; - s << "\\U"; - s << hex; - s.width(8); - s.fill('0'); - s << value; - return s.str(); -} - -void -writeU8Buffer(const vector<unsigned char>& u8buffer, ostringstream& out) -{ - vector<unsigned int> u32buffer; - IceUtilInternal::ConversionResult result = convertUTF8ToUTF32(u8buffer, u32buffer, IceUtil::lenientConversion); - switch(result) - { - case conversionOK: - break; - case sourceExhausted: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source exhausted"); - case sourceIllegal: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source illegal"); - default: - { - assert(0); - throw IceUtil::IllegalConversionException(__FILE__, __LINE__); - } - } - - for(vector<unsigned int>::const_iterator c = u32buffer.begin(); c != u32buffer.end(); ++c) - { - out << u32CodePoint(*c); - } -} - static string lookupKwd(const string& name) { @@ -288,7 +274,7 @@ splitScopedName(const string& scoped) } static string -getDictLookup(const ContainedPtr& cont, const string& suffix = string()) +getDictLookup(const ContainedPtr& cont, const string& suffix = "", const string& prefix = "") { string scope = Slice::Python::scopedToName(cont->scope()); assert(!scope.empty()); @@ -299,7 +285,7 @@ getDictLookup(const ContainedPtr& cont, const string& suffix = string()) scope = package + "." + scope; } - return "'" + suffix + Slice::Python::fixIdent(cont->name()) + "' not in _M_" + scope + "__dict__"; + return "'" + suffix + Slice::Python::fixIdent(cont->name() + prefix) + "' not in _M_" + scope + "__dict__"; } // @@ -356,7 +342,8 @@ Slice::Python::ModuleVisitor::visitModuleStart(const ModulePtr& p) // CodeVisitor implementation. // Slice::Python::CodeVisitor::CodeVisitor(Output& out, set<string>& moduleHistory) : - _out(out), _moduleHistory(moduleHistory) + _out(out), + _moduleHistory(moduleHistory) { } @@ -440,10 +427,15 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) { _out << sp << nl << "if " << getDictLookup(p) << ':'; _out.inc(); - string type = getAbsolute(p, "_t_"); - _out << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')"; - if(!p->isLocal()) + + if(!p->isInterface() || p->isLocal()) { + _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.declareValue('" << scoped << "')"; + } + + if(!p->isLocal() && (p->isInterface() || p->definition()->allOperations().size())) + { + _out << nl << "_M_" << getAbsolute(p, "_t_", "Disp") << " = IcePy.declareClass('" << scoped << "')"; _out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')"; } _out.dec(); @@ -451,150 +443,10 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) } } -bool -Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) +void +Slice::Python::CodeVisitor::writeOperations(const ClassDefPtr& p) { - string scoped = p->scoped(); - string type = getAbsolute(p, "_t_"); - string abs = getAbsolute(p); - string name = fixIdent(p->name()); - string prxAbs = getAbsolute(p, "", "Prx"); - string prxName = fixIdent(p->name() + "Prx"); - string prxType = getAbsolute(p, "_t_", "Prx"); - ClassList bases = p->bases(); - ClassDefPtr base; OperationList ops = p->operations(); - bool isAbstract = p->isInterface() || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739 - - // - // Define the class. - // - _out << sp << nl << "if " << getDictLookup(p) << ':'; - _out.inc(); - _out << nl << "_M_" << abs << " = Ice.createTempClass()"; - _out << nl << "class " << name << '('; - if(bases.empty()) - { - if(p->isLocal()) - { - _out << "object"; - } - else - { - _out << "Ice.Object"; - } - } - else - { - for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) - { - if(q != bases.begin()) - { - _out << ", "; - } - _out << getSymbol(*q); - } - if(!bases.front()->isInterface()) - { - base = bases.front(); - } - } - _out << "):"; - - _out.inc(); - - writeDocstring(p->comment(), p->dataMembers()); - - // - // __init__ - // - _out << nl << "def __init__(self"; - MemberInfoList allMembers; - collectClassMembers(p, allMembers, false); - writeConstructorParams(allMembers); - _out << "):"; - _out.inc(); - if(!base && !p->hasDataMembers() && !isAbstract) - { - _out << nl << "pass"; - } - else - { - if(isAbstract) - { - _out << nl << "if Ice.getType(self) == _M_" << abs << ':'; - _out.inc(); - _out << nl << "raise RuntimeError('" << abs << " is an abstract class')"; - _out.dec(); - } - if(base) - { - _out << nl << getSymbol(base) << ".__init__(self"; - for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) - { - if(q->inherited) - { - _out << ", " << q->fixedName; - } - } - _out << ')'; - } - for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) - { - if(!q->inherited) - { - writeAssign(*q); - } - } - } - _out.dec(); - - if(!p->isLocal()) - { - // - // ice_ids - // - ClassList allBases = p->allBases(); - StringList ids; - transform(allBases.begin(), allBases.end(), back_inserter(ids), IceUtil::constMemFun(&Contained::scoped)); - StringList other; - other.push_back(scoped); - other.push_back("::Ice::Object"); - other.sort(); - ids.merge(other); - ids.unique(); - _out << sp << nl << "def ice_ids(self, current=None):"; - _out.inc(); - _out << nl << "return ("; - for(StringList::iterator q = ids.begin(); q != ids.end(); ++q) - { - if(q != ids.begin()) - { - _out << ", "; - } - _out << "'" << *q << "'"; - } - _out << ')'; - _out.dec(); - - // - // ice_id - // - _out << sp << nl << "def ice_id(self, current=None):"; - _out.inc(); - _out << nl << "return '" << scoped << "'"; - _out.dec(); - - // - // ice_staticId - // - _out << sp << nl << "def ice_staticId():"; - _out.inc(); - _out << nl << "return '" << scoped << "'"; - _out.dec(); - _out << nl << "ice_staticId = staticmethod(ice_staticId)"; - } - if(!ops.empty()) { // @@ -603,9 +455,9 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) { string fixedOpName = fixIdent((*oli)->name()); - if(!p->isLocal() && (p->hasMetaData("amd") || (*oli)->hasMetaData("amd"))) + if(!p->isLocal()) { - _out << sp << nl << "def " << (*oli)->name() << "_async(self, _cb"; + _out << sp << nl << "def " << fixedOpName << "(self"; ParamDeclList params = (*oli)->parameters(); @@ -616,9 +468,11 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << ", " << fixIdent((*pli)->name()); } } + if(!p->isLocal()) { - _out << ", current=None"; + const string currentParamName = getEscapedParamName(*oli, "current"); + _out << ", " << currentParamName << "=None"; } _out << "):"; _out.inc(); @@ -643,7 +497,8 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) } if(!p->isLocal()) { - _out << ", current=None"; + const string currentParamName = getEscapedParamName(*oli, "current"); + _out << ", " << currentParamName << "=None"; } _out << "):"; _out.inc(); @@ -653,44 +508,276 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) } } } +} - // - // __str__ - // - _out << sp << nl << "def __str__(self):"; - _out.inc(); - _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_") << ")"; - _out.dec(); - _out << sp << nl << "__repr__ = __str__"; +bool +Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) +{ + bool isLocal = p->isLocal(); + bool isInterface = p->isInterface(); + bool isAbstract = isInterface || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739 - _out.dec(); + string scoped = p->scoped(); + string type = getAbsolute(p, "_t_"); + string classType = getAbsolute(p, "_t_", "Disp"); + string abs = getAbsolute(p); + string className = isLocal ? fixIdent(p->name()) : isAbstract ? fixIdent("_" + p->name() + "Disp") : "None"; + string classAbs = getAbsolute(p, "_", "Disp"); + string valueName = (isInterface && !isLocal) ? "Ice.Value" : fixIdent(p->name()); + string prxAbs = getAbsolute(p, "", "Prx"); + string prxName = fixIdent(p->name() + "Prx"); + string prxType = getAbsolute(p, "_t_", "Prx"); + ClassList bases = p->bases(); + ClassDefPtr base; + + if(!bases.empty() && !bases.front()->isInterface()) + { + base = bases.front(); + } // - // Define the proxy class. + // Define a class type for Value types or local classes. // - if(!p->isLocal()) + if(isLocal || !isInterface) { - _out << sp << nl << "_M_" << prxAbs << " = Ice.createTempClass()"; - _out << nl << "class " << prxName << "("; - if(bases.empty()) + _out << sp << nl << "if " << getDictLookup(p) << ':'; + _out.inc(); + _out << nl << "_M_" << abs << " = Ice.createTempClass()"; + _out << nl << "class " << valueName << '('; + if(isLocal) { - _out << "Ice.ObjectPrx"; + if(bases.empty()) + { + _out << "object"; + } + else + { + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) + { + if(q != bases.begin()) + { + _out << ", "; + } + _out << getSymbol(*q); + } + } } else { - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) + if(bases.empty() || bases.front()->isInterface()) { - _out << getSymbol(*q, "Prx"); - if(++q != bases.end()) + _out << "Ice.Value"; + } + else + { + _out << getSymbol(bases.front()); + } + } + _out << "):"; + + _out.inc(); + + writeDocstring(p->comment(), p->dataMembers()); + + // + // __init__ + // + _out << nl << "def __init__(self"; + MemberInfoList allMembers; + collectClassMembers(p, allMembers, false); + writeConstructorParams(allMembers); + _out << "):"; + _out.inc(); + if(!base && !p->hasDataMembers() && (!isAbstract || !isLocal)) + { + _out << nl << "pass"; + } + else + { + if(isAbstract && isLocal) + { + _out << nl << "if Ice.getType(self) == _M_" << abs << ':'; + _out.inc(); + _out << nl << "raise RuntimeError('" << abs << " is an abstract class')"; + _out.dec(); + } + if(base) + { + _out << nl << getSymbol(base) << ".__init__(self"; + for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { - _out << ", "; + if(q->inherited) + { + _out << ", " << q->fixedName; + } + } + _out << ')'; + } + for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) + { + if(!q->inherited) + { + writeAssign(*q); + } + } + } + _out.dec(); + + if(!isLocal) + { + // + // ice_id + // + _out << sp << nl << "def ice_id(self):"; + _out.inc(); + _out << nl << "return '" << scoped << "'"; + _out.dec(); + + // + // ice_staticId + // + _out << sp << nl << "@staticmethod"; + _out << nl << "def ice_staticId():"; + _out.inc(); + _out << nl << "return '" << scoped << "'"; + _out.dec(); + } + else + { + writeOperations(p); + } + + // + // __str__ + // + _out << sp << nl << "def __str__(self):"; + _out.inc(); + _out << nl << "return IcePy.stringify(self, _M_" << type << ")"; + _out.dec(); + _out << sp << nl << "__repr__ = __str__"; + + _out.dec(); + + if(_classHistory.count(scoped) == 0 && p->canBeCyclic()) + { + // + // Emit a forward declaration for the class in case a data member refers to this type. + // + _out << sp << nl << "_M_" << type << " = IcePy.declareValue('" << scoped << "')"; + } + DataMemberList members = p->dataMembers(); + _out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', " << valueName + << ", " << p->compactId() << ", "; + writeMetaData(p->getMetaData()); + const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice"); + _out << ", " << (preserved ? "True" : "False") << ", " << (isInterface ? "True" : "False") << ", "; + if(!base) + { + _out << "None"; + } + else + { + _out << "_M_" << getAbsolute(base, "_t_"); + } + _out << ", ("; + // + // Members + // + // Data members are represented as a tuple: + // + // ('MemberName', MemberMetaData, MemberType, Optional, Tag) + // + // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. + // + if(members.size() > 1) + { + _out.inc(); + _out << nl; + } + bool isProtected = p->hasMetaData("protected"); + for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r) + { + if(r != members.begin()) + { + _out << ',' << nl; + } + _out << "('"; + if(isProtected || (*r)->hasMetaData("protected")) + { + _out << '_'; + } + _out << fixIdent((*r)->name()) << "', "; + writeMetaData((*r)->getMetaData()); + _out << ", "; + writeType((*r)->type()); + _out << ", " << ((*r)->optional() ? "True" : "False") << ", " + << ((*r)->optional() ? (*r)->tag() : 0) << ')'; + } + if(members.size() == 1) + { + _out << ','; + } + else if(members.size() > 1) + { + _out.dec(); + _out << nl; + } + _out << "))"; + _out << nl << valueName << "._ice_type = _M_" << type; + + registerName(valueName); + + _out.dec(); + } + else if(!isLocal && isInterface) + { + _out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', Ice.Value, -1, "; + writeMetaData(p->getMetaData()); + _out << ", False, True, None, ())"; + } + + if(!isLocal && isAbstract) + { + _out << sp << nl << "if " << getDictLookup(p, "", "Prx") << ':'; + _out.inc(); + + // Define the proxy class + _out << nl << "_M_" << prxAbs << " = Ice.createTempClass()"; + _out << nl << "class " << prxName << '('; + + { + vector<string> baseClasses; + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) + { + ClassDefPtr d = *q; + if(d->isInterface() || d->allOperations().size() > 0) + { + baseClasses.push_back(getSymbol(*q, "", "Prx")); + } + } + + if(baseClasses.empty()) + { + _out << "Ice.ObjectPrx"; + } + else + { + vector<string>::const_iterator q = baseClasses.begin(); + while(q != baseClasses.end()) + { + _out << *q; + + if(++q != baseClasses.end()) + { + _out << ", "; + } } } } _out << "):"; _out.inc(); + OperationList ops = p->operations(); for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) { string fixedOpName = fixIdent((*oli)->name()); @@ -721,170 +808,227 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << ", " << inParams; } - _out << ", _ctx=None):"; + const string contextParamName = getEscapedParamName(*oli, "context"); + _out << ", " << contextParamName << "=None):"; _out.inc(); - _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".invoke(self, ((" << inParams; + _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".invoke(self, ((" << inParams; if(!inParams.empty() && inParams.find(',') == string::npos) { _out << ", "; } - _out << "), _ctx))"; + _out << "), " << contextParamName << "))"; _out.dec(); // // Async operations. // _out << sp; + writeDocstring(*oli, DocAsync, false); + _out << nl << "def " << (*oli)->name() << "Async(self"; + if(!inParams.empty()) + { + _out << ", " << inParams; + } + _out << ", " << contextParamName << "=None):"; + _out.inc(); + _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".invokeAsync(self, ((" << inParams; + if(!inParams.empty() && inParams.find(',') == string::npos) + { + _out << ", "; + } + _out << "), " << contextParamName << "))"; + _out.dec(); + + _out << sp; writeDocstring(*oli, DocAsyncBegin, false); _out << nl << "def begin_" << (*oli)->name() << "(self"; if(!inParams.empty()) { _out << ", " << inParams; } - _out << ", _response=None, _ex=None, _sent=None, _ctx=None):"; + _out << ", _response=None, _ex=None, _sent=None, " << contextParamName << "=None):"; _out.inc(); - _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".begin(self, ((" << inParams; + _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".begin(self, ((" << inParams; if(!inParams.empty() && inParams.find(',') == string::npos) { _out << ", "; } - _out << "), _response, _ex, _sent, _ctx))"; + _out << "), _response, _ex, _sent, " << contextParamName << "))"; _out.dec(); _out << sp; writeDocstring(*oli, DocAsyncEnd, false); _out << nl << "def end_" << (*oli)->name() << "(self, _r):"; _out.inc(); - _out << nl << "return _M_" << abs << "._op_" << (*oli)->name() << ".end(self, _r)"; + _out << nl << "return _M_" << classAbs << "._op_" << (*oli)->name() << ".end(self, _r)"; _out.dec(); } - _out << sp << nl << "def checkedCast(proxy, facetOrCtx=None, _ctx=None):"; + _out << sp << nl << "@staticmethod"; + _out << nl << "def checkedCast(proxy, facetOrContext=None, context=None):"; _out.inc(); - _out << nl << "return _M_" << prxAbs << ".ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)"; + _out << nl << "return _M_" << prxAbs << ".ice_checkedCast(proxy, '" << scoped << "', facetOrContext, context)"; _out.dec(); - _out << nl << "checkedCast = staticmethod(checkedCast)"; - _out << sp << nl << "def uncheckedCast(proxy, facet=None):"; + _out << sp << nl << "@staticmethod"; + _out << nl << "def uncheckedCast(proxy, facet=None):"; _out.inc(); _out << nl << "return _M_" << prxAbs << ".ice_uncheckedCast(proxy, facet)"; _out.dec(); - _out << nl << "uncheckedCast = staticmethod(uncheckedCast)"; - // + // // ice_staticId // - _out << sp << nl << "def ice_staticId():"; + _out << sp << nl << "@staticmethod"; + _out << nl << "def ice_staticId():"; _out.inc(); _out << nl << "return '" << scoped << "'"; _out.dec(); - _out << nl << "ice_staticId = staticmethod(ice_staticId)"; - _out.dec(); + _out.dec(); // end prx class - _out << sp << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")"; - } + _out << nl << "_M_" << prxType << " = IcePy.defineProxy('" << scoped << "', " << prxName << ")"; + + registerName(prxName); + + // Define the servant class + _out << sp << nl << "_M_" << classAbs << " = Ice.createTempClass()"; + _out << nl << "class " << className << '('; + { + vector<string> baseClasses; + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) + { + ClassDefPtr d = *q; + if(d->isInterface() || d->allOperations().size() > 0) + { + baseClasses.push_back(getSymbol(*q, "_", "Disp")); + } + } + + if(baseClasses.empty()) + { + _out << "Ice.Object"; + } + else + { + vector<string>::const_iterator q = baseClasses.begin(); + while(q != baseClasses.end()) + { + _out << *q; + + if(++q != baseClasses.end()) + { + _out << ", "; + } + } + } + } + _out << "):"; + + _out.inc(); - if(_classHistory.count(scoped) == 0 && p->canBeCyclic()) - { // - // Emit a forward declaration for the class in case a data member refers to this type. + // ice_ids // - _out << sp << nl << "_M_" << type << " = IcePy.declareClass('" << scoped << "')"; - } - - DataMemberList members = p->dataMembers(); - _out << sp << nl << "_M_" << type << " = IcePy.defineClass('" << scoped << "', " << name << ", " << p->compactId() - << ", "; - writeMetaData(p->getMetaData()); - const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice"); - _out << ", " << (isAbstract ? "True" : "False") << ", " << (preserved ? "True" : "False") << ", "; - if(!base) - { - _out << "None"; - } - else - { - _out << "_M_" << getAbsolute(base, "_t_"); - } - _out << ", ("; - // - // Interfaces - // - int interfaceCount = 0; - for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) - { - if((*q)->isInterface()) + ClassList allBases = p->allBases(); + StringList ids; + transform(allBases.begin(), allBases.end(), back_inserter(ids), IceUtil::constMemFun(&Contained::scoped)); + StringList other; + other.push_back(scoped); + other.push_back("::Ice::Object"); + other.sort(); + ids.merge(other); + ids.unique(); + _out << sp << nl << "def ice_ids(self, current=None):"; + _out.inc(); + _out << nl << "return ("; + for(StringList::iterator q = ids.begin(); q != ids.end(); ++q) { - if(interfaceCount > 0) + if(q != ids.begin()) { _out << ", "; } - _out << "_M_" << getAbsolute(*q, "_t_"); - ++interfaceCount; + _out << "'" << *q << "'"; } - } - if(interfaceCount == 1) - { - _out << ','; - } - // - // Members - // - // Data members are represented as a tuple: - // - // ('MemberName', MemberMetaData, MemberType, Optional, Tag) - // - // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. - // - _out << "), ("; - if(members.size() > 1) - { + _out << ')'; + _out.dec(); + + // + // ice_id + // + _out << sp << nl << "def ice_id(self, current=None):"; _out.inc(); - _out << nl; - } - bool isProtected = p->hasMetaData("protected"); - for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r) - { - if(r != members.begin()) + _out << nl << "return '" << scoped << "'"; + _out.dec(); + + // + // ice_staticId + // + _out << sp << nl << "@staticmethod"; + _out << nl << "def ice_staticId():"; + _out.inc(); + _out << nl << "return '" << scoped << "'"; + _out.dec(); + + writeOperations(p); + + // + // __str__ + // + _out << sp << nl << "def __str__(self):"; + _out.inc(); + _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_", "Disp") << ")"; + _out.dec(); + _out << sp << nl << "__repr__ = __str__"; + + _out.dec(); + + _out << sp << nl << "_M_" << classType << " = IcePy.defineClass('" << scoped << "', " << className + << ", "; + writeMetaData(p->getMetaData()); + _out << ", "; + if(!base || (!base->isInterface() && base->allOperations().size() == 0)) { - _out << ',' << nl; + _out << "None"; } - _out << "('"; - if(isProtected || (*r)->hasMetaData("protected")) + else { - _out << '_'; + _out << "_M_" << getAbsolute(base, "_t_", "Disp"); } - _out << fixIdent((*r)->name()) << "', "; - writeMetaData((*r)->getMetaData()); - _out << ", "; - writeType((*r)->type()); - _out << ", " << ((*r)->optional() ? "True" : "False") << ", " - << ((*r)->optional() ? (*r)->tag() : 0) << ')'; - } - if(members.size() == 1) - { - _out << ','; - } - else if(members.size() > 1) - { - _out.dec(); - _out << nl; - } - _out << "))"; - _out << nl << name << "._ice_type = _M_" << type; + _out << ", ("; + // + // Interfaces + // + int interfaceCount = 0; + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) + { + if((*q)->isInterface()) + { + if(interfaceCount > 0) + { + _out << ", "; + } + _out << "_M_" << getAbsolute(*q, "_t_", "Disp"); + ++interfaceCount; + } + } + if(interfaceCount == 1) + { + _out << ','; + } + _out << "))"; + _out << nl << className << "._ice_type = _M_" << classType; - // - // Define each operation. The arguments to the IcePy.Operation constructor are: - // - // 'opName', Mode, SendMode, AMD, Format, MetaData, (InParams), (OutParams), ReturnParam, (Exceptions) - // - // where InParams and OutParams are tuples of type descriptions, and Exceptions - // is a tuple of exception type ids. - // - if(!p->isLocal()) - { + + // + // Define each operation. The arguments to the IcePy.Operation constructor are: + // + // 'opName', Mode, SendMode, AMD, Format, MetaData, (InParams), (OutParams), ReturnParam, (Exceptions) + // + // where InParams and OutParams are tuples of type descriptions, and Exceptions + // is a tuple of exception type ids. + // if(!ops.empty()) { _out << sp; @@ -908,10 +1052,10 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) break; } - _out << nl << name << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', " - << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", " - << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", " - << format << ", "; + _out << nl << className << "._op_" << (*s)->name() << " = IcePy.Operation('" << (*s)->name() << "', " + << getOperationMode((*s)->mode()) << ", " << getOperationMode((*s)->sendMode()) << ", " + << ((p->hasMetaData("amd") || (*s)->hasMetaData("amd")) ? "True" : "False") << ", " + << format << ", "; writeMetaData((*s)->getMetaData()); _out << ", ("; for(t = params.begin(), count = 0; t != params.end(); ++t) @@ -949,7 +1093,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << ", "; writeType((*t)->type()); _out << ", " << ((*t)->optional() ? "True" : "False") << ", " - << ((*t)->optional() ? (*t)->tag() : 0) << ')'; + << ((*t)->optional() ? (*t)->tag() : 0) << ')'; ++count; } } @@ -1000,20 +1144,14 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { msg = deprecateMetadata.substr(pos + 1); } - _out << nl << name << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")"; + _out << nl << className << "._op_" << (*s)->name() << ".deprecate(\"" << msg << "\")"; } } - } - registerName(name); - - if(!p->isLocal()) - { - registerName(prxName); + registerName(className); + _out.dec(); } - _out.dec(); - if(_classHistory.count(scoped) == 0) { _classHistory.insert(scoped); // Avoid redundant declarations. @@ -1102,9 +1240,9 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) _out << sp << nl << "__repr__ = __str__"; // - // _ice_name + // _ice_id // - _out << sp << nl << "_ice_name = '" << scoped.substr(2) << "'"; + _out << sp << nl << "_ice_id = '" << scoped << "'"; _out.dec(); @@ -1515,7 +1653,7 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p) string scoped = p->scoped(); string abs = getAbsolute(p); string name = fixIdent(p->name()); - EnumeratorList enums = p->getEnumerators(); + EnumeratorList enums = p->enumerators(); EnumeratorList::iterator q; _out << sp << nl << "if " << getDictLookup(p) << ':'; @@ -1586,12 +1724,12 @@ Slice::Python::CodeVisitor::visitConst(const ConstPtr& p) } string -Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& nameSuffix) +Slice::Python::CodeVisitor::getSymbol(const ContainedPtr& p, const string& prefix, const string& suffix) { // // An explicit reference to another type must always be prefixed with "_M_". // - return "_M_" + getAbsolute(p, "", nameSuffix); + return "_M_" + getAbsolute(p, prefix, suffix); } void @@ -1651,8 +1789,9 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p) break; } case Builtin::KindObject: + case Builtin::KindValue: { - _out << "IcePy._t_Object"; + _out << "IcePy._t_Value"; break; } case Builtin::KindObjectProxy: @@ -1672,7 +1811,15 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p) ProxyPtr prx = ProxyPtr::dynamicCast(p); if(prx) { - _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx"); + ClassDefPtr def = prx->_class()->definition(); + if(def->isInterface() || def->allOperations().size() > 0) + { + _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx"); + } + else + { + _out << "IcePy._t_ObjectPrx"; + } return; } @@ -1714,6 +1861,7 @@ Slice::Python::CodeVisitor::writeInitializer(const DataMemberPtr& m) _out << "''"; break; } + case Builtin::KindValue: case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: @@ -1728,7 +1876,7 @@ Slice::Python::CodeVisitor::writeInitializer(const DataMemberPtr& m) EnumPtr en = EnumPtr::dynamicCast(p); if(en) { - EnumeratorList enums = en->getEnumerators(); + EnumeratorList enums = en->enumerators(); _out << getSymbol(en) << "." << fixIdent(enums.front()->name()); return; } @@ -1875,274 +2023,17 @@ Slice::Python::CodeVisitor::writeConstantValue(const TypePtr& type, const Syntax } case Slice::Builtin::KindString: { - ostringstream sv2; - ostringstream sv3; - - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=, '"; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); + string sv2 = toStringLiteral(value, "\a\b\f\n\r\t\v", "", Octal, 0); + string sv3 = toStringLiteral(value, "\a\b\f\n\r\t\v", "", UCN, 0); - for(size_t i = 0; i < value.size();) + _out << "\"" << sv2<< "\""; + if(sv2 != sv3) { - char c = value[i]; - switch(c) - { - case '"': - { - sv2 << "\\\""; - break; - } - case '\\': - { - string s = "\\"; - size_t j = i + 1; - for(; j < value.size(); ++j) - { - if(value[j] != '\\') - { - break; - } - s += "\\"; - } - - // - // An even number of slash \ will escape the backslash and - // the codepoint will be interpreted as its charaters - // - // \\u00000041 - ['\\', 'u', '0', '0', '0', '0', '0', '0', '4', '1'] - // \\\u00000041 - ['\\', 'A'] (41 is the codepoint for 'A') - // - if(s.size() % 2 != 0 && (value[j] == 'U' || value[j] == 'u')) - { - // - // Convert codepoint to UTF8 bytes and write the escaped bytes - // - sv2 << s.substr(0, s.size() - 1); - - size_t sz = value[j] == 'U' ? 8 : 4; - string codepoint = value.substr(j + 1, sz); - assert(codepoint.size() == sz); - - IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16); - - vector<unsigned int> u32buffer; - u32buffer.push_back(static_cast<unsigned int>(v)); - - vector<unsigned char> u8buffer; - IceUtilInternal::ConversionResult result = convertUTF32ToUTF8(u32buffer, u8buffer, IceUtil::lenientConversion); - switch(result) - { - case conversionOK: - break; - case sourceExhausted: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source exhausted"); - case sourceIllegal: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source illegal"); - default: - { - assert(0); - throw IceUtil::IllegalConversionException(__FILE__, __LINE__); - } - } - - ostringstream s; - for(vector<unsigned char>::const_iterator q = u8buffer.begin(); q != u8buffer.end(); ++q) - { - s << "\\"; - s.fill('0'); - s.width(3); - s << oct; - s << static_cast<unsigned int>(*q); - } - sv2 << s.str(); - - i = j + 1 + sz; - } - else - { - sv2 << s; - i = j; - } - continue; - } - case '\r': - { - sv2 << "\\r"; - break; - } - case '\n': - { - sv2 << "\\n"; - break; - } - case '\t': - { - sv2 << "\\t"; - break; - } - case '\b': - { - sv2 << "\\b"; - break; - } - case '\f': - { - sv2 << "\\f"; - break; - } - default: - { - if(charSet.find(c) == charSet.end()) - { - unsigned char uc = c; // Char may be signed, so make it positive. - stringstream s; - s << "\\"; // Print as octal if not in basic source character set. - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast<unsigned>(uc); - sv2 << s.str(); - } - else - { - sv2 << c; // Print normally if in basic source character set. - } - break; - } - } - ++i; - } - - vector<unsigned char> u8buffer; // Buffer to convert multibyte characters - - for(size_t i = 0; i < value.size();) - { - if(charSet.find(value[i]) == charSet.end()) - { - char c = value[i]; - if(static_cast<unsigned char>(c) < 128) // Single byte character - { - // - // Print as unicode if not in basic source character set - // - switch(c) - { - // - // Don't encode this special characters as universal characters - // - case '\r': - { - sv3 << "\\r"; - break; - } - case '\n': - { - sv3 << "\\n"; - break; - } - case '\\': - { - sv3 << "\\"; - break; - } - default: - { - sv3 << u32CodePoint(c); - break; - } - } - } - else - { - u8buffer.push_back(value[i]); - } - } - else - { - // - // Write any pedding characters in the utf8 buffer - // - if(!u8buffer.empty()) - { - writeU8Buffer(u8buffer, sv3); - u8buffer.clear(); - } - switch(value[i]) - { - case '\\': - { - string s = "\\"; - size_t j = i + 1; - for(; j < value.size(); ++j) - { - if(value[j] != '\\') - { - break; - } - s += "\\"; - } - - // - // An even number of slash \ will escape the backslash and - // the codepoint will be interpreted as its charaters - // - // \\U00000041 - ['\\', 'U', '0', '0', '0', '0', '0', '0', '4', '1'] - // \\\U00000041 - ['\\', 'A'] (41 is the codepoint for 'A') - // - if(s.size() % 2 != 0 && (value[j] == 'U' || value[j] == 'u')) - { - size_t sz = value[j] == 'U' ? 8 : 4; - sv3 << s.substr(0, s.size() - 1); - i = j + 1; - - string codepoint = value.substr(j + 1, sz); - assert(codepoint.size() == sz); - - IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16); - sv3 << u32CodePoint(static_cast<unsigned int>(v)); - i = j + 1 + sz; - } - else - { - sv3 << s; - i = j; - } - continue; - } - case '"': - { - sv3 << "\\"; - break; - } - } - sv3 << value[i]; // Print normally if in basic source character set - } - i++; - } - - // - // Write any pedding characters in the utf8 buffer - // - if(!u8buffer.empty()) - { - writeU8Buffer(u8buffer, sv3); - u8buffer.clear(); - } - - - _out << "\"" << sv2.str() << "\""; - if(sv2.str() != sv3.str()) - { - _out << " if _version_info_[0] < 3 else \"" << sv3.str() << "\""; + _out << " if _version_info_[0] < 3 else \"" << sv3 << "\""; } break; } + case Slice::Builtin::KindValue: case Slice::Builtin::KindObject: case Slice::Builtin::KindObjectProxy: case Slice::Builtin::KindLocalObject: @@ -2151,18 +2042,9 @@ Slice::Python::CodeVisitor::writeConstantValue(const TypePtr& type, const Syntax } else if(en) { - string enumName = getSymbol(en); - string::size_type colon = value.rfind(':'); - string enumerator; - if(colon != string::npos) - { - enumerator = fixIdent(value.substr(colon + 1)); - } - else - { - enumerator = fixIdent(value); - } - _out << enumName << '.' << enumerator; + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); + assert(lte); + _out << getSymbol(lte); } else { @@ -2781,7 +2663,7 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode { return; } - else if(mode == DocAsyncBegin && inParams.empty()) + else if((mode == DocAsync || mode == DocAsyncBegin) && inParams.empty()) { return; } @@ -2814,6 +2696,7 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode switch(mode) { case DocSync: + case DocAsync: case DocAsyncBegin: case DocDispatch: needArgs = !local || !inParams.empty(); @@ -2827,10 +2710,6 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode if(needArgs) { _out << nl << "Arguments:"; - if(mode == DocAsyncDispatch) - { - _out << nl << "_cb -- The asynchronous callback object."; - } for(vector<string>::iterator q = inParams.begin(); q != inParams.end(); ++q) { string fixed = fixIdent(*q); @@ -2851,13 +2730,15 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode << nl << "_ex -- The asynchronous exception callback." << nl << "_sent -- The asynchronous sent callback."; } - if(!local && (mode == DocSync || mode == DocAsyncBegin)) + if(!local && (mode == DocSync || mode == DocAsync || mode == DocAsyncBegin)) { - _out << nl << "_ctx -- The request context for the invocation."; + const string contextParamName = getEscapedParamName(op, "context"); + _out << nl << contextParamName << " -- The request context for the invocation."; } if(!local && (mode == DocDispatch || mode == DocAsyncDispatch)) { - _out << nl << "current -- The Current object for the invocation."; + const string currentParamName = getEscapedParamName(op, "current"); + _out << nl << currentParamName << " -- The Current object for the invocation."; } } else if(mode == DocAsyncEnd) @@ -2869,6 +2750,10 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode // // Emit return value(s). // + if(mode == DocAsync || mode == DocAsyncDispatch) + { + _out << nl << "Returns: A future object for the invocation."; + } if(mode == DocAsyncBegin) { _out << nl << "Returns: An asynchronous result object for the invocation."; @@ -2936,7 +2821,8 @@ Slice::Python::CodeVisitor::writeDocstring(const OperationPtr& op, DocstringMode } void -Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, Output& out) +Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector<string>& includePaths, + Output& out) { Slice::Python::MetaDataVisitor visitor; un->visit(&visitor, false); @@ -3064,14 +2950,7 @@ Slice::Python::getAbsolute(const ContainedPtr& cont, const string& suffix, const } } - if(suffix.empty()) - { - return scope + fixIdent(cont->name() + nameSuffix); - } - else - { - return scope + suffix + fixIdent(cont->name() + nameSuffix); - } + return scope + suffix + fixIdent(cont->name() + nameSuffix); } void @@ -3103,30 +2982,28 @@ Slice::Python::MetaDataVisitor::visitUnitStart(const UnitPtr& p) // Validate global metadata in the top-level file and all included files. // StringList files = p->allFiles(); - for(StringList::iterator q = files.begin(); q != files.end(); ++q) { string file = *q; DefinitionContextPtr dc = p->findDefinitionContext(file); assert(dc); StringList globalMetaData = dc->getMetaData(); - for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end(); ++r) + for(StringList::const_iterator r = globalMetaData.begin(); r != globalMetaData.end();) { - string s = *r; - if(_history.count(s) == 0) + string s = *r++; + if(s.find(prefix) == 0) { - _history.insert(s); - if(s.find(prefix) == 0) + static const string packagePrefix = "python:package:"; + if(s.find(packagePrefix) == 0 && s.size() > packagePrefix.size()) { - static const string packagePrefix = "python:package:"; - if(s.find(packagePrefix) == 0 && s.size() > packagePrefix.size()) - { - continue; - } - emitWarning(file, "", "ignoring invalid global metadata `" + s + "'"); + continue; } + + dc->warning(InvalidMetaData, file, "", "ignoring invalid global metadata `" + s + "'"); + globalMetaData.remove(s); } } + dc->setMetaData(globalMetaData); } return true; } @@ -3194,6 +3071,11 @@ Slice::Python::MetaDataVisitor::visitSequence(const SequencePtr& p) StringList metaData = p->getMetaData(); const string file = p->file(); const string line = p->line(); + StringList protobufMetaData; + const UnitPtr unit = p->unit(); + const DefinitionContextPtr dc = unit->findDefinitionContext(file); + assert(dc); + for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ) { string s = *q++; @@ -3203,17 +3085,22 @@ Slice::Python::MetaDataVisitor::visitSequence(const SequencePtr& p) // Remove from list so validateSequence does not try to handle as well. // metaData.remove(s); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type()); if(!builtin || builtin->kind() != Builtin::KindByte) { - emitWarning(file, line, "ignoring invalid metadata `" + s + ": " + + dc->warning(InvalidMetaData, file, line, "ignoring invalid metadata `" + s + ": " + "`protobuf' encoding must be a byte sequence"); } + else + { + protobufMetaData.push_back(s); + } } } - validateSequence(file, line, p, metaData); + metaData = validateSequence(file, line, p, metaData); + metaData.insert(metaData.end(), protobufMetaData.begin(), protobufMetaData.end()); + p->setMetaData(metaData); } void @@ -3234,15 +3121,19 @@ Slice::Python::MetaDataVisitor::visitConst(const ConstPtr& p) reject(p); } -void +StringList Slice::Python::MetaDataVisitor::validateSequence(const string& file, const string& line, - const TypePtr& type, const StringList& meta) + const TypePtr& type, const StringList& metaData) { - static const string prefix = "python:"; + const UnitPtr unit = type->unit(); + const DefinitionContextPtr dc = unit->findDefinitionContext(file); + assert(dc); - for(StringList::const_iterator p = meta.begin(); p != meta.end(); ++p) + static const string prefix = "python:"; + StringList newMetaData = metaData; + for(StringList::const_iterator p = newMetaData.begin(); p != newMetaData.end();) { - string s = *p; + string s = *p++; if(s.find(prefix) == 0) { string::size_type pos = s.find(':', prefix.size()); @@ -3258,9 +3149,11 @@ Slice::Python::MetaDataVisitor::validateSequence(const string& file, const strin } } } - emitWarning(file, line, "ignoring invalid metadata `" + s + "'"); + dc->warning(InvalidMetaData, file, line, "ignoring invalid metadata `" + s + "'"); + newMetaData.remove(s); } } + return newMetaData; } void @@ -3268,11 +3161,19 @@ Slice::Python::MetaDataVisitor::reject(const ContainedPtr& cont) { StringList localMetaData = cont->getMetaData(); static const string prefix = "python:"; - for(StringList::const_iterator p = localMetaData.begin(); p != localMetaData.end(); ++p) + + const UnitPtr unit = cont->unit(); + const DefinitionContextPtr dc = unit->findDefinitionContext(cont->file()); + assert(dc); + + for(StringList::const_iterator p = localMetaData.begin(); p != localMetaData.end();) { - if(p->find(prefix) == 0) + string s = *p++; + if(s.find(prefix) == 0) { - emitWarning(cont->file(), cont->line(), "ignoring invalid metadata `" + *p + "'"); + dc->warning(InvalidMetaData, cont->file(), cont->line(), "ignoring invalid metadata `" + s + "'"); + localMetaData.remove(s); } } + cont->setMetaData(localMetaData); } diff --git a/cpp/src/Slice/PythonUtil.h b/cpp/src/Slice/PythonUtil.h new file mode 100644 index 00000000000..9d48b3d3871 --- /dev/null +++ b/cpp/src/Slice/PythonUtil.h @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_PYTHON_UTIL_H +#define SLICE_PYTHON_UTIL_H + +#include <Slice/Parser.h> +#include <IceUtil/OutputUtil.h> + +namespace Slice +{ +namespace Python +{ + +// +// Generate Python code for a translation unit. +// +void generate(const Slice::UnitPtr&, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&); + +// +// Convert a scoped name into a Python name. +// +std::string scopedToName(const std::string&); + +// +// Check the given identifier against Python's list of reserved words. If it matches +// a reserved word, then an escaped version is returned with a leading underscore. +// +std::string fixIdent(const std::string&); + +// +// Return the package specified in the global metadata for the given definition, +// or an empty string if no metadata was found. +// +std::string getPackageMetadata(const Slice::ContainedPtr&); + +// +// Get the fully-qualified name of the given definition, including any +// package defined via metadata. If a suffix is provided, it is +// prepended to the definition's unqualified name. If the nameSuffix +// is provided, it is appended to the containers name. +// +// COMPILERFIX: MSVC 6 seems to have a problem with const std::string +// = std::string(), const std::string = std::string(). +// +std::string getAbsolute(const Slice::ContainedPtr&, const std::string& = "", const std::string& = ""); + +// +// Emit a comment header. +// +void printHeader(IceUtilInternal::Output&); + +int compile(const std::vector<std::string>&); + +} +} + +#endif diff --git a/cpp/src/Slice/Ruby.cpp b/cpp/src/Slice/Ruby.cpp index 4534474929b..310b84bf4a6 100644 --- a/cpp/src/Slice/Ruby.cpp +++ b/cpp/src/Slice/Ruby.cpp @@ -12,6 +12,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/RubyUtil.h> @@ -22,6 +23,7 @@ using namespace std; using namespace Slice; using namespace Slice::Ruby; +using namespace IceUtilInternal; namespace { @@ -58,8 +60,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -73,10 +75,12 @@ usage(const string& n) "--depend-xml Generate dependencies in XML format.\n" "--depend-file FILE Write dependencies to FILE instead of standard output.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only).\n" - "--underscore Permit underscores in Slice identifiers.\n" "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" + "--ice Allow reserved Ice prefix in Slice identifiers\n" + " deprecated: use instead [[\"ice-prefix\"]] metadata.\n" + "--underscore Allow underscores in Slice identifiers\n" + " deprecated: use instead [[\"underscore\"]] metadata.\n" ; } @@ -109,7 +113,7 @@ Slice::Ruby::compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -122,7 +126,7 @@ Slice::Ruby::compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -167,14 +171,14 @@ Slice::Ruby::compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; usage(argv[0]); return EXIT_FAILURE; } if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -184,10 +188,10 @@ Slice::Ruby::compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -208,7 +212,6 @@ Slice::Ruby::compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -218,20 +221,17 @@ Slice::Ruby::compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, "-D__SLICE2RB__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -248,7 +248,7 @@ Slice::Ruby::compile(const vector<string>& argv) if(preprocess) { char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != ICE_NULLPTR) { if(fputs(buf, stdout) == EOF) { @@ -321,7 +321,7 @@ Slice::Ruby::compile(const vector<string>& argv) // any created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -335,7 +335,6 @@ Slice::Ruby::compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -344,7 +343,12 @@ Slice::Ruby::compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index e79c065cde8..b27f91d75bb 100644 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -12,7 +12,6 @@ #include <Slice/Util.h> #include <IceUtil/Functional.h> #include <IceUtil/InputUtil.h> -#include <IceUtil/Unicode.h> #include <iterator> using namespace std; @@ -20,6 +19,27 @@ using namespace Slice; using namespace IceUtil; using namespace IceUtilInternal; + +namespace +{ + +string +getEscapedParamName(const OperationPtr& p, const string& name) +{ + ParamDeclList params = p->parameters(); + + for(ParamDeclList::const_iterator i = params.begin(); i != params.end(); ++i) + { + if((*i)->name() == name) + { + return name + "_"; + } + } + return name; +} + +} + namespace Slice { namespace Ruby @@ -48,12 +68,12 @@ public: private: // - // Return a Python symbol for the given parser element. + // Return a Ruby symbol for the given parser element. // string getSymbol(const ContainedPtr&); // - // Emit Python code to assign the given symbol in the current module. + // Emit Ruby code to assign the given symbol in the current module. // void registerName(const string&); @@ -214,225 +234,54 @@ Slice::Ruby::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) bool Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { - string scoped = p->scoped(); - string name = fixIdent(p->name(), IdentToUpper); - ClassList bases = p->bases(); - ClassDefPtr base; - OperationList ops = p->operations(); + bool isInterface = p->isInterface(); + bool isLocal = p->isLocal(); + bool isAbstract = isInterface || p->allOperations().size() > 0; // Don't use isAbstract() - see bug 3739 + // - // Define a mix-in module for the class. + // Do not generate any code for local interfaces. // - _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << "_mixin)"; - _out.inc(); - _out << nl << "module " << name << "_mixin"; - _out.inc(); - - if(!p->isLocal()) + if(isLocal && isInterface) { - if(!bases.empty() && !bases.front()->isInterface()) - { - base = bases.front(); - _out << nl << "include " << getAbsolute(bases.front(), IdentToUpper) << "_mixin"; - } - else - { - _out << nl << "include ::Ice::Object_mixin"; - } - - // - // ice_ids - // - ClassList allBases = p->allBases(); - StringList ids; - transform(allBases.begin(), allBases.end(), back_inserter(ids), IceUtil::constMemFun(&Contained::scoped)); - StringList other; - other.push_back(scoped); - other.push_back("::Ice::Object"); - other.sort(); - ids.merge(other); - ids.unique(); - _out << sp << nl << "def ice_ids(current=nil)"; - _out.inc(); - _out << nl << "["; - for(StringList::iterator q = ids.begin(); q != ids.end(); ++q) - { - if(q != ids.begin()) - { - _out << ", "; - } - _out << "'" << *q << "'"; - } - _out << ']'; - _out.dec(); - _out << nl << "end"; - - // - // ice_id - // - _out << sp << nl << "def ice_id(current=nil)"; - _out.inc(); - _out << nl << "'" << scoped << "'"; - _out.dec(); - _out << nl << "end"; + return false; } - if(!ops.empty()) - { - // - // Emit a comment for each operation. - // - _out << sp - << nl << "#" - << nl << "# Operation signatures." - << nl << "#"; - for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) - { - string fixedOpName = fixIdent((*oli)->name(), IdentNormal); -/* If AMI/AMD is ever implemented... - if(!p->isLocal() && (p->hasMetaData("amd") || (*oli)->hasMetaData("amd"))) - { - _out << nl << "# def " << fixedOpName << "_async(_cb"; - - ParamDeclList params = (*oli)->parameters(); - - for(ParamDeclList::iterator pli = params.begin(); pli != params.end(); ++pli) - { - if(!(*pli)->isOutParam()) - { - _out << ", " << fixIdent((*pli)->name(), IdentToLower); - } - } - if(!p->isLocal()) - { - _out << ", current=nil"; - } - _out << ")"; - } - else -*/ - { - _out << nl << "# def " << fixedOpName << "("; - - ParamDeclList params = (*oli)->parameters(); - - bool first = true; - for(ParamDeclList::iterator pli = params.begin(); pli != params.end(); ++pli) - { - if(!(*pli)->isOutParam()) - { - if(first) - { - first = false; - } - else - { - _out << ", "; - } - _out << fixIdent((*pli)->name(), IdentToLower); - } - } - if(!p->isLocal()) - { - if(!first) - { - _out << ", "; - } - _out << "current=nil"; - } - _out << ")"; - } - } - } + _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << "_Mixin)"; + _out.inc(); // - // inspect + // Marker to avoid redefinitions, we don't use the actual class names at those might + // be defined by IceRuby for some internal classes // - _out << sp << nl << "def inspect"; - _out.inc(); - _out << nl << "::Ice::__stringify(self, T_" << name << ")"; - _out.dec(); + _out << sp << nl << "module " << getAbsolute(p, IdentToUpper) << "_Mixin"; _out << nl << "end"; + + string scoped = p->scoped(); + string name = fixIdent(p->name(), IdentToUpper); + ClassList bases = p->bases(); + ClassDefPtr base; + OperationList ops = p->operations(); - // - // read/write accessors for data members. - // DataMemberList members = p->dataMembers(); - if(!members.empty()) - { - bool prot = p->hasMetaData("protected"); - DataMemberList protectedMembers; - _out << sp << nl << "attr_accessor "; - for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q) - { - if(q != members.begin()) - { - _out << ", "; - } - _out << ":" << fixIdent((*q)->name(), IdentNormal); - if(prot || (*q)->hasMetaData("protected")) - { - protectedMembers.push_back(*q); - } - } - - if(!protectedMembers.empty()) + if(isLocal || !isInterface) + { + if(!bases.empty() && !bases.front()->isInterface()) { - _out << nl << "protected "; - for(DataMemberList::iterator q = protectedMembers.begin(); q != protectedMembers.end(); ++q) - { - if(q != protectedMembers.begin()) - { - _out << ", "; - } - // - // We need to list the symbols of the reader and the writer (e.g., ":member" and ":member="). - // - _out << ":" << fixIdent((*q)->name(), IdentNormal) << ", :" - << fixIdent((*q)->name(), IdentNormal) << '='; - } + base = bases.front(); } - } - _out.dec(); - _out << nl << "end"; // End of mix-in module for class. - - if(p->isInterface()) - { - // - // Class. - // - _out << nl << "class " << name; - _out.inc(); - _out << nl << "include " << name << "_mixin"; - _out << nl; - _out << nl << "def " << name << ".ice_staticId()"; - _out.inc(); - _out << nl << "'" << scoped << "'"; - _out.dec(); - _out << nl << "end"; - _out.dec(); - _out << nl << "end"; - } - else - { - // - // Class. - // _out << nl << "class " << name; if(base) { _out << " < " << getAbsolute(base, IdentToUpper); } + else if(!isLocal) + { + _out << " < ::Ice::Value"; + } _out.inc(); - _out << nl << "include " << name << "_mixin"; - _out << nl; - _out << nl << "def " << name << ".ice_staticId()"; - _out.inc(); - _out << nl << "'" << scoped << "'"; - _out.dec(); - _out << nl << "end"; // // initialize @@ -480,6 +329,47 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out.dec(); _out << nl << "end"; } + + // + // read/write accessors for data members. + // + DataMemberList members = p->dataMembers(); + if(!members.empty()) + { + bool prot = p->hasMetaData("protected"); + DataMemberList protectedMembers; + + _out << sp << nl << "attr_accessor "; + for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + { + if(q != members.begin()) + { + _out << ", "; + } + _out << ":" << fixIdent((*q)->name(), IdentNormal); + if(prot || (*q)->hasMetaData("protected")) + { + protectedMembers.push_back(*q); + } + } + + if(!protectedMembers.empty()) + { + _out << nl << "protected "; + for(DataMemberList::iterator q = protectedMembers.begin(); q != protectedMembers.end(); ++q) + { + if(q != protectedMembers.begin()) + { + _out << ", "; + } + // + // We need to list the symbols of the reader and the writer (e.g., ":member" and ":member="). + // + _out << ":" << fixIdent((*q)->name(), IdentNormal) << ", :" + << fixIdent((*q)->name(), IdentNormal) << '='; + } + } + } _out.dec(); _out << nl << "end"; // End of class. @@ -489,13 +379,17 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // Generate proxy support. This includes a mix-in module for the proxy's // operations and a class for the proxy itself. // - if(!p->isLocal()) + if(!p->isLocal() && isAbstract) { _out << nl << "module " << name << "Prx_mixin"; _out.inc(); for(ClassList::iterator cli = bases.begin(); cli != bases.end(); ++cli) { - _out << nl << "include " << getAbsolute(*cli, IdentToUpper) << "Prx_mixin"; + ClassDefPtr def = *cli; + if(def->isInterface() || def->allOperations().size() > 0) + { + _out << nl << "include " << getAbsolute(*cli, IdentToUpper) << "Prx_mixin"; + } } for(OperationList::iterator oli = ops.begin(); oli != ops.end(); ++oli) { @@ -525,38 +419,21 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << inParams << ", "; } - _out << "_ctx=nil)"; + const string contextParamName = getEscapedParamName(*oli, "context"); + _out << contextParamName << "=nil)"; _out.inc(); - _out << nl << name << "_mixin::OP_" << (*oli)->name() << ".invoke(self, [" << inParams; - _out << "], _ctx)"; + _out << nl << name << "Prx_mixin::OP_" << (*oli)->name() << ".invoke(self, [" << inParams; + _out << "], " << contextParamName << ")"; _out.dec(); _out << nl << "end"; } _out.dec(); _out << nl << "end"; // End of mix-in module for proxy. - _out << nl << "class " << name << "Prx < ::Ice::ObjectPrx"; + _out << sp << nl << "class " << name << "Prx < ::Ice::ObjectPrx"; _out.inc(); + _out << nl << "include ::Ice::Proxy_mixin"; _out << nl << "include " << name << "Prx_mixin"; - - _out << sp << nl << "def " << name << "Prx.checkedCast(proxy, facetOrCtx=nil, _ctx=nil)"; - _out.inc(); - _out << nl << "ice_checkedCast(proxy, '" << scoped << "', facetOrCtx, _ctx)"; - _out.dec(); - _out << nl << "end"; - - _out << sp << nl << "def " << name << "Prx.uncheckedCast(proxy, facet=nil)"; - _out.inc(); - _out << nl << "ice_uncheckedCast(proxy, facet)"; - _out.dec(); - _out << nl << "end"; - - _out << nl << "def " << name << "Prx.ice_staticId()"; - _out.inc(); - _out << nl << "'" << scoped << "'"; - _out.dec(); - _out << nl << "end"; - _out.dec(); _out << nl << "end"; // End of proxy class. } @@ -564,7 +441,12 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // // Emit type descriptions. // - _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_") << ')'; + _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_"); + if(isInterface) + { + _out << "Prx"; + } + _out << ')'; _out.inc(); if(p->isLocal()) { @@ -573,16 +455,23 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) else { _out << nl << "T_" << name << " = ::Ice::__declareClass('" << scoped << "')"; - _out << nl << "T_" << name << "Prx = ::Ice::__declareProxy('" << scoped << "')"; + if(isAbstract) + { + _out << nl << "T_" << name << "Prx = ::Ice::__declareProxy('" << scoped << "')"; + } } _out.dec(); _out << nl << "end"; _classHistory.insert(scoped); // Avoid redundant declarations. - bool isAbstract = p->isInterface() || p->allOperations().size() > 0; // Don't use isAbstract() here - see bug 3739 const bool preserved = p->hasMetaData("preserve-slice") || p->inheritsMetaData("preserve-slice"); - _out << sp << nl << "T_" << name << ".defineClass(" << name << ", " << p->compactId() << ", " - << (isAbstract ? "true" : "false") << ", " << (preserved ? "true" : "false") << ", "; + + + _out << sp << nl << "T_" << name << ".defineClass(" + << (isInterface ? "::Ice::Value" : name) << ", " + << p->compactId() << ", " + << (preserved ? "true" : "false") << ", " + << (isInterface ? "true" : "false") << ", "; if(!base) { _out << "nil"; @@ -591,25 +480,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << getAbsolute(base, IdentToUpper, "T_"); } - _out << ", ["; - // - // Interfaces - // - { - int interfaceCount = 0; - for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) - { - if((*q)->isInterface()) - { - if(interfaceCount > 0) - { - _out << ", "; - } - _out << getAbsolute(*q, IdentToUpper, "T_"); - ++interfaceCount; - } - } - } + _out << ", "; // // Members // @@ -619,7 +490,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. // - _out << "], ["; + _out << "["; if(members.size() > 1) { _out.inc(); @@ -644,7 +515,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl; } _out << "])"; - _out << nl << name << "_mixin::ICE_TYPE = T_" << name; + // // Define each operation. The arguments to __defineOperation are: @@ -654,10 +525,39 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // where InParams and OutParams are arrays of type descriptions, and Exceptions // is an array of exception types. // - if(!p->isLocal()) + if(!p->isLocal() && isAbstract) { - _out << sp << nl << "T_" << name << "Prx.defineProxy(" << name << "Prx, T_" << name << ')'; - _out << nl << name << "Prx::ICE_TYPE = T_" << name << "Prx"; + _out << sp << nl << "T_" << name << "Prx.defineProxy(" << name << "Prx, "; + + if(!base || (!base->isInterface() && base->allOperations().size() == 0)) + { + _out << "nil"; + } + else + { + _out << getAbsolute(base, IdentToUpper, "T_") << "Prx"; + } + + // + // Interfaces + // + _out << ", ["; + { + int interfaceCount = 0; + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) + { + if((*q)->isInterface()) + { + if(interfaceCount > 0) + { + _out << ", "; + } + _out << getAbsolute(*q, IdentToUpper, "T_") << "Prx"; + ++interfaceCount; + } + } + } + _out << "])"; if(!ops.empty()) { @@ -682,7 +582,7 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) break; } - _out << nl << name << "_mixin::OP_" << (*s)->name() << " = ::Ice::__defineOperation('" + _out << nl << name << "Prx_mixin::OP_" << (*s)->name() << " = ::Ice::__defineOperation('" << (*s)->name() << "', "; switch((*s)->mode()) { @@ -781,11 +681,11 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { msg = deprecateMetadata.substr(pos + 1); } - _out << nl << name << "_mixin::OP_" << (*s)->name() << ".deprecate(\"" << msg << "\")"; + _out << nl << name << "Prx_mixin::OP_" << (*s)->name() << ".deprecate(\"" << msg << "\")"; } } } - + _out.dec(); _out << nl << "end"; // if not defined?() @@ -871,7 +771,7 @@ Slice::Ruby::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) // _out << sp << nl << "def to_s"; _out.inc(); - _out << nl << "'" << scoped.substr(2) << "'"; + _out << nl << "'" << scoped << "'"; _out.dec(); _out << nl << "end"; @@ -938,7 +838,6 @@ Slice::Ruby::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) _out << nl; } _out << "])"; - _out << nl << name << "::ICE_TYPE = T_" << name; _out.dec(); _out << nl << "end"; // if not defined?() @@ -969,6 +868,7 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) _out.inc(); _out << nl << "class " << name; _out.inc(); + _out << nl << "include ::Ice::Inspect_mixin"; if(!memberList.empty()) { _out << nl << "def initialize("; @@ -1027,15 +927,6 @@ Slice::Ruby::CodeVisitor::visitStructStart(const StructPtr& p) _out << nl << "end"; // - // inspect - // - _out << sp << nl << "def inspect"; - _out.inc(); - _out << nl << "::Ice::__stringify(self, T_" << name << ")"; - _out.dec(); - _out << nl << "end"; - - // // read/write accessors for data members. // if(!memberList.empty()) @@ -1134,7 +1025,7 @@ Slice::Ruby::CodeVisitor::visitEnum(const EnumPtr& p) { string scoped = p->scoped(); string name = fixIdent(p->name(), IdentToUpper); - EnumeratorList enums = p->getEnumerators(); + EnumeratorList enums = p->enumerators(); _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << ')'; _out.inc(); @@ -1199,15 +1090,6 @@ Slice::Ruby::CodeVisitor::visitEnum(const EnumPtr& p) _out << nl << "end"; // - // inspect - // - _out << sp << nl << "def inspect"; - _out.inc(); - _out << nl << "@name + \"(#{@value})\""; - _out.dec(); - _out << nl << "end"; - - // // each // _out << sp << nl << "def " << name << ".each(&block)"; @@ -1319,9 +1201,10 @@ Slice::Ruby::CodeVisitor::writeType(const TypePtr& p) _out << "::Ice::T_string"; break; } + case Builtin::KindValue: case Builtin::KindObject: { - _out << "::Ice::T_Object"; + _out << "::Ice::T_Value"; break; } case Builtin::KindObjectProxy: @@ -1337,11 +1220,19 @@ Slice::Ruby::CodeVisitor::writeType(const TypePtr& p) } return; } - + ProxyPtr prx = ProxyPtr::dynamicCast(p); if(prx) { - _out << getAbsolute(prx->_class(), IdentToUpper, "T_") << "Prx"; + ClassDefPtr def = prx->_class()->definition(); + if(def->isInterface() || def->allOperations().size() > 0) + { + _out << getAbsolute(prx->_class(), IdentToUpper, "T_") << "Prx"; + } + else + { + _out << "::Ice::T_ObjectPrx"; + } return; } @@ -1379,6 +1270,7 @@ Slice::Ruby::CodeVisitor::getInitializer(const DataMemberPtr& m) { return "''"; } + case Builtin::KindValue: case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: @@ -1391,7 +1283,7 @@ Slice::Ruby::CodeVisitor::getInitializer(const DataMemberPtr& m) EnumPtr en = EnumPtr::dynamicCast(p); if(en) { - EnumeratorList enums = en->getEnumerators(); + EnumeratorList enums = en->enumerators(); return getAbsolute(en, IdentToUpper) + "::" + fixIdent(enums.front()->name(), IdentToUpper); } @@ -1446,152 +1338,12 @@ Slice::Ruby::CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTr } case Slice::Builtin::KindString: { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=, '"; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - - _out << "\""; // Opening " - - for(size_t i = 0; i < value.size();) - { - char c = value[i]; - switch(c) - { - case '"': - { - _out << "\\\""; - break; - } - case '\\': - { - string s = "\\"; - size_t j = i + 1; - for(; j < value.size(); ++j) - { - if(value[j] != '\\') - { - break; - } - s += "\\"; - } - - // - // An even number of slash \ will escape the backslash and - // the codepoint will be interpreted as its charaters - // - // \\u00000041 - ['\\', 'u', '0', '0', '0', '0', '0', '0', '4', '1'] - // \\\u00000041 - ['\\', 'A'] (41 is the codepoint for 'A') - // - if(s.size() % 2 != 0 && (value[j] == 'U' || value[j] == 'u')) - { - // - // Convert codepoint to UTF8 bytes and write the escaped bytes - // - _out << s.substr(0, s.size() - 1); - - size_t sz = value[j] == 'U' ? 8 : 4; - string codepoint = value.substr(j + 1, sz); - assert(codepoint.size() == sz); - IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16); - - vector<unsigned int> u32buffer; - u32buffer.push_back(static_cast<unsigned int>(v)); - - vector<unsigned char> u8buffer; - IceUtilInternal::ConversionResult result = convertUTF32ToUTF8(u32buffer, u8buffer, IceUtil::lenientConversion); - switch(result) - { - case conversionOK: - break; - case sourceExhausted: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source exhausted"); - case sourceIllegal: - throw IceUtil::IllegalConversionException(__FILE__, __LINE__, "string source illegal"); - default: - { - assert(0); - throw IceUtil::IllegalConversionException(__FILE__, __LINE__); - } - } - - ostringstream s; - for(vector<unsigned char>::const_iterator q = u8buffer.begin(); q != u8buffer.end(); ++q) - { - s << "\\"; - s.fill('0'); - s.width(3); - s << oct; - s << static_cast<unsigned int>(*q); - } - _out << s.str(); - - i = j + 1 + sz; - } - else - { - _out << s; - i = j; - } - continue; - } - case '\r': - { - _out << "\\r"; - break; - } - case '\n': - { - _out << "\\n"; - break; - } - case '\t': - { - _out << "\\t"; - break; - } - case '\b': - { - _out << "\\b"; - break; - } - case '\f': - { - _out << "\\f"; - break; - } - default: - { - if(charSet.find(c) == charSet.end()) - { - unsigned char uc = c; // Char may be signed, so make it positive. - stringstream s; - s << "\\"; // Print as octal if not in basic source character set. - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast<unsigned>(uc); - _out << s.str(); - } - else - { - _out << c; // Print normally if in basic source character set. - } - break; - } - } - ++i; - } - - _out << "\""; // Closing " + // RubyUCN available in Ruby 1.9 or greater + _out << "\"" << toStringLiteral(value, "\a\b\f\n\r\t\v\x20\x1b", "", EC6UCN, 0) << "\""; break; } + case Slice::Builtin::KindValue: case Slice::Builtin::KindObject: case Slice::Builtin::KindObjectProxy: case Slice::Builtin::KindLocalObject: @@ -1600,16 +1352,9 @@ Slice::Ruby::CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTr } else if(en) { - _out << getAbsolute(en, IdentToUpper) << "::"; - string::size_type colon = value.rfind(':'); - if(colon != string::npos) - { - _out << fixIdent(value.substr(colon + 1), IdentToUpper); - } - else - { - _out << fixIdent(value, IdentToUpper); - } + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); + assert(lte); + _out << getAbsolute(lte, IdentToUpper); } else { diff --git a/cpp/src/Slice/RubyUtil.h b/cpp/src/Slice/RubyUtil.h new file mode 100644 index 00000000000..e67ecd1b623 --- /dev/null +++ b/cpp/src/Slice/RubyUtil.h @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_RUBY_UTIL_H +#define SLICE_RUBY_UTIL_H + +#include <Slice/Parser.h> +#include <IceUtil/OutputUtil.h> + +namespace Slice +{ +namespace Ruby +{ + +// +// Generate Ruby code for a translation unit. +// +void generate(const Slice::UnitPtr&, bool, bool, const std::vector<std::string>&, IceUtilInternal::Output&); + +// +// Check the given identifier against Ruby's list of reserved words. If it matches +// a reserved word, then an escaped version is returned with a leading underscore. +// +enum IdentStyle +{ + IdentNormal, + IdentToUpper, // Mapped identifier must begin with an upper-case letter. + IdentToLower // Mapped identifier must begin with a lower-case letter. +}; +std::string fixIdent(const std::string&, IdentStyle); + +// +// Get the fully-qualified name of the given definition. If a prefix is provided, +// it is prepended to the definition's unqualified name. +// +std::string getAbsolute(const Slice::ContainedPtr&, IdentStyle, const std::string& = std::string()); + +// +// Emit a comment header. +// +void printHeader(IceUtilInternal::Output&); + +int compile(const std::vector<std::string>&); + +} +} + +#endif diff --git a/cpp/src/Slice/Scanner.cpp b/cpp/src/Slice/Scanner.cpp index e7f9600233a..b338b8e5390 100644 --- a/cpp/src/Slice/Scanner.cpp +++ b/cpp/src/Slice/Scanner.cpp @@ -1,7 +1,7 @@ #include <IceUtil/ScannerConfig.h> -#line 2 "lex.yy.c" +#line 1 "lex.yy.c" -#line 4 "lex.yy.c" +#line 3 "lex.yy.c" #define YY_INT_ALIGNED short int @@ -28,12 +28,90 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 39 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 3 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif + #define yy_create_buffer slice__create_buffer + + #define yy_delete_buffer slice__delete_buffer + + #define yy_scan_buffer slice__scan_buffer + + #define yy_scan_string slice__scan_string + + #define yy_scan_bytes slice__scan_bytes + + #define yy_init_buffer slice__init_buffer + + #define yy_flush_buffer slice__flush_buffer + + #define yy_load_buffer_state slice__load_buffer_state + + #define yy_switch_to_buffer slice__switch_to_buffer + + #define yypush_buffer_state slice_push_buffer_state + + #define yypop_buffer_state slice_pop_buffer_state + + #define yyensure_buffer_stack slice_ensure_buffer_stack + + #define yylex slice_lex + + #define yyrestart slice_restart + + #define yylex_init slice_lex_init + + #define yylex_init_extra slice_lex_init_extra + + #define yylex_destroy slice_lex_destroy + + #define yyget_debug slice_get_debug + + #define yyset_debug slice_set_debug + + #define yyget_extra slice_get_extra + + #define yyset_extra slice_set_extra + + #define yyget_in slice_get_in + + #define yyset_in slice_set_in + + #define yyget_out slice_get_out + + #define yyset_out slice_set_out + + #define yyget_leng slice_get_leng + + #define yyget_text slice_get_text + + #define yyget_lineno slice_get_lineno + + #define yyset_lineno slice_set_lineno + + #define yywrap slice_wrap + + #define yyalloc slice_alloc + + #define yyrealloc slice_realloc + + #define yyfree slice_free + + #define yytext slice_text + + #define yyleng slice_leng + + #define yyin slice_in + + #define yyout slice_out + + #define yy_flex_debug slice__flex_debug + + #define yylineno slice_lineno + /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ @@ -108,56 +186,38 @@ typedef unsigned int flex_uint32_t; #endif /* ! FLEXINT_H */ -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST +/* TODO: this is always defined, so inline it */ #define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) #else -#define yyconst +#define yynoreturn #endif /* Returned upon end-of-file. */ #define YY_NULL 0 -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * - /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START - /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE slice_restart(slice_in ) - #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -187,14 +247,14 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern yy_size_t slice_leng; +extern int slice_leng; extern FILE *slice_in, *slice_out; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - + #define YY_LESS_LINENO(n) #define YY_LINENO_REWIND_TO(ptr) @@ -211,7 +271,6 @@ extern FILE *slice_in, *slice_out; YY_DO_BEFORE_ACTION; /* set up slice_text again */ \ } \ while ( 0 ) - #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_STRUCT_YY_BUFFER_STATE @@ -226,12 +285,12 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - yy_size_t yy_buf_size; + int yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - yy_size_t yy_n_chars; + int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -254,7 +313,7 @@ struct yy_buffer_state int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ - + /* Whether to try to fill the input buffer when we reach the * end of it. */ @@ -282,7 +341,7 @@ struct yy_buffer_state /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general @@ -293,7 +352,6 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) - /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ @@ -301,11 +359,11 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when slice_text is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t slice_leng; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int slice_leng; /* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; +static char *yy_c_buf_p = NULL; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ @@ -314,30 +372,28 @@ static int yy_start = 0; /* start state number */ */ static int yy_did_buffer_switch_on_eof; -void slice_restart (FILE *input_file ); -void slice__switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE slice__create_buffer (FILE *file,int size ); -void slice__delete_buffer (YY_BUFFER_STATE b ); -void slice__flush_buffer (YY_BUFFER_STATE b ); -void slice_push_buffer_state (YY_BUFFER_STATE new_buffer ); -void slice_pop_buffer_state (void ); - -static void slice_ensure_buffer_stack (void ); -static void slice__load_buffer_state (void ); -static void slice__init_buffer (YY_BUFFER_STATE b,FILE *file ); - +void slice_restart ( FILE *input_file ); +void slice__switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE slice__create_buffer ( FILE *file, int size ); +void slice__delete_buffer ( YY_BUFFER_STATE b ); +void slice__flush_buffer ( YY_BUFFER_STATE b ); +void slice_push_buffer_state ( YY_BUFFER_STATE new_buffer ); +void slice_pop_buffer_state ( void ); + +static void slice_ensure_buffer_stack ( void ); +static void slice__load_buffer_state ( void ); +static void slice__init_buffer ( YY_BUFFER_STATE b, FILE *file ); #define YY_FLUSH_BUFFER slice__flush_buffer(YY_CURRENT_BUFFER ) -YY_BUFFER_STATE slice__scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE slice__scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE slice__scan_bytes (yyconst char *bytes,yy_size_t len ); +YY_BUFFER_STATE slice__scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE slice__scan_string ( const char *yy_str ); +YY_BUFFER_STATE slice__scan_bytes ( const char *bytes, int len ); -void *slice_alloc (yy_size_t ); -void *slice_realloc (void *,yy_size_t ); -void slice_free (void * ); +void *slice_alloc ( yy_size_t ); +void *slice_realloc ( void *, yy_size_t ); +void slice_free ( void * ); #define yy_new_buffer slice__create_buffer - #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ @@ -347,7 +403,6 @@ void slice_free (void * ); } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } - #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ @@ -357,42 +412,41 @@ void slice_free (void * ); } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } - #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define slice_wrap() 1 +#define slice_wrap() (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP +typedef flex_uint8_t YY_CHAR; -typedef unsigned char YY_CHAR; - -FILE *slice_in = (FILE *) 0, *slice_out = (FILE *) 0; +FILE *slice_in = NULL, *slice_out = NULL; typedef int yy_state_type; extern int slice_lineno; - int slice_lineno = 1; extern char *slice_text; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #define yytext_ptr slice_text -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); /* Done after the current pattern has been matched and before the * corresponding action - sets up slice_text. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - slice_leng = (size_t) (yy_cp - yy_bp); \ + slice_leng = (int) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; - #define YY_NUM_RULES 20 #define YY_END_OF_BUFFER 21 /* This struct is not used in this scanner, @@ -402,7 +456,7 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[73] = +static const flex_int16_t yy_accept[73] = { 0, 0, 0, 0, 0, 0, 0, 21, 19, 17, 17, 14, 19, 19, 19, 15, 15, 19, 13, 8, 19, @@ -414,7 +468,7 @@ static yyconst flex_int16_t yy_accept[73] = 4, 0 } ; -static yyconst flex_int32_t yy_ec[256] = +static const YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, @@ -446,7 +500,7 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[32] = +static const YY_CHAR yy_meta[32] = { 0, 1, 2, 3, 4, 1, 1, 4, 1, 5, 5, 1, 1, 6, 6, 6, 1, 7, 7, 7, 8, @@ -454,7 +508,7 @@ static yyconst flex_int32_t yy_meta[32] = 1 } ; -static yyconst flex_int16_t yy_base[85] = +static const flex_int16_t yy_base[85] = { 0, 0, 185, 0, 26, 0, 184, 189, 192, 192, 192, 192, 22, 25, 33, 47, 35, 153, 40, 147, 0, @@ -467,7 +521,7 @@ static yyconst flex_int16_t yy_base[85] = 156, 164, 170, 179 } ; -static yyconst flex_int16_t yy_def[85] = +static const flex_int16_t yy_def[85] = { 0, 72, 1, 1, 1, 1, 1, 72, 72, 72, 72, 72, 72, 72, 72, 72, 15, 72, 73, 72, 74, @@ -480,7 +534,7 @@ static yyconst flex_int16_t yy_def[85] = 72, 72, 72, 72 } ; -static yyconst flex_int16_t yy_nxt[224] = +static const flex_int16_t yy_nxt[224] = { 0, 8, 9, 10, 9, 11, 8, 8, 8, 12, 12, 13, 14, 15, 16, 16, 17, 18, 18, 18, 18, @@ -509,7 +563,7 @@ static yyconst flex_int16_t yy_nxt[224] = 72, 72, 72 } ; -static yyconst flex_int16_t yy_chk[224] = +static const flex_int16_t yy_chk[224] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -552,8 +606,8 @@ int slice__flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *slice_text; -#line 1 "Scanner.l" -#line 2 "Scanner.l" +#line 1 "src/Slice/Scanner.l" +#line 2 "src/Slice/Scanner.l" // ********************************************************************** // @@ -564,7 +618,7 @@ char *slice_text; // // ********************************************************************** -#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined +#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined #include <Slice/Grammar.h> #include <IceUtil/InputUtil.h> @@ -593,6 +647,10 @@ char *slice_text; # pragma warning( 4 : 4018 ) #endif +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wsign-compare" +#endif + #ifdef _MSC_VER # ifdef slice_wrap # undef slice_wrap @@ -607,7 +665,7 @@ char *slice_text; # define slice_wrap() 1 # endif # ifdef ICE_64 -# pragma error_messages(off,truncwarn) +# pragma error_messages(off,truncwarn) # endif #endif @@ -620,7 +678,7 @@ namespace Slice // // Definitions for the case-insensitive keyword-token map. // -typedef std::map<std::string, int, Slice::CICompare> StringTokenMap; +typedef std::map<std::string, int> StringTokenMap; static StringTokenMap keywordMap; void initScanner(); @@ -628,11 +686,11 @@ int checkKeyword(string&); } -#define YY_USER_INIT initScanner(); - +#define YY_USER_INIT initScanner(); +#line 690 "lex.yy.c" -#line 635 "lex.yy.c" +#line 692 "lex.yy.c" #define INITIAL 0 #define BOMSCAN 1 @@ -650,36 +708,36 @@ int checkKeyword(string&); #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals (void ); +static int yy_init_globals ( void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int slice_lex_destroy (void ); +int slice_lex_destroy ( void ); -int slice_get_debug (void ); +int slice_get_debug ( void ); -void slice_set_debug (int debug_flag ); +void slice_set_debug ( int debug_flag ); -YY_EXTRA_TYPE slice_get_extra (void ); +YY_EXTRA_TYPE slice_get_extra ( void ); -void slice_set_extra (YY_EXTRA_TYPE user_defined ); +void slice_set_extra ( YY_EXTRA_TYPE user_defined ); -FILE *slice_get_in (void ); +FILE *slice_get_in ( void ); -void slice_set_in (FILE * in_str ); +void slice_set_in ( FILE * _in_str ); -FILE *slice_get_out (void ); +FILE *slice_get_out ( void ); -void slice_set_out (FILE * out_str ); +void slice_set_out ( FILE * _out_str ); -yy_size_t slice_get_leng (void ); + int slice_get_leng ( void ); -char *slice_get_text (void ); +char *slice_get_text ( void ); -int slice_get_lineno (void ); +int slice_get_lineno ( void ); -void slice_set_lineno (int line_number ); +void slice_set_lineno ( int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -687,28 +745,31 @@ void slice_set_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int slice_wrap (void ); +extern "C" int slice_wrap ( void ); #else -extern int slice_wrap (void ); +extern int slice_wrap ( void ); #endif #endif - static void yyunput (int c,char *buf_ptr ); +#ifndef YY_NO_UNPUT + static void yyunput ( int c, char *buf_ptr ); + +#endif + #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy ( char *, const char *, int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen ( const char * ); #endif #ifndef YY_NO_INPUT - #ifdef __cplusplus -static int yyinput (void ); +static int yyinput ( void ); #else -static int input (void ); +static int input ( void ); #endif #endif @@ -728,7 +789,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( slice_text, slice_leng, 1, slice_out )) {} } while (0) +#define ECHO do { if (fwrite( slice_text, (size_t) slice_leng, 1, slice_out )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -739,7 +800,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - size_t n; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( slice_in )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -752,7 +813,7 @@ static int input (void ); else \ { \ errno=0; \ - while ( (result = fread(buf, 1, max_size, slice_in))==0 && ferror(slice_in)) \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, slice_in)) == 0 && ferror(slice_in)) \ { \ if( errno != EINTR) \ { \ @@ -807,7 +868,7 @@ extern int slice_lex (void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -820,9 +881,9 @@ extern int slice_lex (void); */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; if ( !(yy_init) ) { @@ -851,12 +912,12 @@ YY_DECL } { -#line 94 "Scanner.l" +#line 98 "src/Slice/Scanner.l" -#line 857 "lex.yy.c" +#line 917 "lex.yy.c" - while ( 1 ) /* loops until end-of-file is reached */ + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); @@ -873,7 +934,7 @@ YY_DECL yy_match: do { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -883,9 +944,9 @@ yy_match: { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 73 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } while ( yy_current_state != 72 ); @@ -913,9 +974,9 @@ case 1: (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up slice_text again */ YY_RULE_SETUP -#line 96 "Scanner.l" +#line 100 "src/Slice/Scanner.l" { - if(unit->scanPosition(slice_text)) + if(unit->scanPosition(yytext)) { BEGIN(BOMSCAN); } @@ -928,9 +989,9 @@ YY_LINENO_REWIND_TO(yy_cp - 1); (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up slice_text again */ YY_RULE_SETUP -#line 103 "Scanner.l" +#line 107 "src/Slice/Scanner.l" { - if(unit->scanPosition(slice_text)) + if(unit->scanPosition(yytext)) { BEGIN(BOMSCAN); } @@ -941,9 +1002,9 @@ case 3: (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up slice_text again */ YY_RULE_SETUP -#line 110 "Scanner.l" +#line 114 "src/Slice/Scanner.l" { - if(unit->scanPosition(slice_text)) + if(unit->scanPosition(yytext)) { BEGIN(BOMSCAN); } @@ -956,9 +1017,9 @@ YY_LINENO_REWIND_TO(yy_cp - 1); (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up slice_text again */ YY_RULE_SETUP -#line 117 "Scanner.l" +#line 121 "src/Slice/Scanner.l" { - if(unit->scanPosition(slice_text)) + if(unit->scanPosition(yytext)) { BEGIN(BOMSCAN); } @@ -966,69 +1027,69 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 124 "Scanner.l" +#line 128 "src/Slice/Scanner.l" { // C++-style comment BEGIN(MAINSCAN); int c; do { - c = yyinput(); - if(c == '\n') - { - unit->nextLine(); - } + c = yyinput(); + if(c == '\n') + { + unit->nextLine(); + } } while(c != '\n' && c != EOF); } YY_BREAK case 6: YY_RULE_SETUP -#line 139 "Scanner.l" +#line 143 "src/Slice/Scanner.l" { // C-style comment BEGIN(MAINSCAN); - string comment = slice_text + 2; + string comment = yytext + 2; while(true) { - int c = yyinput(); - if(c == '\n') - { - comment += static_cast<char>(c); - unit->nextLine(); - } - else if(c == '*') - { - int next = yyinput(); - if(next == '/') - { - break; - } - else - { - comment += static_cast<char>(c); - unput(next); - } - } - else if(c == EOF) - { - unit->warning("EOF in comment"); - break; - } - else - { - comment += static_cast<char>(c); - } + int c = yyinput(); + if(c == '\n') + { + comment += static_cast<char>(c); + unit->nextLine(); + } + else if(c == '*') + { + int next = yyinput(); + if(next == '/') + { + break; + } + else + { + comment += static_cast<char>(c); + unput(next); + } + } + else if(c == EOF) + { + unit->warning(All, "EOF in comment"); + break; + } + else + { + comment += static_cast<char>(c); + } } if(!comment.empty() && comment[0] == '*') { - unit->setComment(comment); + unit->setComment(comment); } } YY_BREAK case 7: YY_RULE_SETUP -#line 180 "Scanner.l" +#line 184 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); return ICE_SCOPE_DELIMITER; @@ -1036,7 +1097,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 185 "Scanner.l" +#line 189 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); return ICE_METADATA_OPEN; @@ -1044,7 +1105,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 190 "Scanner.l" +#line 194 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); return ICE_METADATA_CLOSE; @@ -1052,7 +1113,7 @@ YY_RULE_SETUP YY_BREAK case 10: YY_RULE_SETUP -#line 195 "Scanner.l" +#line 199 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); return ICE_GLOBAL_METADATA_OPEN; @@ -1060,7 +1121,7 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 200 "Scanner.l" +#line 204 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); return ICE_GLOBAL_METADATA_CLOSE; @@ -1069,14 +1130,14 @@ YY_RULE_SETUP case 12: /* rule 12 can match eol */ YY_RULE_SETUP -#line 205 "Scanner.l" +#line 209 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); StringTokPtr ident = new StringTok; - ident->v = *slice_text == '\\' ? slice_text + 1 : slice_text; + ident->v = *yytext == '\\' ? yytext + 1 : yytext; ident->v.erase(ident->v.find_first_of(" \t\v\n\r\f(")); *yylvalp = ident; - if(*slice_text == '\\') + if(*yytext == '\\') { return ICE_IDENT_OP; } @@ -1097,23 +1158,23 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 230 "Scanner.l" +#line 234 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); StringTokPtr ident = new StringTok; - ident->v = *slice_text == '\\' ? slice_text + 1 : slice_text; + ident->v = *yytext == '\\' ? yytext + 1 : yytext; *yylvalp = ident; - return *slice_text == '\\' ? ICE_IDENTIFIER : checkKeyword(ident->v); + return *yytext == '\\' ? ICE_IDENTIFIER : checkKeyword(ident->v); } YY_BREAK case 14: YY_RULE_SETUP -#line 238 "Scanner.l" +#line 242 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); StringTokPtr str = new StringTok; str->literal = "\""; - while(true) + while(true) { char c = static_cast<char>(yyinput()); str->literal += c; @@ -1126,9 +1187,10 @@ YY_RULE_SETUP unit->error("EOF in string"); break; } - else if(c == '\n') + else if(static_cast<unsigned char>(c) < 32 || c == 127) { - unit->error("newline in string"); + unit->error("a string literal can only contain printable ASCII characters and non-ASCII characters"); + break; } else if(c == '\\') { @@ -1138,67 +1200,58 @@ YY_RULE_SETUP { case '\\': { + // + // add extra escape to our internal string + // str->v += '\\'; str->v += '\\'; break; } case '"': case '\'': + case '?': { str->v += next; break; } - - case 'n': - { - str->v += '\n'; - break; - } - - case 'r': + case 'a': { - str->v += '\r'; + str->v += '\a'; break; } - - case 't': + case 'b': { - str->v += '\t'; + str->v += '\b'; break; } - - case 'v': + case 'f': { - str->v += '\v'; + str->v += '\f'; break; } - - case 'f': + case 'n': { - str->v += '\f'; + str->v += '\n'; break; } - - case 'a': + case 'r': { - str->v += '\a'; + str->v += '\r'; break; } - - case 'b': + case 't': { - str->v += '\b'; + str->v += '\t'; break; } - - case '?': + case 'v': { - str->v += '\?'; + str->v += '\v'; break; } // - // Octal value \nnn limited to three octal digits but terminate at the first character + // Octal value \nnn limited to three octal digits but terminate at the first character // that is not a valid octal digit if encountered sooner. // case '0': @@ -1211,7 +1264,6 @@ YY_RULE_SETUP case '7': { static string octalDigits = "01234567"; - IceUtil::Int64 value = 0; string escape; escape += next; for(int i = 0; i < 2; ++i) @@ -1222,158 +1274,92 @@ YY_RULE_SETUP unput(next); break; } - escape += next; + escape += next; } str->literal += escape; - value = IceUtilInternal::strToInt64(escape.c_str(), 0, 8); - - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - else if(value > 255) + IceUtil::Int64 value = IceUtilInternal::strToInt64(escape.c_str(), 0, 8); + if(value > 255) { - ostringstream os; - os << "octal escape sequence out of range: '\\" << oct << value << "'"; - unit->warning(os.str()); + unit->error(string("octal escape sequence out of range: `\\") + escape + "'"); } str->v += static_cast<char>(value); break; } + case 'x': { - IceUtil::Int64 value = 0; string escape = ""; - while(isxdigit(static_cast<unsigned char>(next = static_cast<char>(yyinput())))) + next = static_cast<char>(yyinput()); + + // + // Unlike C++, we limit hex escape sequences to 2 hex digits + // + while(isxdigit(next) && escape.length() < 2) { escape += next; + next = static_cast<char>(yyinput()); } unput(next); - - str->literal += escape; - value = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - else if(value > 255) + if(escape.length() == 0) { - ostringstream os; - os << "hex escape sequence out of range: '\\x" << hex << value << "'"; - unit->warning(os.str()); + unit->error("no hex digit in hex escape sequence"); } + + str->literal += escape; + IceUtil::Int64 value = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); + + assert(value >= 0 && value <= 255); str->v += static_cast<char>(value); break; } - + // - // Universal character name \unnnn code point U+nnnn + // Universal character name // case 'u': + case 'U': { - IceUtil::Int64 value = 0; string escape = ""; - - for(int i = 0; i < 4; ++i) + char c = next; + int size = (c == 'u') ? 4 : 8; + while(size > 0) { next = static_cast<char>(yyinput()); - str->literal += next; if(!isxdigit(static_cast<unsigned char>(next))) { - unit->error("unknown escape sequence in string constant: " + str->literal); + unit->error(string("unknown escape sequence in string literal: `\\") + c + escape + next + "'"); + unput(next); break; } escape += next; - } - - value = escape.size() == 4 ? IceUtilInternal::strToInt64(escape.c_str(), 0, 16) : -1; - - ostringstream os; - os << '\\' << 'u'; - os.fill('0'); - os.width(4); - os << hex << value; - - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - - - // - // Determine if a character is a surrogate: - // - // * High surrogate code point, ranging from 0xd800 to 0xdbff, inclusive - // * Low surrogate code point, ranging from 0xdc00 to 0xdfff, inclusive. - // - else if((value >= 0xd800 && value <= 0xdbff) || (value >= 0xdc00 && value <= 0xdfff)) - { - unit->error("unknown escape sequence in string constant: '" + os.str() + "'"); + --size; } - str->v += os.str(); - - break; - } - - case 'U': - { - IceUtil::Int64 value = 0; - string escape = ""; - - for(int i = 0; i < 8; ++i) + if(size == 0) { - next = static_cast<char>(yyinput()); - str->literal += next; - if(!isxdigit(static_cast<unsigned char>(next))) + // All digits read, check value + IceUtil::Int64 codePoint = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); + if(codePoint >= 0xd800 && codePoint <= 0xdfff) { - - unit->error("unknown escape sequence in string constant: " + str->literal); - break; + unit->error(string("a universal character name cannot designate a surrogate: `\\") + c + escape + "'"); } - escape += next; - } - - value = escape.size() == 8 ? IceUtilInternal::strToInt64(escape.c_str(), 0, 16) : -1; - - ostringstream os; - os << '\\' << 'U'; - os.fill('0'); - os.width(8); - os << hex << value; - - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - - // - // Determine if a character is a surrogate: - // - // * High surrogate code point, ranging from 0xd800 to 0xdbff, inclusive - // * Low surrogate code point, ranging from 0xdc00 to 0xdfff, inclusive. - // - else if((value >= 0xd800 && value <= 0xdbff) || (value >= 0xdc00 && value <= 0xdfff)) - { - unit->error("unknown escape sequence in string constant: '" + os.str() + "'"); } - str->v += os.str(); + str->literal += escape; + str->v += string("\\") + c + escape; break; } default: { ostringstream os; - os << "unknown escape sequence '\\" << next << "'"; - unit->warning(os.str()); - // - // We escape the backslack in a unknown escape sequence - // to keep compativility with 3.6" - // + os << "unknown escape sequence `\\" << next << "'"; + unit->warning(All, os.str()); + + // Escape the \ in this unknown escape sequence + str->v += '\\'; str->v += '\\'; - str->v += c; unput(next); } } @@ -1389,52 +1375,52 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 515 "Scanner.l" +#line 445 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); IntegerTokPtr itp = new IntegerTok; - itp->literal = string(slice_text); + itp->literal = string(yytext); *yylvalp = itp; - if(!IceUtilInternal::stringToInt64(string(slice_text), itp->v)) + if(!IceUtilInternal::stringToInt64(string(yytext), itp->v)) { - assert(itp->v != 0); - string msg = "integer constant `"; - msg += slice_text; - msg += "' out of range"; - unit->error(msg); + assert(itp->v != 0); + string msg = "integer constant `"; + msg += yytext; + msg += "' out of range"; + unit->error(msg); } return ICE_INTEGER_LITERAL; } YY_BREAK case 16: YY_RULE_SETUP -#line 531 "Scanner.l" +#line 461 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); errno = 0; FloatingTokPtr ftp = new FloatingTok; *yylvalp = ftp; - string literal(slice_text); + string literal(yytext); ftp->literal = literal; char lastChar = literal[literal.size() - 1]; if(lastChar == 'f' || lastChar == 'F') { - literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix + literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix } ftp->v = strtod(literal.c_str(), 0); if((ftp->v == HUGE_VAL || ftp->v == -HUGE_VAL) && errno == ERANGE) { - string msg = "floating-point constant `"; - msg += slice_text; - msg += "' too large (overflow)"; - unit->error(msg); + string msg = "floating-point constant `"; + msg += yytext; + msg += "' too large (overflow)"; + unit->error(msg); } else if(ftp->v == 0 && errno == ERANGE) { - string msg = "floating-point constant `"; - msg += slice_text; - msg += "' too small (underflow)"; - unit->error(msg); + string msg = "floating-point constant `"; + msg += yytext; + msg += "' too small (underflow)"; + unit->error(msg); } return ICE_FLOATING_POINT_LITERAL; } @@ -1442,54 +1428,54 @@ YY_RULE_SETUP case 17: /* rule 17 can match eol */ YY_RULE_SETUP -#line 561 "Scanner.l" +#line 491 "src/Slice/Scanner.l" { // Ignore white-space - + if(unit->currentLine() != 0) { BEGIN(MAINSCAN); } - if(slice_text[0] == '\n') + if(yytext[0] == '\n') { - unit->nextLine(); + unit->nextLine(); } } YY_BREAK case 18: YY_RULE_SETUP -#line 574 "Scanner.l" +#line 504 "src/Slice/Scanner.l" { // Ignore UTF-8 BOM, rule only active when parsing start of file. - + BEGIN(MAINSCAN); } YY_BREAK case 19: YY_RULE_SETUP -#line 580 "Scanner.l" +#line 510 "src/Slice/Scanner.l" { BEGIN(MAINSCAN); - if(slice_text[0] < 32 || slice_text[0] > 126) + if(yytext[0] < 32 || yytext[0] > 126) { - stringstream s; - s << "illegal input character: '\\"; - s.width(3); - s.fill('0'); - s << oct << static_cast<int>(static_cast<unsigned char>(slice_text[0])); - s << "'"; - unit->error(s.str()); - return BAD_CHAR; + stringstream s; + s << "illegal input character: '\\"; + s.width(3); + s.fill('0'); + s << oct << static_cast<int>(static_cast<unsigned char>(yytext[0])); + s << "'"; + unit->error(s.str()); + return BAD_CHAR; } - return slice_text[0]; + return yytext[0]; } YY_BREAK case 20: YY_RULE_SETUP -#line 596 "Scanner.l" +#line 526 "src/Slice/Scanner.l" ECHO; YY_BREAK -#line 1491 "lex.yy.c" +#line 1477 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(BOMSCAN): case YY_STATE_EOF(MAINSCAN): @@ -1635,9 +1621,9 @@ case YY_STATE_EOF(MAINSCAN): */ static int yy_get_next_buffer (void) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) @@ -1666,7 +1652,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1679,7 +1665,7 @@ static int yy_get_next_buffer (void) else { - yy_size_t num_to_read = + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1693,7 +1679,7 @@ static int yy_get_next_buffer (void) if ( b->yy_is_our_buffer ) { - yy_size_t new_size = b->yy_buf_size * 2; + int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1702,11 +1688,11 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - slice_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + slice_realloc((void *) b->yy_ch_buf,(yy_size_t) (b->yy_buf_size + 2) ); } else /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; + b->yy_ch_buf = NULL; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( @@ -1748,10 +1734,10 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) slice_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) slice_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,(yy_size_t) new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } @@ -1769,15 +1755,15 @@ static int yy_get_next_buffer (void) static yy_state_type yy_get_previous_state (void) { - register yy_state_type yy_current_state; - register char *yy_cp; + yy_state_type yy_current_state; + char *yy_cp; yy_current_state = (yy_start); yy_current_state += YY_AT_BOL(); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1787,9 +1773,9 @@ static int yy_get_next_buffer (void) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 73 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; } return yy_current_state; @@ -1802,10 +1788,10 @@ static int yy_get_next_buffer (void) */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); - register YY_CHAR yy_c = 1; + YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -1815,17 +1801,19 @@ static int yy_get_next_buffer (void) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 73 ) - yy_c = yy_meta[(unsigned int) yy_c]; + yy_c = yy_meta[yy_c]; } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 72); return yy_is_jam ? 0 : yy_current_state; } - static void yyunput (int c, register char * yy_bp ) +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) { - register char *yy_cp; + char *yy_cp; yy_cp = (yy_c_buf_p); @@ -1835,10 +1823,10 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = + char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) @@ -1847,7 +1835,7 @@ static int yy_get_next_buffer (void) yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); @@ -1860,6 +1848,8 @@ static int yy_get_next_buffer (void) (yy_c_buf_p) = yy_cp; } +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) @@ -1884,7 +1874,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1908,7 +1898,7 @@ static int yy_get_next_buffer (void) case EOB_ACT_END_OF_FILE: { if ( slice_wrap( ) ) - return EOF; + return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -2016,7 +2006,7 @@ static void slice__load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) slice_alloc(b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) slice_alloc((yy_size_t) (b->yy_buf_size + 2) ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in slice__create_buffer()" ); @@ -2166,15 +2156,15 @@ static void slice_ensure_buffer_stack (void) * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ - num_to_alloc = 1; + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ (yy_buffer_stack) = (struct yy_buffer_state**)slice_alloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in slice_ensure_buffer_stack()" ); - + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - + (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; @@ -2183,7 +2173,7 @@ static void slice_ensure_buffer_stack (void) if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)slice_realloc @@ -2203,7 +2193,7 @@ static void slice_ensure_buffer_stack (void) * @param base the character buffer * @param size the size in bytes of the character buffer * - * @return the newly allocated buffer state object. + * @return the newly allocated buffer state object. */ YY_BUFFER_STATE slice__scan_buffer (char * base, yy_size_t size ) { @@ -2213,16 +2203,16 @@ YY_BUFFER_STATE slice__scan_buffer (char * base, yy_size_t size ) base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ - return 0; + return NULL; b = (YY_BUFFER_STATE) slice_alloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in slice__scan_buffer()" ); - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; - b->yy_input_file = 0; + b->yy_input_file = NULL; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; @@ -2242,10 +2232,10 @@ YY_BUFFER_STATE slice__scan_buffer (char * base, yy_size_t size ) * @note If you want to scan bytes that may contain NUL values, then use * slice__scan_bytes() instead. */ -YY_BUFFER_STATE slice__scan_string (yyconst char * yystr ) +YY_BUFFER_STATE slice__scan_string (const char * yystr ) { - return slice__scan_bytes(yystr,strlen(yystr) ); + return slice__scan_bytes(yystr,(int) strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to slice_lex() will @@ -2255,15 +2245,15 @@ YY_BUFFER_STATE slice__scan_string (yyconst char * yystr ) * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE slice__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +YY_BUFFER_STATE slice__scan_bytes (const char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; - yy_size_t i; + int i; /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; + n = (yy_size_t) (_yybytes_len + 2); buf = (char *) slice_alloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in slice__scan_bytes()" ); @@ -2289,9 +2279,9 @@ YY_BUFFER_STATE slice__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_ #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg ) +static void yynoreturn yy_fatal_error (const char* msg ) { - (void) fprintf( stderr, "%s\n", msg ); + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -2319,7 +2309,7 @@ static void yy_fatal_error (yyconst char* msg ) */ int slice_get_lineno (void) { - + return slice_lineno; } @@ -2342,7 +2332,7 @@ FILE *slice_get_out (void) /** Get the length of the current token. * */ -yy_size_t slice_get_leng (void) +int slice_get_leng (void) { return slice_leng; } @@ -2357,29 +2347,29 @@ char *slice_get_text (void) } /** Set the current line number. - * @param line_number + * @param _line_number line number * */ -void slice_set_lineno (int line_number ) +void slice_set_lineno (int _line_number ) { - slice_lineno = line_number; + slice_lineno = _line_number; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. + * @param _in_str A readable stream. * * @see slice__switch_to_buffer */ -void slice_set_in (FILE * in_str ) +void slice_set_in (FILE * _in_str ) { - slice_in = in_str ; + slice_in = _in_str ; } -void slice_set_out (FILE * out_str ) +void slice_set_out (FILE * _out_str ) { - slice_out = out_str ; + slice_out = _out_str ; } int slice_get_debug (void) @@ -2387,9 +2377,9 @@ int slice_get_debug (void) return slice__flex_debug; } -void slice_set_debug (int bdebug ) +void slice_set_debug (int _bdebug ) { - slice__flex_debug = bdebug ; + slice__flex_debug = _bdebug ; } static int yy_init_globals (void) @@ -2398,10 +2388,10 @@ static int yy_init_globals (void) * This function is called from slice_lex_destroy(), so don't allocate here. */ - (yy_buffer_stack) = 0; + (yy_buffer_stack) = NULL; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; + (yy_c_buf_p) = NULL; (yy_init) = 0; (yy_start) = 0; @@ -2410,8 +2400,8 @@ static int yy_init_globals (void) slice_in = stdin; slice_out = stdout; #else - slice_in = (FILE *) 0; - slice_out = (FILE *) 0; + slice_in = NULL; + slice_out = NULL; #endif /* For future reference: Set errno on error, since we are called by @@ -2447,18 +2437,19 @@ int slice_lex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +static void yy_flex_strncpy (char* s1, const char * s2, int n ) { - register int i; + + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int yy_flex_strlen (const char * s ) { - register int n; + int n; for ( n = 0; s[n]; ++n ) ; @@ -2468,11 +2459,12 @@ static int yy_flex_strlen (yyconst char * s ) void *slice_alloc (yy_size_t size ) { - return (void *) malloc( size ); + return malloc(size); } void *slice_realloc (void * ptr, yy_size_t size ) { + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2480,18 +2472,17 @@ void *slice_realloc (void * ptr, yy_size_t size ) * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ - return (void *) realloc( (char *) ptr, size ); + return realloc(ptr, size); } void slice_free (void * ptr ) { - free( (char *) ptr ); /* see slice_realloc() for (char *) cast */ + free( (char *) ptr ); /* see slice_realloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 595 "Scanner.l" - +#line 526 "src/Slice/Scanner.l" namespace Slice { @@ -2532,6 +2523,7 @@ initScanner() keywordMap["true"] = ICE_TRUE; keywordMap["idempotent"] = ICE_IDEMPOTENT; keywordMap["optional"] = ICE_OPTIONAL; + keywordMap["Value"] = ICE_VALUE; } // @@ -2547,15 +2539,15 @@ checkKeyword(string& id) StringTokenMap::const_iterator pos = keywordMap.find(id); if(pos != keywordMap.end()) { - if(pos->first != id) - { - string msg; - msg = "illegal identifier: `" + id + "' differs from keyword `"; - msg += pos->first + "' only in capitalization"; - unit->error(msg); - id = pos->first; - } - return pos->second; + if(pos->first != id) + { + string msg; + msg = "illegal identifier: `" + id + "' differs from keyword `"; + msg += pos->first + "' only in capitalization"; + unit->error(msg); + id = pos->first; + } + return pos->second; } return ICE_IDENTIFIER; } diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index f5fa7b7c78d..6aa153f039d 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -9,7 +9,7 @@ // // ********************************************************************** -#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined +#include <Slice/GrammarUtil.h> // Before Grammer.h, so that YYSTYPE is defined #include <Slice/Grammar.h> #include <IceUtil/InputUtil.h> @@ -38,6 +38,10 @@ # pragma warning( 4 : 4018 ) #endif +#if defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wsign-compare" +#endif + #ifdef _MSC_VER # ifdef slice_wrap # undef slice_wrap @@ -52,7 +56,7 @@ # define slice_wrap() 1 # endif # ifdef ICE_64 -# pragma error_messages(off,truncwarn) +# pragma error_messages(off,truncwarn) # endif #endif @@ -65,7 +69,7 @@ namespace Slice // // Definitions for the case-insensitive keyword-token map. // -typedef std::map<std::string, int, Slice::CICompare> StringTokenMap; +typedef std::map<std::string, int> StringTokenMap; static StringTokenMap keywordMap; void initScanner(); @@ -73,7 +77,7 @@ int checkKeyword(string&); } -#define YY_USER_INIT initScanner(); +#define YY_USER_INIT initScanner(); %} @@ -82,11 +86,11 @@ int checkKeyword(string&); %option prefix="slice_" %option outfile="lex.yy.c" -identifier \\?[[:alpha:]_][[:alnum:]_]* -integer_constant (\+|-)?((0[0-7]+)|(0x[[:xdigit:]]+)|([[:digit:]]+)) -fractional_constant (\+|-)?(([[:digit:]]*\.[[:digit:]]+)|([[:digit:]]+\.)) -exponent_part (e|E)(\+|-)?[[:digit:]]+ -floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{exponent_part}))[fF]? +identifier \\?[[:alpha:]_][[:alnum:]_]* +integer_constant (\+|-)?((0[0-7]+)|(0x[[:xdigit:]]+)|([[:digit:]]+)) +fractional_constant (\+|-)?(([[:digit:]]*\.[[:digit:]]+)|([[:digit:]]+\.)) +exponent_part (e|E)(\+|-)?[[:digit:]]+ +floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{exponent_part}))[fF]? %s BOMSCAN %s MAINSCAN @@ -127,11 +131,11 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e int c; do { - c = yyinput(); - if(c == '\n') - { - unit->nextLine(); - } + c = yyinput(); + if(c == '\n') + { + unit->nextLine(); + } } while(c != '\n' && c != EOF); } @@ -142,38 +146,38 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e string comment = yytext + 2; while(true) { - int c = yyinput(); - if(c == '\n') - { - comment += static_cast<char>(c); - unit->nextLine(); - } - else if(c == '*') - { - int next = yyinput(); - if(next == '/') - { - break; - } - else - { - comment += static_cast<char>(c); - unput(next); - } - } - else if(c == EOF) - { - unit->warning("EOF in comment"); - break; - } - else - { - comment += static_cast<char>(c); - } + int c = yyinput(); + if(c == '\n') + { + comment += static_cast<char>(c); + unit->nextLine(); + } + else if(c == '*') + { + int next = yyinput(); + if(next == '/') + { + break; + } + else + { + comment += static_cast<char>(c); + unput(next); + } + } + else if(c == EOF) + { + unit->warning(All, "EOF in comment"); + break; + } + else + { + comment += static_cast<char>(c); + } } if(!comment.empty() && comment[0] == '*') { - unit->setComment(comment); + unit->setComment(comment); } } @@ -239,7 +243,7 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e BEGIN(MAINSCAN); StringTokPtr str = new StringTok; str->literal = "\""; - while(true) + while(true) { char c = static_cast<char>(yyinput()); str->literal += c; @@ -252,9 +256,10 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e unit->error("EOF in string"); break; } - else if(c == '\n') + else if(static_cast<unsigned char>(c) < 32 || c == 127) { - unit->error("newline in string"); + unit->error("a string literal can only contain printable ASCII characters and non-ASCII characters"); + break; } else if(c == '\\') { @@ -264,67 +269,58 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e { case '\\': { + // + // add extra escape to our internal string + // str->v += '\\'; str->v += '\\'; break; } case '"': case '\'': + case '?': { str->v += next; break; } - - case 'n': - { - str->v += '\n'; - break; - } - - case 'r': + case 'a': { - str->v += '\r'; + str->v += '\a'; break; } - - case 't': + case 'b': { - str->v += '\t'; + str->v += '\b'; break; } - - case 'v': + case 'f': { - str->v += '\v'; + str->v += '\f'; break; } - - case 'f': + case 'n': { - str->v += '\f'; + str->v += '\n'; break; } - - case 'a': + case 'r': { - str->v += '\a'; + str->v += '\r'; break; } - - case 'b': + case 't': { - str->v += '\b'; + str->v += '\t'; break; } - - case '?': + case 'v': { - str->v += '\?'; + str->v += '\v'; break; } // - // Octal value \nnn limited to three octal digits but terminate at the first character + // Octal value \nnn limited to three octal digits but terminate at the first character // that is not a valid octal digit if encountered sooner. // case '0': @@ -337,7 +333,6 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e case '7': { static string octalDigits = "01234567"; - IceUtil::Int64 value = 0; string escape; escape += next; for(int i = 0; i < 2; ++i) @@ -348,158 +343,92 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e unput(next); break; } - escape += next; + escape += next; } str->literal += escape; - value = IceUtilInternal::strToInt64(escape.c_str(), 0, 8); - - if(value == 0) + IceUtil::Int64 value = IceUtilInternal::strToInt64(escape.c_str(), 0, 8); + if(value > 255) { - unit->error("illegal NUL character in string constant"); - } - else if(value > 255) - { - ostringstream os; - os << "octal escape sequence out of range: '\\" << oct << value << "'"; - unit->warning(os.str()); + unit->error(string("octal escape sequence out of range: `\\") + escape + "'"); } str->v += static_cast<char>(value); break; } + case 'x': { - IceUtil::Int64 value = 0; string escape = ""; - while(isxdigit(static_cast<unsigned char>(next = static_cast<char>(yyinput())))) + next = static_cast<char>(yyinput()); + + // + // Unlike C++, we limit hex escape sequences to 2 hex digits + // + while(isxdigit(next) && escape.length() < 2) { escape += next; + next = static_cast<char>(yyinput()); } unput(next); - - str->literal += escape; - value = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - else if(value > 255) + if(escape.length() == 0) { - ostringstream os; - os << "hex escape sequence out of range: '\\x" << hex << value << "'"; - unit->warning(os.str()); + unit->error("no hex digit in hex escape sequence"); } + + str->literal += escape; + IceUtil::Int64 value = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); + + assert(value >= 0 && value <= 255); str->v += static_cast<char>(value); break; } - + // - // Universal character name \unnnn code point U+nnnn + // Universal character name // case 'u': + case 'U': { - IceUtil::Int64 value = 0; string escape = ""; - - for(int i = 0; i < 4; ++i) + char c = next; + int size = (c == 'u') ? 4 : 8; + while(size > 0) { next = static_cast<char>(yyinput()); - str->literal += next; if(!isxdigit(static_cast<unsigned char>(next))) { - unit->error("unknown escape sequence in string constant: " + str->literal); + unit->error(string("unknown escape sequence in string literal: `\\") + c + escape + next + "'"); + unput(next); break; } escape += next; - } - - value = escape.size() == 4 ? IceUtilInternal::strToInt64(escape.c_str(), 0, 16) : -1; - - ostringstream os; - os << '\\' << 'u'; - os.fill('0'); - os.width(4); - os << hex << value; - - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - - - // - // Determine if a character is a surrogate: - // - // * High surrogate code point, ranging from 0xd800 to 0xdbff, inclusive - // * Low surrogate code point, ranging from 0xdc00 to 0xdfff, inclusive. - // - else if((value >= 0xd800 && value <= 0xdbff) || (value >= 0xdc00 && value <= 0xdfff)) - { - unit->error("unknown escape sequence in string constant: '" + os.str() + "'"); + --size; } - str->v += os.str(); - - break; - } - - case 'U': - { - IceUtil::Int64 value = 0; - string escape = ""; - - for(int i = 0; i < 8; ++i) + if(size == 0) { - next = static_cast<char>(yyinput()); - str->literal += next; - if(!isxdigit(static_cast<unsigned char>(next))) + // All digits read, check value + IceUtil::Int64 codePoint = IceUtilInternal::strToInt64(escape.c_str(), 0, 16); + if(codePoint >= 0xd800 && codePoint <= 0xdfff) { - - unit->error("unknown escape sequence in string constant: " + str->literal); - break; + unit->error(string("a universal character name cannot designate a surrogate: `\\") + c + escape + "'"); } - escape += next; - } - - value = escape.size() == 8 ? IceUtilInternal::strToInt64(escape.c_str(), 0, 16) : -1; - - ostringstream os; - os << '\\' << 'U'; - os.fill('0'); - os.width(8); - os << hex << value; - - if(value == 0) - { - unit->error("illegal NUL character in string constant"); - } - - // - // Determine if a character is a surrogate: - // - // * High surrogate code point, ranging from 0xd800 to 0xdbff, inclusive - // * Low surrogate code point, ranging from 0xdc00 to 0xdfff, inclusive. - // - else if((value >= 0xd800 && value <= 0xdbff) || (value >= 0xdc00 && value <= 0xdfff)) - { - unit->error("unknown escape sequence in string constant: '" + os.str() + "'"); } - str->v += os.str(); + str->literal += escape; + str->v += string("\\") + c + escape; break; } default: { ostringstream os; - os << "unknown escape sequence '\\" << next << "'"; - unit->warning(os.str()); - // - // We escape the backslack in a unknown escape sequence - // to keep compativility with 3.6" - // + os << "unknown escape sequence `\\" << next << "'"; + unit->warning(All, os.str()); + + // Escape the \ in this unknown escape sequence + str->v += '\\'; str->v += '\\'; - str->v += c; unput(next); } } @@ -520,11 +449,11 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e *yylvalp = itp; if(!IceUtilInternal::stringToInt64(string(yytext), itp->v)) { - assert(itp->v != 0); - string msg = "integer constant `"; - msg += yytext; - msg += "' out of range"; - unit->error(msg); + assert(itp->v != 0); + string msg = "integer constant `"; + msg += yytext; + msg += "' out of range"; + unit->error(msg); } return ICE_INTEGER_LITERAL; } @@ -539,42 +468,42 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e char lastChar = literal[literal.size() - 1]; if(lastChar == 'f' || lastChar == 'F') { - literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix + literal = literal.substr(0, literal.size() - 1); // Clobber trailing 'f' or 'F' suffix } ftp->v = strtod(literal.c_str(), 0); if((ftp->v == HUGE_VAL || ftp->v == -HUGE_VAL) && errno == ERANGE) { - string msg = "floating-point constant `"; - msg += yytext; - msg += "' too large (overflow)"; - unit->error(msg); + string msg = "floating-point constant `"; + msg += yytext; + msg += "' too large (overflow)"; + unit->error(msg); } else if(ftp->v == 0 && errno == ERANGE) { - string msg = "floating-point constant `"; - msg += yytext; - msg += "' too small (underflow)"; - unit->error(msg); + string msg = "floating-point constant `"; + msg += yytext; + msg += "' too small (underflow)"; + unit->error(msg); } return ICE_FLOATING_POINT_LITERAL; } [[:space:]] { // Ignore white-space - + if(unit->currentLine() != 0) { BEGIN(MAINSCAN); } if(yytext[0] == '\n') { - unit->nextLine(); + unit->nextLine(); } } <BOMSCAN>^"\357\273\277" { // Ignore UTF-8 BOM, rule only active when parsing start of file. - + BEGIN(MAINSCAN); } @@ -582,14 +511,14 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e BEGIN(MAINSCAN); if(yytext[0] < 32 || yytext[0] > 126) { - stringstream s; - s << "illegal input character: '\\"; - s.width(3); - s.fill('0'); - s << oct << static_cast<int>(static_cast<unsigned char>(yytext[0])); - s << "'"; - unit->error(s.str()); - return BAD_CHAR; + stringstream s; + s << "illegal input character: '\\"; + s.width(3); + s.fill('0'); + s << oct << static_cast<int>(static_cast<unsigned char>(yytext[0])); + s << "'"; + unit->error(s.str()); + return BAD_CHAR; } return yytext[0]; } @@ -634,6 +563,7 @@ initScanner() keywordMap["true"] = ICE_TRUE; keywordMap["idempotent"] = ICE_IDEMPOTENT; keywordMap["optional"] = ICE_OPTIONAL; + keywordMap["Value"] = ICE_VALUE; } // @@ -649,15 +579,15 @@ checkKeyword(string& id) StringTokenMap::const_iterator pos = keywordMap.find(id); if(pos != keywordMap.end()) { - if(pos->first != id) - { - string msg; - msg = "illegal identifier: `" + id + "' differs from keyword `"; - msg += pos->first + "' only in capitalization"; - unit->error(msg); - id = pos->first; - } - return pos->second; + if(pos->first != id) + { + string msg; + msg = "illegal identifier: `" + id + "' differs from keyword `"; + msg += pos->first + "' only in capitalization"; + unit->error(msg); + id = pos->first; + } + return pos->second; } return ICE_IDENTIFIER; } diff --git a/cpp/src/Slice/Slice.rc b/cpp/src/Slice/Slice.rc deleted file mode 100644 index c89c5b383ca..00000000000 --- a/cpp/src/Slice/Slice.rc +++ /dev/null @@ -1,38 +0,0 @@ -#include "winver.h" - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,6,3,0 - PRODUCTVERSION 3,6,3,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS VS_FF_DEBUG - #define INTERNALNAME "slice36d\0" - #define ORIGINALFILENAME "slice36d.dll\0" -#else - FILEFLAGS 0x0L - #define INTERNALNAME "slice36\0" - #define ORIGINALFILENAME "slice36.dll\0" -#endif - FILEOS 0x4L - FILETYPE VFT_DLL - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "CompanyName", "ZeroC, Inc.\0" - VALUE "FileDescription", "Slice C++ Library\0" - VALUE "FileVersion", "3.6.3\0" - VALUE "InternalName", INTERNALNAME - VALUE "LegalCopyright", "\251 2003-2016 ZeroC, Inc.\0" - VALUE "OriginalFilename", ORIGINALFILENAME - VALUE "ProductName", "Ice\0" - VALUE "ProductVersion", "3.6.3\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/SliceUtil.cpp index 2ae8200ffec..b148b91dea7 100644 --- a/cpp/src/Slice/Util.cpp +++ b/cpp/src/Slice/SliceUtil.cpp @@ -1,17 +1,21 @@ // ********************************************************************** // -// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** +#include <IceUtil/DisableWarnings.h> #include <Slice/Util.h> +#include <Slice/FileTracker.h> #include <IceUtil/FileUtil.h> #include <IceUtil/StringUtil.h> #include <IceUtil/StringConverter.h> +#include <IceUtil/ConsoleUtil.h> #include <climits> +#include <cstring> #ifndef _MSC_VER # include <unistd.h> // For readlink() @@ -19,6 +23,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -155,8 +160,9 @@ Slice::fullPath(const string& path) } string -Slice::changeInclude(const string& path, const vector<string>& includePaths) +Slice::changeInclude(const string& p, const vector<string>& includePaths) { + string path = normalizePath(p); // // Compare each include path against the included file and select // the path that produces the shortest relative filename. @@ -173,11 +179,11 @@ Slice::changeInclude(const string& path, const vector<string>& includePaths) { paths.push_back(canonicalPath); } - + for(vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) { for(vector<string>::const_iterator j = includePaths.begin(); j != includePaths.end(); ++j) - { + { if(i->compare(0, j->length(), *j) == 0) { string s = i->substr(j->length() + 1); // + 1 for the '/' @@ -187,7 +193,7 @@ Slice::changeInclude(const string& path, const vector<string>& includePaths) } } } - + // // If the path has been already shortened no need to test // with canonical path. @@ -209,38 +215,19 @@ Slice::changeInclude(const string& path, const vector<string>& includePaths) return result; } -namespace -{ - -ostream* errorStream = &cerr; - -} - -void -Slice::setErrorStream(ostream& stream) -{ - errorStream = &stream; -} - -ostream& -Slice::getErrorStream() -{ - return *errorStream; -} - void Slice::emitError(const string& file, int line, const string& message) { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(line != -1) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << message << endl; + consoleErr << message << endl; } void @@ -248,14 +235,14 @@ Slice::emitWarning(const string& file, int line, const string& message) { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(line != -1) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << "warning: " << message << endl; + consoleErr << "warning: " << message << endl; } void @@ -263,14 +250,14 @@ Slice::emitError(const string& file, const std::string& line, const string& mess { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(!line.empty()) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << message << endl; + consoleErr << message << endl; } void @@ -278,20 +265,20 @@ Slice::emitWarning(const string& file, const std::string& line, const string& me { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(!line.empty()) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << "warning: " << message << endl; + consoleErr << "warning: " << message << endl; } void Slice::emitRaw(const char* message) { - *errorStream << message << flush; + consoleErr << message << flush; } vector<string> @@ -397,41 +384,27 @@ Slice::printGeneratedHeader(IceUtilInternal::Output& out, const string& path, co out << comment << "\n"; } -Slice::DependOutputUtil::DependOutputUtil(string& file) : _file(file) -{ - if(!_file.empty()) - { - _os.open(file.c_str(), ios::out); - } -} - -Slice::DependOutputUtil::~DependOutputUtil() +void +Slice::writeDependencies(const string& dependencies, const string& dependFile) { - if(!_file.empty() && _os.is_open()) + if(dependFile.empty()) { - _os.close(); + consoleOut << dependencies << flush; } -} - -void -Slice::DependOutputUtil::cleanup() -{ - if(!_file.empty()) + else { - if(_os.is_open()) + ofstream of(IceUtilInternal::streamFilename(dependFile).c_str()); // dependFile is a UTF-8 string + if(!of) { - _os.close(); + ostringstream os; + os << "cannot open file `" << dependFile << "': " << strerror(errno); + throw Slice::FileException(__FILE__, __LINE__, os.str()); } - IceUtilInternal::unlink(_file); + of << dependencies; + of.close(); } } -ostream& -Slice::DependOutputUtil::os() -{ - return _file.empty() ? cout : _os; -} - #ifdef _WIN32 vector<string> Slice::argvToArgs(int argc, wchar_t* argv[]) diff --git a/cpp/src/Slice/StringLiteralUtil.cpp b/cpp/src/Slice/StringLiteralUtil.cpp new file mode 100644 index 00000000000..9527d30e13f --- /dev/null +++ b/cpp/src/Slice/StringLiteralUtil.cpp @@ -0,0 +1,374 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Slice/Util.h> + +#include <IceUtil/InputUtil.h> +#include <IceUtil/StringConverter.h> + +#include <ostream> +#include <iomanip> + +using namespace std; +using namespace Slice; +using namespace IceUtil; +using namespace IceUtilInternal; + +namespace +{ + +class StringLiteralGenerator +{ +public: + + StringLiteralGenerator(const string&, const string&, EscapeMode, unsigned char); + + string escapeASCIIChar(char) const; + string escapeCodePoint(unsigned int) const; + string flushU8Buffer(vector<unsigned char>&) const; + +private: + + const string _nonPrintableEscaped; + const string _printableEscaped; + const EscapeMode _escapeMode; + const unsigned char _cutOff; +}; + +StringLiteralGenerator::StringLiteralGenerator(const string& nonPrintableEscaped, + const string& printableEscaped, + EscapeMode escapeMode, + unsigned char cutOff) : + _nonPrintableEscaped(nonPrintableEscaped), + _printableEscaped(printableEscaped + "\\\""), + _escapeMode(escapeMode), + _cutOff(cutOff) +{ +} + +string +StringLiteralGenerator::escapeASCIIChar(char c) const +{ + assert(static_cast<unsigned char>(c) < 128); + + string result; + + if(_nonPrintableEscaped.find(c) != string::npos) + { + switch(c) + { + case '\a': + { + result = "\\a"; + break; + } + case '\b': + { + result = "\\b"; + break; + } + case '\f': + { + result = "\\f"; + break; + } + case '\n': + { + result = "\\n"; + break; + } + case '\r': + { + result = "\\r"; + break; + } + case '\t': + { + result = "\\t"; + break; + } + case '\v': + { + result = "\\v"; + break; + } + case '\0': + { + result = "\\0"; + break; + } + case '\x20': + { + result = "\\s"; + break; + } + case '\x1b': + { + result = "\\e"; + break; + } + default: + { + // The caller cannot add additional non-printable ASCII characters! + assert(0); + } + } + } + else if(_printableEscaped.find(c) != string::npos) + { + result = '\\'; + result += c; + } + else if(c >= 32 && c <= 126) + { + // Other printable ASCII + result = c; + } + else + { + // Other non-printable ASCII character + ostringstream os; + if((static_cast<unsigned char>(c) < _cutOff) || (_escapeMode == Octal)) + { + os << "\\" << oct << setfill('0') << setw(3) << static_cast<unsigned int>(c & 0xFF); + } + else + { + os << "\\u" << hex << setfill('0') << setw(4) << static_cast<unsigned int>(c & 0xFF); + } + result = os.str(); + } + return result; +} + +string +StringLiteralGenerator::escapeCodePoint(unsigned int codePoint) const +{ + if(codePoint < 128) + { + return escapeASCIIChar(static_cast<char>(codePoint)); + } + else if(_escapeMode == Octal) + { + vector<unsigned int> u32buffer; + u32buffer.push_back(codePoint); + vector<unsigned char> u8buffer = fromUTF32(u32buffer); + + ostringstream os; + for(vector<unsigned char>::const_iterator q = u8buffer.begin(); q != u8buffer.end(); ++q) + { + os << "\\" << setfill('0') << setw(3) << oct << static_cast<unsigned int>(*q); + } + return os.str(); + } + else + { + ostringstream os; + if(codePoint < _cutOff) + { + // + // Output octal escape + // + os << "\\" << setfill('0') << setw(3) << oct << codePoint; + } + else if(codePoint <= 0xFFFF) + { + os << "\\u" << setfill('0') << setw(4) << hex << codePoint; + } + else if(_escapeMode == ShortUCN) + { + // + // Convert to surrogate pair + // + unsigned int highSurrogate = ((codePoint - 0x10000) / 0x400) + 0xD800; + unsigned int lowSurrogate = ((codePoint - 0x10000) % 0x400) + 0xDC00; + os << "\\u" << setfill('0') << setw(4) << hex << highSurrogate; + os << "\\u" << setfill('0') << setw(4) << hex << lowSurrogate; + } + else if(_escapeMode == EC6UCN) + { + os << "\\u{" << hex << codePoint << "}"; + } + else + { + os << "\\U" << setfill('0') << setw(8) << hex << codePoint; + } + return os.str(); + } +} + +string +StringLiteralGenerator::flushU8Buffer(vector<unsigned char>& u8buffer) const +{ + if(u8buffer.empty()) + { + return ""; + } + else + { + ostringstream os; + vector<unsigned int> u32buffer = toUTF32(u8buffer); + + for(vector<unsigned int>::const_iterator p = u32buffer.begin(); p != u32buffer.end(); ++p) + { + os << escapeCodePoint(*p); + } + u8buffer.clear(); + return os.str(); + } +} + +} + +string +Slice::toStringLiteral(const string& value, + const string& nonPrintableEscaped, + const string& printableEscaped, + EscapeMode escapeMode, + unsigned char cutOff) +{ + StringLiteralGenerator generator(nonPrintableEscaped, printableEscaped, escapeMode, cutOff); + + ostringstream os; + + if(escapeMode != Octal) + { + vector<unsigned char> u8buffer; // Buffer to convert multibyte characters + + for(size_t i = 0; i < value.size(); ++i) + { + char c = value[i]; + + if(static_cast<unsigned char>(c) >= 128) + { + // New UTF-8 byte + u8buffer.push_back(static_cast<unsigned char>(c)); + } + else + { + // + // First write any outstanding UTF-8 -encoded characters + // + os << generator.flushU8Buffer(u8buffer); + + if(c == '\\') + { + if(i + 1 == value.size()) + { + // trailing backslash, add a second one + os << "\\\\"; + } + else + { + c = value[++i]; + + if(c == '\\') + { + os << "\\\\"; + } + else if(c == 'u' || c == 'U') + { + size_t sz = c == 'U' ? 8 : 4; + string codePointStr = value.substr(i + 1, sz); + assert(codePointStr.size() == sz); + + IceUtil::Int64 v = IceUtilInternal::strToInt64(codePointStr.c_str(), 0, 16); + if(v < 128) + { + // ASCII character that may need to escaped in languages such as Java + os << generator.escapeASCIIChar(static_cast<char>(v)); + } + else if(escapeMode == UCN || c == 'u') + { + // keep this escape as is + os << "\\" << c << codePointStr; + } + else + { + os << generator.escapeCodePoint(static_cast<unsigned int>(v)); + } + i += sz; + } + else + { + // unescaped backslash: escape it! + os << "\\\\"; + os << generator.escapeASCIIChar(c); + } + } + } + else + { + os << generator.escapeASCIIChar(c); + } + } + } + + // + // Write any outstanding UTF-8 -encoded characters + // + os << generator.flushU8Buffer(u8buffer); + } + else + { + assert(escapeMode == Octal); + + for(size_t i = 0; i < value.size(); ++i) + { + char c = value[i]; + + if(static_cast<unsigned char>(c) >= 128) + { + // Write octal escape + os << "\\" << setfill('0') << setw(3) << oct << static_cast<unsigned int>(c & 0xFF); + } + else if(c == '\\') + { + if(i + 1 == value.size()) + { + // trailing backslash, add a second one + os << "\\\\"; + } + else + { + c = value[++i]; + + if(c == '\\') + { + os << "\\\\"; + } + else if(c == 'u' || c == 'U') + { + // + // Convert code point to UTF-8 bytes and write the escaped bytes + // + size_t sz = c == 'U' ? 8 : 4; + string codePointStr = value.substr(i + 1, sz); + assert(codePointStr.size() == sz); + + IceUtil::Int64 v = IceUtilInternal::strToInt64(codePointStr.c_str(), 0, 16); + os << generator.escapeCodePoint(static_cast<unsigned int>(v)); + i += sz; + } + else + { + // unescaped backslash + os << "\\\\"; + os << generator.escapeASCIIChar(c); + } + } + } + else + { + os << generator.escapeASCIIChar(c); + } + } + } + return os.str(); +} diff --git a/cpp/src/Slice/Util.h b/cpp/src/Slice/Util.h new file mode 100644 index 00000000000..783b0973d3e --- /dev/null +++ b/cpp/src/Slice/Util.h @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef SLICE_UTIL_H +#define SLICE_UTIL_H + +#include <Slice/Parser.h> +#include <IceUtil/OutputUtil.h> + +namespace Slice +{ + +std::string fullPath(const std::string&); +std::string changeInclude(const std::string&, const std::vector<std::string>&); +void emitError(const std::string&, int, const std::string&); +void emitWarning(const std::string&, int, const std::string&); +void emitError(const std::string&, const std::string&, const std::string&); +void emitWarning(const std::string&, const std::string&, const std::string&); +void emitRaw(const char*); +std::vector<std::string> filterMcppWarnings(const std::string&); +void printGeneratedHeader(IceUtilInternal::Output& out, const std::string&, const std::string& commentStyle = "//"); +#ifdef _WIN32 +std::vector<std::string> argvToArgs(int argc, wchar_t* argv[]); +#else +std::vector<std::string> argvToArgs(int argc, char* argv[]); +#endif + + +enum EscapeMode { UCN, Octal, ShortUCN, EC6UCN }; + +// Parameters: +// const string& value: input string provided by Slice Parser +// const string& nonPrintableEscaped: which of \a, \b, \f, \n, \r, \t, \v, \0 (null), \x20 (\s), \x1b (\e) are +// escaped in the target language +// Warning: don't include \0 if the target language recognizes octal escapes +// const string& printableEscaped: additional printable ASCII characters other than \ and " that need to be escaped +// EscapeMode escapeMode: whether we generate both UCNs, octal escape sequences, only short UCNs (\unnnn), +// or ECMAScript 6-style UCNs with \u{...} for astral characters +// unsigned char cutOff: characters < cutOff other than the nonPrintableEscaped are generated as +// octal escape sequences, regardless of escapeMode. +std::string +toStringLiteral(const std::string&, const std::string&, const std::string&, EscapeMode, unsigned char); + + +void +writeDependencies(const std::string&, const std::string&); + +} + +#endif diff --git a/cpp/src/Slice/msbuild/slice.vcxproj b/cpp/src/Slice/msbuild/slice.vcxproj new file mode 100644 index 00000000000..39152a54705 --- /dev/null +++ b/cpp/src/Slice/msbuild/slice.vcxproj @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{57CD6AC2-0C9D-4648-9E9D-5DF60C90F18A}</ProjectGuid> + <RootNamespace>Slice</RootNamespace> + <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <Import Project="$(MSBuildThisFileDirectory)\..\..\..\msbuild\ice.cpp98.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PreprocessorDefinitions>ICE_BUILDING_SLICE_COMPILERS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PreprocessorDefinitions>ICE_BUILDING_SLICE_COMPILERS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PreprocessorDefinitions>ICE_BUILDING_SLICE_COMPILERS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PreprocessorDefinitions>ICE_BUILDING_SLICE_COMPILERS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="..\*.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\*.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets" /> +</Project>
\ No newline at end of file diff --git a/cpp/src/Slice/msbuild/slice.vcxproj.filters b/cpp/src/Slice/msbuild/slice.vcxproj.filters new file mode 100644 index 00000000000..09e0f16cb50 --- /dev/null +++ b/cpp/src/Slice/msbuild/slice.vcxproj.filters @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{86EEC4C6-451D-4E42-AC48-87773B310643}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{8A6EAD0B-649C-4B94-9B49-C2D08D61A8A5}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{F4629E6B-3ADA-4290-96D5-68BA0E7D068D}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\Checksum.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\CPlusPlusUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\FileTracker.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Grammar.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\JavaUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\MD5.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\MD5I.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Parser.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\PHPUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Preprocessor.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Python.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\PythonUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Ruby.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\RubyUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\Scanner.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\SliceUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\Grammar.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\GrammarUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\MD5.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\MD5I.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\Checksum.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\CPlusPlusUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\FileTracker.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\JavaUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\Parser.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\Preprocessor.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\RubyUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\Util.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\PHPUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="..\PythonUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file |