1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// **********************************************************************
//
// 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_VISITOR_H
#define FREEZE_SCRIPT_TRANSFORM_VISITOR_H
#include <FreezeScript/Data.h>
namespace FreezeScript
{
//
// ObjectDataMap associates old instances of ObjectData to their
// transformed equivalents.
//
typedef std::map<const ObjectData*, ObjectDataPtr> ObjectDataMap;
//
// TransformInfo supplies information required by TransformVisitor.
//
class TransformInfo
{
public:
virtual ~TransformInfo() {}
//
// Indicates whether the default transformation should be performed.
//
virtual bool doDefaultTransform(const Slice::TypePtr&) = 0;
//
// Indicates whether a base class transformation should be performed.
//
virtual bool doBaseTransform(const Slice::ClassDefPtr&) = 0;
//
// Given an old type, return the equivalent new type if the type
// has been renamed.
//
virtual Slice::TypePtr getRenamedType(const Slice::TypePtr&) = 0;
//
// Execute the custom transformation for the given old and new Data values.
//
virtual void executeCustomTransform(const DataPtr&, const DataPtr&) = 0;
//
// Indicates whether objects should be removed if no class definition is found.
//
virtual bool purgeObjects() = 0;
//
// Associates old object instances with their transformed equivalents.
//
virtual ObjectDataMap& getObjectDataMap() = 0;
};
//
// TransformVisitor is used to visit a destination Data value and
// preserve as much information as possible from the source Data value.
//
class TransformVisitor : public DataVisitor
{
public:
TransformVisitor(const DataPtr&, const DataFactoryPtr&, const ErrorReporterPtr&, TransformInfo*,
const std::string& = std::string());
virtual void visitBoolean(const BooleanDataPtr&);
virtual void visitInteger(const IntegerDataPtr&);
virtual void visitDouble(const DoubleDataPtr&);
virtual void visitString(const StringDataPtr&);
virtual void visitProxy(const ProxyDataPtr&);
virtual void visitStruct(const StructDataPtr&);
virtual void visitSequence(const SequenceDataPtr&);
virtual void visitEnum(const EnumDataPtr&);
virtual void visitDictionary(const DictionaryDataPtr&);
virtual void visitObject(const ObjectRefPtr&);
private:
void transformObject(const ObjectDataPtr&, const ObjectDataPtr&);
bool checkRename(const Slice::TypePtr&, const Slice::TypePtr&);
bool isCompatible(const Slice::TypePtr&, const Slice::TypePtr&);
bool checkClasses(const Slice::ClassDeclPtr&, const Slice::ClassDeclPtr&);
void typeMismatchError(const Slice::TypePtr&, const Slice::TypePtr&);
void conversionError(const Slice::TypePtr&, const Slice::TypePtr&, const std::string&);
void rangeError(const std::string&, const Slice::TypePtr&);
void warning(const std::string&);
DataPtr _src;
DataFactoryPtr _factory;
ErrorReporterPtr _errorReporter;
TransformInfo* _info;
std::string _context; // Provides additional detail for use in warning messages.
};
} // End of namespace FreezeScript
#endif
|