Matthias Brantner has proposed merging 
lp:~zorba-coders/zorba/feature-gen_audit_props into lp:zorba.

Commit message:
generate audit properties

Requested reviews:
  Till Westmann (tillw)
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/feature-gen_audit_props/+merge/156994
-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-gen_audit_props/+merge/156994
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'cmake_modules/ZorbaRuntimeGenerator.cmake'
--- cmake_modules/ZorbaRuntimeGenerator.cmake	2013-03-04 16:17:30 +0000
+++ cmake_modules/ZorbaRuntimeGenerator.cmake	2013-04-03 23:00:42 +0000
@@ -127,3 +127,36 @@
     -D "test_only:BOOLEAN=TRUE"
     -P "${GEN_SCRIPT}")
 ENDMACRO(ZORBA_DIAGNOSTIC_GENERATOR)
+
+MACRO(ZORBA_AUDIT_GENERATOR GEN_QUERY EXTVARS EXTRA_DEPS OUTPUT)
+  # CMake is annoyingly limited when it comes to lists. There's no way
+  # (that I know of) to create a list where any item contains a
+  # semicolon. Since some of our arguments contain semicolons, we
+  # cannot create a variable to hold the arguments to CMake
+  # here. Therefore, we must duplicate them. It is important for
+  # testing purposes that the arguments to CMAKE_COMMAND in both
+  # ADD_CUSTOM_COMMAND() and ADD_TEST() here be the same, except for
+  # -Dtest_only.
+  STRING(REPLACE " " "_" TEST_NAME "${OUTPUT}")
+  ADD_CUSTOM_COMMAND(OUTPUT "${OUTPUT}"
+    COMMAND "${CMAKE_COMMAND}"
+    -D "source_dir=\"${CMAKE_SOURCE_DIR}\""
+    -D "binary_dir=\"${CMAKE_BINARY_DIR}\""
+    -D "ZORBA_EXE=\"${ZORBA_EXE}\"" 
+    -D "query=\"${GEN_QUERY}\"" 
+    -D "gen_file=\"${OUTPUT}\""
+    -D "extvars:STRING=${EXTVARS}"
+    -P "${GEN_SCRIPT}"
+    MAIN_DEPENDENCY ${GEN_QUERY}
+    DEPENDS ${EXTRA_DEPS}
+    ${GEN_SCRIPT} ${CMAKE_SOURCE_DIR}/cmake_modules/ZorbaRuntimeGenerator.cmake)
+  ADD_TEST("RuntimeGeneratorTest-${TEST_NAME}" "${CMAKE_COMMAND}"
+    -D "source_dir=${CMAKE_SOURCE_DIR}"
+    -D "binary_dir=${CMAKE_BINARY_DIR}"
+    -D "ZORBA_EXE=${ZORBA_EXE}"
+    -D "query=${GEN_QUERY}" 
+    -D "gen_file=${OUTPUT}"
+    -D "extvars:STRING=${EXTVARS}"
+    -D "test_only:BOOLEAN=TRUE"
+    -P "${GEN_SCRIPT}")
+ENDMACRO(ZORBA_AUDIT_GENERATOR)

=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt	2013-02-07 17:24:36 +0000
+++ src/api/CMakeLists.txt	2013-04-03 23:00:42 +0000
@@ -81,4 +81,28 @@
   ${CMAKE_CURRENT_BINARY_DIR}/api/version.cpp
   )
 
