summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2009-01-27 19:28:59 +0100
committerJose <jose@zeroc.com>2009-01-27 19:28:59 +0100
commit55f6e6863b8f17312e8ff58d05d6d035c822187b (patch)
tree787029a35e03a48456d1ed3cb8cc5965d0657319 /cpp
parentAdded missing libs (diff)
downloadice-55f6e6863b8f17312e8ff58d05d6d035c822187b.tar.bz2
ice-55f6e6863b8f17312e8ff58d05d6d035c822187b.tar.xz
ice-55f6e6863b8f17312e8ff58d05d6d035c822187b.zip
Squashed commit of the following:
commit 9aa67a8862e402cb52276282b26a40422fae4adb Author: Jose Gutierrez <jose@zeroc.com> Date: Tue Jan 27 19:25:22 2009 +0100 Fixed 3374 --header-ext not work as intended.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Slice/Preprocessor.h3
-rw-r--r--cpp/src/Freeze/PingObject.ice2
-rw-r--r--cpp/src/IceGrid/Internal.ice2
-rw-r--r--cpp/src/IceStorm/Election.ice2
-rw-r--r--cpp/src/IceStorm/IceStormInternal.ice2
-rw-r--r--cpp/src/IceStorm/LinkRecord.ice2
-rw-r--r--cpp/src/IceStorm/SubscriberRecord.ice2
-rw-r--r--cpp/src/IceStorm/V31Format.ice2
-rw-r--r--cpp/src/IceStorm/V32Format.ice2
-rw-r--r--cpp/src/Slice/Preprocessor.cpp7
-rw-r--r--cpp/src/slice2cpp/Gen.cpp132
-rw-r--r--cpp/src/slice2cpp/Gen.h16
-rw-r--r--cpp/src/slice2cpp/Main.cpp4
13 files changed, 144 insertions, 34 deletions
diff --git a/cpp/include/Slice/Preprocessor.h b/cpp/include/Slice/Preprocessor.h
index 98a018fbfbe..54535e28812 100644
--- a/cpp/include/Slice/Preprocessor.h
+++ b/cpp/include/Slice/Preprocessor.h
@@ -32,7 +32,7 @@ class SLICE_API Preprocessor
{
public:
- Preprocessor(const std::string&, const std::string&, const std::vector<std::string>&);
+ Preprocessor(const std::string&, const std::string&, const std::vector<std::string>&, const std::string& = "cpp");
~Preprocessor();
FILE* preprocess(bool);
@@ -54,6 +54,7 @@ private:
const std::string _path;
const std::string _fileName;
const std::vector<std::string> _args;
+ const std::string _cppSourceExt;
#ifdef _WIN32
std::wstring _cppFile;
#else
diff --git a/cpp/src/Freeze/PingObject.ice b/cpp/src/Freeze/PingObject.ice
index 9ef1772eb57..ac0262e47d5 100644
--- a/cpp/src/Freeze/PingObject.ice
+++ b/cpp/src/Freeze/PingObject.ice
@@ -10,6 +10,8 @@
#ifndef FREEZE_PING_OBJECT_ICE
#define FREEZE_PING_OBJECT_ICE
+[["cpp:header-ext:h"]]
+
module Freeze
{
diff --git a/cpp/src/IceGrid/Internal.ice b/cpp/src/IceGrid/Internal.ice
index 63d2bfb8f12..a1e510d8c38 100644
--- a/cpp/src/IceGrid/Internal.ice
+++ b/cpp/src/IceGrid/Internal.ice
@@ -10,6 +10,8 @@
#ifndef ICE_GRID_INTERNAL_ICE
#define ICE_GRID_INTERNAL_ICE
+[["cpp:header-ext:h"]]
+
#include <Ice/Identity.ice>
#include <Ice/BuiltinSequences.ice>
#include <Ice/ProcessF.ice>
diff --git a/cpp/src/IceStorm/Election.ice b/cpp/src/IceStorm/Election.ice
index 2ba02e1035c..2a2fde7f0e9 100644
--- a/cpp/src/IceStorm/Election.ice
+++ b/cpp/src/IceStorm/Election.ice
@@ -10,6 +10,8 @@
#ifndef ELECTION_ICE
#define ELECTION_ICE
+[["cpp:header-ext:h"]]
+
#include <Ice/Identity.ice>
#include <Ice/BuiltinSequences.ice>
#include <IceStorm/SubscriberRecord.ice>
diff --git a/cpp/src/IceStorm/IceStormInternal.ice b/cpp/src/IceStorm/IceStormInternal.ice
index 744a5339eab..476dde4c346 100644
--- a/cpp/src/IceStorm/IceStormInternal.ice
+++ b/cpp/src/IceStorm/IceStormInternal.ice
@@ -10,6 +10,8 @@
#ifndef ICE_STORM_INTERNAL_ICE
#define ICE_STORM_INTERNAL_ICE
+[["cpp:header-ext:h"]]
+
#include <IceStorm/IceStorm.ice>
#include <IceStorm/Election.ice>
#include <Ice/Current.ice>
diff --git a/cpp/src/IceStorm/LinkRecord.ice b/cpp/src/IceStorm/LinkRecord.ice
index 6d30eb428c7..744755fedef 100644
--- a/cpp/src/IceStorm/LinkRecord.ice
+++ b/cpp/src/IceStorm/LinkRecord.ice
@@ -10,6 +10,8 @@
#ifndef LINK_RECORD_ICE
#define LINK_RECORD_ICE
+[["cpp:header-ext:h"]]
+
#include <Ice/Identity.ice>
#include <IceStorm/IceStormInternal.ice>
diff --git a/cpp/src/IceStorm/SubscriberRecord.ice b/cpp/src/IceStorm/SubscriberRecord.ice
index 6a8c4133189..2c37010150d 100644
--- a/cpp/src/IceStorm/SubscriberRecord.ice
+++ b/cpp/src/IceStorm/SubscriberRecord.ice
@@ -10,6 +10,8 @@
#ifndef SUBSCRIBER_RECORD_ICE
#define SUBSCRIBER_RECORD_ICE
+[["cpp:header-ext:h"]]
+
#include <Ice/Identity.ice>
#include <IceStorm/IceStorm.ice>
diff --git a/cpp/src/IceStorm/V31Format.ice b/cpp/src/IceStorm/V31Format.ice
index ca45b0a7f0c..9607990a156 100644
--- a/cpp/src/IceStorm/V31Format.ice
+++ b/cpp/src/IceStorm/V31Format.ice
@@ -10,6 +10,8 @@
#ifndef V31_FORMAT_ICE
#define V31_FORMAT_ICE
+[["cpp:header-ext:h"]]
+
#include <IceStorm/LinkRecord.ice>
module IceStorm
diff --git a/cpp/src/IceStorm/V32Format.ice b/cpp/src/IceStorm/V32Format.ice
index 248de06da41..860120756a2 100644
--- a/cpp/src/IceStorm/V32Format.ice
+++ b/cpp/src/IceStorm/V32Format.ice
@@ -10,6 +10,8 @@
#ifndef V32_FORMAT_ICE
#define V32_FORMAT_ICE
+[["cpp:header-ext:h"]]
+
#include <IceStorm/LinkRecord.ice>
module IceStorm
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index 6c226c2db72..636c772b94d 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -44,10 +44,11 @@ extern "C" int mcpp_lib_main(int argc, char** argv);
extern "C" void mcpp_use_mem_buffers(int tf);
extern "C" char* mcpp_get_mem_buffer(Outdest od);
-Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, const vector<string>& args) :
+Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, const vector<string>& args, const string& cppSourceExt) :
_path(path),
_fileName(fileName),
_args(args),
+ _cppSourceExt(cppSourceExt),
_cppHandle(0)
{
}
@@ -390,12 +391,12 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
case CPlusPlus:
{
//
- // Change .o[bj] suffix to .cpp suffix.
+ // Change .o[bj] suffix to the cpp source extension suffix.
//
string::size_type pos;
while((pos = result.find(suffix)) != string::npos)
{
- result.replace(pos, suffix.size() - 1, ".cpp");
+ result.replace(pos, suffix.size() - 1, "." + _cppSourceExt);
}
break;
}
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index d442b2a7586..51ea19f40d2 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -15,11 +15,14 @@
#include <IceUtil/Iterator.h>
#include <Slice/Checksum.h>
#include <Slice/FileTracker.h>
+#include <Slice/Preprocessor.h>
#include <limits>
#include <sys/stat.h>
-#include <string.h>
+#include <string.h>
+
+#include <iostream> //TODO
using namespace std;
using namespace Slice;
@@ -44,11 +47,13 @@ Slice::Gen::Gen(const string& base, const string& headerExtension, const string&
bool imp, bool checksum, bool stream, bool ice) :
_base(base),
_headerExtension(headerExtension),
+ _implHeaderExtension(headerExtension),
_sourceExtension(sourceExtension),
_extraHeaders(extraHeaders),
_include(include),
_includePaths(includePaths),
_dllExport(dllExport),
+ _dir(dir),
_impl(imp),
_checksum(checksum),
_stream(stream),
@@ -64,15 +69,41 @@ Slice::Gen::Gen(const string& base, const string& headerExtension, const string&
{
_base.erase(0, pos + 1);
}
+}
+
+Slice::Gen::~Gen()
+{
+ H << "\n\n#endif\n";
+ C << '\n';
+
+ if(_impl)
+ {
+ implH << "\n\n#endif\n";
+ implC << '\n';
+ }
+}
+
+void
+Slice::Gen::generate(const UnitPtr& p)
+{
+
+ //
+ // Check the header-ext global meta data if is not empty we override _headerExtension
+ //
+ string headerExtension = getHeaderExt(p->modules());
+ if(!headerExtension.empty())
+ {
+ _headerExtension = headerExtension;
+ }
if(_impl)
{
- string fileImplH = _base + "I." + _headerExtension;
+ string fileImplH = _base + "I." + _implHeaderExtension;
string fileImplC = _base + "I." + _sourceExtension;
- if(!dir.empty())
+ if(!_dir.empty())
{
- fileImplH = dir + '/' + fileImplH;
- fileImplC = dir + '/' + fileImplC;
+ fileImplH = _dir + '/' + fileImplH;
+ fileImplC = _dir + '/' + fileImplC;
}
struct stat st;
@@ -120,10 +151,10 @@ Slice::Gen::Gen(const string& base, const string& headerExtension, const string&
string fileH = _base + "." + _headerExtension;
string fileC = _base + "." + _sourceExtension;
- if(!dir.empty())
+ if(!_dir.empty())
{
- fileH = dir + '/' + fileH;
- fileC = dir + '/' + fileC;
+ fileH = _dir + '/' + fileH;
+ fileC = _dir + '/' + fileC;
}
H.open(fileH.c_str());
@@ -158,23 +189,7 @@ Slice::Gen::Gen(const string& base, const string& headerExtension, const string&
H << "\n#ifndef __" << s << "__";
H << "\n#define __" << s << "__";
H << '\n';
-}
-
-Slice::Gen::~Gen()
-{
- H << "\n\n#endif\n";
- C << '\n';
-
- if(_impl)
- {
- implH << "\n\n#endif\n";
- implC << '\n';
- }
-}
-void
-Slice::Gen::generate(const UnitPtr& p)
-{
validateMetaData(p);
writeExtraHeaders(C);
@@ -193,6 +208,7 @@ Slice::Gen::generate(const UnitPtr& p)
}
C << _base << "." << _headerExtension << ">";
+
H << "\n#include <Ice/LocalObjectF.h>";
H << "\n#include <Ice/ProxyF.h>";
H << "\n#include <Ice/ObjectF.h>";
@@ -224,6 +240,7 @@ Slice::Gen::generate(const UnitPtr& p)
}
else if(p->hasNonLocalClassDecls())
{
+
H << "\n#include <Ice/Object.h>";
}
@@ -274,7 +291,12 @@ Slice::Gen::generate(const UnitPtr& p)
for(StringList::const_iterator q = includes.begin(); q != includes.end(); ++q)
{
- H << "\n#include <" << changeInclude(*q, _includePaths) << "." << _headerExtension << ">";
+ string extension = getHeaderExt((*q), p->modules());
+ if(extension.empty())
+ {
+ extension = _headerExtension;
+ }
+ H << "\n#include <" << changeInclude(*q, _includePaths) << "." << extension << ">";
}
H << "\n#include <Ice/UndefSysMacros.h>";
@@ -339,7 +361,7 @@ Slice::Gen::generate(const UnitPtr& p)
{
implH << _include << '/';
}
- implH << _base << ".h>";
+ implH << _base << "." << _headerExtension << ">";
writeExtraHeaders(implC);
@@ -348,7 +370,7 @@ Slice::Gen::generate(const UnitPtr& p)
{
implC << _include << '/';
}
- implC << _base << "I.h>";
+ implC << _base << "I." << _implHeaderExtension << ">";
ImplVisitor implVisitor(implH, implC, _dllExport);
p->visit(&implVisitor, false);
@@ -5641,6 +5663,8 @@ Slice::Gen::MetaDataVisitor::visitModuleStart(const ModulePtr& p)
StringList globalMetaData = dc->getMetaData();
string file = dc->filename();
static const string prefix = "cpp:";
+
+ int headerExtension = 0;
for(StringList::const_iterator q = globalMetaData.begin(); q != globalMetaData.end(); ++q)
{
string s = *q;
@@ -5653,7 +5677,15 @@ Slice::Gen::MetaDataVisitor::visitModuleStart(const ModulePtr& p)
{
continue;
}
- cerr << file << ": warning: ignoring invalid global metadata `" << s << "'" << endl;
+ else if(ss.find("header-ext:") == 0)
+ {
+ headerExtension++;
+ if(headerExtension == 1)
+ {
+ continue;
+ }
+ }
+ cerr << file << ": warning: ignoring invalid global metadata `" << s << "', the cpp:header-ext global metadata can only appear once per file." << endl;
}
_history.insert(s);
}
@@ -5866,3 +5898,47 @@ Slice::Gen::resetUseWstring(list<bool>& hist)
hist.pop_back();
return use;
}
+
+string
+Slice::Gen::getHeaderExt(const string& file, const ModuleList& modules)
+{
+ string ext = "";
+ if(!modules.empty()) // Just in case the Slice file has no definitions
+ {
+ for(ModuleList::const_iterator i = modules.begin(); i != modules.end(); ++i)
+ {
+ if((*i)->definitionContext()->filename() == file)
+ {
+ string meta = (*i)->definitionContext()->findMetaData("cpp:header-ext");
+ string::size_type index = meta.find_last_of(":");
+ if(index != string::npos && index + 1 < meta.size())
+ {
+ ext = meta.substr(index + 1, meta.size() - index - 1);
+ }
+ }
+ }
+ }
+ return ext;
+}
+
+string
+Slice::Gen::getHeaderExt(const ModuleList& modules)
+{
+ string ext = "";
+ if(!modules.empty()) // Just in case the Slice file has no definitions
+ {
+ for(ModuleList::const_iterator i = modules.begin(); i != modules.end(); ++i)
+ {
+ if((*i)->definitionContext()->includeLevel() == 0)
+ {
+ string meta = (*i)->definitionContext()->findMetaData("cpp:header-ext");
+ string::size_type index = meta.find_last_of(":");
+ if(index != string::npos && index + 1 < meta.size())
+ {
+ ext = meta.substr(index + 1, meta.size() - index - 1);
+ }
+ }
+ }
+ }
+ return ext;
+}
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index e3c1c9afc01..9cb699a205c 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -44,6 +44,20 @@ private:
void writeExtraHeaders(::IceUtilInternal::Output&);
+
+ //
+ // Get the header extension defined in the global metadata for a given file
+ // if there isn't defined returns a empty string
+ //
+ std::string getHeaderExt(const std::string& file, const ModuleList& modules);
+
+ //
+ // Get the header extension defined in the global metadata for the current
+ // compiling file.
+ // if there isn't defined returns a empty string
+ //
+ std::string getHeaderExt(const ModuleList& modules);
+
::IceUtilInternal::Output H;
::IceUtilInternal::Output C;
@@ -52,11 +66,13 @@ private:
std::string _base;
std::string _headerExtension;
+ std::string _implHeaderExtension;
std::string _sourceExtension;
std::vector<std::string> _extraHeaders;
std::string _include;
std::vector<std::string> _includePaths;
std::string _dllExport;
+ std::string _dir;
bool _impl;
bool _checksum;
bool _stream;
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index 7e2ff8b58b1..86eafe9e64f 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -169,7 +169,7 @@ main(int argc, char* argv[])
{
if(depend)
{
- Preprocessor icecpp(argv[0], *i, cppArgs);
+ Preprocessor icecpp(argv[0], *i, cppArgs, sourceExtension);
if(!icecpp.printMakefileDependencies(Preprocessor::CPlusPlus, includePaths))
{
return EXIT_FAILURE;
@@ -177,7 +177,7 @@ main(int argc, char* argv[])
}
else
{
- Preprocessor icecpp(argv[0], *i, cppArgs);
+ Preprocessor icecpp(argv[0], *i, cppArgs, sourceExtension);
FILE* cppHandle = icecpp.preprocess(false);
if(cppHandle == 0)