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
1=== modified file 'include/zorba/annotation.h'
2--- include/zorba/annotation.h 2013-06-12 04:55:14 +0000
3+++ include/zorba/annotation.h 2014-05-08 13:54:15 +0000
4@@ -55,6 +55,9 @@
5 */
6 virtual Item
7 getLiteral(unsigned int i) const = 0;
8+
9+protected:
10+ Annotation() { }
11 };
12
13 } /* namespace zorba */
14
15=== modified file 'include/zorba/static_context.h'
16--- include/zorba/static_context.h 2013-09-16 09:08:27 +0000
17+++ include/zorba/static_context.h 2014-05-08 13:54:15 +0000
18@@ -651,6 +651,18 @@
19 virtual void
20 getExternalVariables(Iterator_t& aVarsIter) const = 0;
21
22+ /** \brief Gets the Annotations (if any) for the given external variable.
23+ *
24+ * @param var_name The QName of the variable.
25+ * @param result The vector into which to put all of the variable's
26+ * annotations.
27+ * @return Returns \c true only if the given external variable exists and has
28+ * at least one annotation.
29+ */
30+ virtual bool
31+ getExternalVariableAnnotations( Item const &var_name,
32+ std::vector<Annotation_t> &result ) const = 0;
33+
34 /**
35 * @brief Set the URI lookup path (list of filesystem directories) for this
36 * static context.
37
38=== modified file 'src/annotations/annotations.h'
39--- src/annotations/annotations.h 2014-04-16 18:23:55 +0000
40+++ src/annotations/annotations.h 2014-05-08 13:54:15 +0000
41@@ -189,6 +189,10 @@
42
43 size_type size() const { return theAnnotationList.size(); }
44
45+ void swap( AnnotationList &a ) {
46+ theAnnotationList.swap( a.theAnnotationList );
47+ }
48+
49 AnnotationInternal* get(size_type index) const;
50
51 AnnotationInternal* get(AnnotationInternal::AnnotationId id) const;
52
53=== modified file 'src/api/staticcontextimpl.cpp'
54--- src/api/staticcontextimpl.cpp 2013-12-14 00:44:26 +0000
55+++ src/api/staticcontextimpl.cpp 2014-05-08 13:54:15 +0000
56@@ -1797,12 +1797,30 @@
57 extVars.push_back((*ite)->getName());
58 }
59
60- Iterator_t vIter = new VectorIterator(extVars, theDiagnosticHandler);
61- aVarsIter = vIter;
62+ aVarsIter = new VectorIterator(extVars, theDiagnosticHandler);
63 ZORBA_CATCH
64 }
65
66
67+bool StaticContextImpl::
68+getExternalVariableAnnotations( Item const &api_qname,
69+ std::vector<Annotation_t> &result ) const {
70+ store::Item const *const qname = Unmarshaller::getInternalItem( api_qname );
71+ VarInfo const *const var_info = theCtx->lookup_var( qname );
72+ if ( var_info && var_info->isExternal() ) {
73+ if ( var_expr const *const var_expr = var_info->getVar() ) {
74+ AnnotationList const &annotation_list = var_expr->get_annotations();
75+ AnnotationList::size_type const n = annotation_list.size();
76+ result.clear();
77+ for ( AnnotationList::size_type i = 0; i < n; ++i )
78+ result.push_back( new AnnotationImpl( annotation_list.get( i ) ) );
79+ return !!n;
80+ }
81+ }
82+ return false;
83+}
84+
85+
86 Item
87 StaticContextImpl::fetch(const String& aURI) const
88 {
89
90=== modified file 'src/api/staticcontextimpl.h'
91--- src/api/staticcontextimpl.h 2013-09-26 09:38:51 +0000
92+++ src/api/staticcontextimpl.h 2014-05-08 13:54:15 +0000
93@@ -307,6 +307,10 @@
94 virtual void
95 getExternalVariables(Iterator_t& aVarsIter) const;
96
97+ virtual bool
98+ getExternalVariableAnnotations( Item const&,
99+ std::vector<Annotation_t>& ) const;
100+
101 virtual void
102 setURIPath(const std::vector<String>& aURIPath);
103
104
105=== modified file 'src/compiler/expression/var_expr.h'
106--- src/compiler/expression/var_expr.h 2013-09-12 07:54:03 +0000
107+++ src/compiler/expression/var_expr.h 2014-05-08 13:54:15 +0000
108@@ -17,6 +17,7 @@
109 #ifndef ZORBA_COMPILER_VAR_EXPR
110 #define ZORBA_COMPILER_VAR_EXPR
111
112+#include "annotations/annotations.h"
113 #include "compiler/expression/expr_base.h"
114
115 namespace zorba
116@@ -178,6 +179,8 @@
117
118 VarInfo * theVarInfo;
119
120+ AnnotationList theAnnotations;
121+
122 csize theNumRefs;
123
124 bool theIsExternal;
125@@ -207,6 +210,14 @@
126 public:
127 void set_var_info(VarInfo* v);
128
129+ AnnotationList const& get_annotations() const {
130+ return theAnnotations;
131+ }
132+
133+ void swap_annotations( AnnotationList &a ) {
134+ theAnnotations.swap( a );
135+ }
136+
137 VarInfo* get_var_info() const { return theVarInfo; }
138
139 ulong get_unique_id() const { return theUniqueId; }
140
141=== modified file 'src/compiler/translator/translator.cpp'
142--- src/compiler/translator/translator.cpp 2014-04-16 18:23:55 +0000
143+++ src/compiler/translator/translator.cpp 2014-05-08 13:54:15 +0000
144@@ -3993,7 +3993,10 @@
145 ve->set_mutable(theSctx->is_feature_set(feature::scripting));
146 }
147
148- theAnnotations.reset(NULL);
149+ if ( theAnnotations.get() ) {
150+ ve->swap_annotations( *theAnnotations.get() );
151+ theAnnotations.reset(NULL);
152+ }
153
154 // Put a mapping between the var name and the var_expr in the local sctx.
155 // Raise error if var name exists already in local sctx obj.

Subscribers

People subscribed via source and target branches