+SET(AUDIT_HEADER_GENERATOR "${CMAKE_SOURCE_DIR}/src/api/auditprops_h.xq")
+SET(AUDIT_CPP_GENERATOR    "${CMAKE_SOURCE_DIR}/src/api/auditprops_cpp.xq")
+SET(AUDIT_HEADER           "${CMAKE_BINARY_DIR}/src/api/auditprops.h")
+SET(AUDIT_CPP              "${CMAKE_BINARY_DIR}/src/api/auditprops.cpp")
+SET(AUDIT_PROPS_SPEC       "${CMAKE_SOURCE_DIR}/src/api/audit.xml")
+
+ZORBA_AUDIT_GENERATOR(
+    ${AUDIT_CPP_GENERATOR}
+    "auditspecfile:=${AUDIT_PROPS_SPEC}"
+    ${AUDIT_PROPS_SPEC}
+    ${AUDIT_CPP})
+
+ZORBA_AUDIT_GENERATOR(
+    ${AUDIT_HEADER_GENERATOR}
+    "auditspecfile:=${AUDIT_PROPS_SPEC}"
+    ${AUDIT_PROPS_SPEC}
+    ${AUDIT_HEADER})
+
+SET_SOURCE_FILES_PROPERTIES("${CMAKE_SOURCE_DIR}/src/api/auditimpl.cpp"
+                              PROPERTIES OBJECT_DEPENDS
+                              "${CMAKE_BINARY_DIR}/src/api/auditprops.cpp;${CMAKE_BINARY_DIR}/src/api/auditprops.h")
+SET_SOURCE_FILES_PROPERTIES("${CMAKE_SOURCE_DIR}/src/api/auditimpl.h"
+                              PROPERTIES OBJECT_DEPENDS
+                              "${CMAKE_BINARY_DIR}/src/api/auditprops.h")
 # vim:set et sw=2 ts=2:

=== added file 'src/api/audit.xml'
--- src/api/audit.xml	1970-01-01 00:00:00 +0000
+++ src/api/audit.xml	2013-04-03 23:00:42 +0000
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ : Copyright 2013 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+-->
+
+<audit>
+
+  <group name="xquery">
+    <group name="compilation">
+      <property name="filename" type="string"/>
+      <property name="parse-duration" type="int"/>
+      <property name="translation-duration" type="int"/>
+      <property name="optimization-duration" type="int"/>
+      <property name="codegeneration-duration" type="int"/>
+    </group>
+  </group>
+
+</audit>

=== modified file 'src/api/auditimpl.cpp'
--- src/api/auditimpl.cpp	2013-02-07 17:24:36 +0000
+++ src/api/auditimpl.cpp	2013-04-03 23:00:42 +0000
@@ -30,10 +30,7 @@
 // PropertyGroupImpl
 //************************************************************************
 
-const char* XQUERY_COMPILATION_PATH[] = { "xquery", "compilation" };
-
 const PropertyGroupImpl EMPTY_OBJECT      (0, NULL);
-const PropertyGroupImpl XQUERY_COMPILATION(2, XQUERY_COMPILATION_PATH);
 
 PropertyGroupImpl::PropertyGroupImpl(const size_t pathLength, const char** path)
   : m_pathLength(pathLength), m_path(path) {
@@ -60,29 +57,6 @@
 
 const PropertyImpl INVALID("");
 
-const PropertyImpl XQUERY_COMPILATION_FILENAME(
-    XQUERY_COMPILATION, "filename", 0, Property::STRING);
-
-const PropertyImpl XQUERY_COMPILATION_PARSE_DURATION(
-    XQUERY_COMPILATION, "parse-duration", 1, Property::INT);
-
-const PropertyImpl XQUERY_COMPILATION_TRANSLATION_DURATION(
-    XQUERY_COMPILATION, "translation-duration", 2, Property::INT);
-
-const PropertyImpl XQUERY_COMPILATION_OPTIMIZATION_DURATION(
-    XQUERY_COMPILATION, "optimization-duration", 3, Property::INT);
-
-const PropertyImpl XQUERY_COMPILATION_CODEGENERATION_DURATION(
-    XQUERY_COMPILATION, "codegeneration-duration", 4, Property::INT);
-
-const PropertyImpl* PROPERTIES[] = {
-  &XQUERY_COMPILATION_FILENAME,
-  &XQUERY_COMPILATION_PARSE_DURATION,
-  &XQUERY_COMPILATION_TRANSLATION_DURATION,
-  &XQUERY_COMPILATION_OPTIMIZATION_DURATION,
-  &XQUERY_COMPILATION_CODEGENERATION_DURATION
-};
-
 PropertyImpl::PropertyImpl(const PropertyGroup& g, const char n[], long i, Type t)
   : m_group(g), m_id(i), m_type(t) {
   String result;
@@ -120,6 +94,8 @@
   return m_type;
 }
 
+#include "api/auditprops.cpp"
+
 //************************************************************************
 // Observation
 //************************************************************************

=== modified file 'src/api/auditimpl.h'
--- src/api/auditimpl.h	2013-02-07 17:24:36 +0000
+++ src/api/auditimpl.h	2013-04-03 23:00:42 +0000
@@ -43,8 +43,6 @@
     const char** m_path;
   };
 
