← Back to team overview

zorba-coders team mailing list archive

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

 

Paul J. Lucas has proposed merging lp:~zorba-coders/zorba/api-var-annot into lp:zorba.

Commit message:
Added public introspection API for external variable annotations.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/api-var-annot/+merge/218485

Added public introspection API for external variable annotations.
-- 
https://code.launchpad.net/~zorba-coders/zorba/api-var-annot/+merge/218485
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/annotation.h'
--- include/zorba/annotation.h	2013-06-12 04:55:14 +0000
+++ include/zorba/annotation.h	2014-05-06 18:07:18 +0000
@@ -55,6 +55,9 @@
    */
   virtual Item
   getLiteral(unsigned int i) const = 0;
+
+protected:
+  Annotation() { }
 };
 
 } /* namespace zorba */

=== 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-06 18:07:18 +0000
@@ -651,6 +651,18 @@
   virtual void
 	getExternalVariables(Iterator_t& aVarsIter) const = 0;
 
+  /** \brief Gets the Annotations (if any) for the given external variable.
+   *
+   * @param var_name The QName of the variable.
+   * @param result The vector into which to put all of the variable's
+   * annotations.
+   * @return Returns \c true only if the given external variable exists and has
+   * at least one annotation.
+   */
+  virtual bool
+  getExternalVariableAnnotations( Item const &var_name,
+                                  std::vector<Annotation_t> &result ) const = 0;
+
   /**
    * @brief Set the URI lookup path (list of filesystem directories) for this
    * static context.

=== modified file 'src/annotations/annotations.h'
--- src/annotations/annotations.h	2014-04-16 18:23:55 +0000
+++ src/annotations/annotations.h	2014-05-06 18:07:18 +0000
@@ -189,6 +189,10 @@
 
   size_type size() const { return theAnnotationList.size(); }
 
+  void swap( AnnotationList &a ) {
+    theAnnotationList.swap( a.theAnnotationList );
+  }
+
   AnnotationInternal* get(size_type index) const;
 
   AnnotationInternal* get(AnnotationInternal::AnnotationId id) const;

=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp	2013-12-14 00:44:26 +0000
+++ src/api/staticcontextimpl.cpp	2014-05-06 18:07:18 +0000
@@ -1797,12 +1797,30 @@
     extVars.push_back((*ite)->getName());        
   }
 
-  Iterator_t vIter = new VectorIterator(extVars, theDiagnosticHandler);
-  aVarsIter = vIter; 
+  aVarsIter = new VectorIterator(extVars, theDiagnosticHandler);
   ZORBA_CATCH
 }
 
 
+bool StaticContextImpl::
+getExternalVariableAnnotations( Item const &api_qname,
+                                std::vector<Annotation_t> &result ) const {
+  store::Item const *const qname = Unmarshaller::getInternalItem( api_qname );
+  VarInfo const *const var_info = theCtx->lookup_var( qname );
+  if ( var_info && var_info->isExternal() ) {
+    if ( var_expr const *const var_expr = var_info->getVar() ) {
+      AnnotationList const &annotation_list = var_expr->get_annotations();
+      AnnotationList::size_type const n = annotation_list.size();
+      result.clear();
+      for ( AnnotationList::size_type i = 0; i < n; ++i )
+        result.push_back( new AnnotationImpl( annotation_list.get( i ) ) );
+      return !!n;
+    }
+  }
+  return false;
+}
+
+
 Item
 StaticContextImpl::fetch(const String& aURI) const
 {

=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h	2013-09-26 09:38:51 +0000
+++ src/api/staticcontextimpl.h	2014-05-06 18:07:18 +0000
@@ -307,6 +307,10 @@
   virtual void
   getExternalVariables(Iterator_t& aVarsIter) const;  
 
+  virtual bool
+  getExternalVariableAnnotations( Item const&,
+                                  std::vector<Annotation_t>& ) const;
+
   virtual void
   setURIPath(const std::vector<String>& aURIPath);
 

=== 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-06 18:07:18 +0000
@@ -17,6 +17,7 @@
 #ifndef ZORBA_COMPILER_VAR_EXPR
 #define ZORBA_COMPILER_VAR_EXPR
 
+#include "annotations/annotations.h"
 #include "compiler/expression/expr_base.h"
 
 namespace zorba
@@ -178,6 +179,8 @@
 
   VarInfo             * theVarInfo;
 
+  AnnotationList        theAnnotations;
+
   csize                 theNumRefs;
 
   bool                  theIsExternal;
@@ -207,6 +210,14 @@
 public:
   void set_var_info(VarInfo* v);
 
+  AnnotationList const& get_annotations() const {
+    return theAnnotations;
+  }
+
+  void swap_annotations( AnnotationList &a ) {
+    theAnnotations.swap( a );
+  }
+
   VarInfo* get_var_info() const { return theVarInfo; }
 
   ulong get_unique_id() const { return theUniqueId; }

=== 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-06 18:07:18 +0000
@@ -3993,6 +3993,7 @@
         ve->set_mutable(theSctx->is_feature_set(feature::scripting));
       }
 
+      ve->swap_annotations( *theAnnotations.get() );
       theAnnotations.reset(NULL);
 
       // Put a mapping between the var name and the var_expr in the local sctx.


References