diff options
author | Jose <jose@zeroc.com> | 2013-07-17 00:09:35 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2013-07-17 00:09:35 +0200 |
commit | 3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86 (patch) | |
tree | 26fa5dbd2ff580933dc28b90af40ba9e3ca6fe7b | |
parent | Fixed ICE-5356 - Consider adding man pages for unix executables (diff) | |
download | ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.tar.bz2 ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.tar.xz ice-3288f5190bafcf1d9a71bbef7cd0b7d287fb7b86.zip |
Fixed ICE-5375 - Consider to add ICE_TRANSLATOR preprocessor macro
63 files changed, 1302 insertions, 59 deletions
diff --git a/cpp/allTests.py b/cpp/allTests.py index edcb7533a8f..bf69d3496b2 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -35,6 +35,7 @@ tests = [ ("Slice/errorDetection", ["once"]), ("Slice/keyword", ["once"]), ("Slice/structure", ["once"]), + ("Slice/macros", ["once"]), ("Ice/properties", ["once", "nomingw"]), ("Ice/proxy", ["core"]), ("Ice/operations", ["core"]), diff --git a/cpp/include/Slice/Preprocessor.h b/cpp/include/Slice/Preprocessor.h index 44f7becb344..16e3aa7c1da 100644 --- a/cpp/include/Slice/Preprocessor.h +++ b/cpp/include/Slice/Preprocessor.h @@ -36,12 +36,12 @@ public: ~Preprocessor(); - FILE* preprocess(bool); + FILE* preprocess(bool, const std::string& = ""); bool close(); enum Language { CPlusPlus, Java, JavaXML, CSharp, Python, Ruby, PHP }; - bool printMakefileDependencies(Language, const std::vector<std::string>&, const std::string& = "cpp", + bool printMakefileDependencies(Language, const std::vector<std::string>&, const std::string& = "", const std::string& = "cpp", const std::string& = ""); std::string getBaseName(); diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp index a31148abda5..ca011caedb0 100644 --- a/cpp/src/FreezeScript/DumpDB.cpp +++ b/cpp/src/FreezeScript/DumpDB.cpp @@ -343,7 +343,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator Slice::UnitPtr unit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer<Slice::UnitPtr> unitD(unit); - if(!FreezeScript::parseSlice(appName, unit, slice, cppArgs, debug)) + if(!FreezeScript::parseSlice(appName, unit, slice, cppArgs, debug, "-DICE_COMPILER=ICE_DUMPDB")) { return EXIT_FAILURE; } diff --git a/cpp/src/FreezeScript/Util.cpp b/cpp/src/FreezeScript/Util.cpp index 52e72b956a0..6ba2715713a 100644 --- a/cpp/src/FreezeScript/Util.cpp +++ b/cpp/src/FreezeScript/Util.cpp @@ -170,7 +170,7 @@ FreezeScript::createEvictorSliceTypes(const Slice::UnitPtr& u) bool FreezeScript::parseSlice(const string& n, const Slice::UnitPtr& u, const vector<string>& files, - const vector<string>& cppArgs, bool debug) + const vector<string>& cppArgs, bool debug, const std::string& extraArgs) { // // Parse the Slice files. @@ -179,7 +179,7 @@ FreezeScript::parseSlice(const string& n, const Slice::UnitPtr& u, const vector< { PreprocessorPtr icecpp = Preprocessor::create(n, *p, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, extraArgs); if(cppHandle == 0) { diff --git a/cpp/src/FreezeScript/Util.h b/cpp/src/FreezeScript/Util.h index 67986f18515..47d4dc751ba 100644 --- a/cpp/src/FreezeScript/Util.h +++ b/cpp/src/FreezeScript/Util.h @@ -56,7 +56,7 @@ std::string typeToString(const Slice::TypePtr&); bool ignoreType(const std::string&); void createEvictorSliceTypes(const Slice::UnitPtr&); bool parseSlice(const std::string&, const Slice::UnitPtr&, const std::vector<std::string>&, - const std::vector<std::string>&, bool); + const std::vector<std::string>&, bool, const std::string&); typedef std::map<std::string, Freeze::CatalogData> CatalogDataMap; diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp index 09c870b2c78..c4c3f1fe002 100644 --- a/cpp/src/FreezeScript/transformdb.cpp +++ b/cpp/src/FreezeScript/transformdb.cpp @@ -436,14 +436,16 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator Slice::UnitPtr oldUnit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer<Slice::UnitPtr> oldD(oldUnit); - if(!FreezeScript::parseSlice(appName, oldUnit, oldSlice, oldCppArgs, debug)) + if(!FreezeScript::parseSlice(appName, oldUnit, oldSlice, oldCppArgs, debug, + "-DICE_COMPILER=ICE_TRANSFORMDB")) { return EXIT_FAILURE; } Slice::UnitPtr newUnit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer<Slice::UnitPtr> newD(newUnit); - if(!FreezeScript::parseSlice(appName, newUnit, newSlice, newCppArgs, debug)) + if(!FreezeScript::parseSlice(appName, newUnit, newSlice, newCppArgs, debug, + "-DICE_COMPILER=ICE_TRANSFORMDB")) { return EXIT_FAILURE; } diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 68072500ece..352cdf4147a 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -136,18 +136,12 @@ Slice::Preprocessor::normalizeIncludePath(const string& path) return result; } -FILE* -Slice::Preprocessor::preprocess(bool keepComments) +namespace { - if(!checkInputFile()) - { - return 0; - } - // - // Build arguments list. - // - vector<string> args = _args; +vector<string> +baseArgs(vector<string> args, bool keepComments, const string& extraArgs, const string& fileName) +{ if(keepComments) { args.push_back("-C"); @@ -157,7 +151,41 @@ Slice::Preprocessor::preprocess(bool keepComments) ostringstream version; version << "-DICE_VERSION=" << ICE_INT_VERSION; args.push_back(version.str()); - args.push_back(_fileName); + + args.push_back("-DICE_SLICE2CPP=1"); + args.push_back("-DICE_SLICE2CS=2"); + args.push_back("-DICE_SLICE2FREEZE=3"); + args.push_back("-DICE_SLICE2FREEZEJ=4"); + args.push_back("-DICE_SLICE2HTML=5"); + args.push_back("-DICE_SLICE2JAVA=6"); + args.push_back("-DICE_SLICE2PHP=7"); + args.push_back("-DICE_SLICE2PY=8"); + args.push_back("-DICE_SLICE2RB=9"); + args.push_back("-DICE_TRANSFORMDB=10"); + args.push_back("-DICE_DUMPDB=11"); + + if(!extraArgs.empty()) + { + args.push_back(extraArgs); + } + args.push_back(fileName); + return args; +} + +} + +FILE* +Slice::Preprocessor::preprocess(bool keepComments, const string& extraArgs) +{ + if(!checkInputFile()) + { + return 0; + } + + // + // Build arguments list. + // + vector<string> args = baseArgs(_args, keepComments, extraArgs, _fileName); const char** argv = new const char*[args.size() + 1]; argv[0] = "mcpp"; for(unsigned int i = 0; i < args.size(); ++i) @@ -251,7 +279,8 @@ Slice::Preprocessor::preprocess(bool keepComments) bool Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<string>& includePaths, - const string& cppSourceExt, const string& optValue) + const std::string& extraArgs, const string& cppSourceExt, + const string& optValue) { if(!checkInputFile()) { @@ -272,11 +301,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin // // Build arguments list. // - vector<string> args = _args; - args.push_back("-M"); - args.push_back("-e"); - args.push_back("en_us.utf8"); - args.push_back(_fileName); + vector<string> args = baseArgs(_args, false, extraArgs, _fileName); const char** argv = new const char*[args.size() + 1]; for(unsigned int i = 0; i < args.size(); ++i) diff --git a/cpp/src/slice2confluence/Gen.cpp b/cpp/src/slice2confluence/Gen.cpp index 4b059667033..91ae7a4e99a 100644 --- a/cpp/src/slice2confluence/Gen.cpp +++ b/cpp/src/slice2confluence/Gen.cpp @@ -888,7 +888,7 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) bool isFirst = prev == _symbols.end(); bool isLast = next == _symbols.end(); - bool hasParent = false; + /*bool hasParent = false; if(EnumPtr::dynamicCast(c)) { hasParent = true; @@ -904,7 +904,7 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) else if(ContainedPtr::dynamicCast(c)) { hasParent = true; - } + }*/ bool onEnumPage = EnumPtr::dynamicCast(c); diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index e90edc5d4fd..eb31d0414db 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -204,7 +204,7 @@ compile(int argc, char* argv[]) if(depend) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2CPP"); if(cppHandle == 0) { @@ -220,7 +220,8 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(Preprocessor::CPlusPlus, includePaths, sourceExtension, headerExtension)) + if(!icecpp->printMakefileDependencies(Preprocessor::CPlusPlus, includePaths, + "-DICE_COMPILER=ICE_SLICE2CPP", sourceExtension, headerExtension)) { return EXIT_FAILURE; } @@ -233,7 +234,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2CPP"); if(cppHandle == 0) { diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 0129ecfbeba..0f91002bbf3 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -198,7 +198,7 @@ compile(int argc, char* argv[]) if(depend) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2CS"); if(cppHandle == 0) { @@ -214,7 +214,8 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(Preprocessor::CSharp, includePaths)) + if(!icecpp->printMakefileDependencies(Preprocessor::CSharp, includePaths, + "-DICE_COMPILER=ICE_SLICE2CS")) { return EXIT_FAILURE; } @@ -227,7 +228,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(true); + FILE* cppHandle = icecpp->preprocess(true, "-DICE_COMPILER=ICE_SLICE2CS"); if(cppHandle == 0) { diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index ee807a38989..958e3438fab 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -1952,7 +1952,7 @@ compile(int argc, char* argv[]) // includes.push_back(icecpp->getBaseName() + ".h"); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2FREEZE"); if(cppHandle == 0) { diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 3b38ec8e667..6a80a241904 100644 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -1771,7 +1771,7 @@ compile(int argc, char* argv[]) if(depend || dependxml) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], args[idx], cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2FREEZEJ"); if(cppHandle == 0) { @@ -1787,7 +1787,8 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(depend ? Preprocessor::Java : Preprocessor::JavaXML, includePaths)) + if(!icecpp->printMakefileDependencies(depend ? Preprocessor::Java : Preprocessor::JavaXML, includePaths, + "-DICE_COMPILER=ICE_SLICE2FREEZEJ")) { u->destroy(); return EXIT_FAILURE; @@ -1802,7 +1803,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], args[idx], cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2FREEZEJ"); if(cppHandle == 0) { diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index 43646495f9e..b58360de8ed 100644 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -222,7 +222,7 @@ compile(int argc, char* argv[]) for(vector<string>::size_type idx = 0; idx < args.size(); ++idx) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], args[idx], cppArgs); - FILE* cppHandle = icecpp->preprocess(true); + FILE* cppHandle = icecpp->preprocess(true, "-DICE_COMPILER=ICE_SLICE2HTML"); if(cppHandle == 0) { diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 2d0f6cb06f1..d06b1477a66 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -219,7 +219,7 @@ compile(int argc, char* argv[]) if(depend || dependxml) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2JAVA"); if(cppHandle == 0) { @@ -235,7 +235,9 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(depend ? Preprocessor::Java : Preprocessor::JavaXML, includePaths)) + if(!icecpp->printMakefileDependencies(depend ? Preprocessor::Java : Preprocessor::JavaXML, includePaths, + "-DICE_COMPILER=ICE_SLICE2JAVA" + )) { return EXIT_FAILURE; } @@ -256,7 +258,7 @@ compile(int argc, char* argv[]) FileTracker::instance()->setSource(*i); PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(true); + FILE* cppHandle = icecpp->preprocess(true, "-DICE_COMPILER=ICE_SLICE2JAVA"); if(cppHandle == 0) { diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index 42eac38e19f..1be68d99238 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1670,7 +1670,7 @@ compile(int argc, char* argv[]) if(depend) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2PHP"); if(cppHandle == 0) { @@ -1686,7 +1686,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(Preprocessor::PHP, includePaths)) + if(!icecpp->printMakefileDependencies(Preprocessor::PHP, includePaths, "-DICE_COMPILER=ICE_SLICE2PHP")) { return EXIT_FAILURE; } @@ -1699,7 +1699,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2PHP"); if(cppHandle == 0) { diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 15aec1b42b4..317f0d7c68f 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -490,7 +490,7 @@ compile(int argc, char* argv[]) if(depend) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2PY"); if(cppHandle == 0) { @@ -506,7 +506,8 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(Preprocessor::Python, includePaths, "", prefix)) + if(!icecpp->printMakefileDependencies(Preprocessor::Python, includePaths, + "-DICE_COMPILER=ICE_SLICE2PY", "", prefix)) { return EXIT_FAILURE; } @@ -519,7 +520,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(keepComments); + FILE* cppHandle = icecpp->preprocess(keepComments, "-DICE_COMPILER=ICE_SLICE2PY"); if(cppHandle == 0) { diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index c793f2b5b3b..a8d2764a2f5 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -194,7 +194,7 @@ compile(int argc, char* argv[]) if(depend) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2RB"); if(cppHandle == 0) { @@ -210,7 +210,8 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(Preprocessor::Ruby, includePaths)) + if(!icecpp->printMakefileDependencies(Preprocessor::Ruby, includePaths, + "-DICE_COMPILER=ICE_SLICE2RB")) { return EXIT_FAILURE; } @@ -223,7 +224,7 @@ compile(int argc, char* argv[]) else { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2RB"); if(cppHandle == 0) { diff --git a/cpp/test/Slice/Makefile b/cpp/test/Slice/Makefile index 5981153b272..ee003135bd9 100644 --- a/cpp/test/Slice/Makefile +++ b/cpp/test/Slice/Makefile @@ -13,7 +13,8 @@ include $(top_srcdir)/config/Make.rules SUBDIRS = keyword \ parser \ - structure + structure \ + macros .PHONY: $(EVERYTHING) $(SUBDIRS) diff --git a/cpp/test/Slice/Makefile.mak b/cpp/test/Slice/Makefile.mak index 487e968ec03..e2f51a27dd2 100644 --- a/cpp/test/Slice/Makefile.mak +++ b/cpp/test/Slice/Makefile.mak @@ -13,7 +13,8 @@ top_srcdir = ..\.. SUBDIRS = keyword \ parser \ - structure + structure \ + macros $(EVERYTHING):: @for %i in ( $(SUBDIRS) ) do \ diff --git a/cpp/test/Slice/macros/.depend b/cpp/test/Slice/macros/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/test/Slice/macros/.depend diff --git a/cpp/test/Slice/macros/.depend.mak b/cpp/test/Slice/macros/.depend.mak new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/test/Slice/macros/.depend.mak diff --git a/cpp/test/Slice/macros/.gitignore b/cpp/test/Slice/macros/.gitignore new file mode 100644 index 00000000000..182a4020a50 --- /dev/null +++ b/cpp/test/Slice/macros/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +Test.cpp +Test.h + diff --git a/cpp/test/Slice/macros/Client.cpp b/cpp/test/Slice/macros/Client.cpp new file mode 100644 index 00000000000..b7955fa1367 --- /dev/null +++ b/cpp/test/Slice/macros/Client.cpp @@ -0,0 +1,43 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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 <Ice/Ice.h> +#include <TestCommon.h> +#include <Test.h> + +using namespace Test; +using namespace std; + +int +main(int argc, char* argv[]) +{ + int status = EXIT_SUCCESS; + try + { + cout << "Testing Slice predefined macros... " << flush; + DefaultPtr d = new Default(); + test(d->x == 10); + test(d->y == 10); + + NoDefaultPtr nd = new NoDefault(); + test(nd->x != 10); + test(nd->y != 10); + + CppOnlyPtr c = new CppOnly(); + test(c->lang == "cpp"); + test(c->version == ICE_INT_VERSION); + cout << "ok" << endl; + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + return status; +} diff --git a/cpp/test/Slice/macros/Makefile b/cpp/test/Slice/macros/Makefile new file mode 100644 index 00000000000..125dffe7af1 --- /dev/null +++ b/cpp/test/Slice/macros/Makefile @@ -0,0 +1,32 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ../../.. + +CLIENT = $(call mktestname,client) + +TARGETS = $(CLIENT) + +COBJS = Client.o \ + Test.o + +SRCS = $(COBJS:.o=.cpp) + +SLICE_SRCS = Test.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) +SLICE2CPPFLAGS := --underscore --stream $(SLICE2CPPFLAGS) + +$(CLIENT): $(COBJS) + rm -f $@ + $(call mktest,$@,$(COBJS),$(LIBS)) + +include .depend diff --git a/cpp/test/Slice/macros/Makefile.mak b/cpp/test/Slice/macros/Makefile.mak new file mode 100644 index 00000000000..f10a61f1da6 --- /dev/null +++ b/cpp/test/Slice/macros/Makefile.mak @@ -0,0 +1,38 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ..\..\.. + +CLIENT = client.exe + +TARGETS = $(CLIENT) + +COBJS = Test.obj \ + Client.obj + +SRCS = $(COBJS:.obj=.cpp) + +!include $(top_srcdir)/config/Make.rules.mak + +CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN +SLICE2CPPFLAGS = --underscore --stream $(SLICE2CPPFLAGS) + +!if "$(GENERATE_PDB)" == "yes" +CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb) +!endif + +$(CLIENT): $(COBJS) + $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +clean:: + del /q Test.cpp Test.h + +!include .depend.mak diff --git a/cpp/test/Slice/macros/Test.ice b/cpp/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..e156f51beee --- /dev/null +++ b/cpp/test/Slice/macros/Test.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + + +// +// This macro sets the default value only when compile with slice2cpp +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2CPP) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2cpp +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2CPP) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2cpp. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2CPP) +class CppOnly +{ + string lang DEFAULT("cpp"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/cpp/test/Slice/macros/run.py b/cpp/test/Slice/macros/run.py new file mode 100755 index 00000000000..de12d2ecf70 --- /dev/null +++ b/cpp/test/Slice/macros/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") +TestUtil.simpleTest(client) diff --git a/cs/allTests.py b/cs/allTests.py index 9a89444dcb1..9a3998842f2 100755 --- a/cs/allTests.py +++ b/cs/allTests.py @@ -27,6 +27,7 @@ import TestUtil tests = [ ("Slice/keyword", ["once", "nosilverlight"]), ("Slice/structure", ["once", "nosilverlight"]), + ("Slice/macros", ["once", "nosilverlight"]), ("IceUtil/inputUtil", ["once", "nosilverlight"]), ("Ice/proxy", ["core"]), ("Ice/properties", ["once", "nosilverlight"]), diff --git a/cs/test/Slice/Makefile b/cs/test/Slice/Makefile index e4bc64b54fb..d987aa3135f 100644 --- a/cs/test/Slice/Makefile +++ b/cs/test/Slice/Makefile @@ -11,7 +11,7 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules.cs -SUBDIRS = keyword structure +SUBDIRS = keyword structure macros $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cs/test/Slice/Makefile.mak b/cs/test/Slice/Makefile.mak index 8cac14054e5..afbb1dea798 100644 --- a/cs/test/Slice/Makefile.mak +++ b/cs/test/Slice/Makefile.mak @@ -11,7 +11,7 @@ top_srcdir = ..\.. !include $(top_srcdir)\config\Make.rules.mak.cs -SUBDIRS = keyword structure +SUBDIRS = keyword structure macros $(EVERYTHING):: @for %i in ( $(SUBDIRS) ) do \ diff --git a/cs/test/Slice/macros/.depend b/cs/test/Slice/macros/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cs/test/Slice/macros/.depend diff --git a/cs/test/Slice/macros/.depend.mak b/cs/test/Slice/macros/.depend.mak new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cs/test/Slice/macros/.depend.mak diff --git a/cs/test/Slice/macros/Client.cs b/cs/test/Slice/macros/Client.cs new file mode 100644 index 00000000000..63b209fdb6a --- /dev/null +++ b/cs/test/Slice/macros/Client.cs @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + +using System; +using System.Diagnostics; +using System.Collections.Generic; + +using Test; + +public class Client +{ + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public static int Main(string[] args) + { + int status = 0; + try + { + Console.Out.Write("Testing Slice predefined macros... "); + Console.Out.Flush(); + Default d = new Default(); + test(d.x == 10); + test(d.y == 10); + + NoDefault nd = new NoDefault(); + test(nd.x != 10); + test(nd.y != 10); + + CsOnly c = new CsOnly(); + test(c.lang.Equals("cs")); + test(c.version == Ice.Util.intVersion()); + Console.Out.WriteLine("ok"); + + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + return status; + } +} diff --git a/cs/test/Slice/macros/Makefile b/cs/test/Slice/macros/Makefile new file mode 100644 index 00000000000..2abf475fcee --- /dev/null +++ b/cs/test/Slice/macros/Makefile @@ -0,0 +1,31 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ../../.. + +TARGETS = client.exe + +C_SRCS = Client.cs + +SLICE_SRCS = $(SDIR)/Test.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) --stream + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,Ice) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Slice/macros/Makefile.mak b/cs/test/Slice/macros/Makefile.mak new file mode 100644 index 00000000000..fe0128712e6 --- /dev/null +++ b/cs/test/Slice/macros/Makefile.mak @@ -0,0 +1,31 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ..\..\.. + +TARGETS = client.exe + +C_SRCS = Client.cs + +GEN_SRCS = $(GDIR)\Test.cs + +SDIR = . + +GDIR = generated + +!include $(top_srcdir)\config\Make.rules.mak.cs + +MCSFLAGS = $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS = $(SLICE2CSFLAGS) --stream + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:"$(refdir)\Ice.dll" $(C_SRCS) $(GEN_SRCS) + +!include .depend.mak diff --git a/cs/test/Slice/macros/Test.ice b/cs/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..24109798ee9 --- /dev/null +++ b/cs/test/Slice/macros/Test.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + +// +// This macro sets the default value only when compile with slice2cs. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2CS) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2cs. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2CS) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2cs. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2CS) +class CsOnly +{ + string lang DEFAULT("cs"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/cs/test/Slice/macros/client.exe.config b/cs/test/Slice/macros/client.exe.config new file mode 100755 index 00000000000..d3fa65b4563 --- /dev/null +++ b/cs/test/Slice/macros/client.exe.config @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<configuration> + <runtime> + <developmentMode developerInstallation="true"/> + </runtime> +</configuration> diff --git a/cs/test/Slice/macros/run.py b/cs/test/Slice/macros/run.py new file mode 100755 index 00000000000..0338171006c --- /dev/null +++ b/cs/test/Slice/macros/run.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys, getopt + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient(client, startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/java/allTests.py b/java/allTests.py index ba28b83b8f0..c63013af76c 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -27,6 +27,7 @@ import TestUtil tests = [ ("Slice/generation", ["once"]), ("Slice/keyword", ["once"]), + ("Slice/macros", ["once"]), ("Slice/structure", ["once"]), ("IceUtil/inputUtil", ["once"]), ("IceUtil/fileLock", ["once"]), diff --git a/java/build.xml b/java/build.xml index a0ae57fa2df..c3d30a0bd35 100644 --- a/java/build.xml +++ b/java/build.xml @@ -471,6 +471,7 @@ <include name="test/IceBox/configuration/Test.ice" /> <include name="test/IceSSL/configuration/Test.ice" /> <include name="test/Slice/keyword/Key.ice" /> + <include name="test/Slice/macros/Test.ice" /> <include name="test/Slice/structure/Test.ice" /> </fileset> </slice2java> diff --git a/java/test/Slice/macros/Client.java b/java/test/Slice/macros/Client.java new file mode 100644 index 00000000000..3ba7ac80f9c --- /dev/null +++ b/java/test/Slice/macros/Client.java @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + +package test.Slice.macros; + +import test.Slice.macros.Test.Default; +import test.Slice.macros.Test.NoDefault; +import test.Slice.macros.Test.JavaOnly; + +public class Client +{ + private static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + main(String[] args) + { + int status = 0; + try + { + System.out.print("Testing Slice predefined macros... "); + Default d = new Default(); + test(d.x == 10); + test(d.y == 10); + + NoDefault nd = new NoDefault(); + test(nd.x != 10); + test(nd.y != 10); + + JavaOnly c = new JavaOnly(); + test(c.lang.equals("java")); + test(c.version == Ice.Util.intVersion()); + System.out.println("ok"); + } + catch(Exception ex) + { + ex.printStackTrace(); + status = 1; + } + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Slice/macros/Test.ice b/java/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..57d90703e6a --- /dev/null +++ b/java/test/Slice/macros/Test.ice @@ -0,0 +1,60 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + +#pragma once + +[["java:package:test.Slice.macros"]] + +// +// This macro sets the default value only when compile with slice2java +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2JAVA) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2java +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2JAVA) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2java. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2JAVA) +class JavaOnly +{ + string lang DEFAULT("java"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/java/test/Slice/macros/run.py b/java/test/Slice/macros/run.py new file mode 100755 index 00000000000..97426047aec --- /dev/null +++ b/java/test/Slice/macros/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("test.Slice.macros.Client",startReader=False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/php/allTests.py b/php/allTests.py index d4e601e313a..63ae6e84442 100755 --- a/php/allTests.py +++ b/php/allTests.py @@ -42,7 +42,8 @@ tests = [ ("Ice/ini", ["once"]), ("Ice/scope", ["once"]), ("Slice/keyword", ["once"]), - ("Slice/structure", ["once"]) + ("Slice/structure", ["once"]), + ("Slice/macros", ["once"]), ] if __name__ == "__main__": diff --git a/php/test/Slice/Makefile b/php/test/Slice/Makefile index 7a26e258656..368d17f5c17 100644 --- a/php/test/Slice/Makefile +++ b/php/test/Slice/Makefile @@ -11,7 +11,7 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules.php -SUBDIRS = keyword structure +SUBDIRS = keyword structure macros $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/php/test/Slice/Makefile.mak b/php/test/Slice/Makefile.mak index 2cd5bcd15fc..c18d09311ee 100644 --- a/php/test/Slice/Makefile.mak +++ b/php/test/Slice/Makefile.mak @@ -11,7 +11,7 @@ top_srcdir = ..\.. !include $(top_srcdir)\config\Make.rules.mak.php -SUBDIRS = keyword structure +SUBDIRS = keyword structure macros $(EVERYTHING):: @for %i in ( $(SUBDIRS) ) do \ diff --git a/php/test/Slice/macros/.depend b/php/test/Slice/macros/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/php/test/Slice/macros/.depend diff --git a/php/test/Slice/macros/Client.php b/php/test/Slice/macros/Client.php new file mode 100644 index 00000000000..4237ee87b7b --- /dev/null +++ b/php/test/Slice/macros/Client.php @@ -0,0 +1,73 @@ +<? +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + +error_reporting(E_ALL | E_STRICT); + +if(!extension_loaded("ice")) +{ + echo "\nerror: Ice extension is not loaded.\n\n"; + exit(1); +} + +$NS = function_exists("Ice\\initialize"); +require_once ($NS ? 'Ice_ns.php' : 'Ice.php'); +require_once 'Test.php'; + +function test($b) +{ + if(!$b) + { + $bt = debug_backtrace(); + die("\ntest failed in ".$bt[0]["file"]." line ".$bt[0]["line"]."\n"); + } +} + +function allTests() +{ + global $NS; + + echo "Testing Slice predefined macros... "; + flush(); + + if($NS) + { + $d = new Test\_Default(); + test($d->x == 10); + test($d->y == 10); + + $nd = new Test\NoDefault(); + test($nd->x != 10); + test($nd->y != 10); + + $c = new Test\PhpOnly(); + test($c->lang == "php"); + test($c->version == Ice\intVersion()); + } + else + { + $d = new Test_Default(); + test($d->x == 10); + test($d->y == 10); + + $nd = new Test_NoDefault(); + test($nd->x != 10); + test($nd->y != 10); + + $c = new Test_PhpOnly(); + test($c->lang == "php"); + test($c->version == Ice_intVersion()); + } + echo "ok\n"; +} + +allTests(); + +exit(); +?> diff --git a/php/test/Slice/macros/Makefile b/php/test/Slice/macros/Makefile new file mode 100644 index 00000000000..59d46595bda --- /dev/null +++ b/php/test/Slice/macros/Makefile @@ -0,0 +1,26 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ../../.. + +SLICE_SRCS = Test.ice + +include $(top_srcdir)/config/Make.rules.php + +SRCS = Test.php + +all:: $(SRCS) + +%.php: %.ice + $(SLICE2PHP) $(SLICE2PHPFLAGS) $< + +clean:: + rm -f $(SRCS) + +include .depend diff --git a/php/test/Slice/macros/Makefile.mak b/php/test/Slice/macros/Makefile.mak new file mode 100644 index 00000000000..a4786c6f5d2 --- /dev/null +++ b/php/test/Slice/macros/Makefile.mak @@ -0,0 +1,24 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 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 = ..\..\.. + +!include $(top_srcdir)\config\Make.rules.mak.php + +SRCS = Test.php + +all:: $(SRCS) + +$(SRCS): $*.ice + -"$(SLICE2PHP)" $(SLICE2PHPFLAGS) $*.ice + +clean:: + del /q $(SRCS) + +include .depend.mak diff --git a/php/test/Slice/macros/Test.ice b/php/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..f7a4021115f --- /dev/null +++ b/php/test/Slice/macros/Test.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + + +// +// This macro sets the default value only when compile with slice2php +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PHP) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2php +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2PHP) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2php. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PHP) +class PhpOnly +{ + string lang DEFAULT("php"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/php/test/Slice/macros/Test.php b/php/test/Slice/macros/Test.php new file mode 100644 index 00000000000..c5922148437 --- /dev/null +++ b/php/test/Slice/macros/Test.php @@ -0,0 +1,157 @@ +<?php +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** +// +// Ice version 3.5.0 +// +// <auto-generated> +// +// Generated from file `Test.ice' +// +// Warning: do not edit this file. +// +// </auto-generated> +// + + +if(!class_exists('Test_Default')) +{ + class Test_Default extends Ice_ObjectImpl + { + public function __construct($x=10, $y=10) + { + $this->x = $x; + $this->y = $y; + } + + public static function ice_staticId() + { + return '::Test::Default'; + } + + public function __toString() + { + global $Test__t_Default; + return IcePHP_stringify($this, $Test__t_Default); + } + + public $x; + public $y; + } + + class Test_DefaultPrxHelper + { + public static function checkedCast($proxy, $facetOrCtx=null, $ctx=null) + { + return $proxy->ice_checkedCast('::Test::Default', $facetOrCtx, $ctx); + } + + public static function uncheckedCast($proxy, $facet=null) + { + return $proxy->ice_uncheckedCast('::Test::Default', $facet); + } + } + + $Test__t_Default = IcePHP_defineClass('::Test::Default', 'Test_Default', -1, false, false, $Ice__t_Object, null, array( + array('x', $IcePHP__t_int, false, 0), + array('y', $IcePHP__t_int, false, 0))); + + $Test__t_DefaultPrx = IcePHP_defineProxy($Test__t_Default); +} + +if(!class_exists('Test_NoDefault')) +{ + class Test_NoDefault extends Ice_ObjectImpl + { + public function __construct($x=0, $y=0) + { + $this->x = $x; + $this->y = $y; + } + + public static function ice_staticId() + { + return '::Test::NoDefault'; + } + + public function __toString() + { + global $Test__t_NoDefault; + return IcePHP_stringify($this, $Test__t_NoDefault); + } + + public $x; + public $y; + } + + class Test_NoDefaultPrxHelper + { + public static function checkedCast($proxy, $facetOrCtx=null, $ctx=null) + { + return $proxy->ice_checkedCast('::Test::NoDefault', $facetOrCtx, $ctx); + } + + public static function uncheckedCast($proxy, $facet=null) + { + return $proxy->ice_uncheckedCast('::Test::NoDefault', $facet); + } + } + + $Test__t_NoDefault = IcePHP_defineClass('::Test::NoDefault', 'Test_NoDefault', -1, false, false, $Ice__t_Object, null, array( + array('x', $IcePHP__t_int, false, 0), + array('y', $IcePHP__t_int, false, 0))); + + $Test__t_NoDefaultPrx = IcePHP_defineProxy($Test__t_NoDefault); +} + +if(!class_exists('Test_PhpOnly')) +{ + class Test_PhpOnly extends Ice_ObjectImpl + { + public function __construct($lang="php", $version=30500) + { + $this->lang = $lang; + $this->version = $version; + } + + public static function ice_staticId() + { + return '::Test::PhpOnly'; + } + + public function __toString() + { + global $Test__t_PhpOnly; + return IcePHP_stringify($this, $Test__t_PhpOnly); + } + + public $lang; + public $version; + } + + class Test_PhpOnlyPrxHelper + { + public static function checkedCast($proxy, $facetOrCtx=null, $ctx=null) + { + return $proxy->ice_checkedCast('::Test::PhpOnly', $facetOrCtx, $ctx); + } + + public static function uncheckedCast($proxy, $facet=null) + { + return $proxy->ice_uncheckedCast('::Test::PhpOnly', $facet); + } + } + + $Test__t_PhpOnly = IcePHP_defineClass('::Test::PhpOnly', 'Test_PhpOnly', -1, false, false, $Ice__t_Object, null, array( + array('lang', $IcePHP__t_string, false, 0), + array('version', $IcePHP__t_int, false, 0))); + + $Test__t_PhpOnlyPrx = IcePHP_defineProxy($Test__t_PhpOnly); +} +?> diff --git a/php/test/Slice/macros/run.py b/php/test/Slice/macros/run.py new file mode 100755 index 00000000000..28dcfd43b5d --- /dev/null +++ b/php/test/Slice/macros/run.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +testdir = os.getcwd() + +client = os.path.join(testdir, "Client.php") + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient(client, startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/py/allTests.py b/py/allTests.py index 5ce49abc82f..32fc14b7704 100755 --- a/py/allTests.py +++ b/py/allTests.py @@ -26,6 +26,7 @@ import TestUtil tests = [ ("Slice/keyword", ["once"]), ("Slice/structure", ["once"]), + ("Slice/macros", ["once"]), ("Ice/adapterDeactivation", ["core"]), ("Ice/binding", ["core"]), ("Ice/exceptions", ["core"]), diff --git a/py/modules/IcePy/Slice.cpp b/py/modules/IcePy/Slice.cpp index 1614fd6b27e..841dded5079 100644 --- a/py/modules/IcePy/Slice.cpp +++ b/py/modules/IcePy/Slice.cpp @@ -136,7 +136,7 @@ IcePy_loadSlice(PyObject* /*self*/, PyObject* args) { string file = *p; Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("icecpp", file, cppArgs); - FILE* cppHandle = icecpp->preprocess(keepComments); + FILE* cppHandle = icecpp->preprocess(keepComments, "-DICE_COMPILER=ICE_SLICE2PY"); if(cppHandle == 0) { diff --git a/py/test/Slice/macros/Client.py b/py/test/Slice/macros/Client.py new file mode 100755 index 00000000000..0913eb041ab --- /dev/null +++ b/py/test/Slice/macros/Client.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys, traceback + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "python", "Ice.py")): + break +else: + raise RuntimeError("can't find toplevel directory!") + +import Ice + +Ice.loadSlice('Test.ice') +import Test, copy + +status = True + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + +try: + sys.stdout.write("Testing Slice predefined macros... ") + sys.stdout.flush() + + d = Test.Default() + test(d.x == 10) + test(d.y == 10) + + nd = Test.NoDefault() + test(nd.x != 10) + test(nd.y != 10) + + c = Test.PythonOnly() + test(c.lang == "python") + test(c.version == Ice.intVersion()) + print("ok") +except: + traceback.print_exc() + status = False + +sys.exit(not status) diff --git a/py/test/Slice/macros/Test.ice b/py/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..c889ba75164 --- /dev/null +++ b/py/test/Slice/macros/Test.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + + +// +// This macro sets the default value only when compile with slice2py +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PY) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2py +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2PY) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2py. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2PY) +class PythonOnly +{ + string lang DEFAULT("python"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/py/test/Slice/macros/run.py b/py/test/Slice/macros/run.py new file mode 100755 index 00000000000..aed5c7927ed --- /dev/null +++ b/py/test/Slice/macros/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.py", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() diff --git a/rb/allTests.py b/rb/allTests.py index 87ef49adfd4..13123463907 100755 --- a/rb/allTests.py +++ b/rb/allTests.py @@ -26,6 +26,8 @@ import TestUtil # tests = [ ("Slice/keyword", ["once"]), + ("Slice/structure", ["once"]), + ("Slice/macros", ["once"]), ("Ice/binding", ["core"]), ("Ice/checksum", ["core"]), ("Ice/exceptions", ["core"]), diff --git a/rb/src/IceRuby/Slice.cpp b/rb/src/IceRuby/Slice.cpp index 7c98670c489..f586b990703 100644 --- a/rb/src/IceRuby/Slice.cpp +++ b/rb/src/IceRuby/Slice.cpp @@ -122,7 +122,7 @@ IceRuby_loadSlice(int argc, VALUE* argv, VALUE self) { string file = *p; Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("icecpp", file, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); + FILE* cppHandle = icecpp->preprocess(false, "-DICE_COMPILER=ICE_SLICE2RB"); if(cppHandle == 0) { diff --git a/rb/test/Slice/macros/Client.rb b/rb/test/Slice/macros/Client.rb new file mode 100755 index 00000000000..b8d37960d6d --- /dev/null +++ b/rb/test/Slice/macros/Client.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +require 'pathname' + +rubyDir = nil +for toplevel in [".", "..", "../..", "../../..", "../../../.."] + path = Pathname.new(toplevel).join("ruby", "Ice.rb") + if path.file? + rubyDir = Pathname.new(toplevel).join("ruby") + break + end +end +if not rubyDir + fail "can't find toplevel directory!" +end + +require 'Ice' +Ice::loadSlice('Test.ice') + +def test(b) + if !b + raise RuntimeError, 'test assertion failed' + end +end + +status = true + +begin + print "Testing Slice predefined macros... " + STDOUT.flush + d = Test::Default.new + test(d.x == 10) + test(d.y == 10) + + nd = Test::NoDefault.new + test(nd.x != 10) + test(nd.y != 10) + + c = Test::RubyOnly.new + test(c.lang.eql? "ruby") + test(c.version == Ice::intVersion()) + puts "ok" +rescue => ex + puts $! + print ex.backtrace.join("\n") + status = false +end + +exit(status ? 0 : 1) diff --git a/rb/test/Slice/macros/Test.ice b/rb/test/Slice/macros/Test.ice new file mode 100644 index 00000000000..5a26e83a6d1 --- /dev/null +++ b/rb/test/Slice/macros/Test.ice @@ -0,0 +1,57 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2013 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. +// +// ********************************************************************** + + +// +// This macro sets the default value only when compile with slice2rb +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2RB) +# define DEFAULT(X) = X +#else +# define DEFAULT(X) /**/ +#endif + +// +// This macro sets the default value only when not compile with slice2rb +// +#if defined(ICE_COMPILER) && (ICE_COMPILER != ICE_SLICE2RB) +# define NODEFAULT(X) = X +#else +# define NODEFAULT(X) /**/ +#endif + + + +module Test +{ + +class Default +{ + int x DEFAULT(10); + int y DEFAULT(10); +}; + +class NoDefault +{ + int x NODEFAULT(10); + int y NODEFAULT(10); +}; + +// +// This class is only defined when compile with slice2rb. +// +#if defined(ICE_COMPILER) && (ICE_COMPILER == ICE_SLICE2RB) +class RubyOnly +{ + string lang DEFAULT("ruby"); + int version DEFAULT(ICE_VERSION); +}; +#endif + +}; diff --git a/rb/test/Slice/macros/run.py b/rb/test/Slice/macros/run.py new file mode 100755 index 00000000000..e9a14b55e70 --- /dev/null +++ b/rb/test/Slice/macros/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +sys.stdout.write("starting client... ") +sys.stdout.flush() +clientProc = TestUtil.startClient("Client.rb", "--Ice.Default.Host=127.0.0.1", startReader = False) +print("ok") +clientProc.startReader() +clientProc.waitTestSuccess() + |