-  extern const PropertyGroupImpl XQUERY_COMPILATION;
-
   class PropertyImpl : public Property {
   public:
 
@@ -74,12 +72,6 @@
     const Type           m_type;
   };
 
-  extern const PropertyImpl XQUERY_COMPILATION_FILENAME;
-  extern const PropertyImpl XQUERY_COMPILATION_PARSE_DURATION;
-  extern const PropertyImpl XQUERY_COMPILATION_TRANSLATION_DURATION;
-  extern const PropertyImpl XQUERY_COMPILATION_OPTIMIZATION_DURATION;
-  extern const PropertyImpl XQUERY_COMPILATION_CODEGENERATION_DURATION;
-
   class ObservationImpl : public Observation {
   public:
     union Value {
@@ -210,6 +202,8 @@
   };
 
   extern ProviderImpl PROVIDER_IMPL;
+
+#include "api/auditprops.h"
 }
 }
 

=== added file 'src/api/auditprops_cpp.xq'
--- src/api/auditprops_cpp.xq	1970-01-01 00:00:00 +0000
+++ src/api/auditprops_cpp.xq	2013-04-03 23:00:42 +0000
@@ -0,0 +1,74 @@
+(:
+ : Copyright 2013 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+:)
+import module namespace file = "http://expath.org/ns/file";;
+
+declare variable $auditspecfile as xs:string external;
+
+declare function local:gen-group-spec($group as element()?) as xs:string*
+{
+  if ($group)
+  then
+    ($group/@name, local:gen-group-spec($group/parent::group))
+  else ()
+};
+
+declare function local:group-path($group-spec as xs:string*) as xs:string
+{
+let $name := string-join($group-spec ! upper-case(.), "_")
+let $path := $name || "_PATH"
+return
+  'const char* '
+    || $path || "[]"
+    || " = { " || string-join($group-spec ! concat('"', ., '"'), ", ")
+    || " };&#10;"
+    || 'const PropertyGroupImpl ' || $name
+    || "(" || count($group-spec) || ", " || $path || ");&#10;"
+};
+
+variable $counter := -1;
+
+(
+let $spec := parse-xml(file:read-text($auditspecfile))
+return
+  string-join(
+    for $first-prop in $spec//group/property[1]
+    let $group-spec := reverse(local:gen-group-spec($first-prop/parent::group))
+    return
+        local:group-path($group-spec) ||
+        string-join(
+          for $prop in ($first-prop, $first-prop/following-sibling::property)
+          let $group := string-join($group-spec ! upper-case(.), "_")
+          return {
+            $counter := $counter + 1;
+            "const PropertyImpl " || $group || "_" || replace(upper-case($prop/@name), "-", "_")
+            || "(" || $group || ', "' || $prop/@name || '", ' || $counter
+            || ", Property::" || upper-case($prop/@type) || ");&#10;"
+          }
+        ) || "&#10;"
+    ) || "&#10;" ||
+    "const PropertyImpl* PROPERTIES[] = {&#10;" ||
+    string-join(
+      for $first-prop in $spec//group/property[1]
+      let $group-spec := reverse(local:gen-group-spec($first-prop/parent::group))
+      return
+          string-join(
+            for $prop in ($first-prop, $first-prop/following-sibling::property)
+            return
+              ("  &amp;" || string-join($group-spec ! upper-case(.), "_") || "_"
+              || replace(upper-case($prop/@name), "-", "_")), ",&#10;"
+          ), ",&#10;"
+    ) || "&#10;};&#10;"
+)

