Merge lp:~davidagraf/zorba/trace_without_debug_info into lp:zorba
- trace_without_debug_info
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | David Graf |
Approved revision: | 10883 |
Merged at revision: | 10936 |
Proposed branch: | lp:~davidagraf/zorba/trace_without_debug_info |
Merge into: | lp:zorba |
Diff against target: |
302 lines (+81/-22) 7 files modified
doc/cxx/examples/context.cpp (+4/-3) src/api/serialization/serializer.cpp (+19/-11) src/api/serialization/serializer.h (+23/-5) src/runtime/errors_and_diagnostics/errors_and_diagnostics_impl.cpp (+28/-3) src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.cpp (+2/-0) src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.h (+1/-0) src/runtime/spec/errors_and_diagnostics/errors_and_diagnostics.xml (+4/-0) |
To merge this branch: | bzr merge lp:~davidagraf/zorba/trace_without_debug_info |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Hillery | Approve | ||
David Graf (community) | Approve | ||
Review via email: mp+110377@code.launchpad.net |
Commit message
Removed internal debug info from fn:trace out by using zorba serializer instead of the internal show function.
Description of the change
David Graf (davidagraf) wrote : | # |
Matthias Brantner (matthias-brantner) wrote : | # |
It would be great if the usage of API classes such as SingletonItemSe
Chris Hillery (ceejatec) wrote : | # |
Matthias: why is that desirable? Especially for SingletonItemSe
Matthias Brantner (matthias-brantner) wrote : | # |
> Matthias: why is that desirable? Especially for SingletonItemSe
> there any internal-runtime class with equivalent functionality?
It's one level of indirection which is not necessary and it bloats includes and dependencies.
Chris Hillery (ceejatec) wrote : | # |
David:
1. I agree, the duplication of code to output attributes is not pretty. I don't think it would be too difficult to add support for directly serializing attributes to the serializer itself. And it wouldn't have to be changed in every emitter, only whichever emitter is used for basic XML serialization.
2. I think adding the serializer to the either the state or the iterator class is the right answer. I'm not quite clear enough on how the whole state/STACK_PUSH stuff works in the runtime to say whether the state or the iterator is the better place for it.
I don't immediately see any problem with adding the #include of serializer to the corresponding header file. If you're desperate to avoid this, however, you could have a forward reference to Serializer and put a Serializer* on the appropriate class. Yes, that means the Serializer would need to be heap-allocated and you'd have to worry about de-allocating it in the destructor.
I wonder if you could have a forward reference to Serializer and then have a data member that was an auto_ptr<
Chris Hillery (ceejatec) wrote : | # |
> > Matthias: why is that desirable? Especially for SingletonItemSe
> > there any internal-runtime class with equivalent functionality?
> It's one level of indirection which is not necessary and it bloats includes
> and dependencies.
In that case, can you answer my other question: Is there equivalent functionality he could use in the runtime?
Matthias Brantner (matthias-brantner) wrote : | # |
> > > Matthias: why is that desirable? Especially for SingletonItemSe
> > > there any internal-runtime class with equivalent functionality?
> > It's one level of indirection which is not necessary and it bloats includes
> > and dependencies.
>
> In that case, can you answer my other question: Is there equivalent
> functionality he could use in the runtime?
store::TempSeq_t Store::
David Graf (davidagraf) wrote : | # |
> David:
>
> 1. I agree, the duplication of code to output attributes is not pretty. I
> don't think it would be too difficult to add support for directly serializing
> attributes to the serializer itself. And it wouldn't have to be changed in
> every emitter, only whichever emitter is used for basic XML serialization.
>
Hello Chris
The only solution I see is to pass an additional parameter to emitter::emit_item to tell the function if it should throw an error or not if an attribute is passed. But this implies changing the emit_item function of all emitters. Do you see a nicer solution?
Chris Hillery (ceejatec) wrote : | # |
Ah, I see what you're saying. Another option, though, would be to have the flag on the xml_emitter constructor; then you just need to pass it from setup(), and wouldn't need to change the emit_item() signature. I haven't looked deeply to see whether it would be possible to get the option value easily at setup() time or not, though.
David Graf (davidagraf) wrote : | # |
- Extended serializer to print attributes
- storing serializer in the trace state object
David Graf (davidagraf) wrote : | # |
Chris, can you review the change again and give some feedback?
Thanks
Chris Hillery (ceejatec) wrote : | # |
The changes all look good.
Is there any way you can add any test cases for this? I don't know if testdriver captures fn:trace() output, but if it does (or can do so easily) I'd feel better if we had at least one or two tests showing the functionality.
David Graf (davidagraf) wrote : | # |
Hey Chris
There is a quick solution: I could just pipe the trace stuff into the result file of a test. But I think this is not clean. The query result file should not contain trace stuff.
But implementing a clean solution would take quite some time. I don't know if it is worth it. I think I would need to introduce fn:trace output files in the ExpQueryResults directory. Something like test/rbkt/
Do you think this is necessary?
David Graf (davidagraf) : | # |
Chris Hillery (ceejatec) wrote : | # |
Ok, yeah, I see your point. I'd prefer it if we could test this SOMEhow, but it's not too critical. For now, I've tested your changes locally and the work fine, so let's run with it.
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~davidagraf/zorba/trace_without_debug_info into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job trace_without_
finished. The final status was:
1 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
- 10882. By David Graf
-
merged trunk
- 10883. By David Graf
-
changed trace comparison in a test
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job trace_without_
All tests succeeded!
Preview Diff
1 | === modified file 'doc/cxx/examples/context.cpp' |
2 | --- doc/cxx/examples/context.cpp 2012-07-12 17:29:55 +0000 |
3 | +++ doc/cxx/examples/context.cpp 2012-07-13 08:35:21 +0000 |
4 | @@ -462,9 +462,10 @@ |
5 | |
6 | // check if the trace was successful |
7 | std::string lTraceString = lTraceStream.str(); |
8 | - if (lTraceString.compare("foo [0]: xs:integer(1)\n" |
9 | - "foo [1]: xs:integer(2)\n" |
10 | - "foo [2]: xs:integer(3)\n") != 0) { |
11 | + std::cout << lTraceString << std::endl; |
12 | + if (lTraceString.compare("foo [0]: 1\n" |
13 | + "foo [1]: 2\n" |
14 | + "foo [2]: 3\n") != 0) { |
15 | return false; |
16 | } |
17 | std::cout << lTraceString << std::endl; |
18 | |
19 | === modified file 'src/api/serialization/serializer.cpp' |
20 | --- src/api/serialization/serializer.cpp 2012-07-12 17:29:55 +0000 |
21 | +++ src/api/serialization/serializer.cpp 2012-07-13 08:35:21 +0000 |
22 | @@ -112,14 +112,18 @@ |
23 | /******************************************************************************* |
24 | |
25 | ********************************************************************************/ |
26 | -serializer::emitter::emitter(serializer* the_serializer, transcoder& the_transcoder) |
27 | +serializer::emitter::emitter( |
28 | + serializer* the_serializer, |
29 | + transcoder& the_transcoder, |
30 | + bool aEmitAttributes) |
31 | : |
32 | ser(the_serializer), |
33 | tr(the_transcoder), |
34 | previous_item(INVALID_ITEM), |
35 | theChildIters(8), |
36 | theFirstFreeChildIter(0), |
37 | - isFirstElementNode(true) |
38 | + isFirstElementNode(true), |
39 | + theEmitAttributes(aEmitAttributes) |
40 | { |
41 | for (ulong i = 0; i < 8; i++) |
42 | theChildIters[i] = GENV_ITERATOR_FACTORY->createChildrenIterator(); |
43 | @@ -442,7 +446,8 @@ |
44 | |
45 | previous_item = PREVIOUS_ITEM_WAS_TEXT; |
46 | } |
47 | - else if (item->getNodeKind() == store::StoreConsts::attributeNode) |
48 | + else if (!theEmitAttributes |
49 | + && item->getNodeKind() == store::StoreConsts::attributeNode) |
50 | { |
51 | throw XQUERY_EXCEPTION(err::SENR0001, |
52 | ERROR_PARAMS(item->getStringValue(), ZED(AttributeNode))); |
53 | @@ -855,9 +860,10 @@ |
54 | ********************************************************************************/ |
55 | serializer::xml_emitter::xml_emitter( |
56 | serializer* the_serializer, |
57 | - transcoder& the_transcoder) |
58 | + transcoder& the_transcoder, |
59 | + bool aEmitAttributes) |
60 | : |
61 | - emitter(the_serializer, the_transcoder) |
62 | + emitter(the_serializer, the_transcoder, aEmitAttributes) |
63 | { |
64 | } |
65 | |
66 | @@ -2664,14 +2670,14 @@ |
67 | /******************************************************************************* |
68 | |
69 | ********************************************************************************/ |
70 | -bool serializer::setup(std::ostream& os) |
71 | +bool serializer::setup(std::ostream& os, bool aEmitAttributes) |
72 | { |
73 | tr = create_transcoder(os); |
74 | if (!tr) { |
75 | return false; |
76 | } |
77 | if (method == PARAMETER_VALUE_XML) |
78 | - e = new xml_emitter(this, *tr); |
79 | + e = new xml_emitter(this, *tr, aEmitAttributes); |
80 | else if (method == PARAMETER_VALUE_HTML) |
81 | e = new html_emitter(this, *tr); |
82 | else if (method == PARAMETER_VALUE_XHTML) |
83 | @@ -2728,9 +2734,10 @@ |
84 | ********************************************************************************/ |
85 | void serializer::serialize( |
86 | store::Iterator_t aObject, |
87 | - std::ostream& aOStream) |
88 | + std::ostream& aOStream, |
89 | + bool aEmitAttributes) |
90 | { |
91 | - serialize(aObject, aOStream, 0); |
92 | + serialize(aObject, aOStream, 0, aEmitAttributes); |
93 | } |
94 | |
95 | |
96 | @@ -2741,13 +2748,14 @@ |
97 | serializer::serialize( |
98 | store::Iterator_t aObject, |
99 | std::ostream& aOStream, |
100 | - SAX2_ContentHandler* aHandler) |
101 | + SAX2_ContentHandler* aHandler, |
102 | + bool aEmitAttributes) |
103 | { |
104 | std::stringstream temp_sstream; // used to temporarily hold expanded strings for the SAX serializer |
105 | |
106 | validate_parameters(); |
107 | |
108 | - if (!setup(aOStream)) |
109 | + if (!setup(aOStream, aEmitAttributes)) |
110 | { |
111 | return; |
112 | } |
113 | |
114 | === modified file 'src/api/serialization/serializer.h' |
115 | --- src/api/serialization/serializer.h 2012-07-12 17:29:55 +0000 |
116 | +++ src/api/serialization/serializer.h 2012-07-13 08:35:21 +0000 |
117 | @@ -141,8 +141,12 @@ |
118 | * @param object The serializable object that provides a sequence |
119 | * to be serialized. |
120 | * @param stream The stream to serialize to. |
121 | + * @param aEmitAttributeValue If true, attributes are emitted. |
122 | */ |
123 | - void serialize(store::Iterator_t object, std::ostream& stream); |
124 | + void serialize( |
125 | + store::Iterator_t object, |
126 | + std::ostream& stream, |
127 | + bool aEmitAttributes = false); |
128 | |
129 | void serialize( |
130 | store::Iterator_t object, |
131 | @@ -158,11 +162,13 @@ |
132 | * to be serialized. |
133 | * @param stream The stream to serialize to. |
134 | * @param handler The SAX handler. |
135 | + * @param aEmitAttributes If true, attributes are emitted. |
136 | */ |
137 | void serialize( |
138 | store::Iterator_t object, |
139 | std::ostream& stream, |
140 | - SAX2_ContentHandler* handler); |
141 | + SAX2_ContentHandler* handler, |
142 | + bool aEmitAttributes = false); |
143 | |
144 | /** |
145 | * Set the serializer's parameters. The list of handled parameters |
146 | @@ -185,7 +191,7 @@ |
147 | |
148 | void validate_parameters(); |
149 | |
150 | - bool setup(std::ostream& os); |
151 | + bool setup(std::ostream& os, bool aEmitAttributes = false); |
152 | |
153 | transcoder* create_transcoder(std::ostream& os); |
154 | |
155 | @@ -205,8 +211,12 @@ |
156 | * |
157 | * @param the_serializer The parent serializer object. |
158 | * @param output_stream Target output stream. |
159 | + * @param aEmitAttributes If true, attributes are emitted. |
160 | */ |
161 | - emitter(serializer* the_serializer, transcoder& the_transcoder); |
162 | + emitter( |
163 | + serializer* the_serializer, |
164 | + transcoder& the_transcoder, |
165 | + bool aEmitAttributes = false); |
166 | |
167 | /** |
168 | * Outputs the start of the serialized document, which, depending on |
169 | @@ -324,6 +334,7 @@ |
170 | store::AttributesIterator * theAttrIter; |
171 | |
172 | bool isFirstElementNode; |
173 | + bool theEmitAttributes; |
174 | }; |
175 | |
176 | |
177 | @@ -336,12 +347,19 @@ |
178 | class xml_emitter : public emitter |
179 | { |
180 | public: |
181 | - xml_emitter(serializer* the_serializer, transcoder& the_transcoder); |
182 | + xml_emitter( |
183 | + serializer* the_serializer, |
184 | + transcoder& the_transcoder, |
185 | + bool aEmitAttributes = false |
186 | + ); |
187 | |
188 | virtual void emit_declaration(); |
189 | |
190 | protected: |
191 | virtual void emit_doctype(const zstring& elementName); |
192 | + |
193 | + protected: |
194 | + bool theEmitAttributes; |
195 | }; |
196 | |
197 | /////////////////////////////////////////////////////////// |
198 | |
199 | === modified file 'src/runtime/errors_and_diagnostics/errors_and_diagnostics_impl.cpp' |
200 | --- src/runtime/errors_and_diagnostics/errors_and_diagnostics_impl.cpp 2012-07-12 17:29:55 +0000 |
201 | +++ src/runtime/errors_and_diagnostics/errors_and_diagnostics_impl.cpp 2012-07-13 08:35:21 +0000 |
202 | @@ -27,10 +27,15 @@ |
203 | |
204 | #include "store/api/item.h" |
205 | #include "store/api/item_factory.h" |
206 | +#include "store/api/store.h" |
207 | +#include "store/api/temp_seq.h" |
208 | |
209 | #include "system/globalenv.h" |
210 | #include "zorbatypes/zstring.h" |
211 | |
212 | +#include "api/serialization/serializer.h" |
213 | +#include "api/serializerimpl.h" |
214 | + |
215 | namespace zorba |
216 | { |
217 | |
218 | @@ -97,14 +102,34 @@ |
219 | ); |
220 | } |
221 | |
222 | + if (state->theSerializer.get() == 0) { |
223 | + state->theSerializer.reset(new serializer(0)); |
224 | + Zorba_SerializerOptions options; |
225 | + options.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES; |
226 | + SerializerImpl::setSerializationParameters( |
227 | + *(state->theSerializer), |
228 | + options); |
229 | + } |
230 | state->theOS = theSctx->get_trace_stream(); |
231 | |
232 | while (consumeNext(result, theChildren[0], planState)) |
233 | { |
234 | (*state->theOS) << state->theTagItem->getStringValue() |
235 | - << " [" << state->theIndex << "]: " |
236 | - << result->show() |
237 | - << std::endl; |
238 | + << " [" << state->theIndex << "]: "; |
239 | + |
240 | + { |
241 | + store::Item_t lTmp = result; |
242 | + store::TempSeq_t lSequence = GENV_STORE.createTempSeq(lTmp); |
243 | + store::Iterator_t seq_iter = lSequence->getIterator(); |
244 | + seq_iter->open(); |
245 | + state->theSerializer->serialize( |
246 | + seq_iter, |
247 | + (*state->theOS), |
248 | + true); |
249 | + seq_iter->close(); |
250 | + } |
251 | + |
252 | + (*state->theOS) << std::endl; |
253 | ++state->theIndex; |
254 | |
255 | STACK_PUSH(true, state); |
256 | |
257 | === modified file 'src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.cpp' |
258 | --- src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.cpp 2012-07-12 17:29:55 +0000 |
259 | +++ src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.cpp 2012-07-13 08:35:21 +0000 |
260 | @@ -95,6 +95,7 @@ |
261 | theTagItem = NULL; |
262 | theIndex = 0; |
263 | theOS = 0; |
264 | + theSerializer = std::auto_ptr<serializer>(0); |
265 | } |
266 | |
267 | void TraceIteratorState::reset(PlanState& planState) { |
268 | @@ -102,6 +103,7 @@ |
269 | theTagItem = NULL; |
270 | theIndex = 0; |
271 | theOS = 0; |
272 | + theSerializer = std::auto_ptr<serializer>(0); |
273 | } |
274 | // </TraceIterator> |
275 | |
276 | |
277 | === modified file 'src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.h' |
278 | --- src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.h 2012-07-12 17:29:55 +0000 |
279 | +++ src/runtime/errors_and_diagnostics/pregenerated/errors_and_diagnostics.h 2012-07-13 08:35:21 +0000 |
280 | @@ -73,6 +73,7 @@ |
281 | store::Item_t theTagItem; // |
282 | uint32_t theIndex; // |
283 | std::ostream* theOS; // |
284 | + std::auto_ptr<serializer> theSerializer; // |
285 | |
286 | TraceIteratorState(); |
287 | |
288 | |
289 | === modified file 'src/runtime/spec/errors_and_diagnostics/errors_and_diagnostics.xml' |
290 | --- src/runtime/spec/errors_and_diagnostics/errors_and_diagnostics.xml 2012-07-12 17:29:55 +0000 |
291 | +++ src/runtime/spec/errors_and_diagnostics/errors_and_diagnostics.xml 2012-07-13 08:35:21 +0000 |
292 | @@ -88,6 +88,10 @@ |
293 | <zorba:member type="store::Item_t" name="theTagItem" defaultValue="NULL" brief=""/> |
294 | <zorba:member type="uint32_t" name="theIndex" defaultValue="0" brief=""/> |
295 | <zorba:member type="std::ostream*" name="theOS" defaultValue="0" brief=""/> |
296 | + <zorba:member type="std::auto_ptr<serializer>" |
297 | + name="theSerializer" |
298 | + defaultValue="std::auto_ptr<serializer>(0)" |
299 | + brief=""/> |
300 | </zorba:state> |
301 | |
302 | </zorba:iterator> |
Hello Chris
Here is the current work I've done to remove the debug output in fn:trace (as discussed in the email with markos). It's working fine. But I need some advice to make it better. I am doing this via a merge request. I think that's easier for you because I can see the diff.
In the current implementation, I am doing two nasty things:
1) The code to print an attribute is redundant. That's bad. Would it make sense to add an option to the serializer to enable printing of all nodes? I am not sure. Especially because it is not so easy to do. All the emmitter need to be changed. Do you see a nicer solution?
2) If the node is not an attribute, I create a serializer in each iteration! Although I always need the same. But I didn't find a nice solution to use just one serializer. If I do a singleton, I need to create the serializer on the heap. If I put the seralizer as a member in the state or the iterator, I need to import the serializer in the header file.
Best
David