summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-01-24 00:20:04 +0000
committerMark Spruiell <mes@zeroc.com>2004-01-24 00:20:04 +0000
commit7dfbe2611e8b821d05386e13fd3d6cd7a80bbb3f (patch)
tree35c01de2a29205bf30dac738c74a850c88fd2e2b
parentassert (diff)
downloadice-7dfbe2611e8b821d05386e13fd3d6cd7a80bbb3f.tar.bz2
ice-7dfbe2611e8b821d05386e13fd3d6cd7a80bbb3f.tar.xz
ice-7dfbe2611e8b821d05386e13fd3d6cd7a80bbb3f.zip
reorganizing transform code
-rw-r--r--cpp/src/FreezeScript/.depend5
-rw-r--r--cpp/src/FreezeScript/Data.cpp38
-rw-r--r--cpp/src/FreezeScript/Data.h26
-rw-r--r--cpp/src/FreezeScript/Makefile1
-rw-r--r--cpp/src/FreezeScript/TransformDescriptors.cpp2232
-rw-r--r--cpp/src/FreezeScript/TransformDescriptors.h351
-rw-r--r--cpp/src/FreezeScript/TransformVisitor.cpp31
-rw-r--r--cpp/src/FreezeScript/TransformVisitor.h20
-rw-r--r--cpp/src/FreezeScript/Transformer.cpp2677
-rw-r--r--cpp/src/FreezeScript/Transformer.h27
-rw-r--r--cpp/src/FreezeScript/transformdb.cpp53
-rw-r--r--cpp/src/FreezeScript/transformdb.dsp8
12 files changed, 2664 insertions, 2805 deletions
diff --git a/cpp/src/FreezeScript/.depend b/cpp/src/FreezeScript/.depend
index 2c7b5c8a327..52c7820d48c 100644
--- a/cpp/src/FreezeScript/.depend
+++ b/cpp/src/FreezeScript/.depend
@@ -9,9 +9,8 @@ Parser.o: Parser.cpp ../FreezeScript/Parser.h ../FreezeScript/Data.h ../../inclu
Print.o: Print.cpp ../FreezeScript/Print.h ../FreezeScript/Data.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Error.h ../FreezeScript/Util.h ../../include/IceUtil/OutputUtil.h
Util.o: Util.cpp ../FreezeScript/Util.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Exception.h ../../include/Slice/Preprocessor.h
TransformAnalyzer.o: TransformAnalyzer.cpp ../FreezeScript/TransformAnalyzer.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Util.h ../../include/IceUtil/OutputUtil.h
-TransformDescriptors.o: TransformDescriptors.cpp ../FreezeScript/TransformDescriptors.h ../FreezeScript/Parser.h ../FreezeScript/Data.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Error.h ../FreezeScript/TransformVisitor.h ../../include/IceXML/Parser.h ../FreezeScript/AssignVisitor.h ../FreezeScript/Print.h ../FreezeScript/Functions.h ../FreezeScript/Exception.h ../FreezeScript/Util.h
TransformVisitor.o: TransformVisitor.cpp ../FreezeScript/TransformVisitor.h ../FreezeScript/Data.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Error.h ../FreezeScript/Util.h
-Transformer.o: Transformer.cpp ../FreezeScript/Transformer.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Exception.h ../FreezeScript/TransformDescriptors.h ../FreezeScript/Parser.h ../FreezeScript/Data.h ../FreezeScript/Error.h ../FreezeScript/TransformVisitor.h ../../include/IceXML/Parser.h ../FreezeScript/TransformAnalyzer.h ../FreezeScript/Util.h
-TransformDB.o: TransformDB.cpp ../FreezeScript/Transformer.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Exception.h ../FreezeScript/Util.h
+Transformer.o: Transformer.cpp ../FreezeScript/Transformer.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Parser.h ../FreezeScript/Data.h ../FreezeScript/Error.h ../FreezeScript/TransformVisitor.h ../FreezeScript/AssignVisitor.h ../FreezeScript/Print.h ../FreezeScript/Functions.h ../FreezeScript/Exception.h ../FreezeScript/Util.h ../../include/IceXML/Parser.h
+TransformDB.o: TransformDB.cpp ../FreezeScript/Transformer.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/TransformAnalyzer.h ../FreezeScript/Exception.h ../FreezeScript/Util.h
DumpDescriptors.o: DumpDescriptors.cpp ../FreezeScript/DumpDescriptors.h ../FreezeScript/Parser.h ../FreezeScript/Data.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Error.h ../../include/IceXML/Parser.h ../FreezeScript/AssignVisitor.h ../FreezeScript/Print.h ../FreezeScript/Functions.h ../FreezeScript/Exception.h ../FreezeScript/Util.h
DumpDB.o: DumpDB.cpp ../FreezeScript/DumpDescriptors.h ../FreezeScript/Parser.h ../FreezeScript/Data.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantManagerF.h ../../include/Ice/Direct.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Stats.h ../../include/Ice/Communicator.h ../../include/Ice/StatsF.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../../include/Ice/PluginF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/OutgoingAsync.h ../../include/Ice/IncomingAsync.h ../../include/Ice/Application.h ../../include/Slice/Parser.h ../../include/IceUtil/InputUtil.h ../FreezeScript/Error.h ../../include/IceXML/Parser.h ../FreezeScript/Util.h ../FreezeScript/Exception.h ../../include/IceUtil/OutputUtil.h
diff --git a/cpp/src/FreezeScript/Data.cpp b/cpp/src/FreezeScript/Data.cpp
index 63d56ef8354..9c0dc9911eb 100644
--- a/cpp/src/FreezeScript/Data.cpp
+++ b/cpp/src/FreezeScript/Data.cpp
@@ -200,18 +200,11 @@ FreezeScript::ObjectReader::getValue() const
}
//
-// DataInitializer
-//
-FreezeScript::DataInitializer::~DataInitializer()
-{
-}
-
-//
// DataFactory
//
FreezeScript::DataFactory::DataFactory(const Ice::CommunicatorPtr& communicator, const Slice::UnitPtr& unit,
const ErrorReporterPtr& errorReporter) :
- _communicator(communicator), _unit(unit), _errorReporter(errorReporter), _initializersEnabled(true)
+ _communicator(communicator), _unit(unit), _errorReporter(errorReporter)
{
}
@@ -325,24 +318,6 @@ FreezeScript::DataFactory::getBuiltin(Slice::Builtin::Kind kind) const
return _unit->builtin(kind);
}
-void
-FreezeScript::DataFactory::addInitializer(const string& type, const DataInitializerPtr& init)
-{
- _initializers.insert(InitMap::value_type(type, init));
-}
-
-void
-FreezeScript::DataFactory::enableInitializers()
-{
- _initializersEnabled = true;
-}
-
-void
-FreezeScript::DataFactory::disableInitializers()
-{
- _initializersEnabled = false;
-}
-
Ice::CommunicatorPtr
FreezeScript::DataFactory::getCommunicator() const
{
@@ -436,17 +411,8 @@ FreezeScript::DataFactory::createImpl(const Slice::TypePtr& type, bool readOnly)
}
void
-FreezeScript::DataFactory::initialize(const DataPtr& data)
+FreezeScript::DataFactory::initialize(const DataPtr&)
{
- if(_initializersEnabled)
- {
- string name = typeToString(data->getType());
- InitMap::iterator p = _initializers.find(name);
- if(p != _initializers.end())
- {
- p->second->initialize(this, data, _communicator);
- }
- }
}
//
diff --git a/cpp/src/FreezeScript/Data.h b/cpp/src/FreezeScript/Data.h
index 4d0883f951f..b7adb5c7da6 100644
--- a/cpp/src/FreezeScript/Data.h
+++ b/cpp/src/FreezeScript/Data.h
@@ -22,9 +22,6 @@
namespace FreezeScript
{
-class DataFactory;
-typedef IceUtil::Handle<DataFactory> DataFactoryPtr;
-
class Data;
typedef IceUtil::Handle<Data> DataPtr;
@@ -40,16 +37,6 @@ class ObjectReader;
class ObjectData;
typedef IceUtil::Handle<ObjectData> ObjectDataPtr;
-class DataInitializer : virtual public IceUtil::SimpleShared
-{
-public:
-
- virtual ~DataInitializer();
-
- virtual void initialize(const DataFactoryPtr&, const DataPtr&, const Ice::CommunicatorPtr&) = 0;
-};
-typedef IceUtil::Handle<DataInitializer> DataInitializerPtr;
-
class DataFactory : public IceUtil::SimpleShared
{
public:
@@ -66,25 +53,20 @@ public:
Slice::BuiltinPtr getBuiltin(Slice::Builtin::Kind) const;
- void addInitializer(const std::string&, const DataInitializerPtr&);
- void enableInitializers();
- void disableInitializers();
-
Ice::CommunicatorPtr getCommunicator() const;
ErrorReporterPtr getErrorReporter() const;
-private:
+protected:
DataPtr createImpl(const Slice::TypePtr&, bool);
- void initialize(const DataPtr&);
+
+ virtual void initialize(const DataPtr&);
Ice::CommunicatorPtr _communicator;
Slice::UnitPtr _unit; // Only used for creating builtin types.
ErrorReporterPtr _errorReporter;
- typedef std::map<std::string, DataInitializerPtr> InitMap;
- InitMap _initializers;
- bool _initializersEnabled;
};
+typedef IceUtil::Handle<DataFactory> DataFactoryPtr;
class Data : public IceUtil::SimpleShared
{
diff --git a/cpp/src/FreezeScript/Makefile b/cpp/src/FreezeScript/Makefile
index 3b6f5f64664..66da1ecd583 100644
--- a/cpp/src/FreezeScript/Makefile
+++ b/cpp/src/FreezeScript/Makefile
@@ -31,7 +31,6 @@ COMMON_OBJS = Grammar.o \
Util.o
TRANSFORM_OBJS = TransformAnalyzer.o \
- TransformDescriptors.o \
TransformVisitor.o \
Transformer.o \
TransformDB.o
diff --git a/cpp/src/FreezeScript/TransformDescriptors.cpp b/cpp/src/FreezeScript/TransformDescriptors.cpp
deleted file mode 100644
index c8e363ce739..00000000000
--- a/cpp/src/FreezeScript/TransformDescriptors.cpp
+++ /dev/null
@@ -1,2232 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2004
-// ZeroC, Inc.
-// Billerica, MA, USA
-//
-// All Rights Reserved.
-//
-// Ice is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation.
-//
-// **********************************************************************
-
-#include <FreezeScript/TransformDescriptors.h>
-#include <FreezeScript/AssignVisitor.h>
-#include <FreezeScript/Print.h>
-#include <FreezeScript/Functions.h>
-#include <FreezeScript/Exception.h>
-#include <FreezeScript/Util.h>
-#include <db_cxx.h>
-
-using namespace std;
-
-namespace FreezeScript
-{
-
-class SymbolTableI;
-typedef IceUtil::Handle<SymbolTableI> SymbolTableIPtr;
-
-class SymbolTableI : public SymbolTable
-{
-public:
-
- SymbolTableI(const DataFactoryPtr&, const Slice::UnitPtr&, const Slice::UnitPtr&, const ErrorReporterPtr&,
- TransformInfo*, const SymbolTablePtr& = SymbolTablePtr());
-
- virtual void add(const string&, const DataPtr&);
-
- virtual DataPtr getValue(const EntityNodePtr&) const;
-
- virtual DataPtr getConstantValue(const string&) const;
-
- virtual SymbolTablePtr createChild();
-
- virtual Slice::TypePtr lookupType(const string&);
-
- virtual DataPtr invokeFunction(const string&, const DataPtr&, const DataList&);
-
-private:
-
- DataPtr findValue(const string&) const;
-
- class EntityVisitor : public EntityNodeVisitor
- {
- public:
-
- EntityVisitor(SymbolTableI*);
-
- virtual void visitIdentifier(const string&);
- virtual void visitElement(const NodePtr&);
-
- DataPtr getCurrent() const;
-
- private:
-
- SymbolTableI* _table;
- DataPtr _current;
- bool _error;
- };
-
- friend class EntityVisitor;
-
- DataFactoryPtr _factory;
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- ErrorReporterPtr _errorReporter;
- TransformInfo* _info;
- SymbolTablePtr _parent;
- typedef map<string, DataPtr> DataMap;
- DataMap _dataMap;
- DataMap _constantCache;
-};
-
-class ObjectVisitor : public DataVisitor
-{
-public:
-
- ObjectVisitor(ObjectDataMap&);
-
- virtual void visitStruct(const StructDataPtr&);
- virtual void visitSequence(const SequenceDataPtr&);
- virtual void visitDictionary(const DictionaryDataPtr&);
- virtual void visitObject(const ObjectRefPtr&);
-
-private:
-
- ObjectDataMap& _map;
-};
-
-typedef map<string, TransformDescriptorPtr> TransformMap;
-typedef map<string, Slice::TypePtr> RenameMap;
-
-class TransformInfoI : public TransformInfo
-{
-public:
-
- TransformInfoI(const DataFactoryPtr&, const ErrorReporterPtr&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- virtual bool doDefaultTransform(const Slice::TypePtr&);
- virtual bool doBaseTransform(const Slice::ClassDefPtr&);
- virtual Slice::TypePtr getRenamedType(const Slice::TypePtr&);
- virtual void executeCustomTransform(const DataPtr&, const DataPtr&);
- virtual bool purgeObjects();
- virtual ObjectDataMap& getObjectDataMap();
-
- DataFactoryPtr factory;
- ErrorReporterPtr errorReporter;
- Slice::UnitPtr oldUnit;
- Slice::UnitPtr newUnit;
- SymbolTablePtr symbolTable;
- TransformMap transformMap;
- RenameMap renameMap;
- ObjectDataMap objectDataMap;
- Slice::TypePtr oldKeyType;
- Slice::TypePtr oldValueType;
- Slice::TypePtr newKeyType;
- Slice::TypePtr newValueType;
- Ice::CommunicatorPtr communicator;
- bool purge;
- Db* oldDb;
- DbTxn* oldDbTxn;
- Db* newDb;
- DbTxn* newDbTxn;
-};
-
-void assignOrTransform(const DataPtr&, const DataPtr&, bool, const DataFactoryPtr&, const ErrorReporterPtr&,
- TransformInfo*);
-
-} // End of namespace FreezeScript
-
-//
-// Descriptor
-//
-FreezeScript::Descriptor::Descriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter) :
- _parent(parent), _line(line), _factory(factory), _errorReporter(errorReporter)
-{
-}
-
-FreezeScript::Descriptor::~Descriptor()
-{
-}
-
-FreezeScript::DescriptorPtr
-FreezeScript::Descriptor::parent() const
-{
- return _parent;
-}
-
-FreezeScript::NodePtr
-FreezeScript::Descriptor::parse(const string& expr) const
-{
- return parseExpression(expr, _factory, _errorReporter);
-}
-
-Slice::TypePtr
-FreezeScript::Descriptor::findType(const Slice::UnitPtr& u, const string& type)
-{
- Slice::TypeList l;
-
- l = u->lookupType(type, false);
- if(l.empty())
- {
- _errorReporter->error("unknown type `" + type + "'");
- }
-
- return l.front();
-}
-
-//
-// SetDescriptor
-//
-FreezeScript::SetDescriptor::SetDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "set", _line);
-
- IceXML::Attributes::const_iterator p;
-
- string target;
- p = attributes.find("target");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `target' is missing");
- }
- target = p->second;
-
- p = attributes.find("value");
- if(p != attributes.end())
- {
- _valueStr = p->second;
- }
-
- p = attributes.find("type");
- if(p != attributes.end())
- {
- _type = p->second;
- }
-
- p = attributes.find("length");
- if(p != attributes.end())
- {
- _lengthStr = p->second;
- }
-
- p = attributes.find("convert");
- if(p != attributes.end())
- {
- _convert = p->second == "true";
- }
-
- if(!_valueStr.empty() && !_type.empty())
- {
- _errorReporter->error("attributes `value' and 'type' are mutually exclusive");
- }
-
- if(_valueStr.empty() && _type.empty() && _lengthStr.empty())
- {
- _errorReporter->error("requires a value for attributes `value', 'type' or 'length'");
- }
-
- NodePtr node = parse(target);
- _target = EntityNodePtr::dynamicCast(node);
- if(!_target)
- {
- _errorReporter->error("`target' attribute is not an entity: `" + target + "'");
- }
-
- if(!_valueStr.empty())
- {
- _value = parse(_valueStr);
- }
-
- if(!_lengthStr.empty())
- {
- _length = parse(_lengthStr);
- }
-}
-
-void
-FreezeScript::SetDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "set", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::SetDescriptor::validate()
-{
-}
-
-void
-FreezeScript::SetDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- DescriptorErrorContext ctx(_errorReporter, "set", _line);
-
- DataPtr data = sym->getValue(_target);
- if(data->readOnly())
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' cannot be modified");
- }
-
- DataPtr value;
- if(_value)
- {
- try
- {
- value = _value->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
- }
- }
-
- Destroyer<DataPtr> valueDestroyer;
- if(!_type.empty())
- {
- assert(!value);
- Slice::TypePtr type = sym->lookupType(_type);
- if(!type)
- {
- _errorReporter->error("type `" + _type + "' not found");
- }
- value = _factory->createObject(type, false);
- valueDestroyer.set(value);
- }
-
- DataPtr length;
- if(_length)
- {
- SequenceDataPtr seq = SequenceDataPtr::dynamicCast(data);
- if(!seq)
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' is not a sequence");
- }
-
- try
- {
- length = _length->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of length `" + _lengthStr + "' failed:\n" + ex.reason());
- }
-
- DataList& elements = seq->getElements();
- Ice::Long l = length->integerValue();
- if(l < 0 || l > INT_MAX)
- {
- _errorReporter->error("sequence length " + length->toString() + " is out of range");
- }
-
- DataList::size_type len = static_cast<DataList::size_type>(l);
- if(len < elements.size())
- {
- for(DataList::size_type i = len; i < elements.size(); ++i)
- {
- elements[i]->destroy();
- }
- elements.resize(len);
- }
- else if(len > elements.size())
- {
- Slice::SequencePtr seqType = Slice::SequencePtr::dynamicCast(seq->getType());
- assert(seqType);
- Slice::TypePtr elemType = seqType->type();
- for(DataList::size_type i = elements.size(); i < len; ++i)
- {
- DataPtr v = _factory->create(elemType, false);
- if(value)
- {
- assignOrTransform(v, value, _convert, _factory, _errorReporter, info);
- }
- elements.push_back(v);
- }
- }
- }
- else
- {
- assignOrTransform(data, value, _convert, _factory, _errorReporter, info);
- }
-}
-
-//
-// DefineDescriptor
-//
-FreezeScript::DefineDescriptor::DefineDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes, const Slice::UnitPtr& oldUnit,
- const Slice::UnitPtr& newUnit) :
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "define", _line);
-
- IceXML::Attributes::const_iterator p;
-
- p = attributes.find("name");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `name' is missing");
- }
- _name = p->second;
-
- p = attributes.find("type");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `type' is missing");
- }
- if(p->second.find("::New") != string::npos)
- {
- Slice::TypeList l = newUnit->lookupType(p->second.substr(5), false);
- if(l.empty())
- {
- _errorReporter->error("type `" + p->second + "' not found");
- }
- _type = l.front();
- }
- else if(p->second.find("::Old") != string::npos)
- {
- Slice::TypeList l = oldUnit->lookupType(p->second.substr(5), false);
- if(l.empty())
- {
- _errorReporter->error("type `" + p->second + "' not found");
- }
- _type = l.front();
- }
- else
- {
- Slice::TypeList l = newUnit->lookupType(p->second, false);
- if(l.empty())
- {
- _errorReporter->error("type `" + p->second + "' not found");
- }
- _type = l.front();
- }
-
- p = attributes.find("value");
- if(p != attributes.end())
- {
- _valueStr = p->second;
- }
-
- p = attributes.find("convert");
- if(p != attributes.end())
- {
- _convert = p->second == "true";
- }
-
- if(!_valueStr.empty())
- {
- _value = parse(_valueStr);
- }
-}
-
-void
-FreezeScript::DefineDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "define", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::DefineDescriptor::validate()
-{
-}
-
-void
-FreezeScript::DefineDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- DescriptorErrorContext ctx(_errorReporter, "define", _line);
-
- DataPtr data = _factory->create(_type, false);
-
- DataPtr value;
- if(_value)
- {
- try
- {
- value = _value->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
- }
- }
-
- if(value)
- {
- assignOrTransform(data, value, _convert, _factory, _errorReporter, info);
- }
-
- sym->add(_name, data);
-}
-
-//
-// AddDescriptor
-//
-FreezeScript::AddDescriptor::AddDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "add", _line);
-
- IceXML::Attributes::const_iterator p;
-
- string target;
- p = attributes.find("target");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `target' is missing");
- }
- target = p->second;
-
- p = attributes.find("key");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `key' is missing");
- }
- _keyStr = p->second;
-
- p = attributes.find("value");
- if(p != attributes.end())
- {
- _valueStr = p->second;
- }
-
- p = attributes.find("type");
- if(p != attributes.end())
- {
- _type = p->second;
- }
-
- p = attributes.find("convert");
- if(p != attributes.end())
- {
- _convert = p->second == "true";
- }
-
- if(!_valueStr.empty() && !_type.empty())
- {
- _errorReporter->error("attributes `value' and 'type' are mutually exclusive");
- }
-
- NodePtr node = parse(target);
- _target = EntityNodePtr::dynamicCast(node);
- if(!_target)
- {
- _errorReporter->error("`target' attribute is not an entity: `" + target + "'");
- }
-
- assert(!_keyStr.empty());
- _key = parse(_keyStr);
-
- if(!_valueStr.empty())
- {
- _value = parse(_valueStr);
- }
-}
-
-void
-FreezeScript::AddDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "add", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::AddDescriptor::validate()
-{
-}
-
-void
-FreezeScript::AddDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- DescriptorErrorContext ctx(_errorReporter, "add", _line);
-
- DataPtr data = sym->getValue(_target);
- if(data->readOnly())
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' cannot be modified");
- }
-
- DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
- if(!dict)
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' is not a dictionary");
- }
-
- Slice::DictionaryPtr type = Slice::DictionaryPtr::dynamicCast(dict->getType());
- assert(type);
-
- DataPtr key;
- Destroyer<DataPtr> keyDestroyer;
- try
- {
- DataPtr v = _key->evaluate(sym);
- key = _factory->create(type->keyType(), false);
- keyDestroyer.set(key);
- assignOrTransform(key, v, _convert, _factory, _errorReporter, info);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of key `" + _keyStr + "' failed:\n" + ex.reason());
- }
-
- if(dict->getElement(key))
- {
- ostringstream ostr;
- printData(key, ostr);
- _errorReporter->error("key " + ostr.str() + " already exists in dictionary");
- }
-
- DataPtr elem = _factory->create(type->valueType(), false);
- Destroyer<DataPtr> elemDestroyer(elem);
-
- DataPtr value;
- if(_value)
- {
- try
- {
- value = _value->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
- }
- }
-
- Destroyer<DataPtr> valueDestroyer;
- if(!_type.empty())
- {
- assert(!value);
- Slice::TypePtr type = sym->lookupType(_type);
- if(!type)
- {
- _errorReporter->error("type `" + _type + "' not found");
- }
- value = _factory->createObject(type, false);
- valueDestroyer.set(value);
- }
-
- if(value)
- {
- assignOrTransform(elem, value, _convert, _factory, _errorReporter, info);
- }
- DataMap& map = dict->getElements();
- map.insert(DataMap::value_type(key, elem));
- keyDestroyer.release();
- elemDestroyer.release();
-}
-
-//
-// RemoveDescriptor
-//
-FreezeScript::RemoveDescriptor::RemoveDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "remove", _line);
-
- IceXML::Attributes::const_iterator p;
-
- string target;
- p = attributes.find("target");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `target' is missing");
- }
- target = p->second;
-
- p = attributes.find("key");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `key' is missing");
- }
- _keyStr = p->second;
-
- NodePtr node = parse(target);
- _target = EntityNodePtr::dynamicCast(node);
- if(!_target)
- {
- _errorReporter->error("`target' attribute is not an entity: `" + target + "'");
- }
-
- _key = parse(_keyStr);
-}
-
-void
-FreezeScript::RemoveDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "remove", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::RemoveDescriptor::validate()
-{
-}
-
-void
-FreezeScript::RemoveDescriptor::execute(const SymbolTablePtr& sym, TransformInfo*)
-{
- DescriptorErrorContext ctx(_errorReporter, "remove", _line);
-
- DataPtr key;
- try
- {
- key = _key->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of key `" + _keyStr + "' failed:\n" + ex.reason());
- }
-
- DataPtr data = sym->getValue(_target);
- if(data->readOnly())
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' cannot be modified");
- }
-
- DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
- if(!dict)
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' is not a dictionary");
- }
-
- DataMap& map = dict->getElements();
- DataMap::iterator p = map.find(key);
- if(p != map.end())
- {
- p->first->destroy();
- p->second->destroy();
- map.erase(p);
- }
-}
-
-//
-// DeleteDescriptor
-//
-FreezeScript::DeleteDescriptor::DeleteDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter, const IceXML::Attributes&) :
- Descriptor(parent, line, factory, errorReporter)
-{
-}
-
-void
-FreezeScript::DeleteDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "delete", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::DeleteDescriptor::validate()
-{
-}
-
-void
-FreezeScript::DeleteDescriptor::execute(const SymbolTablePtr&, TransformInfo*)
-{
- throw DeleteRecordException();
-}
-
-//
-// FailDescriptor
-//
-FreezeScript::FailDescriptor::FailDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- Descriptor(parent, line, factory, errorReporter)
-{
- IceXML::Attributes::const_iterator p;
-
- p = attributes.find("test");
- if(p != attributes.end())
- {
- _testStr = p->second;
- }
-
- p = attributes.find("message");
- if(p != attributes.end())
- {
- _message = p->second;
- }
-
- if(!_testStr.empty())
- {
- _test = parse(_testStr);
- }
-
- if(_message.empty())
- {
- ostringstream ostr;
- ostr << "<fail> executed at line " << line << endl;
- _message = ostr.str();
- }
-}
-
-void
-FreezeScript::FailDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "fail", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::FailDescriptor::validate()
-{
-}
-
-void
-FreezeScript::FailDescriptor::execute(const SymbolTablePtr& sym, TransformInfo*)
-{
- DescriptorErrorContext ctx(_errorReporter, "fail", _line);
-
- if(_test)
- {
- try
- {
- DataPtr b = _test->evaluate(sym);
- BooleanDataPtr bd = BooleanDataPtr::dynamicCast(b);
- if(!bd)
- {
- _errorReporter->error("expression `" + _testStr + "' does not evaluate to a boolean");
- }
- if(!bd->booleanValue())
- {
- return;
- }
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of expression `" + _testStr + "' failed:\n" + ex.reason());
- }
- }
-
- throw Exception(__FILE__, __LINE__, _message);
-}
-
-//
-// EchoDescriptor
-//
-FreezeScript::EchoDescriptor::EchoDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- Descriptor(parent, line, factory, errorReporter)
-{
- IceXML::Attributes::const_iterator p;
-
- p = attributes.find("message");
- if(p != attributes.end())
- {
- _message = p->second;
- }
-
- p = attributes.find("value");
- if(p != attributes.end())
- {
- _valueStr = p->second;
- }
-
- if(!_valueStr.empty())
- {
- _value = parse(_valueStr);
- }
-}
-
-void
-FreezeScript::EchoDescriptor::addChild(const DescriptorPtr&)
-{
- DescriptorErrorContext ctx(_errorReporter, "echo", _line);
- _errorReporter->error("child elements are not supported");
-}
-
-void
-FreezeScript::EchoDescriptor::validate()
-{
-}
-
-void
-FreezeScript::EchoDescriptor::execute(const SymbolTablePtr& sym, TransformInfo*)
-{
- DescriptorErrorContext ctx(_errorReporter, "echo", _line);
-
- ostream& out = _errorReporter->stream();
-
- if(!_message.empty())
- {
- out << _message;
- }
-
- if(_value)
- {
- DataPtr v;
- try
- {
- v = _value->evaluate(sym);
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
- }
- printData(v, out);
- }
-
- out << endl;
-}
-
-//
-// ExecutableContainerDescriptor
-//
-FreezeScript::ExecutableContainerDescriptor::ExecutableContainerDescriptor(const DescriptorPtr& parent, int line,
- const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes&,
- const string& name) :
- Descriptor(parent, line, factory, errorReporter), _name(name)
-{
-}
-
-void
-FreezeScript::ExecutableContainerDescriptor::addChild(const DescriptorPtr& child)
-{
- _children.push_back(child);
-}
-
-void
-FreezeScript::ExecutableContainerDescriptor::validate()
-{
- for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
- {
- (*p)->validate();
- }
-}
-
-void
-FreezeScript::ExecutableContainerDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
- {
- (*p)->execute(sym, info);
- }
-}
-
-//
-// IfDescriptor
-//
-FreezeScript::IfDescriptor::IfDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "if"),
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "if", _line);
-
- IceXML::Attributes::const_iterator p = attributes.find("test");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `test' is missing");
- }
- _testStr = p->second;
-
- _test = parse(_testStr);
-}
-
-void
-FreezeScript::IfDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- DescriptorErrorContext ctx(_errorReporter, "if", _line);
-
- try
- {
- DataPtr b = _test->evaluate(sym);
- BooleanDataPtr bd = BooleanDataPtr::dynamicCast(b);
- if(!bd)
- {
- _errorReporter->error("expression `" + _testStr + "' does not evaluate to a boolean");
- }
- if(bd->booleanValue())
- {
- ExecutableContainerDescriptor::execute(sym, info);
- }
- }
- catch(const EvaluateException& ex)
- {
- _errorReporter->error("evaluation of conditional expression `" + _testStr + "' failed:\n" + ex.reason());
- }
-}
-
-//
-// IterateDescriptor
-//
-FreezeScript::IterateDescriptor::IterateDescriptor(const DescriptorPtr& parent, int line,
- const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "iterate"),
- Descriptor(parent, line, factory, errorReporter)
-{
- DescriptorErrorContext ctx(_errorReporter, "iterate", _line);
-
- IceXML::Attributes::const_iterator p;
- string target;
-
- p = attributes.find("target");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `target' is missing");
- }
- target = p->second;
-
- p = attributes.find("key");
- if(p != attributes.end())
- {
- _key = p->second;
- }
-
- p = attributes.find("value");
- if(p != attributes.end())
- {
- _value = p->second;
- }
-
- p = attributes.find("element");
- if(p != attributes.end())
- {
- _element = p->second;
- }
-
- p = attributes.find("index");
- if(p != attributes.end())
- {
- _index = p->second;
- }
-
- NodePtr node = parse(target);
- _target = EntityNodePtr::dynamicCast(node);
- if(!_target)
- {
- _errorReporter->error("`target' attribute is not an entity: `" + target + "'");
- }
-}
-
-void
-FreezeScript::IterateDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- DescriptorErrorContext ctx(_errorReporter, "iterate", _line);
-
- DataPtr data = sym->getValue(_target);
-
- DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
- SequenceDataPtr seq = SequenceDataPtr::dynamicCast(data);
- if(!dict && !seq)
- {
- ostringstream ostr;
- ostr << _target;
- _errorReporter->error("target `" + ostr.str() + "' is not a dictionary or sequence");
- }
-
- if(dict)
- {
- if(!_element.empty())
- {
- _errorReporter->error("attribute `element' specified for dictionary target");
- }
- if(!_index.empty())
- {
- _errorReporter->error("attribute `index' specified for dictionary target");
- }
-
- string key = _key;
- if(key.empty())
- {
- key = "key";
- }
-
- string value = _value;
- if(value.empty())
- {
- value = "value";
- }
-
- DataMap& map = dict->getElements();
- for(DataMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- SymbolTablePtr elemSym = sym->createChild();
- elemSym->add(key, p->first);
- elemSym->add(value, p->second);
- ExecutableContainerDescriptor::execute(elemSym, info);
- }
- }
- else
- {
- if(!_key.empty())
- {
- _errorReporter->error("attribute `key' specified for sequence target");
- }
- if(!_value.empty())
- {
- _errorReporter->error("attribute `value' specified for sequence target");
- }
-
- string element = _element;
- if(element.empty())
- {
- element = "elem";
- }
-
- string index = _index;
- if(index.empty())
- {
- index = "i";
- }
-
- DataList& l = seq->getElements();
- Ice::Long i = 0;
- for(DataList::iterator p = l.begin(); p != l.end(); ++p, ++i)
- {
- SymbolTablePtr elemSym = sym->createChild();
- elemSym->add(element, *p);
- elemSym->add(index, _factory->createInteger(i, true));
- ExecutableContainerDescriptor::execute(elemSym, info);
- }
- }
-}
-
-//
-// TransformDescriptor
-//
-FreezeScript::TransformDescriptor::TransformDescriptor(const DescriptorPtr& parent, int line,
- const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes,
- const Slice::UnitPtr& oldUnit, const Slice::UnitPtr& newUnit) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "transform"),
- Descriptor(parent, line, factory, errorReporter), _default(true), _base(true)
-{
- DescriptorErrorContext ctx(_errorReporter, "transform", _line);
-
- IceXML::Attributes::const_iterator p;
-
- string type, rename;
-
- p = attributes.find("type");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `type' is missing");
- }
- type = p->second;
-
- p = attributes.find("default");
- if(p != attributes.end())
- {
- if(p->second == "false")
- {
- _default = false;
- }
- }
-
- p = attributes.find("base");
- if(p != attributes.end())
- {
- if(p->second == "false")
- {
- _base = false;
- }
- }
-
- p = attributes.find("rename");
- if(p != attributes.end())
- {
- rename = p->second;
- }
-
- Slice::TypeList l;
-
- l = newUnit->lookupType(type, false);
- if(l.empty())
- {
- _errorReporter->error("unable to find type `" + type + "' in new Slice definitions");
- }
- else
- {
- _newType = l.front();
- }
-
- if(!rename.empty())
- {
- l = oldUnit->lookupType(rename, false);
- if(l.empty())
- {
- _errorReporter->error("unable to find type `" + rename + "' in old Slice definitions");
- }
- _renameType = l.front();
- }
-}
-
-Slice::TypePtr
-FreezeScript::TransformDescriptor::type() const
-{
- return _newType;
-}
-
-string
-FreezeScript::TransformDescriptor::typeName() const
-{
- return typeToString(_newType);
-}
-
-Slice::TypePtr
-FreezeScript::TransformDescriptor::renameType() const
-{
- return _renameType;
-}
-
-string
-FreezeScript::TransformDescriptor::renameTypeName() const
-{
- string result;
- if(_renameType)
- {
- result = typeToString(_renameType);
- }
- return result;
-}
-
-bool
-FreezeScript::TransformDescriptor::doDefaultTransform() const
-{
- return _default;
-}
-
-bool
-FreezeScript::TransformDescriptor::doBaseTransform() const
-{
- return _base;
-}
-
-//
-// InitDescriptor
-//
-FreezeScript::InitDescriptor::InitDescriptor(const DescriptorPtr& parent, int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes,
- const Slice::UnitPtr& oldUnit, const Slice::UnitPtr& newUnit) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "init"),
- Descriptor(parent, line, factory, errorReporter), _old(oldUnit), _new(newUnit)
-{
- DescriptorErrorContext ctx(_errorReporter, "init", _line);
-
- IceXML::Attributes::const_iterator p = attributes.find("type");
-
- string type;
-
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `type' is missing");
- }
- type = p->second;
-
- Slice::TypeList l = _new->lookupType(type, false);
- if(l.empty())
- {
- _errorReporter->error("unable to find type `" + type + "' in new Slice definitions");
- }
- else
- {
- _type = l.front();
- }
-}
-
-void
-FreezeScript::InitDescriptor::initialize(const DataFactoryPtr& factory, const DataPtr& data,
- const Ice::CommunicatorPtr& communicator)
-{
- //
- // Create a new symbol table for the initializer and add the value to be initialized
- // as the symbol "value".
- //
- TransformInfo* info = 0;
-
- // TODO: Initialializers should have access to the main symbol table.
- SymbolTablePtr sym = new SymbolTableI(factory, _old, _new, _errorReporter, info);
- sym->add("value", data);
-
- execute(sym, info);
-}
-
-string
-FreezeScript::InitDescriptor::typeName() const
-{
- return typeToString(_type);
-}
-
-//
-// RecordDescriptor
-//
-FreezeScript::RecordDescriptor::RecordDescriptor(const DescriptorPtr& parent, int line,
- const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes,
- const Slice::UnitPtr& oldUnit, const Slice::UnitPtr& newUnit) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "record"),
- Descriptor(parent, line, factory, errorReporter), _old(oldUnit), _new(newUnit)
-{
-}
-
-void
-FreezeScript::RecordDescriptor::execute(const SymbolTablePtr& sym, TransformInfo* info)
-{
- TransformInfoI* infoI = dynamic_cast<TransformInfoI*>(info);
- assert(infoI);
-
- //
- // We need the Instance in order to use BasicStream.
- //
- IceInternal::InstancePtr instance = IceInternal::getInstance(infoI->communicator);
-
- //
- // Temporarily add an object factory.
- //
- infoI->communicator->addObjectFactory(new FreezeScript::ObjectFactory(_factory, _old), "");
-
- //
- // Iterate over the database.
- //
- Dbc* dbc = 0;
- infoI->oldDb->cursor(infoI->oldDbTxn, &dbc, 0);
- try
- {
- Dbt dbKey, dbValue;
- while(dbc->get(&dbKey, &dbValue, DB_NEXT) == 0)
- {
- IceInternal::BasicStream inKey(instance.get());
- inKey.b.resize(dbKey.get_size());
- memcpy(&inKey.b[0], dbKey.get_data(), dbKey.get_size());
- inKey.i = inKey.b.begin();
-
- IceInternal::BasicStream inValue(instance.get());
- inValue.b.resize(dbValue.get_size());
- memcpy(&inValue.b[0], dbValue.get_data(), dbValue.get_size());
- inValue.i = inValue.b.begin();
- inValue.startReadEncaps();
-
- IceInternal::BasicStream outKey(instance.get());
- IceInternal::BasicStream outValue(instance.get());
- outValue.startWriteEncaps();
- try
- {
- transformRecord(inKey, inValue, outKey, outValue, info);
- outValue.endWriteEncaps();
- Dbt dbNewKey(&outKey.b[0], outKey.b.size()), dbNewValue(&outValue.b[0], outValue.b.size());
- if(infoI->newDb->put(infoI->newDbTxn, &dbNewKey, &dbNewValue, DB_NOOVERWRITE) == DB_KEYEXIST)
- {
- _errorReporter->error("duplicate key encountered");
- }
- }
- catch(const DeleteRecordException&)
- {
- // The record is deleted simply by not adding it to the new database.
- }
- catch(const ClassNotFoundException& ex)
- {
- if(!infoI->purge)
- {
- _errorReporter->error("class " + ex.id + " not found in new Slice definitions");
- }
- else
- {
- // The record is deleted simply by not adding it to the new database.
- _errorReporter->warning("purging database record due to missing class type " + ex.id);
- }
- }
- }
- }
- catch(...)
- {
- if(dbc)
- {
- dbc->close();
- }
- infoI->communicator->removeObjectFactory("");
- throw;
- }
-
- infoI->communicator->removeObjectFactory("");
-
- if(dbc)
- {
- dbc->close();
- }
-}
-
-void
-FreezeScript::RecordDescriptor::transformRecord(IceInternal::BasicStream& inKey, IceInternal::BasicStream& inValue,
- IceInternal::BasicStream& outKey, IceInternal::BasicStream& outValue,
- TransformInfo* info)
-{
- TransformInfoI* infoI = dynamic_cast<TransformInfoI*>(info);
- assert(infoI);
-
- //
- // Create data representations of the old key and value types.
- //
- _factory->disableInitializers();
- DataPtr oldKeyData = _factory->create(infoI->oldKeyType, true);
- Destroyer<DataPtr> oldKeyDataDestroyer(oldKeyData);
- DataPtr oldValueData = _factory->create(infoI->oldValueType, true);
- Destroyer<DataPtr> oldValueDataDestroyer(oldValueData);
-
- //
- // Unmarshal the old key and value.
- //
- oldKeyData->unmarshal(inKey);
- oldValueData->unmarshal(inValue);
- infoI->objectDataMap.clear();
- if(infoI->oldValueType->usesClasses())
- {
- inValue.readPendingObjects();
- ObjectVisitor visitor(infoI->objectDataMap);
- oldValueData->visit(visitor);
- }
- _factory->enableInitializers();
-
- //
- // Create data representations of the new key and value types.
- //
- DataPtr newKeyData = _factory->create(infoI->newKeyType, false);
- Destroyer<DataPtr> newKeyDataDestroyer(newKeyData);
- DataPtr newValueData = _factory->create(infoI->newValueType, false);
- Destroyer<DataPtr> newValueDataDestroyer(newValueData);
-
- //
- // Copy the data from the old key and value to the new key and value, if possible.
- //
- TransformVisitor keyVisitor(oldKeyData, _factory, _errorReporter, info);
- newKeyData->visit(keyVisitor);
- TransformVisitor valueVisitor(oldValueData, _factory, _errorReporter, info);
- newValueData->visit(valueVisitor);
-
- if(!_children.empty())
- {
- //
- // Execute the child descriptors.
- //
- // TODO: Revisit identifiers.
- //
- SymbolTablePtr st = new SymbolTableI(_factory, _old, _new, _errorReporter, info, infoI->symbolTable);
- st->add("oldkey", oldKeyData);
- st->add("newkey", newKeyData);
- st->add("oldvalue", oldValueData);
- st->add("newvalue", newValueData);
- ExecutableContainerDescriptor::execute(st, info);
- }
-
- newKeyData->marshal(outKey);
- newValueData->marshal(outValue);
- if(infoI->newValueType->usesClasses())
- {
- outValue.writePendingObjects();
- }
-}
-
-//
-// DatabaseDescriptor
-//
-FreezeScript::DatabaseDescriptor::DatabaseDescriptor(const DescriptorPtr& parent, int line,
- const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes,
- const Slice::UnitPtr& oldUnit, const Slice::UnitPtr& newUnit) :
- ExecutableContainerDescriptor(parent, line, factory, errorReporter, attributes, "database"),
- Descriptor(parent, line, factory, errorReporter), _old(oldUnit), _new(newUnit)
-{
- DescriptorErrorContext ctx(_errorReporter, "database", _line);
-
- IceXML::Attributes::const_iterator p = attributes.find("key");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `key' is missing");
- }
- string keyTypes = p->second;
-
- p = attributes.find("value");
- if(p == attributes.end())
- {
- _errorReporter->error("required attribute `value' is missing");
- }
- string valueTypes = p->second;
-
- string oldKeyName, newKeyName;
- string oldValueName, newValueName;
- string::size_type pos;
-
- pos = keyTypes.find(',');
- if(pos == 0 || pos == keyTypes.size())
- {
- _errorReporter->error("invalid key type specification `" + keyTypes +"'");
- }
- if(pos == string::npos)
- {
- oldKeyName = keyTypes;
- newKeyName = keyTypes;
- }
- else
- {
- oldKeyName = keyTypes.substr(0, pos);
- newKeyName = keyTypes.substr(pos + 1);
- }
-
- pos = valueTypes.find(',');
- if(pos == 0 || pos == valueTypes.size())
- {
- _errorReporter->error("invalid value type specification `" + valueTypes +"'");
- }
- if(pos == string::npos)
- {
- oldValueName = valueTypes;
- newValueName = valueTypes;
- }
- else
- {
- oldValueName = valueTypes.substr(0, pos);
- newValueName = valueTypes.substr(pos + 1);
- }
-
- //
- // Look up the Slice definitions for the key and value types.
- //
- _oldKey = findType(_old, oldKeyName);
- _newKey = findType(_new, newKeyName);
- _oldValue = findType(_old, oldValueName);
- _newValue = findType(_new, newValueName);
-}
-
-void
-FreezeScript::DatabaseDescriptor::addChild(const DescriptorPtr& child)
-{
- DescriptorErrorContext ctx(_errorReporter, "database", _line);
-
- RecordDescriptorPtr rec = RecordDescriptorPtr::dynamicCast(child);
- if(rec)
- {
- if(_record)
- {
- _errorReporter->error("only one <record> element can be specified");
- }
- _record = rec;
- }
-
- ExecutableContainerDescriptor::addChild(child);
-}
-
-void
-FreezeScript::DatabaseDescriptor::execute(const SymbolTablePtr&, TransformInfo* info)
-{
- TransformInfoI* infoI = dynamic_cast<TransformInfoI*>(info);
- assert(infoI);
-
- //
- // Store the key and value types.
- //
- infoI->oldKeyType = _oldKey;
- infoI->oldValueType = _oldValue;
- infoI->newKeyType = _newKey;
- infoI->newValueType = _newValue;
-
- ExecutableContainerDescriptor::execute(infoI->symbolTable, info);
-}
-
-//
-// TransformDBDescriptor
-//
-FreezeScript::TransformDBDescriptor::TransformDBDescriptor(int line, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter,
- const IceXML::Attributes& attributes,
- const Slice::UnitPtr& oldUnit,
- const Slice::UnitPtr& newUnit) :
- Descriptor(0, line, factory, errorReporter), _old(oldUnit), _new(newUnit),
- _info(new TransformInfoI(factory, errorReporter, oldUnit, newUnit))
-{
-}
-
-FreezeScript::TransformDBDescriptor::~TransformDBDescriptor()
-{
- delete _info;
-}
-
-void
-FreezeScript::TransformDBDescriptor::addChild(const DescriptorPtr& child)
-{
- DescriptorErrorContext ctx(_errorReporter, "transformdb", _line);
-
- DatabaseDescriptorPtr db = DatabaseDescriptorPtr::dynamicCast(child);
- TransformDescriptorPtr transform = TransformDescriptorPtr::dynamicCast(child);
- InitDescriptorPtr init = InitDescriptorPtr::dynamicCast(child);
-
- if(db)
- {
- if(_database)
- {
- _errorReporter->error("only one <database> element can be specified");
- }
- else
- {
- _database = db;
- _children.push_back(db);
- }
- }
- else if(transform)
- {
- string name = transform->typeName();
- TransformMap::iterator p = _info->transformMap.find(name);
- if(p != _info->transformMap.end())
- {
- _errorReporter->error("transform `" + name + "' specified more than once");
- }
- _info->transformMap.insert(TransformMap::value_type(name, transform));
-
- string renameTypeName = transform->renameTypeName();
- if(!renameTypeName.empty())
- {
- RenameMap::iterator q = _info->renameMap.find(renameTypeName);
- if(q != _info->renameMap.end())
- {
- _errorReporter->error("multiple transform descriptors specify the rename value `" + renameTypeName +
- "'");
- }
- _info->renameMap.insert(RenameMap::value_type(renameTypeName, transform->type()));
- }
-
- _children.push_back(transform);
- }
- else if(init)
- {
- string name = init->typeName();
- _factory->addInitializer(name, init);
- _children.push_back(init);
- }
- else
- {
- _errorReporter->error("invalid child element");
- }
-}
-
-void
-FreezeScript::TransformDBDescriptor::validate()
-{
- DescriptorErrorContext ctx(_errorReporter, "transformdb", _line);
-
- if(!_database)
- {
- _errorReporter->error("no <database> element specified");
- }
-
- for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
- {
- (*p)->validate();
- }
-}
-
-void
-FreezeScript::TransformDBDescriptor::execute(const SymbolTablePtr&, TransformInfo*)
-{
- assert(false);
-}
-
-void
-FreezeScript::TransformDBDescriptor::transform(const Ice::CommunicatorPtr& communicator, Db* oldDb, DbTxn* oldDbTxn,
- Db* newDb, DbTxn* newDbTxn, bool purgeObjects)
-{
- _info->communicator = communicator;
- _info->oldDb = oldDb;
- _info->oldDbTxn = oldDbTxn;
- _info->newDb = newDb;
- _info->newDbTxn = newDbTxn;
- _info->purge = purgeObjects;
-
- try
- {
- _database->execute(0, _info);
- }
- catch(...)
- {
- _info->communicator = 0;
- _info->oldDb = 0;
- _info->oldDbTxn = 0;
- _info->newDb = 0;
- _info->newDbTxn = 0;
- throw;
- }
-
- _info->communicator = 0;
- _info->oldDb = 0;
- _info->oldDbTxn = 0;
- _info->newDb = 0;
- _info->newDbTxn = 0;
-}
-
-//
-// SymbolTableI
-//
-FreezeScript::SymbolTableI::SymbolTableI(const DataFactoryPtr& factory, const Slice::UnitPtr& oldUnit,
- const Slice::UnitPtr& newUnit,
- const ErrorReporterPtr& errorReporter, TransformInfo* info,
- const SymbolTablePtr& parent) :
- _factory(factory), _old(oldUnit), _new(newUnit), _errorReporter(errorReporter), _info(info), _parent(parent)
-{
-}
-
-void
-FreezeScript::SymbolTableI::add(const string& name, const DataPtr& data)
-{
- DataPtr d = findValue(name);
- if(d)
- {
- _errorReporter->error("`" + name + "' is already defined");
- }
-
- _dataMap.insert(DataMap::value_type(name, data));
-}
-
-FreezeScript::DataPtr
-FreezeScript::SymbolTableI::getValue(const EntityNodePtr& entity) const
-{
- EntityVisitor visitor(const_cast<SymbolTableI*>(this));
- entity->visit(visitor);
- DataPtr result = visitor.getCurrent();
- if(!result)
- {
- ostringstream ostr;
- ostr << "invalid entity `" << entity << "'";
- _errorReporter->error(ostr.str());
- }
-
- return result;
-}
-
-FreezeScript::DataPtr
-FreezeScript::SymbolTableI::getConstantValue(const string& name) const
-{
- string::size_type pos;
- Slice::UnitPtr unit;
- string key;
-
- DataMap::const_iterator p = _constantCache.find(name);
- if(p != _constantCache.end())
- {
- return p->second;
- }
-
- if(_parent)
- {
- return _parent->getConstantValue(name);
- }
-
- //
- // Name must start with "::Old" or "::New" to indicate the Slice unit.
- //
- pos = name.find("::Old");
- if(pos == 0)
- {
- if(name.length() > 5)
- {
- key = name.substr(5);
- unit = _old;
- }
- }
- else
- {
- pos = name.find("::New");
- if(pos == 0)
- {
- if(name.length() > 5)
- {
- key = name.substr(5);
- unit = _new;
- }
- }
- }
-
- if(key.empty())
- {
- _errorReporter->error("invalid constant name `" + name + "'");
- }
-
- Slice::ContainedList l = unit->findContents(key);
- if(l.empty())
- {
- _errorReporter->error("unknown constant `" + name + "'");
- }
-
- Slice::EnumeratorPtr e = Slice::EnumeratorPtr::dynamicCast(l.front());
- Slice::ConstPtr c = Slice::ConstPtr::dynamicCast(l.front());
- if(!e && !c)
- {
- _errorReporter->error("`" + name + "' does not refer to a Slice constant or enumerator");
- }
-
- DataPtr result;
-
- if(c)
- {
- Slice::TypePtr type = c->type();
- string value = c->value();
- Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type);
- if(b)
- {
- switch(b->kind())
- {
- case Slice::Builtin::KindByte:
- case Slice::Builtin::KindShort:
- case Slice::Builtin::KindInt:
- case Slice::Builtin::KindLong:
- {
- string::size_type end;
- Ice::Long n;
- if(!IceUtil::stringToInt64(value, n, end))
- {
- assert(false);
- }
- result = _factory->createInteger(n, true);
- break;
- }
-
- case Slice::Builtin::KindBool:
- {
- result = _factory->createBoolean(value == "true", true);
- break;
- }
-
- case Slice::Builtin::KindFloat:
- case Slice::Builtin::KindDouble:
- {
- double v = strtod(value.c_str(), 0);
- result = _factory->createDouble(v, true);
- break;
- }
-
- case Slice::Builtin::KindString:
- {
- result = _factory->createString(value, true);
- break;
- }
-
- case Slice::Builtin::KindObject:
- case Slice::Builtin::KindObjectProxy:
- case Slice::Builtin::KindLocalObject:
- assert(false);
- }
- }
- else
- {
- Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type);
- assert(en);
- Slice::EnumeratorList el = en->getEnumerators();
- for(Slice::EnumeratorList::iterator q = el.begin(); q != el.end(); ++q)
- {
- if((*q)->name() == value)
- {
- e = *q;
- break;
- }
- }
- assert(e);
- }
- }
-
- if(!result)
- {
- assert(e);
- result = _factory->create(e->type(), true);
- EnumDataPtr ed = EnumDataPtr::dynamicCast(result);
- assert(ed);
- ed->setValueAsString(e->name());
- }
-
- //
- // Cache the value.
- //
- const_cast<DataMap&>(_constantCache).insert(DataMap::value_type(name, result));
-
- return result;
-}
-
-FreezeScript::SymbolTablePtr
-FreezeScript::SymbolTableI::createChild()
-{
- return new SymbolTableI(_factory, _old, _new, _errorReporter, _info, this);
-}
-
-Slice::TypePtr
-FreezeScript::SymbolTableI::lookupType(const string& name)
-{
- Slice::TypeList l = _new->lookupType(name, false);
- Slice::TypePtr result;
- if(!l.empty())
- {
- result = l.front();
- }
- return result;
-}
-
-FreezeScript::DataPtr
-FreezeScript::SymbolTableI::invokeFunction(const string& name, const DataPtr& target, const DataList& args)
-{
- if(target)
- {
- DictionaryDataPtr targetDict = DictionaryDataPtr::dynamicCast(target);
- if(targetDict && name == "containsKey")
- {
- if(args.size() != 1)
- {
- _errorReporter->error("containsKey() requires one argument");
- }
- Slice::DictionaryPtr dictType = Slice::DictionaryPtr::dynamicCast(targetDict->getType());
- assert(dictType);
- DataPtr key = _factory->create(dictType->keyType(), false);
- assignOrTransform(key, args[0], false, _factory, _errorReporter, _info);
- DataPtr value = targetDict->getElement(key);
- return _factory->createBoolean(value ? true : false, false);
- }
-
- DataPtr result;
- if(invokeMemberFunction(name, target, args, result, _factory, _errorReporter))
- {
- return result;
- }
-
- _errorReporter->error("unknown function `" + name + "' invoked on type " + typeToString(target->getType()));
- }
- else
- {
- //
- // Global function.
- //
- DataPtr result;
- if(invokeGlobalFunction(name, args, result, _factory, _errorReporter))
- {
- return result;
- }
- else
- {
- _errorReporter->error("unknown global function `" + name + "'");
- }
- }
-
- return 0;
-}
-
-FreezeScript::DataPtr
-FreezeScript::SymbolTableI::findValue(const string& name) const
-{
- DataMap::const_iterator p = _dataMap.find(name);
- if(p != _dataMap.end())
- {
- return p->second;
- }
-
- if(_parent)
- {
- SymbolTableIPtr parentI = SymbolTableIPtr::dynamicCast(_parent);
- assert(parentI);
- return parentI->findValue(name);
- }
-
- return 0;
-}
-
-FreezeScript::SymbolTableI::EntityVisitor::EntityVisitor(SymbolTableI* table) :
- _table(table), _error(false)
-{
-}
-
-void
-FreezeScript::SymbolTableI::EntityVisitor::visitIdentifier(const string& name)
-{
- if(!_error)
- {
- if(!_current)
- {
- _current = _table->findValue(name);
- }
- else
- {
- _current = _current->getMember(name);
- }
-
- if(!_current)
- {
- _error = true;
- }
- }
-}
-
-void
-FreezeScript::SymbolTableI::EntityVisitor::visitElement(const NodePtr& value)
-{
- if(!_error)
- {
- assert(_current);
-
- DataPtr val = value->evaluate(_table);
- _current = _current->getElement(val);
-
- if(!_current)
- {
- _error = true;
- }
- }
-}
-
-FreezeScript::DataPtr
-FreezeScript::SymbolTableI::EntityVisitor::getCurrent() const
-{
- return _current;
-}
-
-//
-// ObjectVisitor
-//
-FreezeScript::ObjectVisitor::ObjectVisitor(ObjectDataMap& objectDataMap) :
- _map(objectDataMap)
-{
-}
-
-void
-FreezeScript::ObjectVisitor::visitStruct(const StructDataPtr& data)
-{
- Slice::TypePtr type = data->getType();
- if(type->usesClasses())
- {
- DataMemberMap& members = data->getMembers();
- for(DataMemberMap::iterator p = members.begin(); p != members.end(); ++p)
- {
- p->second->visit(*this);
- }
- }
-}
-
-void
-FreezeScript::ObjectVisitor::visitSequence(const SequenceDataPtr& data)
-{
- Slice::TypePtr type = data->getType();
- if(type->usesClasses())
- {
- DataList& elements = data->getElements();
- for(DataList::iterator p = elements.begin(); p != elements.end(); ++p)
- {
- (*p)->visit(*this);
- }
- }
-}
-
-void
-FreezeScript::ObjectVisitor::visitDictionary(const DictionaryDataPtr& data)
-{
- Slice::TypePtr type = data->getType();
- if(type->usesClasses())
- {
- DataMap& elements = data->getElements();
- for(DataMap::iterator p = elements.begin(); p != elements.end(); ++p)
- {
- //
- // NOTE: There's no need to visit the key.
- //
- p->second->visit(*this);
- }
- }
-}
-
-void
-FreezeScript::ObjectVisitor::visitObject(const ObjectRefPtr& data)
-{
- ObjectDataPtr value = data->getValue();
- if(value)
- {
- ObjectDataMap::iterator p = _map.find(value.get());
- if(p == _map.end())
- {
- _map.insert(ObjectDataMap::value_type(value.get(), 0));
- DataMemberMap& members = value->getMembers();
- for(DataMemberMap::iterator q = members.begin(); q != members.end(); ++q)
- {
- q->second->visit(*this);
- }
- }
- }
-}
-
-//
-// TransformInfoI
-//
-FreezeScript::TransformInfoI::TransformInfoI(const DataFactoryPtr& fact, const ErrorReporterPtr& err,
- const Slice::UnitPtr& oldU, const Slice::UnitPtr& newU) :
- factory(fact), errorReporter(err), oldUnit(oldU), newUnit(newU), purge(false), oldDb(0), oldDbTxn(0), newDb(0),
- newDbTxn(0)
-{
- symbolTable = new SymbolTableI(factory, oldUnit, newUnit, errorReporter, this);
-}
-
-bool
-FreezeScript::TransformInfoI::doDefaultTransform(const Slice::TypePtr& type)
-{
- TransformMap::const_iterator p = transformMap.find(typeToString(type));
- if(p != transformMap.end())
- {
- return p->second->doDefaultTransform();
- }
- return true;
-}
-
-bool
-FreezeScript::TransformInfoI::doBaseTransform(const Slice::ClassDefPtr& type)
-{
- TransformMap::const_iterator p = transformMap.find(type->scoped());
- if(p != transformMap.end())
- {
- return p->second->doBaseTransform();
- }
- return true;
-}
-
-Slice::TypePtr
-FreezeScript::TransformInfoI::getRenamedType(const Slice::TypePtr& old)
-{
- RenameMap::iterator p = renameMap.find(typeToString(old));
- if(p != renameMap.end())
- {
- return p->second;
- }
- return 0;
-}
-
-void
-FreezeScript::TransformInfoI::executeCustomTransform(const DataPtr& dest, const DataPtr& src)
-{
- //
- // Execute the type's transform (if any). Non-nil objects need special consideration,
- // for two reasons:
- //
- // 1. The dest and src arguments are ObjectRef instances whose getType()
- // function returns the formal type, which may not match the actual type
- // if inheritance is being used. Therefore, we need to look for the
- // transform of the actual type of the object.
- //
- // 2. It's not sufficient to execute only the transform for the actual type;
- // the transform descriptors for base types must also be executed (if not
- // explicitly precluded).
- //
- // The algorithm goes like this:
- //
- // 1. If a transform exists for the actual type, execute it.
- // 2. If the transform doesn't exist, or if it does exist and does not preclude
- // the execution of the base transform, then obtain the base type. If the
- // type has no user-defined base class, use Object.
- // 3. If a base type was found and a transform exists for the base type, execute it.
- // 4. Repeat step 2.
- //
- ObjectRefPtr obj = ObjectRefPtr::dynamicCast(dest);
- if(obj && obj->getValue())
- {
- ObjectDataPtr data = obj->getValue();
- Slice::TypePtr cls = data->getType(); // Actual type: may be Builtin (Object) or ClassDecl
- bool transformBase = true;
- while(cls)
- {
- string type = typeToString(cls);
- TransformMap::const_iterator p = transformMap.find(type);
- if(p != transformMap.end())
- {
- SymbolTablePtr sym = new SymbolTableI(factory, oldUnit, newUnit, errorReporter, this, symbolTable);
- sym->add("new", dest);
- sym->add("old", src);
- p->second->execute(sym, this);
- transformBase = p->second->doBaseTransform();
- }
- Slice::ClassDeclPtr decl = Slice::ClassDeclPtr::dynamicCast(cls);
- cls = 0;
- if(transformBase && decl)
- {
- Slice::ClassDefPtr def = decl->definition();
- assert(def);
- Slice::ClassList bases = def->bases();
- if(!bases.empty() && !bases.front()->isInterface())
- {
- cls = bases.front()->declaration();
- }
- else
- {
- cls = newUnit->builtin(Slice::Builtin::KindObject);
- }
- }
- }
- }
- else
- {
- string type = typeToString(dest->getType());
- TransformMap::const_iterator p = transformMap.find(type);
- if(p != transformMap.end())
- {
- SymbolTablePtr sym = new SymbolTableI(factory, oldUnit, newUnit, errorReporter, this, symbolTable);
- sym->add("new", dest);
- sym->add("old", src);
- p->second->execute(sym, this);
- }
- }
-}
-
-bool
-FreezeScript::TransformInfoI::purgeObjects()
-{
- return purge;
-}
-
-FreezeScript::ObjectDataMap&
-FreezeScript::TransformInfoI::getObjectDataMap()
-{
- return objectDataMap;
-}
-
-//
-// assignOrTransform
-//
-void
-FreezeScript::assignOrTransform(const DataPtr& dest, const DataPtr& src, bool convert, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter, TransformInfo* info)
-{
- Slice::TypePtr destType = dest->getType();
- Slice::TypePtr srcType = src->getType();
- Slice::BuiltinPtr b1 = Slice::BuiltinPtr::dynamicCast(destType);
- Slice::BuiltinPtr b2 = Slice::BuiltinPtr::dynamicCast(srcType);
-
- if(!b1 && !b2 && dest->getType()->unit().get() != src->getType()->unit().get())
- {
- TransformVisitor v(src, factory, errorReporter, info);
- dest->visit(v);
- }
- else
- {
- AssignVisitor v(src, factory, errorReporter, convert);
- dest->visit(v);
- }
-}
diff --git a/cpp/src/FreezeScript/TransformDescriptors.h b/cpp/src/FreezeScript/TransformDescriptors.h
deleted file mode 100644
index c2f26168b25..00000000000
--- a/cpp/src/FreezeScript/TransformDescriptors.h
+++ /dev/null
@@ -1,351 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2004
-// ZeroC, Inc.
-// Billerica, MA, USA
-//
-// All Rights Reserved.
-//
-// Ice is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation.
-//
-// **********************************************************************
-
-#ifndef FREEZE_SCRIPT_TRANSFORM_DESCRIPTORS_H
-#define FREEZE_SCRIPT_TRANSFORM_DESCRIPTORS_H
-
-#include <FreezeScript/Parser.h>
-#include <FreezeScript/TransformVisitor.h>
-#include <IceXML/Parser.h>
-
-class Db;
-class DbTxn;
-
-namespace FreezeScript
-{
-
-class Descriptor;
-typedef IceUtil::Handle<Descriptor> DescriptorPtr;
-
-class DeleteRecordException {};
-
-class Descriptor : virtual public IceUtil::SimpleShared
-{
-public:
-
- virtual ~Descriptor();
-
- virtual DescriptorPtr parent() const;
- virtual void addChild(const DescriptorPtr&) = 0;
- virtual void validate() = 0;
- virtual void execute(const SymbolTablePtr&, TransformInfo*) = 0;
-
-protected:
-
- Descriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&);
-
- NodePtr parse(const std::string&) const;
-
- Slice::TypePtr findType(const Slice::UnitPtr&, const std::string&);
-
- DescriptorPtr _parent;
- int _line;
- DataFactoryPtr _factory;
- ErrorReporterPtr _errorReporter;
-};
-
-class SetDescriptor : public Descriptor
-{
-public:
-
- SetDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- EntityNodePtr _target;
- NodePtr _value;
- std::string _valueStr;
- std::string _type;
- NodePtr _length;
- std::string _lengthStr;
- bool _convert;
-};
-
-class DefineDescriptor : public Descriptor
-{
-public:
-
- DefineDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- std::string _name;
- NodePtr _value;
- std::string _valueStr;
- Slice::TypePtr _type;
- bool _convert;
-};
-
-class AddDescriptor : public Descriptor
-{
-public:
-
- AddDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- EntityNodePtr _target;
- NodePtr _key;
- std::string _keyStr;
- NodePtr _value;
- std::string _valueStr;
- std::string _type;
- bool _convert;
-};
-
-class RemoveDescriptor : public Descriptor
-{
-public:
-
- RemoveDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- EntityNodePtr _target;
- NodePtr _key;
- std::string _keyStr;
-};
-
-class DeleteDescriptor : public Descriptor
-{
-public:
-
- DeleteDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-};
-
-class FailDescriptor : public Descriptor
-{
-public:
-
- FailDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- NodePtr _test;
- std::string _testStr;
- std::string _message;
-};
-
-class EchoDescriptor : public Descriptor
-{
-public:
-
- EchoDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- std::string _message;
- NodePtr _value;
- std::string _valueStr;
-};
-
-class ExecutableContainerDescriptor : virtual public Descriptor
-{
-public:
-
- ExecutableContainerDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const std::string&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-protected:
-
- std::vector<DescriptorPtr> _children;
-
-private:
-
- std::string _name;
-};
-
-class IfDescriptor : public ExecutableContainerDescriptor
-{
-public:
-
- IfDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&, const IceXML::Attributes&);
-
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- NodePtr _test;
- std::string _testStr;
-};
-
-class IterateDescriptor : public ExecutableContainerDescriptor
-{
-public:
-
- IterateDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&);
-
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- EntityNodePtr _target;
- std::string _key;
- std::string _value;
- std::string _element;
- std::string _index;
-};
-
-class TransformDescriptor : public ExecutableContainerDescriptor
-{
-public:
-
- TransformDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- Slice::TypePtr type() const;
- std::string typeName() const;
- Slice::TypePtr renameType() const;
- std::string renameTypeName() const;
- bool doDefaultTransform() const;
- bool doBaseTransform() const;
-
-private:
-
- bool _default;
- bool _base;
- Slice::TypePtr _newType;
- Slice::TypePtr _renameType;
-};
-typedef IceUtil::Handle<TransformDescriptor> TransformDescriptorPtr;
-
-class InitDescriptor : virtual public ExecutableContainerDescriptor, virtual public DataInitializer
-{
-public:
-
- InitDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- virtual void initialize(const DataFactoryPtr&, const DataPtr&, const Ice::CommunicatorPtr&);
-
- std::string typeName() const;
-
-private:
-
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- Slice::TypePtr _type;
-};
-typedef IceUtil::Handle<InitDescriptor> InitDescriptorPtr;
-
-class RecordDescriptor : public ExecutableContainerDescriptor
-{
-public:
-
- RecordDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- void transformRecord(IceInternal::BasicStream&, IceInternal::BasicStream&, IceInternal::BasicStream&,
- IceInternal::BasicStream&, TransformInfo*);
-
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
-};
-typedef IceUtil::Handle<RecordDescriptor> RecordDescriptorPtr;
-
-class DatabaseDescriptor : public ExecutableContainerDescriptor
-{
-public:
-
- DatabaseDescriptor(const DescriptorPtr&, int, const DataFactoryPtr&, const ErrorReporterPtr&,
- const IceXML::Attributes&, const Slice::UnitPtr&, const Slice::UnitPtr&);
-
- virtual void addChild(const DescriptorPtr&);
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
-private:
-
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- Slice::TypePtr _oldKey;
- Slice::TypePtr _newKey;
- Slice::TypePtr _oldValue;
- Slice::TypePtr _newValue;
- RecordDescriptorPtr _record;
-};
-typedef IceUtil::Handle<DatabaseDescriptor> DatabaseDescriptorPtr;
-
-class TransformInfoI;
-
-class TransformDBDescriptor : public Descriptor
-{
-public:
-
- TransformDBDescriptor(int, const DataFactoryPtr&, const ErrorReporterPtr&, const IceXML::Attributes&,
- const Slice::UnitPtr&, const Slice::UnitPtr&);
- ~TransformDBDescriptor();
-
- virtual void addChild(const DescriptorPtr&);
- virtual void validate();
- virtual void execute(const SymbolTablePtr&, TransformInfo*);
-
- void transform(const Ice::CommunicatorPtr&, Db*, DbTxn*, Db*, DbTxn*, bool);
-
-private:
-
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- DatabaseDescriptorPtr _database;
- std::vector<DescriptorPtr> _children;
- TransformInfoI* _info;
-};
-typedef IceUtil::Handle<TransformDBDescriptor> TransformDBDescriptorPtr;
-
-} // End of namespace FreezeScript
-
-#endif
diff --git a/cpp/src/FreezeScript/TransformVisitor.cpp b/cpp/src/FreezeScript/TransformVisitor.cpp
index 864b46dc66a..b1644906a7c 100644
--- a/cpp/src/FreezeScript/TransformVisitor.cpp
+++ b/cpp/src/FreezeScript/TransformVisitor.cpp
@@ -17,12 +17,11 @@
using namespace std;
-FreezeScript::TransformVisitor::TransformVisitor(const DataPtr& src, const DataFactoryPtr& factory,
- const ErrorReporterPtr& errorReporter, TransformInfo* info,
+FreezeScript::TransformVisitor::TransformVisitor(const DataPtr& src, const TransformInfoPtr& info,
const string& context) :
- _src(src), _factory(factory), _errorReporter(errorReporter), _info(info), _context(context)
+ _src(src), _info(info), _context(context)
{
- assert(_info != 0);
+ assert(_info);
}
void
@@ -223,7 +222,7 @@ FreezeScript::TransformVisitor::visitStruct(const StructDataPtr& dest)
if(q != srcMap.end())
{
string context = typeName + " member " + p->first + " value";
- TransformVisitor v(q->second, _factory, _errorReporter, _info, context);
+ TransformVisitor v(q->second, _info, context);
p->second->visit(v);
}
}
@@ -253,11 +252,11 @@ FreezeScript::TransformVisitor::visitSequence(const SequenceDataPtr& dest)
string typeName = typeToString(type);
for(DataList::const_iterator p = srcElements.begin(); p != srcElements.end(); ++p)
{
- DataPtr element = _factory->create(elemType, false);
+ DataPtr element = _info->getDataFactory()->create(elemType, false);
Destroyer<DataPtr> elementDestroyer(element);
try
{
- TransformVisitor v(*p, _factory, _errorReporter, _info, typeName + " element");
+ TransformVisitor v(*p, _info, typeName + " element");
element->visit(v);
destElements.push_back(element);
elementDestroyer.release();
@@ -341,17 +340,17 @@ FreezeScript::TransformVisitor::visitDictionary(const DictionaryDataPtr& dest)
string typeName = typeToString(type);
for(DataMap::const_iterator p = srcMap.begin(); p != srcMap.end(); ++p)
{
- DataPtr key = _factory->create(keyType, false);
+ DataPtr key = _info->getDataFactory()->create(keyType, false);
Destroyer<DataPtr> keyDestroyer(key);
- DataPtr value = _factory->create(valueType, false);
+ DataPtr value = _info->getDataFactory()->create(valueType, false);
Destroyer<DataPtr> valueDestroyer(value);
- TransformVisitor keyVisitor(p->first, _factory, _errorReporter, _info, typeName + " key");
+ TransformVisitor keyVisitor(p->first, _info, typeName + " key");
key->visit(keyVisitor);
try
{
- TransformVisitor valueVisitor(p->second, _factory, _errorReporter, _info, typeName + " value");
+ TransformVisitor valueVisitor(p->second, _info, typeName + " value");
value->visit(valueVisitor);
}
catch(const ClassNotFoundException& ex)
@@ -465,7 +464,7 @@ FreezeScript::TransformVisitor::visitObject(const ObjectRefPtr& dest)
//
// Use createObject() so that an initializer is invoked if necessary.
//
- DataPtr newObj = _factory->createObject(newType, false);
+ DataPtr newObj = _info->getDataFactory()->createObject(newType, false);
ObjectRefPtr newRef = ObjectRefPtr::dynamicCast(newObj);
assert(newRef);
@@ -524,7 +523,7 @@ FreezeScript::TransformVisitor::transformObject(const ObjectDataPtr& dest, const
if(q != srcMap.end())
{
string context = typeName + " member " + p->first + " value";
- TransformVisitor v(q->second, _factory, _errorReporter, _info, context);
+ TransformVisitor v(q->second, _info, context);
p->second->visit(v);
}
}
@@ -832,7 +831,7 @@ FreezeScript::TransformVisitor::checkClasses(const Slice::ClassDeclPtr& dest, co
Slice::TypeList l = dest->unit()->lookupTypeNoBuiltin(s2, false);
if(l.empty())
{
- _errorReporter->error("class " + s2 + " not found in new Slice definitions");
+ _info->getErrorReporter()->error("class " + s2 + " not found in new Slice definitions");
}
s = Slice::ClassDeclPtr::dynamicCast(l.front());
}
@@ -846,7 +845,7 @@ FreezeScript::TransformVisitor::checkClasses(const Slice::ClassDeclPtr& dest, co
Slice::ClassDefPtr def = s->definition();
if(!def)
{
- _errorReporter->error("class " + s2 + " declared but not defined");
+ _info->getErrorReporter()->error("class " + s2 + " declared but not defined");
}
return def->isA(s1);
}
@@ -897,5 +896,5 @@ FreezeScript::TransformVisitor::rangeError(const string& value, const Slice::Typ
void
FreezeScript::TransformVisitor::warning(const string& msg)
{
- _errorReporter->warning(msg);
+ _info->getErrorReporter()->warning(msg);
}
diff --git a/cpp/src/FreezeScript/TransformVisitor.h b/cpp/src/FreezeScript/TransformVisitor.h
index 6abf97509d6..b3df9adbc1b 100644
--- a/cpp/src/FreezeScript/TransformVisitor.h
+++ b/cpp/src/FreezeScript/TransformVisitor.h
@@ -29,13 +29,23 @@ typedef std::map<const ObjectData*, ObjectDataPtr> ObjectDataMap;
//
// TransformInfo supplies information required by TransformVisitor.
//
-class TransformInfo
+class TransformInfo : public IceUtil::SimpleShared
{
public:
virtual ~TransformInfo() {}
//
+ // Get data factory.
+ //
+ virtual DataFactoryPtr getDataFactory() = 0;
+
+ //
+ // Get error reporter.
+ //
+ virtual ErrorReporterPtr getErrorReporter() = 0;
+
+ //
// Indicates whether the default transformation should be performed.
//
virtual bool doDefaultTransform(const Slice::TypePtr&) = 0;
@@ -66,6 +76,7 @@ public:
//
virtual ObjectDataMap& getObjectDataMap() = 0;
};
+typedef IceUtil::Handle<TransformInfo> TransformInfoPtr;
//
// TransformVisitor is used to visit a destination Data value and
@@ -75,8 +86,7 @@ class TransformVisitor : public DataVisitor
{
public:
- TransformVisitor(const DataPtr&, const DataFactoryPtr&, const ErrorReporterPtr&, TransformInfo*,
- const std::string& = std::string());
+ TransformVisitor(const DataPtr&, const TransformInfoPtr&, const std::string& = std::string());
virtual void visitBoolean(const BooleanDataPtr&);
virtual void visitInteger(const IntegerDataPtr&);
@@ -101,9 +111,7 @@ private:
void warning(const std::string&);
DataPtr _src;
- DataFactoryPtr _factory;
- ErrorReporterPtr _errorReporter;
- TransformInfo* _info;
+ TransformInfoPtr _info;
std::string _context; // Provides additional detail for use in warning messages.
};
diff --git a/cpp/src/FreezeScript/Transformer.cpp b/cpp/src/FreezeScript/Transformer.cpp
index 01a1c7519f1..8f45f6ad093 100644
--- a/cpp/src/FreezeScript/Transformer.cpp
+++ b/cpp/src/FreezeScript/Transformer.cpp
@@ -13,10 +13,14 @@
// **********************************************************************
#include <FreezeScript/Transformer.h>
-#include <FreezeScript/TransformDescriptors.h>
+#include <FreezeScript/Parser.h>
+#include <FreezeScript/TransformVisitor.h>
+#include <FreezeScript/AssignVisitor.h>
+#include <FreezeScript/Print.h>
+#include <FreezeScript/Functions.h>
#include <FreezeScript/Exception.h>
-#include <FreezeScript/TransformAnalyzer.h>
#include <FreezeScript/Util.h>
+#include <IceXML/Parser.h>
#include <db_cxx.h>
using namespace std;
@@ -24,11 +28,495 @@ using namespace std;
namespace FreezeScript
{
+class DeleteRecordException {};
+
+class Descriptor;
+typedef IceUtil::Handle<Descriptor> DescriptorPtr;
+
+class InitDescriptor;
+typedef IceUtil::Handle<InitDescriptor> InitDescriptorPtr;
+
+class TransformDescriptor;
+typedef IceUtil::Handle<TransformDescriptor> TransformDescriptorPtr;
+
+class TransformDataFactory;
+typedef IceUtil::Handle<TransformDataFactory> TransformDataFactoryPtr;
+
+typedef map<string, TransformDescriptorPtr> TransformMap;
+typedef map<string, Slice::TypePtr> RenameMap;
+
+//
+// TransformInfoI
+//
+struct TransformInfoI : public TransformInfo
+{
+ virtual DataFactoryPtr getDataFactory();
+ virtual ErrorReporterPtr getErrorReporter();
+ virtual bool doDefaultTransform(const Slice::TypePtr&);
+ virtual bool doBaseTransform(const Slice::ClassDefPtr&);
+ virtual Slice::TypePtr getRenamedType(const Slice::TypePtr&);
+ virtual void executeCustomTransform(const DataPtr&, const DataPtr&);
+ virtual bool purgeObjects();
+ virtual ObjectDataMap& getObjectDataMap();
+
+ Ice::CommunicatorPtr communicator;
+ Slice::UnitPtr oldUnit;
+ Slice::UnitPtr newUnit;
+ Db* oldDb;
+ DbTxn* oldDbTxn;
+ Db* newDb;
+ DbTxn* newDbTxn;
+ bool purge;
+ ErrorReporterPtr errorReporter;
+ TransformDataFactoryPtr factory;
+ SymbolTablePtr symbolTable;
+ Slice::TypePtr oldKeyType;
+ Slice::TypePtr oldValueType;
+ Slice::TypePtr newKeyType;
+ Slice::TypePtr newValueType;
+ TransformMap transformMap;
+ RenameMap renameMap;
+ ObjectDataMap objectDataMap;
+};
+typedef IceUtil::Handle<TransformInfoI> TransformInfoIPtr;
+
+//
+// TransformDataFactory
+//
+class TransformDataFactory : public DataFactory
+{
+public:
+
+ TransformDataFactory(const Ice::CommunicatorPtr&, const Slice::UnitPtr&, const ErrorReporterPtr&);
+
+ void addInitDescriptor(const InitDescriptorPtr&);
+ void disableInitializers();
+ void enableInitializers();
+
+protected:
+
+ virtual void initialize(const DataPtr&);
+
+private:
+
+ typedef std::map<std::string, InitDescriptorPtr> InitMap;
+ InitMap _initMap;
+ bool _enabled;
+};
+
+//
+// Descriptor
+//
+class Descriptor : public IceUtil::SimpleShared
+{
+public:
+
+ virtual ~Descriptor();
+
+ virtual DescriptorPtr parent() const;
+ virtual void addChild(const DescriptorPtr&) = 0;
+ virtual void validate() = 0;
+ virtual void execute(const SymbolTablePtr&) = 0;
+
+protected:
+
+ Descriptor(const DescriptorPtr&, int, const TransformInfoIPtr&);
+
+ NodePtr parse(const std::string&) const;
+
+ Slice::TypePtr findType(const Slice::UnitPtr&, const std::string&);
+
+ DescriptorPtr _parent;
+ int _line;
+ TransformInfoIPtr _info;
+};
+
+//
+// SetDescriptor
+//
+class SetDescriptor : public Descriptor
+{
+public:
+
+ SetDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ EntityNodePtr _target;
+ NodePtr _value;
+ std::string _valueStr;
+ std::string _type;
+ NodePtr _length;
+ std::string _lengthStr;
+ bool _convert;
+};
+
+//
+// DefineDescriptor
+//
+class DefineDescriptor : public Descriptor
+{
+public:
+
+ DefineDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ std::string _name;
+ NodePtr _value;
+ std::string _valueStr;
+ Slice::TypePtr _type;
+ bool _convert;
+};
+
+//
+// AddDescriptor
+//
+class AddDescriptor : public Descriptor
+{
+public:
+
+ AddDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ EntityNodePtr _target;
+ NodePtr _key;
+ std::string _keyStr;
+ NodePtr _value;
+ std::string _valueStr;
+ std::string _type;
+ bool _convert;
+};
+
+//
+// RemoveDescriptor
+//
+class RemoveDescriptor : public Descriptor
+{
+public:
+
+ RemoveDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ EntityNodePtr _target;
+ NodePtr _key;
+ std::string _keyStr;
+};
+
+//
+// DeleteDescriptor
+//
+class DeleteDescriptor : public Descriptor
+{
+public:
+
+ DeleteDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+};
+
+//
+// FailDescriptor
+//
+class FailDescriptor : public Descriptor
+{
+public:
+
+ FailDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ NodePtr _test;
+ std::string _testStr;
+ std::string _message;
+};
+
+//
+// EchoDescriptor
+//
+class EchoDescriptor : public Descriptor
+{
+public:
+
+ EchoDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ std::string _message;
+ NodePtr _value;
+ std::string _valueStr;
+};
+
+//
+// ExecutableContainerDescriptor
+//
+class ExecutableContainerDescriptor : public Descriptor
+{
+public:
+
+ ExecutableContainerDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&,
+ const std::string&);
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+protected:
+
+ std::vector<DescriptorPtr> _children;
+
+private:
+
+ std::string _name;
+};
+
+//
+// IfDescriptor
+//
+class IfDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ IfDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ NodePtr _test;
+ std::string _testStr;
+};
+
+//
+// IterateDescriptor
+//
+class IterateDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ IterateDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ EntityNodePtr _target;
+ std::string _key;
+ std::string _value;
+ std::string _element;
+ std::string _index;
+};
+
+//
+// TransformDescriptor
+//
+class TransformDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ TransformDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ Slice::TypePtr type() const;
+ std::string typeName() const;
+ Slice::TypePtr renameType() const;
+ std::string renameTypeName() const;
+ bool doDefaultTransform() const;
+ bool doBaseTransform() const;
+
+private:
+
+ bool _default;
+ bool _base;
+ Slice::TypePtr _newType;
+ Slice::TypePtr _renameType;
+};
+typedef IceUtil::Handle<TransformDescriptor> TransformDescriptorPtr;
+
+//
+// InitDescriptor
+//
+class InitDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ InitDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ void initialize(const DataPtr&);
+
+ std::string typeName() const;
+
+private:
+
+ Slice::TypePtr _type;
+};
+
+//
+// RecordDescriptor
+//
+class RecordDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ RecordDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ void transformRecord(IceInternal::BasicStream&, IceInternal::BasicStream&, IceInternal::BasicStream&,
+ IceInternal::BasicStream&);
+
+ Slice::UnitPtr _old;
+ Slice::UnitPtr _new;
+};
+typedef IceUtil::Handle<RecordDescriptor> RecordDescriptorPtr;
+
+//
+// DatabaseDescriptor
+//
+class DatabaseDescriptor : public ExecutableContainerDescriptor
+{
+public:
+
+ DatabaseDescriptor(const DescriptorPtr&, int, const TransformInfoIPtr&, const IceXML::Attributes&);
+
+ virtual void addChild(const DescriptorPtr&);
+
+private:
+
+ RecordDescriptorPtr _record;
+};
+typedef IceUtil::Handle<DatabaseDescriptor> DatabaseDescriptorPtr;
+
+//
+// TransformDBDescriptor
+//
+class TransformDBDescriptor : public Descriptor
+{
+public:
+
+ TransformDBDescriptor(int, const TransformInfoIPtr&, const IceXML::Attributes&);
+ ~TransformDBDescriptor();
+
+ virtual void addChild(const DescriptorPtr&);
+ virtual void validate();
+ virtual void execute(const SymbolTablePtr&);
+
+private:
+
+ DatabaseDescriptorPtr _database;
+ std::vector<DescriptorPtr> _children;
+};
+typedef IceUtil::Handle<TransformDBDescriptor> TransformDBDescriptorPtr;
+
+//
+// SymbolTableI
+//
+class SymbolTableI : public SymbolTable
+{
+public:
+
+ SymbolTableI(const TransformInfoIPtr&, const SymbolTablePtr& = SymbolTablePtr());
+
+ virtual void add(const string&, const DataPtr&);
+
+ virtual DataPtr getValue(const EntityNodePtr&) const;
+
+ virtual DataPtr getConstantValue(const string&) const;
+
+ virtual SymbolTablePtr createChild();
+
+ virtual Slice::TypePtr lookupType(const string&);
+
+ virtual DataPtr invokeFunction(const string&, const DataPtr&, const DataList&);
+
+private:
+
+ DataPtr findValue(const string&) const;
+
+ class EntityVisitor : public EntityNodeVisitor
+ {
+ public:
+
+ EntityVisitor(SymbolTableI*);
+
+ virtual void visitIdentifier(const string&);
+ virtual void visitElement(const NodePtr&);
+
+ DataPtr getCurrent() const;
+
+ private:
+
+ SymbolTableI* _table;
+ DataPtr _current;
+ bool _error;
+ };
+
+ friend class EntityVisitor;
+
+ TransformInfoIPtr _info;
+ SymbolTablePtr _parent;
+ typedef map<string, DataPtr> DataMap;
+ DataMap _dataMap;
+ DataMap _constantCache;
+};
+typedef IceUtil::Handle<SymbolTableI> SymbolTableIPtr;
+
+//
+// ObjectVisitor
+//
+class ObjectVisitor : public DataVisitor
+{
+public:
+
+ ObjectVisitor(ObjectDataMap&);
+
+ virtual void visitStruct(const StructDataPtr&);
+ virtual void visitSequence(const SequenceDataPtr&);
+ virtual void visitDictionary(const DictionaryDataPtr&);
+ virtual void visitObject(const ObjectRefPtr&);
+
+private:
+
+ ObjectDataMap& _map;
+};
+
+//
+// DescriptorHandler
+//
class DescriptorHandler : public IceXML::Handler
{
public:
- DescriptorHandler(const DataFactoryPtr&, const Slice::UnitPtr&, const Slice::UnitPtr&, const ErrorReporterPtr&);
+ DescriptorHandler(const TransformInfoIPtr&);
virtual void startElement(const std::string&, const IceXML::Attributes&, int, int);
virtual void endElement(const std::string&, int, int);
@@ -39,23 +527,2037 @@ public:
private:
- DataFactoryPtr _factory;
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- ErrorReporterPtr _errorReporter;
+ TransformInfoIPtr _info;
DescriptorPtr _current;
TransformDBDescriptorPtr _descriptor;
};
+void assignOrTransform(const DataPtr&, const DataPtr&, bool, const TransformInfoPtr&);
+
} // End of namespace FreezeScript
//
+// TransformDataFactory
+//
+FreezeScript::TransformDataFactory::TransformDataFactory(const Ice::CommunicatorPtr& communicator,
+ const Slice::UnitPtr& unit,
+ const ErrorReporterPtr& errorReporter) :
+ DataFactory(communicator, unit, errorReporter), _enabled(true)
+{
+}
+
+void
+FreezeScript::TransformDataFactory::addInitDescriptor(const InitDescriptorPtr& init)
+{
+ string typeName = init->typeName();
+ assert(_initMap.find(typeName) == _initMap.end());
+ _initMap.insert(InitMap::value_type(typeName, init));
+}
+
+void
+FreezeScript::TransformDataFactory::initialize(const DataPtr& data)
+{
+ if(_enabled)
+ {
+ string typeName = typeToString(data->getType());
+ InitMap::iterator p = _initMap.find(typeName);
+ if(p != _initMap.end())
+ {
+ p->second->initialize(data);
+ }
+ }
+}
+
+void
+FreezeScript::TransformDataFactory::disableInitializers()
+{
+ _enabled = false;
+}
+
+void
+FreezeScript::TransformDataFactory::enableInitializers()
+{
+ _enabled = true;
+}
+
+//
+// Descriptor
+//
+FreezeScript::Descriptor::Descriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info) :
+ _parent(parent), _line(line), _info(info)
+{
+}
+
+FreezeScript::Descriptor::~Descriptor()
+{
+}
+
+FreezeScript::DescriptorPtr
+FreezeScript::Descriptor::parent() const
+{
+ return _parent;
+}
+
+FreezeScript::NodePtr
+FreezeScript::Descriptor::parse(const string& expr) const
+{
+ return parseExpression(expr, _info->factory, _info->errorReporter);
+}
+
+Slice::TypePtr
+FreezeScript::Descriptor::findType(const Slice::UnitPtr& u, const string& type)
+{
+ Slice::TypeList l;
+
+ l = u->lookupType(type, false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("unknown type `" + type + "'");
+ }
+
+ return l.front();
+}
+
+//
+// SetDescriptor
+//
+FreezeScript::SetDescriptor::SetDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "set", _line);
+
+ IceXML::Attributes::const_iterator p;
+
+ string target;
+ p = attributes.find("target");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `target' is missing");
+ }
+ target = p->second;
+
+ p = attributes.find("value");
+ if(p != attributes.end())
+ {
+ _valueStr = p->second;
+ }
+
+ p = attributes.find("type");
+ if(p != attributes.end())
+ {
+ _type = p->second;
+ }
+
+ p = attributes.find("length");
+ if(p != attributes.end())
+ {
+ _lengthStr = p->second;
+ }
+
+ p = attributes.find("convert");
+ if(p != attributes.end())
+ {
+ _convert = p->second == "true";
+ }
+
+ if(!_valueStr.empty() && !_type.empty())
+ {
+ _info->errorReporter->error("attributes `value' and 'type' are mutually exclusive");
+ }
+
+ if(_valueStr.empty() && _type.empty() && _lengthStr.empty())
+ {
+ _info->errorReporter->error("requires a value for attributes `value', 'type' or 'length'");
+ }
+
+ NodePtr node = parse(target);
+ _target = EntityNodePtr::dynamicCast(node);
+ if(!_target)
+ {
+ _info->errorReporter->error("`target' attribute is not an entity: `" + target + "'");
+ }
+
+ if(!_valueStr.empty())
+ {
+ _value = parse(_valueStr);
+ }
+
+ if(!_lengthStr.empty())
+ {
+ _length = parse(_lengthStr);
+ }
+}
+
+void
+FreezeScript::SetDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "set", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::SetDescriptor::validate()
+{
+}
+
+void
+FreezeScript::SetDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "set", _line);
+
+ DataPtr data = sym->getValue(_target);
+ if(data->readOnly())
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' cannot be modified");
+ }
+
+ DataPtr value;
+ if(_value)
+ {
+ try
+ {
+ value = _value->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
+ }
+ }
+
+ Destroyer<DataPtr> valueDestroyer;
+ if(!_type.empty())
+ {
+ assert(!value);
+ Slice::TypePtr type = sym->lookupType(_type);
+ if(!type)
+ {
+ _info->errorReporter->error("type `" + _type + "' not found");
+ }
+ value = _info->factory->createObject(type, false);
+ valueDestroyer.set(value);
+ }
+
+ DataPtr length;
+ if(_length)
+ {
+ SequenceDataPtr seq = SequenceDataPtr::dynamicCast(data);
+ if(!seq)
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' is not a sequence");
+ }
+
+ try
+ {
+ length = _length->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of length `" + _lengthStr + "' failed:\n" + ex.reason());
+ }
+
+ DataList& elements = seq->getElements();
+ Ice::Long l = length->integerValue();
+ if(l < 0 || l > INT_MAX)
+ {
+ _info->errorReporter->error("sequence length " + length->toString() + " is out of range");
+ }
+
+ DataList::size_type len = static_cast<DataList::size_type>(l);
+ if(len < elements.size())
+ {
+ for(DataList::size_type i = len; i < elements.size(); ++i)
+ {
+ elements[i]->destroy();
+ }
+ elements.resize(len);
+ }
+ else if(len > elements.size())
+ {
+ Slice::SequencePtr seqType = Slice::SequencePtr::dynamicCast(seq->getType());
+ assert(seqType);
+ Slice::TypePtr elemType = seqType->type();
+ for(DataList::size_type i = elements.size(); i < len; ++i)
+ {
+ DataPtr v = _info->factory->create(elemType, false);
+ if(value)
+ {
+ assignOrTransform(v, value, _convert, _info);
+ }
+ elements.push_back(v);
+ }
+ }
+ }
+ else
+ {
+ assignOrTransform(data, value, _convert, _info);
+ }
+}
+
+//
+// DefineDescriptor
+//
+FreezeScript::DefineDescriptor::DefineDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "define", _line);
+
+ IceXML::Attributes::const_iterator p;
+
+ p = attributes.find("name");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `name' is missing");
+ }
+ _name = p->second;
+
+ p = attributes.find("type");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `type' is missing");
+ }
+ if(p->second.find("::New") != string::npos)
+ {
+ Slice::TypeList l = _info->newUnit->lookupType(p->second.substr(5), false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("type `" + p->second + "' not found");
+ }
+ _type = l.front();
+ }
+ else if(p->second.find("::Old") != string::npos)
+ {
+ Slice::TypeList l = _info->oldUnit->lookupType(p->second.substr(5), false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("type `" + p->second + "' not found");
+ }
+ _type = l.front();
+ }
+ else
+ {
+ Slice::TypeList l = _info->newUnit->lookupType(p->second, false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("type `" + p->second + "' not found");
+ }
+ _type = l.front();
+ }
+
+ p = attributes.find("value");
+ if(p != attributes.end())
+ {
+ _valueStr = p->second;
+ }
+
+ p = attributes.find("convert");
+ if(p != attributes.end())
+ {
+ _convert = p->second == "true";
+ }
+
+ if(!_valueStr.empty())
+ {
+ _value = parse(_valueStr);
+ }
+}
+
+void
+FreezeScript::DefineDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "define", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::DefineDescriptor::validate()
+{
+}
+
+void
+FreezeScript::DefineDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "define", _line);
+
+ DataPtr data = _info->factory->create(_type, false);
+
+ DataPtr value;
+ if(_value)
+ {
+ try
+ {
+ value = _value->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
+ }
+ }
+
+ if(value)
+ {
+ assignOrTransform(data, value, _convert, _info);
+ }
+
+ sym->add(_name, data);
+}
+
+//
+// AddDescriptor
+//
+FreezeScript::AddDescriptor::AddDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "add", _line);
+
+ IceXML::Attributes::const_iterator p;
+
+ string target;
+ p = attributes.find("target");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `target' is missing");
+ }
+ target = p->second;
+
+ p = attributes.find("key");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `key' is missing");
+ }
+ _keyStr = p->second;
+
+ p = attributes.find("value");
+ if(p != attributes.end())
+ {
+ _valueStr = p->second;
+ }
+
+ p = attributes.find("type");
+ if(p != attributes.end())
+ {
+ _type = p->second;
+ }
+
+ p = attributes.find("convert");
+ if(p != attributes.end())
+ {
+ _convert = p->second == "true";
+ }
+
+ if(!_valueStr.empty() && !_type.empty())
+ {
+ _info->errorReporter->error("attributes `value' and 'type' are mutually exclusive");
+ }
+
+ NodePtr node = parse(target);
+ _target = EntityNodePtr::dynamicCast(node);
+ if(!_target)
+ {
+ _info->errorReporter->error("`target' attribute is not an entity: `" + target + "'");
+ }
+
+ assert(!_keyStr.empty());
+ _key = parse(_keyStr);
+
+ if(!_valueStr.empty())
+ {
+ _value = parse(_valueStr);
+ }
+}
+
+void
+FreezeScript::AddDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "add", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::AddDescriptor::validate()
+{
+}
+
+void
+FreezeScript::AddDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "add", _line);
+
+ DataPtr data = sym->getValue(_target);
+ if(data->readOnly())
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' cannot be modified");
+ }
+
+ DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
+ if(!dict)
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' is not a dictionary");
+ }
+
+ Slice::DictionaryPtr type = Slice::DictionaryPtr::dynamicCast(dict->getType());
+ assert(type);
+
+ DataPtr key;
+ Destroyer<DataPtr> keyDestroyer;
+ try
+ {
+ DataPtr v = _key->evaluate(sym);
+ key = _info->factory->create(type->keyType(), false);
+ keyDestroyer.set(key);
+ assignOrTransform(key, v, _convert, _info);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of key `" + _keyStr + "' failed:\n" + ex.reason());
+ }
+
+ if(dict->getElement(key))
+ {
+ ostringstream ostr;
+ printData(key, ostr);
+ _info->errorReporter->error("key " + ostr.str() + " already exists in dictionary");
+ }
+
+ DataPtr elem = _info->factory->create(type->valueType(), false);
+ Destroyer<DataPtr> elemDestroyer(elem);
+
+ DataPtr value;
+ if(_value)
+ {
+ try
+ {
+ value = _value->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
+ }
+ }
+
+ Destroyer<DataPtr> valueDestroyer;
+ if(!_type.empty())
+ {
+ assert(!value);
+ Slice::TypePtr type = sym->lookupType(_type);
+ if(!type)
+ {
+ _info->errorReporter->error("type `" + _type + "' not found");
+ }
+ value = _info->factory->createObject(type, false);
+ valueDestroyer.set(value);
+ }
+
+ if(value)
+ {
+ assignOrTransform(elem, value, _convert, _info);
+ }
+ DataMap& map = dict->getElements();
+ map.insert(DataMap::value_type(key, elem));
+ keyDestroyer.release();
+ elemDestroyer.release();
+}
+
+//
+// RemoveDescriptor
+//
+FreezeScript::RemoveDescriptor::RemoveDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "remove", _line);
+
+ IceXML::Attributes::const_iterator p;
+
+ string target;
+ p = attributes.find("target");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `target' is missing");
+ }
+ target = p->second;
+
+ p = attributes.find("key");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `key' is missing");
+ }
+ _keyStr = p->second;
+
+ NodePtr node = parse(target);
+ _target = EntityNodePtr::dynamicCast(node);
+ if(!_target)
+ {
+ _info->errorReporter->error("`target' attribute is not an entity: `" + target + "'");
+ }
+
+ _key = parse(_keyStr);
+}
+
+void
+FreezeScript::RemoveDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "remove", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::RemoveDescriptor::validate()
+{
+}
+
+void
+FreezeScript::RemoveDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "remove", _line);
+
+ DataPtr key;
+ try
+ {
+ key = _key->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of key `" + _keyStr + "' failed:\n" + ex.reason());
+ }
+
+ DataPtr data = sym->getValue(_target);
+ if(data->readOnly())
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' cannot be modified");
+ }
+
+ DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
+ if(!dict)
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' is not a dictionary");
+ }
+
+ DataMap& map = dict->getElements();
+ DataMap::iterator p = map.find(key);
+ if(p != map.end())
+ {
+ p->first->destroy();
+ p->second->destroy();
+ map.erase(p);
+ }
+}
+
+//
+// DeleteDescriptor
+//
+FreezeScript::DeleteDescriptor::DeleteDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes&) :
+ Descriptor(parent, line, info)
+{
+}
+
+void
+FreezeScript::DeleteDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "delete", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::DeleteDescriptor::validate()
+{
+}
+
+void
+FreezeScript::DeleteDescriptor::execute(const SymbolTablePtr&)
+{
+ throw DeleteRecordException();
+}
+
+//
+// FailDescriptor
+//
+FreezeScript::FailDescriptor::FailDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ IceXML::Attributes::const_iterator p;
+
+ p = attributes.find("test");
+ if(p != attributes.end())
+ {
+ _testStr = p->second;
+ }
+
+ p = attributes.find("message");
+ if(p != attributes.end())
+ {
+ _message = p->second;
+ }
+
+ if(!_testStr.empty())
+ {
+ _test = parse(_testStr);
+ }
+
+ if(_message.empty())
+ {
+ ostringstream ostr;
+ ostr << "<fail> executed at line " << line << endl;
+ _message = ostr.str();
+ }
+}
+
+void
+FreezeScript::FailDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "fail", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::FailDescriptor::validate()
+{
+}
+
+void
+FreezeScript::FailDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "fail", _line);
+
+ if(_test)
+ {
+ try
+ {
+ DataPtr b = _test->evaluate(sym);
+ BooleanDataPtr bd = BooleanDataPtr::dynamicCast(b);
+ if(!bd)
+ {
+ _info->errorReporter->error("expression `" + _testStr + "' does not evaluate to a boolean");
+ }
+ if(!bd->booleanValue())
+ {
+ return;
+ }
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of expression `" + _testStr + "' failed:\n" + ex.reason());
+ }
+ }
+
+ throw Exception(__FILE__, __LINE__, _message);
+}
+
+//
+// EchoDescriptor
+//
+FreezeScript::EchoDescriptor::EchoDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ Descriptor(parent, line, info)
+{
+ IceXML::Attributes::const_iterator p;
+
+ p = attributes.find("message");
+ if(p != attributes.end())
+ {
+ _message = p->second;
+ }
+
+ p = attributes.find("value");
+ if(p != attributes.end())
+ {
+ _valueStr = p->second;
+ }
+
+ if(!_valueStr.empty())
+ {
+ _value = parse(_valueStr);
+ }
+}
+
+void
+FreezeScript::EchoDescriptor::addChild(const DescriptorPtr&)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "echo", _line);
+ _info->errorReporter->error("child elements are not supported");
+}
+
+void
+FreezeScript::EchoDescriptor::validate()
+{
+}
+
+void
+FreezeScript::EchoDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "echo", _line);
+
+ ostream& out = _info->errorReporter->stream();
+
+ if(!_message.empty())
+ {
+ out << _message;
+ }
+
+ if(_value)
+ {
+ DataPtr v;
+ try
+ {
+ v = _value->evaluate(sym);
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of value `" + _valueStr + "' failed:\n" + ex.reason());
+ }
+ printData(v, out);
+ }
+
+ out << endl;
+}
+
+//
+// ExecutableContainerDescriptor
+//
+FreezeScript::ExecutableContainerDescriptor::ExecutableContainerDescriptor(const DescriptorPtr& parent, int line,
+ const TransformInfoIPtr& info,
+ const IceXML::Attributes&,
+ const string& name) :
+ Descriptor(parent, line, info), _name(name)
+{
+}
+
+void
+FreezeScript::ExecutableContainerDescriptor::addChild(const DescriptorPtr& child)
+{
+ _children.push_back(child);
+}
+
+void
+FreezeScript::ExecutableContainerDescriptor::validate()
+{
+ for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
+ {
+ (*p)->validate();
+ }
+}
+
+void
+FreezeScript::ExecutableContainerDescriptor::execute(const SymbolTablePtr& sym)
+{
+ for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
+ {
+ (*p)->execute(sym);
+ }
+}
+
+//
+// IfDescriptor
+//
+FreezeScript::IfDescriptor::IfDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "if")
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "if", _line);
+
+ IceXML::Attributes::const_iterator p = attributes.find("test");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `test' is missing");
+ }
+ _testStr = p->second;
+
+ _test = parse(_testStr);
+}
+
+void
+FreezeScript::IfDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "if", _line);
+
+ try
+ {
+ DataPtr b = _test->evaluate(sym);
+ BooleanDataPtr bd = BooleanDataPtr::dynamicCast(b);
+ if(!bd)
+ {
+ _info->errorReporter->error("expression `" + _testStr + "' does not evaluate to a boolean");
+ }
+ if(bd->booleanValue())
+ {
+ ExecutableContainerDescriptor::execute(sym);
+ }
+ }
+ catch(const EvaluateException& ex)
+ {
+ _info->errorReporter->error("evaluation of conditional expression `" + _testStr + "' failed:\n" + ex.reason());
+ }
+}
+
+//
+// IterateDescriptor
+//
+FreezeScript::IterateDescriptor::IterateDescriptor(const DescriptorPtr& parent, int line,
+ const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "iterate")
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "iterate", _line);
+
+ IceXML::Attributes::const_iterator p;
+ string target;
+
+ p = attributes.find("target");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `target' is missing");
+ }
+ target = p->second;
+
+ p = attributes.find("key");
+ if(p != attributes.end())
+ {
+ _key = p->second;
+ }
+
+ p = attributes.find("value");
+ if(p != attributes.end())
+ {
+ _value = p->second;
+ }
+
+ p = attributes.find("element");
+ if(p != attributes.end())
+ {
+ _element = p->second;
+ }
+
+ p = attributes.find("index");
+ if(p != attributes.end())
+ {
+ _index = p->second;
+ }
+
+ NodePtr node = parse(target);
+ _target = EntityNodePtr::dynamicCast(node);
+ if(!_target)
+ {
+ _info->errorReporter->error("`target' attribute is not an entity: `" + target + "'");
+ }
+}
+
+void
+FreezeScript::IterateDescriptor::execute(const SymbolTablePtr& sym)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "iterate", _line);
+
+ DataPtr data = sym->getValue(_target);
+
+ DictionaryDataPtr dict = DictionaryDataPtr::dynamicCast(data);
+ SequenceDataPtr seq = SequenceDataPtr::dynamicCast(data);
+ if(!dict && !seq)
+ {
+ ostringstream ostr;
+ ostr << _target;
+ _info->errorReporter->error("target `" + ostr.str() + "' is not a dictionary or sequence");
+ }
+
+ if(dict)
+ {
+ if(!_element.empty())
+ {
+ _info->errorReporter->error("attribute `element' specified for dictionary target");
+ }
+ if(!_index.empty())
+ {
+ _info->errorReporter->error("attribute `index' specified for dictionary target");
+ }
+
+ string key = _key;
+ if(key.empty())
+ {
+ key = "key";
+ }
+
+ string value = _value;
+ if(value.empty())
+ {
+ value = "value";
+ }
+
+ DataMap& map = dict->getElements();
+ for(DataMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ SymbolTablePtr elemSym = sym->createChild();
+ elemSym->add(key, p->first);
+ elemSym->add(value, p->second);
+ ExecutableContainerDescriptor::execute(elemSym);
+ }
+ }
+ else
+ {
+ if(!_key.empty())
+ {
+ _info->errorReporter->error("attribute `key' specified for sequence target");
+ }
+ if(!_value.empty())
+ {
+ _info->errorReporter->error("attribute `value' specified for sequence target");
+ }
+
+ string element = _element;
+ if(element.empty())
+ {
+ element = "elem";
+ }
+
+ string index = _index;
+ if(index.empty())
+ {
+ index = "i";
+ }
+
+ DataList& l = seq->getElements();
+ Ice::Long i = 0;
+ for(DataList::iterator p = l.begin(); p != l.end(); ++p, ++i)
+ {
+ SymbolTablePtr elemSym = sym->createChild();
+ elemSym->add(element, *p);
+ elemSym->add(index, _info->factory->createInteger(i, true));
+ ExecutableContainerDescriptor::execute(elemSym);
+ }
+ }
+}
+
+//
+// TransformDescriptor
+//
+FreezeScript::TransformDescriptor::TransformDescriptor(const DescriptorPtr& parent, int line,
+ const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "transform"), _default(true), _base(true)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "transform", _line);
+
+ IceXML::Attributes::const_iterator p;
+
+ string type, rename;
+
+ p = attributes.find("type");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `type' is missing");
+ }
+ type = p->second;
+
+ p = attributes.find("default");
+ if(p != attributes.end())
+ {
+ if(p->second == "false")
+ {
+ _default = false;
+ }
+ }
+
+ p = attributes.find("base");
+ if(p != attributes.end())
+ {
+ if(p->second == "false")
+ {
+ _base = false;
+ }
+ }
+
+ p = attributes.find("rename");
+ if(p != attributes.end())
+ {
+ rename = p->second;
+ }
+
+ Slice::TypeList l;
+
+ l = _info->newUnit->lookupType(type, false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("unable to find type `" + type + "' in new Slice definitions");
+ }
+ else
+ {
+ _newType = l.front();
+ }
+
+ if(!rename.empty())
+ {
+ l = _info->oldUnit->lookupType(rename, false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("unable to find type `" + rename + "' in old Slice definitions");
+ }
+ _renameType = l.front();
+ }
+}
+
+Slice::TypePtr
+FreezeScript::TransformDescriptor::type() const
+{
+ return _newType;
+}
+
+string
+FreezeScript::TransformDescriptor::typeName() const
+{
+ return typeToString(_newType);
+}
+
+Slice::TypePtr
+FreezeScript::TransformDescriptor::renameType() const
+{
+ return _renameType;
+}
+
+string
+FreezeScript::TransformDescriptor::renameTypeName() const
+{
+ string result;
+ if(_renameType)
+ {
+ result = typeToString(_renameType);
+ }
+ return result;
+}
+
+bool
+FreezeScript::TransformDescriptor::doDefaultTransform() const
+{
+ return _default;
+}
+
+bool
+FreezeScript::TransformDescriptor::doBaseTransform() const
+{
+ return _base;
+}
+
+//
+// InitDescriptor
+//
+FreezeScript::InitDescriptor::InitDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "init")
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "init", _line);
+
+ IceXML::Attributes::const_iterator p = attributes.find("type");
+
+ string type;
+
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `type' is missing");
+ }
+ type = p->second;
+
+ Slice::TypeList l = _info->newUnit->lookupType(type, false);
+ if(l.empty())
+ {
+ _info->errorReporter->error("unable to find type `" + type + "' in new Slice definitions");
+ }
+ else
+ {
+ _type = l.front();
+ }
+}
+
+void
+FreezeScript::InitDescriptor::initialize(const DataPtr& data)
+{
+ SymbolTablePtr sym = new SymbolTableI(_info, _info->symbolTable);
+ sym->add("value", data);
+ execute(sym);
+}
+
+string
+FreezeScript::InitDescriptor::typeName() const
+{
+ return typeToString(_type);
+}
+
+//
+// RecordDescriptor
+//
+FreezeScript::RecordDescriptor::RecordDescriptor(const DescriptorPtr& parent, int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "record")
+{
+}
+
+void
+FreezeScript::RecordDescriptor::execute(const SymbolTablePtr& sym)
+{
+ //
+ // We need the Instance in order to use BasicStream.
+ //
+ IceInternal::InstancePtr instance = IceInternal::getInstance(_info->communicator);
+
+ //
+ // Temporarily add an object factory.
+ //
+ _info->communicator->addObjectFactory(new FreezeScript::ObjectFactory(_info->factory, _info->oldUnit), "");
+
+ //
+ // Iterate over the database.
+ //
+ Dbc* dbc = 0;
+ _info->oldDb->cursor(_info->oldDbTxn, &dbc, 0);
+ try
+ {
+ Dbt dbKey, dbValue;
+ while(dbc->get(&dbKey, &dbValue, DB_NEXT) == 0)
+ {
+ IceInternal::BasicStream inKey(instance.get());
+ inKey.b.resize(dbKey.get_size());
+ memcpy(&inKey.b[0], dbKey.get_data(), dbKey.get_size());
+ inKey.i = inKey.b.begin();
+
+ IceInternal::BasicStream inValue(instance.get());
+ inValue.b.resize(dbValue.get_size());
+ memcpy(&inValue.b[0], dbValue.get_data(), dbValue.get_size());
+ inValue.i = inValue.b.begin();
+ inValue.startReadEncaps();
+
+ IceInternal::BasicStream outKey(instance.get());
+ IceInternal::BasicStream outValue(instance.get());
+ outValue.startWriteEncaps();
+ try
+ {
+ transformRecord(inKey, inValue, outKey, outValue);
+ outValue.endWriteEncaps();
+ Dbt dbNewKey(&outKey.b[0], outKey.b.size()), dbNewValue(&outValue.b[0], outValue.b.size());
+ if(_info->newDb->put(_info->newDbTxn, &dbNewKey, &dbNewValue, DB_NOOVERWRITE) == DB_KEYEXIST)
+ {
+ _info->errorReporter->error("duplicate key encountered");
+ }
+ }
+ catch(const DeleteRecordException&)
+ {
+ // The record is deleted simply by not adding it to the new database.
+ }
+ catch(const ClassNotFoundException& ex)
+ {
+ if(!_info->purge)
+ {
+ _info->errorReporter->error("class " + ex.id + " not found in new Slice definitions");
+ }
+ else
+ {
+ // The record is deleted simply by not adding it to the new database.
+ _info->errorReporter->warning("purging database record due to missing class type " + ex.id);
+ }
+ }
+ }
+ }
+ catch(...)
+ {
+ if(dbc)
+ {
+ dbc->close();
+ }
+ _info->communicator->removeObjectFactory("");
+ throw;
+ }
+
+ _info->communicator->removeObjectFactory("");
+
+ if(dbc)
+ {
+ dbc->close();
+ }
+}
+
+void
+FreezeScript::RecordDescriptor::transformRecord(IceInternal::BasicStream& inKey, IceInternal::BasicStream& inValue,
+ IceInternal::BasicStream& outKey, IceInternal::BasicStream& outValue)
+{
+ //
+ // Create data representations of the old key and value types.
+ //
+ _info->factory->disableInitializers();
+ DataPtr oldKeyData = _info->factory->create(_info->oldKeyType, true);
+ Destroyer<DataPtr> oldKeyDataDestroyer(oldKeyData);
+ DataPtr oldValueData = _info->factory->create(_info->oldValueType, true);
+ Destroyer<DataPtr> oldValueDataDestroyer(oldValueData);
+
+ //
+ // Unmarshal the old key and value.
+ //
+ oldKeyData->unmarshal(inKey);
+ oldValueData->unmarshal(inValue);
+ _info->objectDataMap.clear();
+ if(_info->oldValueType->usesClasses())
+ {
+ inValue.readPendingObjects();
+ ObjectVisitor visitor(_info->objectDataMap);
+ oldValueData->visit(visitor);
+ }
+ _info->factory->enableInitializers();
+
+ //
+ // Create data representations of the new key and value types.
+ //
+ DataPtr newKeyData = _info->factory->create(_info->newKeyType, false);
+ Destroyer<DataPtr> newKeyDataDestroyer(newKeyData);
+ DataPtr newValueData = _info->factory->create(_info->newValueType, false);
+ Destroyer<DataPtr> newValueDataDestroyer(newValueData);
+
+ //
+ // Copy the data from the old key and value to the new key and value, if possible.
+ //
+ TransformVisitor keyVisitor(oldKeyData, _info);
+ newKeyData->visit(keyVisitor);
+ TransformVisitor valueVisitor(oldValueData, _info);
+ newValueData->visit(valueVisitor);
+
+ if(!_children.empty())
+ {
+ //
+ // Execute the child descriptors.
+ //
+ // TODO: Revisit identifiers.
+ //
+ SymbolTablePtr st = new SymbolTableI(_info, _info->symbolTable);
+ st->add("oldkey", oldKeyData);
+ st->add("newkey", newKeyData);
+ st->add("oldvalue", oldValueData);
+ st->add("newvalue", newValueData);
+ ExecutableContainerDescriptor::execute(st);
+ }
+
+ newKeyData->marshal(outKey);
+ newValueData->marshal(outValue);
+ if(_info->newValueType->usesClasses())
+ {
+ outValue.writePendingObjects();
+ }
+}
+
+//
+// DatabaseDescriptor
+//
+FreezeScript::DatabaseDescriptor::DatabaseDescriptor(const DescriptorPtr& parent, int line,
+ const TransformInfoIPtr& info,
+ const IceXML::Attributes& attributes) :
+ ExecutableContainerDescriptor(parent, line, info, attributes, "database")
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "database", _line);
+
+ IceXML::Attributes::const_iterator p = attributes.find("key");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `key' is missing");
+ }
+ string keyTypes = p->second;
+
+ p = attributes.find("value");
+ if(p == attributes.end())
+ {
+ _info->errorReporter->error("required attribute `value' is missing");
+ }
+ string valueTypes = p->second;
+
+ string oldKeyName, newKeyName;
+ string oldValueName, newValueName;
+ string::size_type pos;
+
+ pos = keyTypes.find(',');
+ if(pos == 0 || pos == keyTypes.size())
+ {
+ _info->errorReporter->error("invalid key type specification `" + keyTypes +"'");
+ }
+ if(pos == string::npos)
+ {
+ oldKeyName = keyTypes;
+ newKeyName = keyTypes;
+ }
+ else
+ {
+ oldKeyName = keyTypes.substr(0, pos);
+ newKeyName = keyTypes.substr(pos + 1);
+ }
+
+ pos = valueTypes.find(',');
+ if(pos == 0 || pos == valueTypes.size())
+ {
+ _info->errorReporter->error("invalid value type specification `" + valueTypes +"'");
+ }
+ if(pos == string::npos)
+ {
+ oldValueName = valueTypes;
+ newValueName = valueTypes;
+ }
+ else
+ {
+ oldValueName = valueTypes.substr(0, pos);
+ newValueName = valueTypes.substr(pos + 1);
+ }
+
+ //
+ // Look up the Slice definitions for the key and value types.
+ //
+ _info->oldKeyType = findType(_info->oldUnit, oldKeyName);
+ _info->newKeyType = findType(_info->newUnit, newKeyName);
+ _info->oldValueType = findType(_info->oldUnit, oldValueName);
+ _info->newValueType = findType(_info->newUnit, newValueName);
+}
+
+void
+FreezeScript::DatabaseDescriptor::addChild(const DescriptorPtr& child)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "database", _line);
+
+ RecordDescriptorPtr rec = RecordDescriptorPtr::dynamicCast(child);
+ if(rec)
+ {
+ if(_record)
+ {
+ _info->errorReporter->error("only one <record> element can be specified");
+ }
+ _record = rec;
+ }
+
+ ExecutableContainerDescriptor::addChild(child);
+}
+
+//
+// TransformDBDescriptor
+//
+FreezeScript::TransformDBDescriptor::TransformDBDescriptor(int line, const TransformInfoIPtr& info,
+ const IceXML::Attributes&) :
+ Descriptor(0, line, info)
+{
+}
+
+FreezeScript::TransformDBDescriptor::~TransformDBDescriptor()
+{
+}
+
+void
+FreezeScript::TransformDBDescriptor::addChild(const DescriptorPtr& child)
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "transformdb", _line);
+
+ DatabaseDescriptorPtr db = DatabaseDescriptorPtr::dynamicCast(child);
+ TransformDescriptorPtr transform = TransformDescriptorPtr::dynamicCast(child);
+ InitDescriptorPtr init = InitDescriptorPtr::dynamicCast(child);
+
+ if(db)
+ {
+ if(_database)
+ {
+ _info->errorReporter->error("only one <database> element can be specified");
+ }
+ else
+ {
+ _database = db;
+ _children.push_back(db);
+ }
+ }
+ else if(transform)
+ {
+ string name = transform->typeName();
+ TransformMap::iterator p = _info->transformMap.find(name);
+ if(p != _info->transformMap.end())
+ {
+ _info->errorReporter->error("transform `" + name + "' specified more than once");
+ }
+ _info->transformMap.insert(TransformMap::value_type(name, transform));
+
+ string renameTypeName = transform->renameTypeName();
+ if(!renameTypeName.empty())
+ {
+ RenameMap::iterator q = _info->renameMap.find(renameTypeName);
+ if(q != _info->renameMap.end())
+ {
+ _info->errorReporter->error("multiple transform descriptors specify the rename value `" +
+ renameTypeName + "'");
+ }
+ _info->renameMap.insert(RenameMap::value_type(renameTypeName, transform->type()));
+ }
+
+ _children.push_back(transform);
+ }
+ else if(init)
+ {
+ _info->factory->addInitDescriptor(init);
+ _children.push_back(init);
+ }
+ else
+ {
+ _info->errorReporter->error("invalid child element");
+ }
+}
+
+void
+FreezeScript::TransformDBDescriptor::validate()
+{
+ DescriptorErrorContext ctx(_info->errorReporter, "transformdb", _line);
+
+ if(!_database)
+ {
+ _info->errorReporter->error("no <database> element specified");
+ }
+
+ for(vector<DescriptorPtr>::iterator p = _children.begin(); p != _children.end(); ++p)
+ {
+ (*p)->validate();
+ }
+}
+
+void
+FreezeScript::TransformDBDescriptor::execute(const SymbolTablePtr& sym)
+{
+ _database->execute(sym);
+}
+
+//
+// SymbolTableI
+//
+FreezeScript::SymbolTableI::SymbolTableI(const TransformInfoIPtr& info, const SymbolTablePtr& parent) :
+ _info(info), _parent(parent)
+{
+}
+
+void
+FreezeScript::SymbolTableI::add(const string& name, const DataPtr& data)
+{
+ DataPtr d = findValue(name);
+ if(d)
+ {
+ _info->errorReporter->error("`" + name + "' is already defined");
+ }
+
+ _dataMap.insert(DataMap::value_type(name, data));
+}
+
+FreezeScript::DataPtr
+FreezeScript::SymbolTableI::getValue(const EntityNodePtr& entity) const
+{
+ EntityVisitor visitor(const_cast<SymbolTableI*>(this));
+ entity->visit(visitor);
+ DataPtr result = visitor.getCurrent();
+ if(!result)
+ {
+ ostringstream ostr;
+ ostr << "invalid entity `" << entity << "'";
+ _info->errorReporter->error(ostr.str());
+ }
+
+ return result;
+}
+
+FreezeScript::DataPtr
+FreezeScript::SymbolTableI::getConstantValue(const string& name) const
+{
+ string::size_type pos;
+ Slice::UnitPtr unit;
+ string key;
+
+ DataMap::const_iterator p = _constantCache.find(name);
+ if(p != _constantCache.end())
+ {
+ return p->second;
+ }
+
+ if(_parent)
+ {
+ return _parent->getConstantValue(name);
+ }
+
+ //
+ // Name must start with "::Old" or "::New" to indicate the Slice unit.
+ //
+ pos = name.find("::Old");
+ if(pos == 0)
+ {
+ if(name.length() > 5)
+ {
+ key = name.substr(5);
+ unit = _info->oldUnit;
+ }
+ }
+ else
+ {
+ pos = name.find("::New");
+ if(pos == 0)
+ {
+ if(name.length() > 5)
+ {
+ key = name.substr(5);
+ unit = _info->newUnit;
+ }
+ }
+ }
+
+ if(key.empty())
+ {
+ _info->errorReporter->error("invalid constant name `" + name + "'");
+ }
+
+ Slice::ContainedList l = unit->findContents(key);
+ if(l.empty())
+ {
+ _info->errorReporter->error("unknown constant `" + name + "'");
+ }
+
+ Slice::EnumeratorPtr e = Slice::EnumeratorPtr::dynamicCast(l.front());
+ Slice::ConstPtr c = Slice::ConstPtr::dynamicCast(l.front());
+ if(!e && !c)
+ {
+ _info->errorReporter->error("`" + name + "' does not refer to a Slice constant or enumerator");
+ }
+
+ DataPtr result;
+
+ if(c)
+ {
+ Slice::TypePtr type = c->type();
+ string value = c->value();
+ Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type);
+ if(b)
+ {
+ switch(b->kind())
+ {
+ case Slice::Builtin::KindByte:
+ case Slice::Builtin::KindShort:
+ case Slice::Builtin::KindInt:
+ case Slice::Builtin::KindLong:
+ {
+ string::size_type end;
+ Ice::Long n;
+ if(!IceUtil::stringToInt64(value, n, end))
+ {
+ assert(false);
+ }
+ result = _info->factory->createInteger(n, true);
+ break;
+ }
+
+ case Slice::Builtin::KindBool:
+ {
+ result = _info->factory->createBoolean(value == "true", true);
+ break;
+ }
+
+ case Slice::Builtin::KindFloat:
+ case Slice::Builtin::KindDouble:
+ {
+ double v = strtod(value.c_str(), 0);
+ result = _info->factory->createDouble(v, true);
+ break;
+ }
+
+ case Slice::Builtin::KindString:
+ {
+ result = _info->factory->createString(value, true);
+ break;
+ }
+
+ case Slice::Builtin::KindObject:
+ case Slice::Builtin::KindObjectProxy:
+ case Slice::Builtin::KindLocalObject:
+ assert(false);
+ }
+ }
+ else
+ {
+ Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type);
+ assert(en);
+ Slice::EnumeratorList el = en->getEnumerators();
+ for(Slice::EnumeratorList::iterator q = el.begin(); q != el.end(); ++q)
+ {
+ if((*q)->name() == value)
+ {
+ e = *q;
+ break;
+ }
+ }
+ assert(e);
+ }
+ }
+
+ if(!result)
+ {
+ assert(e);
+ result = _info->factory->create(e->type(), true);
+ EnumDataPtr ed = EnumDataPtr::dynamicCast(result);
+ assert(ed);
+ ed->setValueAsString(e->name());
+ }
+
+ //
+ // Cache the value.
+ //
+ const_cast<DataMap&>(_constantCache).insert(DataMap::value_type(name, result));
+
+ return result;
+}
+
+FreezeScript::SymbolTablePtr
+FreezeScript::SymbolTableI::createChild()
+{
+ return new SymbolTableI(_info, this);
+}
+
+Slice::TypePtr
+FreezeScript::SymbolTableI::lookupType(const string& name)
+{
+ Slice::TypeList l = _info->newUnit->lookupType(name, false);
+ Slice::TypePtr result;
+ if(!l.empty())
+ {
+ result = l.front();
+ }
+ return result;
+}
+
+FreezeScript::DataPtr
+FreezeScript::SymbolTableI::invokeFunction(const string& name, const DataPtr& target, const DataList& args)
+{
+ if(target)
+ {
+ DictionaryDataPtr targetDict = DictionaryDataPtr::dynamicCast(target);
+ if(targetDict && name == "containsKey")
+ {
+ if(args.size() != 1)
+ {
+ _info->errorReporter->error("containsKey() requires one argument");
+ }
+ Slice::DictionaryPtr dictType = Slice::DictionaryPtr::dynamicCast(targetDict->getType());
+ assert(dictType);
+ DataPtr key = _info->factory->create(dictType->keyType(), false);
+ assignOrTransform(key, args[0], false, _info);
+ DataPtr value = targetDict->getElement(key);
+ return _info->factory->createBoolean(value ? true : false, false);
+ }
+
+ DataPtr result;
+ if(invokeMemberFunction(name, target, args, result, _info->factory, _info->errorReporter))
+ {
+ return result;
+ }
+
+ _info->errorReporter->error("unknown function `" + name + "' invoked on type " +
+ typeToString(target->getType()));
+ }
+ else
+ {
+ //
+ // Global function.
+ //
+ DataPtr result;
+ if(invokeGlobalFunction(name, args, result, _info->factory, _info->errorReporter))
+ {
+ return result;
+ }
+ else
+ {
+ _info->errorReporter->error("unknown global function `" + name + "'");
+ }
+ }
+
+ return 0;
+}
+
+FreezeScript::DataPtr
+FreezeScript::SymbolTableI::findValue(const string& name) const
+{
+ DataMap::const_iterator p = _dataMap.find(name);
+ if(p != _dataMap.end())
+ {
+ return p->second;
+ }
+
+ if(_parent)
+ {
+ SymbolTableIPtr parentI = SymbolTableIPtr::dynamicCast(_parent);
+ assert(parentI);
+ return parentI->findValue(name);
+ }
+
+ return 0;
+}
+
+FreezeScript::SymbolTableI::EntityVisitor::EntityVisitor(SymbolTableI* table) :
+ _table(table), _error(false)
+{
+}
+
+void
+FreezeScript::SymbolTableI::EntityVisitor::visitIdentifier(const string& name)
+{
+ if(!_error)
+ {
+ if(!_current)
+ {
+ _current = _table->findValue(name);
+ }
+ else
+ {
+ _current = _current->getMember(name);
+ }
+
+ if(!_current)
+ {
+ _error = true;
+ }
+ }
+}
+
+void
+FreezeScript::SymbolTableI::EntityVisitor::visitElement(const NodePtr& value)
+{
+ if(!_error)
+ {
+ assert(_current);
+
+ DataPtr val = value->evaluate(_table);
+ _current = _current->getElement(val);
+
+ if(!_current)
+ {
+ _error = true;
+ }
+ }
+}
+
+FreezeScript::DataPtr
+FreezeScript::SymbolTableI::EntityVisitor::getCurrent() const
+{
+ return _current;
+}
+
+//
+// ObjectVisitor
+//
+FreezeScript::ObjectVisitor::ObjectVisitor(ObjectDataMap& objectDataMap) :
+ _map(objectDataMap)
+{
+}
+
+void
+FreezeScript::ObjectVisitor::visitStruct(const StructDataPtr& data)
+{
+ Slice::TypePtr type = data->getType();
+ if(type->usesClasses())
+ {
+ DataMemberMap& members = data->getMembers();
+ for(DataMemberMap::iterator p = members.begin(); p != members.end(); ++p)
+ {
+ p->second->visit(*this);
+ }
+ }
+}
+
+void
+FreezeScript::ObjectVisitor::visitSequence(const SequenceDataPtr& data)
+{
+ Slice::TypePtr type = data->getType();
+ if(type->usesClasses())
+ {
+ DataList& elements = data->getElements();
+ for(DataList::iterator p = elements.begin(); p != elements.end(); ++p)
+ {
+ (*p)->visit(*this);
+ }
+ }
+}
+
+void
+FreezeScript::ObjectVisitor::visitDictionary(const DictionaryDataPtr& data)
+{
+ Slice::TypePtr type = data->getType();
+ if(type->usesClasses())
+ {
+ DataMap& elements = data->getElements();
+ for(DataMap::iterator p = elements.begin(); p != elements.end(); ++p)
+ {
+ //
+ // NOTE: There's no need to visit the key.
+ //
+ p->second->visit(*this);
+ }
+ }
+}
+
+void
+FreezeScript::ObjectVisitor::visitObject(const ObjectRefPtr& data)
+{
+ ObjectDataPtr value = data->getValue();
+ if(value)
+ {
+ ObjectDataMap::iterator p = _map.find(value.get());
+ if(p == _map.end())
+ {
+ _map.insert(ObjectDataMap::value_type(value.get(), 0));
+ DataMemberMap& members = value->getMembers();
+ for(DataMemberMap::iterator q = members.begin(); q != members.end(); ++q)
+ {
+ q->second->visit(*this);
+ }
+ }
+ }
+}
+
+//
+// TransformInfoI
+//
+FreezeScript::DataFactoryPtr
+FreezeScript::TransformInfoI::getDataFactory()
+{
+ return factory;
+}
+
+FreezeScript::ErrorReporterPtr
+FreezeScript::TransformInfoI::getErrorReporter()
+{
+ return errorReporter;
+}
+
+bool
+FreezeScript::TransformInfoI::doDefaultTransform(const Slice::TypePtr& type)
+{
+ TransformMap::const_iterator p = transformMap.find(typeToString(type));
+ if(p != transformMap.end())
+ {
+ return p->second->doDefaultTransform();
+ }
+ return true;
+}
+
+bool
+FreezeScript::TransformInfoI::doBaseTransform(const Slice::ClassDefPtr& type)
+{
+ TransformMap::const_iterator p = transformMap.find(type->scoped());
+ if(p != transformMap.end())
+ {
+ return p->second->doBaseTransform();
+ }
+ return true;
+}
+
+Slice::TypePtr
+FreezeScript::TransformInfoI::getRenamedType(const Slice::TypePtr& old)
+{
+ RenameMap::iterator p = renameMap.find(typeToString(old));
+ if(p != renameMap.end())
+ {
+ return p->second;
+ }
+ return 0;
+}
+
+void
+FreezeScript::TransformInfoI::executeCustomTransform(const DataPtr& dest, const DataPtr& src)
+{
+ //
+ // Execute the type's transform (if any). Non-nil objects need special consideration,
+ // for two reasons:
+ //
+ // 1. The dest and src arguments are ObjectRef instances whose getType()
+ // function returns the formal type, which may not match the actual type
+ // if inheritance is being used. Therefore, we need to look for the
+ // transform of the actual type of the object.
+ //
+ // 2. It's not sufficient to execute only the transform for the actual type;
+ // the transform descriptors for base types must also be executed (if not
+ // explicitly precluded).
+ //
+ // The algorithm goes like this:
+ //
+ // 1. If a transform exists for the actual type, execute it.
+ // 2. If the transform doesn't exist, or if it does exist and does not preclude
+ // the execution of the base transform, then obtain the base type. If the
+ // type has no user-defined base class, use Object.
+ // 3. If a base type was found and a transform exists for the base type, execute it.
+ // 4. Repeat step 2.
+ //
+ ObjectRefPtr obj = ObjectRefPtr::dynamicCast(dest);
+ if(obj && obj->getValue())
+ {
+ ObjectDataPtr data = obj->getValue();
+ Slice::TypePtr cls = data->getType(); // Actual type: may be Builtin (Object) or ClassDecl
+ bool transformBase = true;
+ while(cls)
+ {
+ string type = typeToString(cls);
+ TransformMap::const_iterator p = transformMap.find(type);
+ if(p != transformMap.end())
+ {
+ SymbolTablePtr sym = new SymbolTableI(this, symbolTable);
+ sym->add("new", dest);
+ sym->add("old", src);
+ p->second->execute(sym);
+ transformBase = p->second->doBaseTransform();
+ }
+ Slice::ClassDeclPtr decl = Slice::ClassDeclPtr::dynamicCast(cls);
+ cls = 0;
+ if(transformBase && decl)
+ {
+ Slice::ClassDefPtr def = decl->definition();
+ assert(def);
+ Slice::ClassList bases = def->bases();
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ cls = bases.front()->declaration();
+ }
+ else
+ {
+ cls = newUnit->builtin(Slice::Builtin::KindObject);
+ }
+ }
+ }
+ }
+ else
+ {
+ string type = typeToString(dest->getType());
+ TransformMap::const_iterator p = transformMap.find(type);
+ if(p != transformMap.end())
+ {
+ SymbolTablePtr sym = new SymbolTableI(this, symbolTable);
+ sym->add("new", dest);
+ sym->add("old", src);
+ p->second->execute(sym);
+ }
+ }
+}
+
+bool
+FreezeScript::TransformInfoI::purgeObjects()
+{
+ return purge;
+}
+
+FreezeScript::ObjectDataMap&
+FreezeScript::TransformInfoI::getObjectDataMap()
+{
+ return objectDataMap;
+}
+
+//
// DescriptorHandler
//
-FreezeScript::DescriptorHandler::DescriptorHandler(const DataFactoryPtr& factory, const Slice::UnitPtr& oldUnit,
- const Slice::UnitPtr& newUnit,
- const ErrorReporterPtr& errorReporter) :
- _factory(factory), _old(oldUnit), _new(newUnit), _errorReporter(errorReporter)
+FreezeScript::DescriptorHandler::DescriptorHandler(const TransformInfoIPtr& info) :
+ _info(info)
{
}
@@ -69,132 +2571,132 @@ FreezeScript::DescriptorHandler::startElement(const string& name, const IceXML::
{
if(_current)
{
- _errorReporter->descriptorError("<transformdb> must be the top-level element", line);
+ _info->errorReporter->descriptorError("<transformdb> must be the top-level element", line);
}
- _descriptor = new TransformDBDescriptor(line, _factory, _errorReporter, attributes, _old, _new);
+ _descriptor = new TransformDBDescriptor(line, _info, attributes);
d = _descriptor;
}
else if(name == "database")
{
if(!_current)
{
- _errorReporter->descriptorError("<database> must be a child of <transformdb>", line);
+ _info->errorReporter->descriptorError("<database> must be a child of <transformdb>", line);
}
- d = new DatabaseDescriptor(_current, line, _factory, _errorReporter, attributes, _old, _new);
+ d = new DatabaseDescriptor(_current, line, _info, attributes);
}
else if(name == "record")
{
if(!_current)
{
- _errorReporter->descriptorError("<record> must be a child of <database>", line);
+ _info->errorReporter->descriptorError("<record> must be a child of <database>", line);
}
- d = new RecordDescriptor(_current, line, _factory, _errorReporter, attributes, _old, _new);
+ d = new RecordDescriptor(_current, line, _info, attributes);
}
else if(name == "transform")
{
if(!_current)
{
- _errorReporter->descriptorError("<transform> must be a child of <transformdb>", line);
+ _info->errorReporter->descriptorError("<transform> must be a child of <transformdb>", line);
}
- d = new TransformDescriptor(_current, line, _factory, _errorReporter, attributes, _old, _new);
+ d = new TransformDescriptor(_current, line, _info, attributes);
}
else if(name == "init")
{
if(!_current)
{
- _errorReporter->descriptorError("<init> must be a child of <transformdb>", line);
+ _info->errorReporter->descriptorError("<init> must be a child of <transformdb>", line);
}
- d = new InitDescriptor(_current, line, _factory, _errorReporter, attributes, _old, _new);
+ d = new InitDescriptor(_current, line, _info, attributes);
}
else if(name == "set")
{
if(!_current)
{
- _errorReporter->descriptorError("<set> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<set> cannot be a top-level element", line);
}
- d = new SetDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new SetDescriptor(_current, line, _info, attributes);
}
else if(name == "define")
{
if(!_current)
{
- _errorReporter->descriptorError("<define> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<define> cannot be a top-level element", line);
}
- d = new DefineDescriptor(_current, line, _factory, _errorReporter, attributes, _old, _new);
+ d = new DefineDescriptor(_current, line, _info, attributes);
}
else if(name == "add")
{
if(!_current)
{
- _errorReporter->descriptorError("<add> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<add> cannot be a top-level element", line);
}
- d = new AddDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new AddDescriptor(_current, line, _info, attributes);
}
else if(name == "remove")
{
if(!_current)
{
- _errorReporter->descriptorError("<remove> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<remove> cannot be a top-level element", line);
}
- d = new RemoveDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new RemoveDescriptor(_current, line, _info, attributes);
}
else if(name == "delete")
{
if(!_current)
{
- _errorReporter->descriptorError("<delete> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<delete> cannot be a top-level element", line);
}
- d = new DeleteDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new DeleteDescriptor(_current, line, _info, attributes);
}
else if(name == "fail")
{
if(!_current)
{
- _errorReporter->descriptorError("<fail> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<fail> cannot be a top-level element", line);
}
- d = new FailDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new FailDescriptor(_current, line, _info, attributes);
}
else if(name == "echo")
{
if(!_current)
{
- _errorReporter->descriptorError("<echo> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<echo> cannot be a top-level element", line);
}
- d = new EchoDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new EchoDescriptor(_current, line, _info, attributes);
}
else if(name == "if")
{
if(!_current)
{
- _errorReporter->descriptorError("<if> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<if> cannot be a top-level element", line);
}
- d = new IfDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new IfDescriptor(_current, line, _info, attributes);
}
else if(name == "iterate")
{
if(!_current)
{
- _errorReporter->descriptorError("<iterate> cannot be a top-level element", line);
+ _info->errorReporter->descriptorError("<iterate> cannot be a top-level element", line);
}
- d = new IterateDescriptor(_current, line, _factory, _errorReporter, attributes);
+ d = new IterateDescriptor(_current, line, _info, attributes);
}
else
{
- _errorReporter->descriptorError("unknown descriptor `" + name + "'", line);
+ _info->errorReporter->descriptorError("unknown descriptor `" + name + "'", line);
}
if(_current)
@@ -219,7 +2721,7 @@ FreezeScript::DescriptorHandler::characters(const std::string&, int, int)
void
FreezeScript::DescriptorHandler::error(const std::string& msg, int line, int col)
{
- _errorReporter->descriptorError(msg, line);
+ _info->errorReporter->descriptorError(msg, line);
}
FreezeScript::TransformDBDescriptorPtr
@@ -229,82 +2731,57 @@ FreezeScript::DescriptorHandler::descriptor() const
}
//
-// Transformer
+// assignOrTransform
//
-FreezeScript::Transformer::Transformer(const Ice::CommunicatorPtr& communicator, const Slice::UnitPtr& oldUnit,
- const Slice::UnitPtr& newUnit, bool ignoreTypeChanges, bool purgeObjects) :
- _communicator(communicator), _old(oldUnit), _new(newUnit), _ignoreTypeChanges(ignoreTypeChanges),
- _purgeObjects(purgeObjects)
-{
- createCoreSliceTypes(_old);
- createCoreSliceTypes(_new);
-
- createEvictorSliceTypes(_old);
- createEvictorSliceTypes(_new);
-}
-
void
-FreezeScript::Transformer::analyze(const string& oldKey, const string& newKey, const string& oldValue,
- const string& newValue, ostream& descriptors, Ice::StringSeq& missingTypes,
- Ice::StringSeq& errors)
+FreezeScript::assignOrTransform(const DataPtr& dest, const DataPtr& src, bool convert, const TransformInfoPtr& info)
{
- //
- // Look up the Slice definitions for the key and value types.
- //
- Slice::TypePtr oldKeyType = findType(_old, oldKey, errors);
- Slice::TypePtr newKeyType = findType(_new, newKey, errors);
- Slice::TypePtr oldValueType = findType(_old, oldValue, errors);
- Slice::TypePtr newValueType = findType(_new, newValue, errors);
- if(!oldKeyType || !newKeyType || !oldValueType || !newValueType)
+ Slice::TypePtr destType = dest->getType();
+ Slice::TypePtr srcType = src->getType();
+ Slice::BuiltinPtr b1 = Slice::BuiltinPtr::dynamicCast(destType);
+ Slice::BuiltinPtr b2 = Slice::BuiltinPtr::dynamicCast(srcType);
+
+ if(!b1 && !b2 && dest->getType()->unit().get() != src->getType()->unit().get())
{
- return;
+ TransformVisitor v(src, info);
+ dest->visit(v);
+ }
+ else
+ {
+ AssignVisitor v(src, info->getDataFactory(), info->getErrorReporter(), convert);
+ dest->visit(v);
}
-
- TransformAnalyzer analyzer(_old, _new, _ignoreTypeChanges);
- analyzer.analyze(oldKeyType, newKeyType, oldValueType, newValueType, descriptors, missingTypes, errors);
-}
-
-void
-FreezeScript::Transformer::analyze(ostream& descriptors, Ice::StringSeq& missingTypes, Ice::StringSeq& errors)
-{
- const string keyType = "::Freeze::EvictorStorageKey";
- const string valueType = "::Freeze::ObjectRecord";
- analyze(keyType, keyType, valueType, valueType, descriptors, missingTypes, errors);
}
void
-FreezeScript::Transformer::transform(istream& is, Db* db, DbTxn* txn, Db* dbNew, DbTxn* txnNew, ostream& errors,
- bool suppress)
+FreezeScript::transformDatabase(const Ice::CommunicatorPtr& communicator,
+ const Slice::UnitPtr& oldUnit, const Slice::UnitPtr& newUnit,
+ Db* oldDb, DbTxn* oldDbTxn, Db* newDb, DbTxn* newDbTxn,
+ bool purgeObjects, ostream& errors, bool suppress, istream& is)
{
- ErrorReporterPtr errorReporter = new ErrorReporter(errors, suppress);
+ TransformInfoIPtr info = new TransformInfoI;
+ info->communicator = communicator;
+ info->oldUnit = oldUnit;
+ info->newUnit = newUnit;
+ info->oldDb = oldDb;
+ info->oldDbTxn = oldDbTxn;
+ info->newDb = newDb;
+ info->newDbTxn = newDbTxn;
+ info->purge = purgeObjects;
+ info->errorReporter = new ErrorReporter(errors, suppress);
+ info->factory = new TransformDataFactory(communicator, newUnit, info->errorReporter);
+ info->symbolTable = new SymbolTableI(info);
try
{
- DataFactoryPtr factory = new DataFactory(_communicator, _new, errorReporter);
- DescriptorHandler dh(factory, _old, _new, errorReporter);
+ DescriptorHandler dh(info);
IceXML::Parser::parse(is, dh);
-
TransformDBDescriptorPtr descriptor = dh.descriptor();
descriptor->validate();
- descriptor->transform(_communicator, db, txn, dbNew, txnNew, _purgeObjects);
+ descriptor->execute(info->symbolTable);
}
catch(const IceXML::ParserException& ex)
{
- errorReporter->error(ex.reason());
+ info->errorReporter->error(ex.reason());
}
}
-
-Slice::TypePtr
-FreezeScript::Transformer::findType(const Slice::UnitPtr& u, const string& type, Ice::StringSeq& errors)
-{
- Slice::TypeList l;
-
- l = u->lookupType(type, false);
- if(l.empty())
- {
- errors.push_back("error: unknown type `" + type + "'");
- return 0;
- }
-
- return l.front();
-}
diff --git a/cpp/src/FreezeScript/Transformer.h b/cpp/src/FreezeScript/Transformer.h
index 1bdaa56fc81..2deda6b556a 100644
--- a/cpp/src/FreezeScript/Transformer.h
+++ b/cpp/src/FreezeScript/Transformer.h
@@ -17,7 +17,6 @@
#include <Ice/Ice.h>
#include <Slice/Parser.h>
-#include <FreezeScript/Exception.h>
class Db;
class DbTxn;
@@ -25,29 +24,9 @@ class DbTxn;
namespace FreezeScript
{
-class Transformer
-{
-public:
-
- Transformer(const Ice::CommunicatorPtr&, const Slice::UnitPtr&, const Slice::UnitPtr&, bool, bool);
-
- void analyze(const std::string&, const std::string&, const std::string&, const std::string&, std::ostream&,
- Ice::StringSeq&, Ice::StringSeq&);
-
- void analyze(std::ostream&, Ice::StringSeq&, Ice::StringSeq&);
-
- void transform(std::istream&, Db*, DbTxn*, Db*, DbTxn*, std::ostream&, bool);
-
-private:
-
- static Slice::TypePtr findType(const Slice::UnitPtr&, const std::string&, Ice::StringSeq&);
-
- Ice::CommunicatorPtr _communicator;
- Slice::UnitPtr _old;
- Slice::UnitPtr _new;
- bool _ignoreTypeChanges;
- bool _purgeObjects;
-};
+void
+transformDatabase(const Ice::CommunicatorPtr&, const Slice::UnitPtr&, const Slice::UnitPtr&,
+ Db*, DbTxn*, Db*, DbTxn*, bool, std::ostream&, bool, std::istream&);
} // End of namespace FreezeScript
diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp
index b85365a8cb7..fa794554b72 100644
--- a/cpp/src/FreezeScript/transformdb.cpp
+++ b/cpp/src/FreezeScript/transformdb.cpp
@@ -13,6 +13,8 @@
// **********************************************************************
#include <FreezeScript/Transformer.h>
+#include <FreezeScript/TransformAnalyzer.h>
+#include <FreezeScript/Exception.h>
#include <FreezeScript/Util.h>
#include <db_cxx.h>
#include <sys/stat.h>
@@ -66,6 +68,21 @@ usage(const char* n)
// Note: --case-sensitive is intentionally not shown here!
}
+static Slice::TypePtr
+findType(const string& prog, const Slice::UnitPtr& u, const string& type)
+{
+ Slice::TypeList l;
+
+ l = u->lookupType(type, false);
+ if(l.empty())
+ {
+ cerr << prog << ": error: unknown type `" << type << "'" << endl;
+ return 0;
+ }
+
+ return l.front();
+}
+
static int
run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
{
@@ -355,9 +372,12 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
}
//
- // Create the Transformer.
+ // Install the core types in the Slice units.
//
- FreezeScript::Transformer transformer(communicator, oldUnit, newUnit, ignoreTypeChanges, purgeObjects);
+ FreezeScript::createCoreSliceTypes(oldUnit);
+ FreezeScript::createEvictorSliceTypes(oldUnit);
+ FreezeScript::createCoreSliceTypes(newUnit);
+ FreezeScript::createEvictorSliceTypes(newUnit);
//
// If no input file was provided, then we need to analyze the Slice types.
@@ -369,13 +389,14 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
vector<string> missingTypes;
vector<string> analyzeErrors;
+ string oldKeyName, newKeyName, oldValueName, newValueName;
if(evictor)
{
- transformer.analyze(out, missingTypes, analyzeErrors);
+ oldKeyName = newKeyName = "::Freeze::EvictorStorageKey";
+ oldValueName = newValueName = "::Freeze::ObjectRecord";
}
else
{
- string oldKeyName, newKeyName, oldValueName, newValueName;
string::size_type pos;
if(keyTypeNames.empty() || valueTypeNames.empty())
@@ -417,10 +438,20 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
oldValueName = valueTypeNames.substr(0, pos);
newValueName = valueTypeNames.substr(pos + 1);
}
+ }
- transformer.analyze(oldKeyName, newKeyName, oldValueName, newValueName, out, missingTypes, analyzeErrors);
+ Slice::TypePtr oldKeyType = findType(argv[0], oldUnit, oldKeyName);
+ Slice::TypePtr newKeyType = findType(argv[0], newUnit, newKeyName);
+ Slice::TypePtr oldValueType = findType(argv[0], oldUnit, oldValueName);
+ Slice::TypePtr newValueType = findType(argv[0], newUnit, newValueName);
+ if(!oldKeyType || !newKeyType || !oldValueType || !newValueType)
+ {
+ return EXIT_FAILURE;
}
+ FreezeScript::TransformAnalyzer analyzer(oldUnit, newUnit, ignoreTypeChanges);
+ analyzer.analyze(oldKeyType, newKeyType, oldValueType, newValueType, out, missingTypes, analyzeErrors);
+
if(!analyzeErrors.empty())
{
for(vector<string>::const_iterator p = analyzeErrors.begin(); p != analyzeErrors.end(); ++p)
@@ -466,6 +497,9 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
}
else
{
+ //
+ // Read the input file.
+ //
ifstream in(inputFile.c_str());
char buff[1024];
while(true)
@@ -486,6 +520,9 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
+ //
+ // Transform the database.
+ //
DbEnv dbEnv(0);
DbEnv dbEnvNew(0);
DbTxn* txn = 0;
@@ -541,8 +578,12 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
dbEnvNew.txn_begin(0, &txnNew, 0);
dbNew->open(txnNew, dbName.c_str(), 0, DB_BTREE, DB_CREATE | DB_EXCL, FREEZE_SCRIPT_DB_MODE);
+ //
+ // Execute the transformation descriptors.
+ //
istringstream istr(descriptors);
- transformer.transform(istr, db, txn, dbNew, txnNew, cerr, suppress);
+ FreezeScript::transformDatabase(communicator, oldUnit, newUnit, db, txn, dbNew, txnNew, purgeObjects, cerr,
+ suppress, istr);
//
// Checkpoint to migrate changes from the log to the database.
diff --git a/cpp/src/FreezeScript/transformdb.dsp b/cpp/src/FreezeScript/transformdb.dsp
index 6d0cb18ba0a..a32622bc0ed 100644
--- a/cpp/src/FreezeScript/transformdb.dsp
+++ b/cpp/src/FreezeScript/transformdb.dsp
@@ -147,10 +147,6 @@ SOURCE=.\TransformDB.cpp
# End Source File
# Begin Source File
-SOURCE=.\TransformDescriptors.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\TransformVisitor.cpp
# End Source File
# Begin Source File
@@ -207,10 +203,6 @@ SOURCE=.\TransformAnalyzer.h
# End Source File
# Begin Source File
-SOURCE=.\TransformDescriptors.h
-# End Source File
-# Begin Source File
-
SOURCE=.\TransformVisitor.h
# End Source File
# Begin Source File