Merge lp:~zorba-coders/zorba/api-var-annot into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11724
Merged at revision: 11723
Proposed branch: lp:~zorba-coders/zorba/api-var-annot
Merge into: lp:zorba
Diff against target: 155 lines (+58/-3)
7 files modified
include/zorba/annotation.h (+3/-0)
include/zorba/static_context.h (+12/-0)
src/annotations/annotations.h (+4/-0)
src/api/staticcontextimpl.cpp (+20/-2)
src/api/staticcontextimpl.h (+4/-0)
src/compiler/expression/var_expr.h (+11/-0)
src/compiler/translator/translator.cpp (+4/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/api-var-annot
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Federico Cavalieri Approve
Paul J. Lucas Approve
Review via email: mp+218485@code.launchpad.net

Commit message

Added public introspection API for external variable annotations.

Description of the change

Added public introspection API for external variable annotations.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Why not allow introspection for non external variables? Does it make sense to restrict it?

review: Needs Information
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

> Why not allow introspection for non external variables? Does it make sense to
> restrict it?

I personally don't care, but the function getExternalVariables() in StaticContext was already there and there is *not* any getAllVariables() (or some such). Since you can't introspect just the names of non-external variables, I didn't see any point in allowing you to get the annotations for them.

Revision history for this message
Federico Cavalieri (fcavalieri) wrote :

I have the same question as Matthias, maybe it make sense to offer the feature for all module level variable declarations.
Apart from that, it looks good.

review: Approve
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

BTW: going with Matthias' private comments to me on another matter: until somebody asks for it, we should focus on 28msec's immediate needs.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/api-var-annot/+merge/218485

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/api-var-annot/+merge/218485

Stage "BuildZorbaUbuntu" failed.

Check compiler output at http://jenkins.zorba.io:8180/job/BuildZorbaUbuntu/583/parsed_console to view the results.

lp:~zorba-coders/zorba/api-var-annot updated
11725. By Paul J. Lucas

Fixed nullptr.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/api-var-annot/+merge/218485

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/zorba/annotation.h'
--- include/zorba/annotation.h 2013-06-12 04:55:14 +0000
+++ include/zorba/annotation.h 2014-05-08 13:54:15 +0000
@@ -55,6 +55,9 @@
55 */55 */
56 virtual Item56 virtual Item
57 getLiteral(unsigned int i) const = 0;57 getLiteral(unsigned int i) const = 0;
58
59protected:
60 Annotation() { }
58};61};
5962
60} /* namespace zorba */63} /* namespace zorba */
6164
=== modified file 'include/zorba/static_context.h'
--- include/zorba/static_context.h 2013-09-16 09:08:27 +0000
+++ include/zorba/static_context.h 2014-05-08 13:54:15 +0000
@@ -651,6 +651,18 @@
651 virtual void651 virtual void
652 getExternalVariables(Iterator_t& aVarsIter) const = 0;652 getExternalVariables(Iterator_t& aVarsIter) const = 0;
653653
654 /** \brief Gets the Annotations (if any) for the given external variable.
655 *
656 * @param var_name The QName of the variable.
657 * @param result The vector into which to put all of the variable's
658 * annotations.
659 * @return Returns \c true only if the given external variable exists and has
660 * at least one annotation.
661 */
662 virtual bool
663 getExternalVariableAnnotations( Item const &var_name,
664 std::vector<Annotation_t> &result ) const = 0;
665
654 /**666 /**
655 * @brief Set the URI lookup path (list of filesystem directories) for this667 * @brief Set the URI lookup path (list of filesystem directories) for this
656 * static context.668 * static context.
657669
=== modified file 'src/annotations/annotations.h'
--- src/annotations/annotations.h 2014-04-16 18:23:55 +0000
+++ src/annotations/annotations.h 2014-05-08 13:54:15 +0000
@@ -189,6 +189,10 @@
189189
190 size_type size() const { return theAnnotationList.size(); }190 size_type size() const { return theAnnotationList.size(); }
191191
192 void swap( AnnotationList &a ) {
193 theAnnotationList.swap( a.theAnnotationList );
194 }
195
192 AnnotationInternal* get(size_type index) const;196 AnnotationInternal* get(size_type index) const;
193197
194 AnnotationInternal* get(AnnotationInternal::AnnotationId id) const;198 AnnotationInternal* get(AnnotationInternal::AnnotationId id) const;
195199
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2013-12-14 00:44:26 +0000
+++ src/api/staticcontextimpl.cpp 2014-05-08 13:54:15 +0000
@@ -1797,12 +1797,30 @@
1797 extVars.push_back((*ite)->getName()); 1797 extVars.push_back((*ite)->getName());
1798 }1798 }
17991799
1800 Iterator_t vIter = new VectorIterator(extVars, theDiagnosticHandler);1800 aVarsIter = new VectorIterator(extVars, theDiagnosticHandler);
1801 aVarsIter = vIter;
1802 ZORBA_CATCH1801 ZORBA_CATCH
1803}1802}
18041803
18051804
1805bool StaticContextImpl::
1806getExternalVariableAnnotations( Item const &api_qname,
1807 std::vector<Annotation_t> &result ) const {
1808 store::Item const *const qname = Unmarshaller::getInternalItem( api_qname );
1809 VarInfo const *const var_info = theCtx->lookup_var( qname );
1810 if ( var_info && var_info->isExternal() ) {
1811 if ( var_expr const *const var_expr = var_info->getVar() ) {
1812 AnnotationList const &annotation_list = var_expr->get_annotations();
1813 AnnotationList::size_type const n = annotation_list.size();
1814 result.clear();
1815 for ( AnnotationList::size_type i = 0; i < n; ++i )
1816 result.push_back( new AnnotationImpl( annotation_list.get( i ) ) );
1817 return !!n;
1818 }
1819 }
1820 return false;
1821}
1822
1823
1806Item1824Item
1807StaticContextImpl::fetch(const String& aURI) const1825StaticContextImpl::fetch(const String& aURI) const
1808{1826{
18091827
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2013-09-26 09:38:51 +0000
+++ src/api/staticcontextimpl.h 2014-05-08 13:54:15 +0000
@@ -307,6 +307,10 @@
307 virtual void307 virtual void
308 getExternalVariables(Iterator_t& aVarsIter) const; 308 getExternalVariables(Iterator_t& aVarsIter) const;
309309
310 virtual bool
311 getExternalVariableAnnotations( Item const&,
312 std::vector<Annotation_t>& ) const;
313
310 virtual void314 virtual void
311 setURIPath(const std::vector<String>& aURIPath);315 setURIPath(const std::vector<String>& aURIPath);
312316
313317
=== modified file 'src/compiler/expression/var_expr.h'
--- src/compiler/expression/var_expr.h 2013-09-12 07:54:03 +0000
+++ src/compiler/expression/var_expr.h 2014-05-08 13:54:15 +0000
@@ -17,6 +17,7 @@
17#ifndef ZORBA_COMPILER_VAR_EXPR17#ifndef ZORBA_COMPILER_VAR_EXPR
18#define ZORBA_COMPILER_VAR_EXPR18#define ZORBA_COMPILER_VAR_EXPR
1919
20#include "annotations/annotations.h"
20#include "compiler/expression/expr_base.h"21#include "compiler/expression/expr_base.h"
2122
22namespace zorba23namespace zorba
@@ -178,6 +179,8 @@
178179
179 VarInfo * theVarInfo;180 VarInfo * theVarInfo;
180181
182 AnnotationList theAnnotations;
183
181 csize theNumRefs;184 csize theNumRefs;
182185
183 bool theIsExternal;186 bool theIsExternal;
@@ -207,6 +210,14 @@
207public:210public:
208 void set_var_info(VarInfo* v);211 void set_var_info(VarInfo* v);
209212
213 AnnotationList const& get_annotations() const {
214 return theAnnotations;
215 }
216
217 void swap_annotations( AnnotationList &a ) {
218 theAnnotations.swap( a );
219 }
220
210 VarInfo* get_var_info() const { return theVarInfo; }221 VarInfo* get_var_info() const { return theVarInfo; }
211222
212 ulong get_unique_id() const { return theUniqueId; }223 ulong get_unique_id() const { return theUniqueId; }
213224
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2014-04-16 18:23:55 +0000
+++ src/compiler/translator/translator.cpp 2014-05-08 13:54:15 +0000
@@ -3993,7 +3993,10 @@
3993 ve->set_mutable(theSctx->is_feature_set(feature::scripting));3993 ve->set_mutable(theSctx->is_feature_set(feature::scripting));
3994 }3994 }
39953995
3996 theAnnotations.reset(NULL);3996 if ( theAnnotations.get() ) {
3997 ve->swap_annotations( *theAnnotations.get() );
3998 theAnnotations.reset(NULL);
3999 }
39974000
3998 // Put a mapping between the var name and the var_expr in the local sctx.4001 // Put a mapping between the var name and the var_expr in the local sctx.
3999 // Raise error if var name exists already in local sctx obj.4002 // Raise error if var name exists already in local sctx obj.

Subscribers

People subscribed via source and target branches