=== added file 'src/api/auditprops_h.xq'
--- src/api/auditprops_h.xq	1970-01-01 00:00:00 +0000
+++ src/api/auditprops_h.xq	2013-04-03 23:00:42 +0000
@@ -0,0 +1,55 @@
+(:
+ : Copyright 2013 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+:)
+import module namespace file = "http://expath.org/ns/file";;
+
+declare variable $auditspecfile as xs:string external;
+
+declare function local:gen-group-spec($group as element()?) as xs:string*
+{
+  if ($group)
+  then
+    ($group/@name, local:gen-group-spec($group/parent::group))
+  else ()
+};
+
+
+declare function local:group($group-spec as xs:string*) as xs:string
+{
+'extern const PropertyGroupImpl '
+  || string-join($group-spec ! upper-case(.), "_")
+  || ';
+'
+};
+
+string-join(
+  (
+  let $spec := parse-xml(file:read-text($auditspecfile))
+  for $first-prop in $spec//group/property[1]
+  let $group-spec := reverse(local:gen-group-spec($first-prop/parent::group))
+  return
+      local:group($group-spec) ||
+      string-join(
+        for $prop in ($first-prop, $first-prop/following-sibling::property)
+        return
+          'extern const PropertyImpl '
+            || string-join($group-spec ! upper-case(.), "_")
+            || '_' || replace(upper-case($prop/@name), "-", "_")
+            || ';'
+      , "
+") || '
+
+'))
+

=== added directory 'src/api/pregenerated'
=== added file 'src/api/pregenerated/auditprops.cpp'
--- src/api/pregenerated/auditprops.cpp	1970-01-01 00:00:00 +0000
+++ src/api/pregenerated/auditprops.cpp	2013-04-03 23:00:42 +0000
@@ -0,0 +1,16 @@
+const char* XQUERY_COMPILATION_PATH[] = { "xquery", "compilation" };
+const PropertyGroupImpl XQUERY_COMPILATION(2, XQUERY_COMPILATION_PATH);
+const PropertyImpl XQUERY_COMPILATION_FILENAME(XQUERY_COMPILATION, "filename", 0, Property::STRING);
+const PropertyImpl XQUERY_COMPILATION_PARSE_DURATION(XQUERY_COMPILATION, "parse-duration", 1, Property::INT);
+const PropertyImpl XQUERY_COMPILATION_TRANSLATION_DURATION(XQUERY_COMPILATION, "translation-duration", 2, Property::INT);
+const PropertyImpl XQUERY_COMPILATION_OPTIMIZATION_DURATION(XQUERY_COMPILATION, "optimization-duration", 3, Property::INT);
+const PropertyImpl XQUERY_COMPILATION_CODEGENERATION_DURATION(XQUERY_COMPILATION, "codegeneration-duration", 4, Property::INT);
+
+
+const PropertyImpl* PROPERTIES[] = {
+  &XQUERY_COMPILATION_FILENAME,
+  &XQUERY_COMPILATION_PARSE_DURATION,
+  &XQUERY_COMPILATION_TRANSLATION_DURATION,
+  &XQUERY_COMPILATION_OPTIMIZATION_DURATION,
+  &XQUERY_COMPILATION_CODEGENERATION_DURATION
+};

=== added file 'src/api/pregenerated/auditprops.h'
--- src/api/pregenerated/auditprops.h	1970-01-01 00:00:00 +0000
+++ src/api/pregenerated/auditprops.h	2013-04-03 23:00:42 +0000
@@ -0,0 +1,7 @@
+extern const PropertyGroupImpl XQUERY_COMPILATION;
+extern const PropertyImpl XQUERY_COMPILATION_FILENAME;
+extern const PropertyImpl XQUERY_COMPILATION_PARSE_DURATION;
+extern const PropertyImpl XQUERY_COMPILATION_TRANSLATION_DURATION;
+extern const PropertyImpl XQUERY_COMPILATION_OPTIMIZATION_DURATION;
+extern const PropertyImpl XQUERY_COMPILATION_CODEGENERATION_DURATION;
+

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to