Initial import from SVN master
authorEbersold <aebersol@n3150.home>
Mon, 20 Dec 2021 20:34:45 +0000 (21:34 +0100)
committerEbersold <aebersol@n3150.home>
Mon, 20 Dec 2021 20:34:45 +0000 (21:34 +0100)
42 files changed:
CMakeLists.txt [new file with mode: 0644]
ast/ast_builder.cpp [new file with mode: 0644]
ast/ast_builder.h [new file with mode: 0644]
ast/ast_recursive_visitor.h [new file with mode: 0644]
gdmo_config.h [new file with mode: 0644]
gdmo_config.h.in [new file with mode: 0644]
libgen/CMakeLists.txt [new file with mode: 0644]
libgen/gdmo_genasn1.cpp [new file with mode: 0644]
libgen/gdmo_genasn1.h [new file with mode: 0644]
libgen/gdmo_gencpp.cpp [new file with mode: 0644]
libgen/gdmo_gencpp.h [new file with mode: 0644]
libgen/gdmo_gencpp_action.cpp [new file with mode: 0644]
libgen/gdmo_gencpp_action.h [new file with mode: 0644]
libgen/gdmo_gencpp_attribute.cpp [new file with mode: 0644]
libgen/gdmo_gencpp_attribute.h [new file with mode: 0644]
libgen/gdmo_gencpp_mo.cpp [new file with mode: 0644]
libgen/gdmo_gencpp_mo.h [new file with mode: 0644]
libgen/gdmo_gencpp_parameter.cpp [new file with mode: 0644]
libgen/gdmo_gencpp_parameter.h [new file with mode: 0644]
libgen/gdmo_generator.cpp [new file with mode: 0644]
libgen/gdmo_generator.h [new file with mode: 0644]
libgen/gdmo_genhpp.cpp [new file with mode: 0644]
libgen/gdmo_genhpp.h [new file with mode: 0644]
libparser/CMakeLists.txt [new file with mode: 0644]
libparser/gdmo.l [new file with mode: 0644]
libparser/gdmo.y [new file with mode: 0644]
libparser/gdmo_parser.h [new file with mode: 0644]
libparser/parser.cpp [new file with mode: 0644]
libparser/parser_listener.cpp [new file with mode: 0644]
main.cpp [new file with mode: 0644]
pgdmo/GDMOTemplates.py [new file with mode: 0644]
pgdmo/GDMOUtils.py [new file with mode: 0644]
pgdmo/Generators/__init__.py [new file with mode: 0644]
pgdmo/Generators/asn1.py [new file with mode: 0644]
pgdmo/Generators/common.py [new file with mode: 0644]
pgdmo/Generators/db.py [new file with mode: 0755]
pgdmo/Generators/mocpp.py [new file with mode: 0644]
pgdmo/__init__.py [new file with mode: 0644]
pgdmo/gdmolex.py [new file with mode: 0644]
pgdmo/gdmoparse.py [new file with mode: 0755]
pgdmo/pgdom [new file with mode: 0755]
rt/managed_object.h [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c09b79e
--- /dev/null
@@ -0,0 +1,184 @@
+PROJECT(gdmo)
+
+SUBDIRS(libparser libgen)
+
+OPTION(WITH_X721 "Gdmo Build" OFF)
+
+INCLUDE(CheckIncludeFiles)
+INCLUDE(CheckIncludeFile)
+INCLUDE(CheckTypeSize)
+INCLUDE(CheckFunctionExists)
+INCLUDE(CheckLibraryExists)
+INCLUDE(CheckSymbolExists)
+CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/gdmo_config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/gdmo_config.h)
+
+IF (NOT CMAKE_BUILD_TYPE)
+  SET(CMAKE_BUILD_TYPE Debug)
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+# Only for Linux not MAC
+IF(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG ")
+ELSE(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -std=c++0x")
+  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++0x")
+ENDIF(APPLE)
+
+
+INCLUDE(${rules_SOURCE_DIR}/flex.cmake)
+INCLUDE_DIRECTORIES(${cmip-lib_BINARY_DIR}/)
+INCLUDE_DIRECTORIES(${asn1_SOURCE_DIR}/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/rt)
+IF (NOT WIN32)
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -D__FILENAME__='\"$(subst ${CMAKE_CURRENT_SOURCE_DIR}/,,$<)\"'")
+ENDIF(NOT WIN32)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+INCLUDE_DIRECTORIES(${aebutils_SOURCE_DIR}/aeb)
+INCLUDE_DIRECTORIES(${aebutils_SOURCE_DIR}/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/libparser)
+ADD_DEFINITIONS(-DWITH_ADT_GDMO)
+
+
+IF (NOT CMAKE_CROSSCOMPILING)
+  ADD_EXECUTABLE(gdmo
+    main.cpp
+    ast/ast_builder.cpp
+  )
+  TARGET_LINK_LIBRARIES(gdmo gdmoparser gdmogen)
+  EXPORT(TARGETS gdmo FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake
+      NAMESPACE native-)
+ENDIF(NOT CMAKE_CROSSCOMPILING)
+
+
+IF(CMAKE_CROSSCOMPILING)
+    SET(gdmo_EXE native-gdmo)
+    GET_TARGET_PROPERTY(test ${gdmo_EXE} IMPORTED_LOCATION_DEBUG)
+    SET(asn1p_EXE ${test})
+ELSE(CMAKE_CROSSCOMPILING)
+    SET(gdmo_EXE ${CMAKE_CURRENT_BINARY_DIR}/gdmo)
+    SET(asn1_EXE ${CMAKE_CURRENT_BINARY_DIR}/../asn1/asn1p)
+ENDIF(CMAKE_CROSSCOMPILING)
+
+#
+# Ok, Add some custom commands 
+#
+IF (WITH_X721)
+
+ADD_CUSTOM_COMMAND(
+    OUTPUT 
+      ${CMAKE_CURRENT_BINARY_DIR}/mo/top.h 
+      ${CMAKE_CURRENT_BINARY_DIR}/mo/top.cpp 
+      ${CMAKE_CURRENT_BINARY_DIR}/attribute/weekMask.cpp 
+    COMMAND ${gdmo_EXE}
+    ARGS   -I ${asn1-data-models_SOURCE_DIR}/cmip/ 
+     -f x721.gdmo
+    DEPENDS ${gdmo_EXE}
+      ${CMAKE_CURRENT_BINARY_DIR}/Attribute_ASN1Module.h
+      ${CMAKE_CURRENT_BINARY_DIR}/Notification_ASN1Module.h
+      ${CMAKE_CURRENT_BINARY_DIR}/Parameter_ASN1Module.h
+      ${CMAKE_CURRENT_BINARY_DIR}/ACSE_1.h
+    COMMENT "Build x721 Managed Objects "
+    )
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/x721.asn1
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/mo/top.cpp
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/attribute/weekMask.cpp
+    GENERATED)
+
+#
+# We need asn1 types
+#
+ADD_CUSTOM_COMMAND(
+    OUTPUT 
+      ${CMAKE_CURRENT_BINARY_DIR}/Attribute_ASN1Module.h 
+      ${CMAKE_CURRENT_BINARY_DIR}/Attribute-ASN1Module.cpp 
+    COMMAND ${asn1_EXE}
+    ARGS   -I ${asn1-data-models_SOURCE_DIR}/cmip/ 
+     -f Attribute-ASN1Module.asn1
+     -f ../CMIP-1.asn1
+     -f ../cstav1/apdu_acse.asn1
+     -o Attribute-ASN1Module
+    DEPENDS ${gdmo_EXE} ${asn1_EXE}
+    COMMENT "Build Attribute-ASN1Module.asn1"
+    )
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Attribute_ASN1Module.h
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Attribute-ASN1Module.cpp
+    GENERATED)
+#
+# ACSE
+ADD_CUSTOM_COMMAND(
+    OUTPUT 
+      ${CMAKE_CURRENT_BINARY_DIR}/ACSE_1.h 
+      ${CMAKE_CURRENT_BINARY_DIR}/ACSE-1.cpp 
+    COMMAND ${asn1_EXE}
+    ARGS   -I ${asn1-data-models_SOURCE_DIR}/cmip/ 
+     -f Attribute-ASN1Module.asn1
+     -f ../CMIP-1.asn1
+     -f ../cstav1/apdu_acse.asn1
+     -o ACSE-1
+    DEPENDS ${gdmo_EXE} ${asn1_EXE}
+    COMMENT "Build ACSE-1.asn1"
+    )
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/ACSE_1.h
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/ACSE-1.cpp
+    GENERATED)
+
+
+#
+# Notif
+ADD_CUSTOM_COMMAND(
+    OUTPUT 
+      ${CMAKE_CURRENT_BINARY_DIR}/Notification_ASN1Module.h 
+      ${CMAKE_CURRENT_BINARY_DIR}/Notification-ASN1Module.cpp 
+    COMMAND ${asn1_EXE}
+    ARGS   -I ${asn1-data-models_SOURCE_DIR}/cmip/ 
+     -f Notification-ASN1Module.asn1
+     -f Attribute-ASN1Module.asn1
+     -f ../CMIP-1.asn1
+     -f ../cstav1/apdu_acse.asn1
+     -o Notification-ASN1Module
+    DEPENDS ${gdmo_EXE} ${asn1_EXE}
+    COMMENT "Compiling Notification-ASN1Module.asn1"
+    )
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Notification_ASN1Module.h
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Notification-ASN1Module.cpp
+    GENERATED)
+
+#
+# Notif
+ADD_CUSTOM_COMMAND(
+    OUTPUT 
+      ${CMAKE_CURRENT_BINARY_DIR}/Parameter_ASN1Module.h 
+      ${CMAKE_CURRENT_BINARY_DIR}/Parameter-ASN1Module.cpp 
+    COMMAND ${asn1_EXE}
+    ARGS   -I ${asn1-data-models_SOURCE_DIR}/cmip/ 
+     -f Parameter-ASN1Module.asn1
+     -f Attribute-ASN1Module.asn1
+     -f ../CMIP-1.asn1
+     -f ../cstav1/apdu_acse.asn1
+     -o Parameter-ASN1Module
+    DEPENDS ${gdmo_EXE} ${asn1_EXE}
+    COMMENT "Compiling Parameter-ASN1Module.asn1"
+    )
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Parameter_ASN1Module.h
+    GENERATED)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/Parameter-ASN1Module.cpp
+    GENERATED)
+
+
+ADD_LIBRARY(x721
+  ${CMAKE_CURRENT_BINARY_DIR}/mo/top.cpp
+  ${CMAKE_CURRENT_BINARY_DIR}/attribute/weekMask.cpp
+)
+ENDIF(WITH_X721)
diff --git a/ast/ast_builder.cpp b/ast/ast_builder.cpp
new file mode 100644 (file)
index 0000000..c2e8efc
--- /dev/null
@@ -0,0 +1,412 @@
+#include "gdmo_config.h"
+#include "ADT/Adt.h"
+
+#include "gdmo_parser.h"
+#include "ast_builder.h"
+
+struct sdisp
+{
+  void operator ()(const std::string &s)
+  {
+    std::cerr<<"ASN1 -> "<<s<<std::endl;         
+  }      
+};
+
+
+ast_builder::ast_builder()
+{
+}
+
+ast_builder::~ast_builder()
+{
+  std::for_each (m_asn1_mset.begin(),
+                m_asn1_mset.end(),
+                sdisp());
+}
+
+void 
+ast_builder::on_module_start(module &m)
+{
+  m_Stack.push(&m);
+  std::cerr<<"ast_builder::got module "<<std::endl;
+}
+
+void
+ast_builder::on_template_start(ADT::GDMO::templates *t)
+{
+  m_Stack.push(t);
+}
+
+void
+ast_builder::on_template(ADT::GDMO::templates &t)
+{
+  parser_listener::on_template(t);
+  ADT::GDMO::templates *tmp(&t);
+  m_Stack.pop();
+  if (m_Stack.size() <2)
+  {
+    module *mod = dynamic_cast<module *>(m_Stack.top());
+    mod->insert(tmp);
+  }
+}
+
+void 
+ast_builder::on_pkg_attribute_start(ADT::GDMO::pkg_attribute &t)
+{
+  m_Stack.push(&t);
+}
+
+void 
+ast_builder::on_pkg_attribute(ADT::GDMO::pkg_attribute &t)
+{
+  m_Stack.pop();
+}
+
+void 
+ast_builder::on_module_end(module &m)
+{
+  std::cerr<<"ast_builder::got module end stack size="<<m_Stack.size()<<std::endl;
+  m_Stack.pop();
+  m_Modules.push_back(&m);
+}
+
+void ast_builder::on_mo_tplt(mo_tplt &t)
+{
+#if 0
+  std::cerr<<"ast_build: Got managed object ";
+  std::cerr<<t.get_label().getName();
+  std::cerr<<" stack size="<<m_Stack.size()<<std::endl;
+#endif
+}
+
+void ast_builder::on_package_tplt(package_tplt &t)
+{
+#if 0
+  std::cerr<<"ast_build: Got package ";
+  std::cerr<<t.get_label().getName();
+  std::cerr<<" stack size="<<m_Stack.size()<<std::endl;
+#endif
+}
+
+void ast_builder::on_name_binding_tplt(name_binding_tplt  &t)
+{
+}
+
+void ast_builder::on_attribute_tplt(attribute_tplt  &t)
+{
+  if (m_Stack.size() > 2)
+  {
+    std::cerr<<"ast_build: Got attribute not root ";
+    std::cerr<<t.get_label().getName();
+    std::cerr<<" stack size="<<m_Stack.size()<<std::endl;
+  }
+}
+
+void ast_builder::on_attribute_group_tplt(attribute_group_tplt &t)
+{
+}
+
+void ast_builder::on_behaviour_tplt(behaviour_tplt &t)
+{
+}
+
+void ast_builder::on_action_tplt(action_tplt &t)
+{
+}
+
+void ast_builder::on_parameter_tplt(parameter_tplt &t)
+{
+}
+
+void ast_builder::on_notification_tplt(notification_tplt &t )
+{
+}
+
+/**
+ * Construst
+ */ 
+
+#define GDMO_CONSTRUCT_DECL(cls,parent)  \
+void ast_builder::on_##cls(cls &_c)      \
+{                                       \
+   parent                               \
+}
+
+GDMO_CONSTRUCT_DECL(mo_derived_from,
+{
+  mo_tplt *mo = dynamic_cast<mo_tplt *>(m_Stack.top());
+  if (mo)
+  {
+    mo->set_derived_from(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_mo_derived_from failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(mo_characterized_by,
+{
+  mo_tplt *mo = dynamic_cast<mo_tplt *>(m_Stack.top());
+  if (mo)
+  {
+    mo->set_characterized_by(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_characterized_by failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(mo_cond_packages,
+{
+  mo_tplt *mo = dynamic_cast<mo_tplt *>(m_Stack.top());
+  if (mo)
+  {
+    mo->set_cond_packages(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_set_cond_packages failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(mo_registered,
+{
+  mo_tplt *mo = dynamic_cast<mo_tplt *>(m_Stack.top());
+  if (mo)
+  {
+    mo->set_registered(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_set_registered failed"<<std::endl;
+  }
+})
+
+/**
+ *
+ */ 
+GDMO_CONSTRUCT_DECL(pkg_behaviour,
+{
+  package_tplt *pkg = dynamic_cast<package_tplt *>(m_Stack.top());
+  if (pkg)
+  {
+    pkg->set_behaviour(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_pkg_behaviour failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(pkg_attributes,
+{
+  package_tplt *pkg = dynamic_cast<package_tplt *>(m_Stack.top());
+  if (pkg)
+  {
+    //std::cerr<<"ast::builder::on_pkg_attributes got "<<_c.size()<<std::endl;
+    pkg->set_attributes(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_pkg_attributes failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(pkg_attribute_group,
+{
+})
+GDMO_CONSTRUCT_DECL(pkg_actions,
+{
+  package_tplt *pkg = dynamic_cast<package_tplt *>(m_Stack.top());
+  if (pkg)
+  {
+    pkg->set_actions(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_pkg_actions failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(pkg_notifications,
+{
+  package_tplt *pkg = dynamic_cast<package_tplt *>(m_Stack.top());
+  if (pkg)
+  {
+    pkg->set_notifications(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_pkg_notifications failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(pkg_registered,{
+})
+
+/**
+ * attribute constructs
+ */ 
+GDMO_CONSTRUCT_DECL(attr_syntax,
+{
+  attribute_tplt *attr = dynamic_cast<attribute_tplt *>(m_Stack.top());
+  if (attr)
+  {
+    attr->set_syntax(&_c);
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+  } else
+  {
+    std::cerr<<"ast::builder::on_attr_syntax failed"<<std::endl;
+  }
+})
+
+GDMO_CONSTRUCT_DECL(attr_match_for,
+{
+  attribute_tplt *attr = dynamic_cast<attribute_tplt *>(m_Stack.top());
+  if (attr)
+  {
+    attr->set_match_for(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_match_for failed"<<std::endl;
+  }
+})
+
+GDMO_CONSTRUCT_DECL(attr_behaviour,
+{
+  attribute_tplt *attr = dynamic_cast<attribute_tplt *>(m_Stack.top());
+  if (attr)
+  {
+    attr->set_behaviour(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_attr_behaviour failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(attr_parameters,
+{
+  attribute_tplt *attr = dynamic_cast<attribute_tplt *>(m_Stack.top());
+  if (attr)
+  {
+    attr->set_parameters(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_attr_parameters failed"<<std::endl;
+  }
+})
+GDMO_CONSTRUCT_DECL(attr_registered,
+{
+  attribute_tplt *attr = dynamic_cast<attribute_tplt *>(m_Stack.top());
+  if (attr)
+  {
+    attr->set_registered(&_c);
+  } else
+  {
+    std::cerr<<"ast::builder::on_attr_parameters failed"<<std::endl;
+  }
+})
+
+#undef GDMO_CONSTRUCT_DECL
+#define GDMO_CONSTRUCT_DECL(tplte,cls,parent)  \
+void ast_builder::on_## tplte##_##cls(tplte ##_## cls &_c)      \
+{                                       \
+  tplte ## _tplt *attr = dynamic_cast<tplte ## _tplt *>(m_Stack.top()); \
+  if (attr)                                                             \
+  {                                                                     \
+    attr->set_##cls(&_c);                                               \
+  } else                                                                \
+  {                                                                     \
+    std::cerr<<"ast::builder::on_attr_parameters " #cls " failed"<<std::endl;    \
+  }                                                                     \
+   parent                                                               \
+}
+
+/**
+ *
+ */ 
+GDMO_CONSTRUCT_DECL(parameter,context,{})
+GDMO_CONSTRUCT_DECL(parameter,syntax,{
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+               
+})
+GDMO_CONSTRUCT_DECL(parameter,attribute,{})
+GDMO_CONSTRUCT_DECL(parameter,behaviour,{})
+GDMO_CONSTRUCT_DECL(parameter,registered,{})
+
+/**
+ *
+ */ 
+GDMO_CONSTRUCT_DECL(name_binding,subordinate,{})
+GDMO_CONSTRUCT_DECL(name_binding,named_by_superior,{})
+GDMO_CONSTRUCT_DECL(name_binding,with_attribute,{})
+GDMO_CONSTRUCT_DECL(name_binding,behaviour,{})
+GDMO_CONSTRUCT_DECL(name_binding,create,{})
+GDMO_CONSTRUCT_DECL(name_binding,delete,{})
+GDMO_CONSTRUCT_DECL(name_binding,registered,{})
+
+/**
+ *
+ */ 
+GDMO_CONSTRUCT_DECL(action,behaviour,{})
+GDMO_CONSTRUCT_DECL(action,mode,{})
+GDMO_CONSTRUCT_DECL(action,parameters,{})
+GDMO_CONSTRUCT_DECL(action,with_information,{
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+               
+})
+GDMO_CONSTRUCT_DECL(action,with_reply,{
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+})
+GDMO_CONSTRUCT_DECL(action,registered,{})
+
+/**
+ *
+ */ 
+GDMO_CONSTRUCT_DECL(notification,mode,{})
+GDMO_CONSTRUCT_DECL(notification,behaviour,{})
+GDMO_CONSTRUCT_DECL(notification,parameters,{})
+GDMO_CONSTRUCT_DECL(notification,with_information,{
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+})
+GDMO_CONSTRUCT_DECL(notification,with_reply,{
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(_c.get_decl()))
+    {
+      m_asn1_mset.insert(ref->get_asn1_module());
+    }
+})
+GDMO_CONSTRUCT_DECL(notification,registered,{})
+
+
+GDMO_CONSTRUCT_DECL(attribute_group,group_elements,{})
+
+GDMO_CONSTRUCT_DECL(behaviour,defined_as,{})
+
+    
+#undef GDMO_PROPLIST_DECL
+#define GDMO_PROPLIST_DECL(tplte,cls,parent)  \
+void ast_builder::on_## tplte##_##cls(tplte ##_## cls &_c)      \
+{                                       \
+  pkg_attribute *attr = dynamic_cast<pkg_attribute *>(m_Stack.top()); \
+  if (attr)                                                             \
+  {                                                                     \
+    attr->set_##cls(&_c);                                               \
+  } else                                                                \
+  {                                                                     \
+    std::cerr<<"ast::builder::on_attr_parameters " #cls " failed"<<std::endl;    \
+  }                                                                     \
+   parent                                                               \
+}
+
+    
+GDMO_PROPLIST_DECL(property,replace_default,{})
+GDMO_PROPLIST_DECL(property,default,{})
+GDMO_PROPLIST_DECL(property,initial,{})
+GDMO_PROPLIST_DECL(property,permitted,{})
+GDMO_PROPLIST_DECL(property,required,{})
+GDMO_PROPLIST_DECL(property,get_replace,{})
+GDMO_PROPLIST_DECL(property,add_remove,{})
+GDMO_PROPLIST_DECL(property,set_by_created,{})
+GDMO_PROPLIST_DECL(property,no_modify,{})
+
diff --git a/ast/ast_builder.h b/ast/ast_builder.h
new file mode 100644 (file)
index 0000000..dee4142
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef AST_BUILD_H
+#define AST_BUILD_H
+
+/**
+ * The ast builder is responsible to
+ * build an abstract syntact tree.
+ *  - This tree will be traversed a second
+ *    time to resolve references 
+ */ 
+class ast_builder : public GDMO::parser_listener
+{
+  public:
+    typedef std::set<std::string>          asn1ModuleSet;        
+    typedef std::list<ADT::GDMO::module *> moduleList;   
+    typedef std::stack<ADT::Adt *>  declStack;   
+    
+    ast_builder();
+    ~ast_builder();
+
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+    virtual void on_##cls(ADT::GDMO::cls &t) ;
+
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+    virtual void on_##cls(ADT::GDMO::cls &t) ;
+#define GDMO_PROPLIST_DECL(cls,p) \
+    virtual void on_##cls(ADT::GDMO::cls &t) ;
+#include  "ADT/gdmo/Gdmo.h.inc"      
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+    virtual void on_module_start(module &m);
+    
+    virtual void on_module_end(module &m);
+    
+    void on_template_start(ADT::GDMO::templates *t);
+    void on_template(ADT::GDMO::templates &t);
+
+    void on_pkg_attribute_start(ADT::GDMO::pkg_attribute &t);
+    void on_pkg_attribute(ADT::GDMO::pkg_attribute &t);
+    GDMO::parser_listener *get_listener()
+    {
+      return this;
+    }
+    moduleList &get_modules()
+    {
+      return m_Modules;  
+    }
+  protected:
+    moduleList    m_Modules;
+    declStack     m_Stack;
+    asn1ModuleSet m_asn1_mset;
+};
+
+#endif /*AST_BUILD_H*/
diff --git a/ast/ast_recursive_visitor.h b/ast/ast_recursive_visitor.h
new file mode 100644 (file)
index 0000000..0d1287e
--- /dev/null
@@ -0,0 +1,250 @@
+#ifndef AST_RECURSIVE_VISITOR_H__
+#define AST_RECURSIVE_VISITOR_H__
+
+template <typename Derived>
+class ast_recursive_visitor
+{
+    public:  
+  ast_recursive_visitor() {};
+
+  Derived &get_derived() { return *static_cast<Derived *>(this); }
+
+#define TRY_TO(x)  do {      \
+    if (! get_derived().x )  \
+      return false;          \
+} while(0)
+
+  bool traverse_templates(templates *S);
+  bool traverse_construct(construct *S);
+  bool traverse_Adt(Adt *S);
+  bool traverse_decl(decl *S);
+  //
+#define  GDMO_DECL(cls,parent) 
+//#define  GDMO_DECL(cls,parent)  bool traverse_##cls(cls *s);
+#define  GDMO_PROPLIST_DECL(cls,parent) 
+#define  GDMO_TPLT_DECL(cls,parent)  bool traverse_##cls(cls *s);
+#define  GDMO_CONSTRUCT_DECL(cls,parent)  bool traverse_##cls(cls *s);
+
+#include "ADT/gdmo/Gdmo.h.inc"
+  //
+  bool walkup_from_decl(decl *S)
+  { return get_derived().visit_decl(S);};
+  
+  bool visit_decl(decl *S)
+  { return true;}
+  //
+  //
+  bool walkup_from_templates(templates *S)
+  { return get_derived().visit_templates(S);};
+  
+  bool visit_templates(templates *S)
+  { return true;}
+  //
+  bool walkup_from_construct(construct *S)
+  { return get_derived().visit_construct(S);};
+  
+  bool visit_construct(construct *S)
+  { return true;}
+
+#define GDMO_DECL(cls,parent) 
+#define GDMO_PROPLIST_DECL(cls,parent) 
+#define GDMO_TPLT_DECL(cls,parent)        \
+  bool walkup_from_##cls(cls *S)          \
+  {                                       \
+    TRY_TO(walkup_from_ ## parent(S));     \
+    TRY_TO(visit_##cls(S));               \
+    return true;                          \
+  }                                       \
+  bool visit_##cls(cls *S) { return true;}
+#define GDMO_CONSTRUCT_DECL(x,y) GDMO_TPLT_DECL(x,y) 
+//#define GDMO_DECL(x,y) GDMO_TPLT_DECL(x,y) 
+#include "ADT/gdmo/Gdmo.h.inc"
+};
+
+/**
+ * Implementation part for traverse
+ */ 
+template <typename Derived>
+bool ast_recursive_visitor<Derived>::traverse_decl(decl *d)
+{
+  if (!d )
+    return true; 
+  TRY_TO(walkup_from_decl(d));
+#if 0
+  switch (d->getClass())
+  {
+#define GDMO_TPLT_DECL(cls,parent) 
+#define GDMO_CONSTRUCT_DECL(cls,parent) 
+#define GDMO_DECL(cls,parent) \
+      case Adt::cls##Class : DISPATCH(cls,d)
+#include "ADT/gdmo/Gdmo.h.inc"                      
+    default: 
+     ;           
+  }
+#endif
+  return true;  
+}
+
+
+template <typename Derived>
+bool ast_recursive_visitor<Derived>::traverse_templates(templates *d)
+{
+#define DISPATCH(cls,v)  \
+    return get_derived().traverse_##cls(static_cast<cls *>(v));
+
+  if (!d )
+    return true; 
+  switch (d->getClass())
+  {
+#define GDMO_DECL(cls,parent)
+#define GDMO_TPLT_DECL(cls,parent) \
+      case Adt::cls##Class : DISPATCH(cls,d)
+#define GDMO_CONSTRUCT_DECL(cls,parent)
+#include "ADT/gdmo/Gdmo.h.inc"                      
+    default: 
+     ;           
+  }
+  return true;
+
+}
+
+template <typename Derived>
+bool ast_recursive_visitor<Derived>::traverse_Adt(Adt *d)
+{
+#define DISPATCH(cls,v)  \
+    return get_derived().traverse_##cls(static_cast<cls *>(v));
+
+  if (!d )
+    return true; 
+  switch (d->getClass())
+  {
+#define GDMO_DECL(cls,parent)
+#define GDMO_TPLT_DECL(cls,parent) \
+      case Adt::cls##Class : DISPATCH(cls,d)
+#define GDMO_CONSTRUCT_DECL(cls,parent)
+#include "ADT/gdmo/Gdmo.h.inc"        
+      case Adt::labelClass:
+         DISPATCH(decl,d) 
+    default: 
+     ;           
+  }
+  return true;
+
+}
+
+
+template <typename Derived>
+bool ast_recursive_visitor<Derived>::traverse_construct(construct *d)
+{
+  if (!d )
+    return true; 
+  switch (d->getClass())
+  {
+#define GDMO_DECL(cls,parent)
+#define GDMO_TPLT_DECL(cls,parent) 
+#define GDMO_CONSTRUCT_DECL(cls,parent) \
+      case Adt::cls##Class : DISPATCH(cls,d)
+#include "ADT/gdmo/Gdmo.h.inc"                      
+    default: 
+     ;           
+  }
+  return true;  
+}
+
+
+#define DEF_TRAVERSE_TPLT(DECL,CODE)                                                        \
+    template <typename Derived>                                                             \
+    bool ast_recursive_visitor<Derived>::traverse_##DECL(DECL *d) {                         \
+        TRY_TO(walkup_from_##DECL(d));                                                      \
+        { CODE;}                                                                            \
+        return true;                                                                        \
+   }                                                                                        \
+
+
+DEF_TRAVERSE_TPLT(mo_tplt,{
+  TRY_TO(traverse_construct(d->get_derived_from()));
+  TRY_TO(traverse_construct(d->get_characterized_by()));
+  TRY_TO(traverse_construct(d->get_cond_packages()));
+})
+DEF_TRAVERSE_TPLT(package_tplt,{
+  TRY_TO(traverse_construct(d->get_attributes()));
+  TRY_TO(traverse_construct(d->get_notifications()));
+  TRY_TO(traverse_construct(d->get_actions()));
+})
+DEF_TRAVERSE_TPLT(name_binding_tplt,{})
+DEF_TRAVERSE_TPLT(attribute_tplt,{})
+DEF_TRAVERSE_TPLT(attribute_group_tplt,{})
+DEF_TRAVERSE_TPLT(behaviour_tplt,{})
+DEF_TRAVERSE_TPLT(action_tplt,{})
+DEF_TRAVERSE_TPLT(parameter_tplt,{})
+DEF_TRAVERSE_TPLT(notification_tplt,{})
+
+//#define GDMO_CONSTRUCT_DECL(x,y) DEF_TRAVERSE_TPLT(x,y) 
+#define GDMO_CONSTRUCT_DECL(DECL,CODE)  \
+    template <typename Derived>                                                             \
+    bool ast_recursive_visitor<Derived>::traverse_##DECL(DECL *d) {                         \
+        TRY_TO(walkup_from_##DECL(d));                                                      \
+        { CODE;}                                                                            \
+       for (Container::iterator i = d->begin() ; i != d->end() ; ++i) {                    \
+          TRY_TO(traverse_Adt(static_cast<Adt *>(&(*i))));                                    \
+        }                                                                                   \
+        return true;                                                                        \
+   }                                                                                        \
+
+
+GDMO_CONSTRUCT_DECL(mo_derived_from,{})
+GDMO_CONSTRUCT_DECL(mo_characterized_by,{})
+GDMO_CONSTRUCT_DECL(mo_cond_packages,{})
+GDMO_CONSTRUCT_DECL(mo_registered,{})
+
+GDMO_CONSTRUCT_DECL(pkg_behaviour,{})
+GDMO_CONSTRUCT_DECL(pkg_attributes,{})
+GDMO_CONSTRUCT_DECL(pkg_attribute_group,{})
+GDMO_CONSTRUCT_DECL(pkg_actions,{})
+GDMO_CONSTRUCT_DECL(pkg_notifications,{})
+GDMO_CONSTRUCT_DECL(pkg_registered,{})
+
+
+GDMO_CONSTRUCT_DECL(attr_syntax,{})
+GDMO_CONSTRUCT_DECL(attr_match_for,{})
+GDMO_CONSTRUCT_DECL(attr_behaviour,{})
+GDMO_CONSTRUCT_DECL(attr_parameters,{})
+GDMO_CONSTRUCT_DECL(attr_registered,{})
+
+GDMO_CONSTRUCT_DECL(parameter_context,{})
+GDMO_CONSTRUCT_DECL(parameter_syntax,{})
+GDMO_CONSTRUCT_DECL(parameter_attribute,{})
+GDMO_CONSTRUCT_DECL(parameter_behaviour,{})
+GDMO_CONSTRUCT_DECL(parameter_registered,{})
+
+GDMO_CONSTRUCT_DECL(name_binding_subordinate,{})
+GDMO_CONSTRUCT_DECL(name_binding_named_by_superior,{})
+GDMO_CONSTRUCT_DECL(name_binding_with_attribute,{})
+GDMO_CONSTRUCT_DECL(name_binding_behaviour,{})
+GDMO_CONSTRUCT_DECL(name_binding_create,{})
+GDMO_CONSTRUCT_DECL(name_binding_delete,{})
+GDMO_CONSTRUCT_DECL(name_binding_registered,{})
+
+GDMO_CONSTRUCT_DECL(action_behaviour,{})
+GDMO_CONSTRUCT_DECL(action_mode,{})
+GDMO_CONSTRUCT_DECL(action_parameters,{})
+GDMO_CONSTRUCT_DECL(action_with_information,{})
+GDMO_CONSTRUCT_DECL(action_with_reply,{})
+GDMO_CONSTRUCT_DECL(action_registered,{})
+
+GDMO_CONSTRUCT_DECL(notification_mode,{})
+GDMO_CONSTRUCT_DECL(notification_behaviour,{})
+GDMO_CONSTRUCT_DECL(notification_parameters,{})
+GDMO_CONSTRUCT_DECL(notification_with_information,{})
+GDMO_CONSTRUCT_DECL(notification_with_reply,{})
+GDMO_CONSTRUCT_DECL(notification_registered,{})
+
+GDMO_CONSTRUCT_DECL(attribute_group_group_elements,{})
+
+GDMO_CONSTRUCT_DECL(behaviour_defined_as,{})
+
+/**
+ * Implementation part for 
+ */ 
+#endif
+
diff --git a/gdmo_config.h b/gdmo_config.h
new file mode 100644 (file)
index 0000000..4d90fd3
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef GDMO_CONFIG_H
+#define GDMO_CONFIG_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/**/
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <cstdio>
+#include <list>
+#include <map>
+#include <set>
+#include <stack>
+#include <algorithm>
+#include <stdio.h>
+// for memset
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#if defined (_WIN32)
+#include <io.h>
+#define access _access_s
+#define F_OK 0
+
+#include <stdlib.h>
+#include <direct.h>
+#define  getcwd _getcwd
+#define  mkdir  _mkdir
+#endif
+
+#endif /*GDMO_CONFIG_H*/
diff --git a/gdmo_config.h.in b/gdmo_config.h.in
new file mode 100644 (file)
index 0000000..9d458e3
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef GDMO_CONFIG_H
+#define GDMO_CONFIG_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/**/
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <cstdio>
+#include <list>
+#include <map>
+#include <set>
+#include <stack>
+#include <algorithm>
+#include <stdio.h>
+// for memset
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#if defined (_WIN32)
+#include <io.h>
+#define access _access_s
+#define F_OK 0
+
+#include <stdlib.h>
+#include <direct.h>
+#define  getcwd _getcwd
+#define  mkdir  _mkdir
+#endif
+
+#endif /*GDMO_CONFIG_H*/
diff --git a/libgen/CMakeLists.txt b/libgen/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1451679
--- /dev/null
@@ -0,0 +1,28 @@
+PROJECT(gdmogen)
+
+
+IF (NOT CMAKE_BUILD_TYPE)
+  SET(CMAKE_BUILD_TYPE Debug)
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+# Only for Linux not MAC
+IF(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG ")
+ELSE(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -std=c++0x")
+  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++0x")
+ENDIF(APPLE)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+
+ADD_LIBRARY(gdmogen 
+    gdmo_generator.cpp 
+    gdmo_genasn1.cpp 
+    gdmo_genhpp.cpp 
+    gdmo_gencpp.cpp 
+    gdmo_gencpp_mo.cpp 
+    gdmo_gencpp_attribute.cpp 
+    gdmo_gencpp_action.cpp 
+    ) 
diff --git a/libgen/gdmo_genasn1.cpp b/libgen/gdmo_genasn1.cpp
new file mode 100644 (file)
index 0000000..de09b81
--- /dev/null
@@ -0,0 +1,139 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_genasn1.h"
+
+    
+genasn1::genasn1(GDMO::generator::moduleList &l)
+  : GDMO::generator(l)
+{
+  std::cout<<"Start generator ASN1"<<std::endl; 
+}
+
+void 
+genasn1::gen_module_start(ADT::GDMO::module &m)
+{
+  std::string  mn       = m.getName();
+  std::string  asn1name = mn.substr(0,mn.find('.'));
+  mn = asn1name + ".asn1";
+  std::cout<<"Start Module "<<mn<<" ("<<asn1name<<")"<<std::endl;
+  m_os.open(mn.c_str(),std::fstream::out);   
+  m_os<<"-- Module CMIP-1 (X.711:10/1997)"<<std::endl;
+  m_os<<"-- See also ITU-T X.711 (10/1997)"<<std::endl;
+  m_os<<"-- See also the index of all ASN.1 assignments needed in this document"<<std::endl;
+  m_os<<""<<std::endl;
+  m_os<<asn1name<<" {joint-iso-itu-t ms(9) cmip(1) modules(0) protocol(3)} ";
+  m_os<<"\nDEFINITIONS ::="<<std::endl;
+  m_os<<"BEGIN"<<std::endl;
+  m_os<<""<<std::endl;
+  m_os<<"IMPORTS"<<std::endl;
+  m_os<<"  ERROR, OPERATION"<<std::endl;
+  m_os<<"    FROM Remote-Operations-Information-Objects {joint-iso-itu-t"<<std::endl;
+  m_os<<"      remote-operations(4) informationObjects(5) version1(0)}"<<std::endl;
+  m_os<<"  ROS{}, InvokeId, noInvokeId"<<std::endl;
+  m_os<<"    FROM Remote-Operations-Generic-ROS-PDUs {joint-iso-itu-t"<<std::endl;
+  m_os<<"      remote-operations(4) generic-ROS-PDUs(6) version1(0)};"<<std::endl;
+
+}
+
+void 
+genasn1::gen_module_end(ADT::GDMO::module &m)
+{
+  m_os<<"END";  
+  m_os.close(); 
+}
+    
+void 
+genasn1::gen_oid(ADT::GDMO::construct *r)
+{
+  if (r)
+  {
+     ADT::Container::iterator i = r->begin();
+     m_os<<" {";
+     for ( ; i != r->end()
+          ; ++i)
+     {
+         ADT::GDMO::oid_item *oidi = dynamic_cast<ADT::GDMO::oid_item *>(&(*i));
+         m_os<<" "<<oidi->get_name();
+     } 
+     m_os<<"}";
+  }
+}
+
+
+#undef GDMO_TPLT_DECL
+#define GDMO_TPLT_DECL(cls,parent)  \
+void genasn1::gen_## cls( ADT::GDMO::cls &c)      \
+{                                      \
+   parent                              \
+}
+
+/**
+ *
+ */ 
+
+GDMO_TPLT_DECL(mo_tplt,{})
+GDMO_TPLT_DECL(package_tplt,{})
+GDMO_TPLT_DECL(name_binding_tplt,{})
+GDMO_TPLT_DECL(attribute_tplt,
+{
+  ADT::GDMO::attr_registered *r = c.get_registered();
+  if (r)
+  {
+    m_os<<c.get_label().getName()<<" OBJECT IDENTIFIER ::= "<<std::endl;
+    gen_oid(r);
+    m_os<<std::endl;
+    m_os<<"\n"<<std::endl;
+  } else
+  {
+    m_os<<"\n--\n-- Abstract "<<c.get_label().getName()<<" CMIP-ATTRIBUTE "<<std::endl;
+    m_os<<"--"<<std::endl;
+  }
+})
+
+GDMO_TPLT_DECL(attribute_group_tplt,{})
+GDMO_TPLT_DECL(behaviour_tplt,{})
+
+GDMO_TPLT_DECL(action_tplt,
+{
+  ADT::GDMO::action_registered *r = c.get_registered();
+  ADT::GDMO::action_with_reply           *reply = c.get_with_reply();
+  ADT::GDMO::action_with_information     *info  = c.get_with_information();
+  if (r)
+  {
+    m_os<<c.get_label().getName()<<"OBJECT IDENTIFIER  ::= "<<std::endl;
+    gen_oid(r);
+    m_os<<std::endl;
+    m_os<<"\n"<<std::endl;
+  } else
+  {
+    m_os<<"\n-- Abstract Action \n-- "<<c.get_label().getName()<<"\n--"<<std::endl;
+  }
+})
+
+GDMO_TPLT_DECL(parameter_tplt,
+{
+  ADT::GDMO::parameter_registered *r = c.get_registered();
+  if (r)
+  {
+    m_os<<"-- Parameter need context\n";
+    m_os<<c.get_label().getName()<<" OBJECT IDENTIFIER ::= "<<std::endl;
+    gen_oid(r);
+    m_os<<std::endl;
+  } else
+  {
+    m_os<<"\n-- Abstract parameter-- "<<c.get_label().getName()<<"\n--"<<std::endl;
+  }
+})
+
+GDMO_TPLT_DECL(notification_tplt,
+{
+  ADT::GDMO::notification_registered *r = c.get_registered();
+  m_os<<c.get_label().getName()<<" OBJECT IDENTIFIER ::= "<<std::endl;
+  gen_oid(r);
+  m_os<<std::endl;
+  m_os<<"\n"<<std::endl;
+
+})
+
diff --git a/libgen/gdmo_genasn1.h b/libgen/gdmo_genasn1.h
new file mode 100644 (file)
index 0000000..bb0054a
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef GDMO_GENASN1_H
+#define GDMO_GENASN1_H
+
+class genasn1 : public GDMO::generator
+{
+  public:    
+    genasn1(GDMO::generator::moduleList &l);
+
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) ;
+
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+    void gen_module_start(ADT::GDMO::module &m);
+    void gen_module_end(ADT::GDMO::module &m)  ;
+  protected:
+    void gen_oid(ADT::GDMO::construct *c);
+  protected:
+    std::fstream m_os;
+};
+#endif /*GDMO_GENASN1_H*/
diff --git a/libgen/gdmo_gencpp.cpp b/libgen/gdmo_gencpp.cpp
new file mode 100644 (file)
index 0000000..e18fa47
--- /dev/null
@@ -0,0 +1,256 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_gencpp.h"
+
+using namespace ADT::GDMO;
+#include "gdmo_gencpp_mo.h"
+#include "gdmo_gencpp_attribute.h"
+#include "gdmo_gencpp_action.h"
+    
+gencpp::gencpp(GDMO::generator::moduleList &l)
+  : GDMO::generator(l)
+  , m_cmodule(NULL)   
+{
+  std::cout<<"Start generator cpp"<<std::endl; 
+}
+
+void 
+gencpp::gen_module_start(ADT::GDMO::module &m)
+{
+  m_cmodule = &m;
+
+}
+
+void 
+gencpp::gen_module_end(ADT::GDMO::module &m)
+{
+  m_cmodule = NULL;  
+}
+    
+ADT::Adt *
+gencpp::lookup(const std::string &s)
+{
+  return m_cmodule->lookup(s);  
+}
+    
+void 
+gencpp::gen_oid(ADT::GDMO::construct *r)
+{
+  if (r)
+  {
+     ADT::Container::iterator i = r->begin();
+     m_os<<" {";
+     for ( ; i != r->end()
+           ; ++i)
+     {
+         ADT::GDMO::oid_item *oidi = dynamic_cast<ADT::GDMO::oid_item *>(&(*i));
+         m_os<<" "<<oidi->get_name();
+     } 
+     m_os<<"}";
+  }
+}
+
+void 
+gencpp::open(ADT::GDMO::templates &t)
+{
+  struct stat st;
+  std::string fn;
+  std::string tname = t.get_label().getName();
+  // Check if gLog directory exists
+#ifdef WIN32
+#define MKDIR(x)      mkdir(x);
+#else
+#define  MKDIR(x)     mkdir(x,0777);
+#endif
+
+#define CHECK_CREATE(x) \
+  if (stat (x,ast) == -1) \
+    MKDIR(x)
+
+#define TPLT(cls)  \
+    case  ADT::Adt::cls ## _tpltClass:  \
+      { MKDIR(#cls); fn.append(#cls) ; fn+="/";} break;
+  switch (t.getClass())
+  {
+    TPLT(mo)
+    TPLT(action)
+    TPLT(notification)
+    TPLT(parameter)
+    TPLT(attribute)
+    default:
+     ;   
+  };
+#undef TPLT
+#undef MKDIR
+#undef CHECK_CREATE
+
+  fn.append(tname);
+  fn += ".cpp";
+  if (m_os.is_open())
+      m_os.close();
+  m_os.open(fn.c_str(),std::fstream::out);   
+}
+
+void 
+gencpp::close()
+{
+  m_os.close();    
+}
+
+#undef GDMO_TPLT_DECL
+#define GDMO_TPLT_DECL(cls,parent)  \
+void gencpp::gen_## cls( ADT::GDMO::cls &c)      \
+{                                      \
+   parent                              \
+}
+
+/**
+ *
+ */ 
+
+/**
+ * Generate code for managed Object
+ */ 
+GDMO_TPLT_DECL(mo_tplt,
+{
+  std::string mo = c.get_label().getName();
+  open(c);
+
+  gencpp_mo gen(m_os,*this,c);
+  gen.generate();
+  close();
+})
+
+/**
+ *
+ *
+ */ 
+void gencpp::gen_mo_package(mo_tplt &mo,ADT::GDMO::package_tplt &t)
+{
+  std::string cname = mo.get_label().getName();
+  ADT::GDMO::pkg_attributes  *attrs   = t.get_attributes();
+  if (attrs)
+  {
+    ADT::Container::iterator i = attrs->begin();
+    for ( ; i != attrs->end()
+          ; ++i)
+    {
+       ADT::GDMO::label   *l = dynamic_cast<ADT::GDMO::label *>(&(*i));
+       if (l)
+       {
+         m_os<<"\n//\n";  
+         m_os<<"void\n"<<cname<<"::"<<l->getName()<<"_set(const "<<l->getName()<<" &e)\n";
+         m_os<<"{}\n";  
+         m_os<<"\n//\nvoid\n"<<cname<<"::"<<l->getName()<<"_get("<<l->getName()<<" &e)\n";
+         m_os<<"{}\n";  
+         // resolve and call gen
+       } else
+       {
+         m_os<<"//"<<"_xxx();\n";
+       }
+    } 
+  }
+    
+}
+
+GDMO_TPLT_DECL(package_tplt,
+{
+  // std::cout<<"gencpp::package_tplt "<<c.get_label().getName()<<std::endl;
+})
+
+GDMO_TPLT_DECL(name_binding_tplt,{})
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(attribute_tplt,
+{
+  open(c);
+  gencpp_attribute gen(m_os,*this,c);
+  gen.generate();
+  close();
+})
+
+GDMO_TPLT_DECL(attribute_group_tplt,{})
+GDMO_TPLT_DECL(behaviour_tplt,{})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(action_tplt,
+{
+  std::string  act = c.get_label().getName(); 
+  ADT::GDMO::action_registered *r = c.get_registered();
+  ADT::GDMO::action_with_reply           *reply = c.get_with_reply();
+  ADT::GDMO::action_with_information     *info  = c.get_with_information();
+  open(c);
+  gencpp_action gen(m_os,*this,c);
+  gen.generate();
+  close();
+})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(parameter_tplt,
+{
+  ADT::GDMO::parameter_registered *r = c.get_registered();
+  open(c);
+  if (r)
+  {
+    m_os<<"-- Parameter need context\n";
+    m_os<<"-- "<<c.get_label().getName()<<" cxt ::= {"<<std::endl;
+  } else
+  {
+    m_os<<"\n-- Abstract parameter-- "<<c.get_label().getName()<<"\n--"<<std::endl;
+  }
+  close();
+})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(notification_tplt,
+{
+  std::string evt = c.get_label().getName();
+  ADT::GDMO::notification_registered *r = c.get_registered();
+  ADT::GDMO::notification_with_reply           *reply = c.get_with_reply();
+  ADT::GDMO::notification_with_information     *info  = c.get_with_information();
+  open(c);
+  m_os<<"#ifndef "<<evt<<"_H__\n";
+  m_os<<"#define "<<evt<<"_H__\n";
+  m_os<<"\n\nstruct "<<c.get_label().getName()<<" : public ICMIP_EVENT\n{\n"<<std::endl;
+  
+  m_os<<"\tpublic:\n"<<std::endl;
+  m_os<<"\t\t"<<evt<<"();\n";
+  m_os<<"\t\t"<<evt<<"(const "<<evt<<" &e);\n";
+  m_os<<"\t\t~"<<evt<<"();\n";
+  m_os<<"\n\t\t"<<evt<<"* Create();\n";
+  m_os<<"\n\t\t"<<evt<<"* clone();\n";
+  //gen_oid(r);
+  m_os<<"\t\tvoid encode(asn1::context &ctx);\n";
+  m_os<<"\t\tint  decode(asn1::context &ctx);\n";
+  m_os<<std::endl;
+  m_os<<"\tprotected:\n"<<std::endl;
+  //
+  if (reply)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(reply->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_reply;\n";
+    }
+  }
+  //
+  if (info)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(info->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_info;\n";
+    }
+  }
+  m_os<<"};\n"<<std::endl;
+  m_os<<"#endif\n";
+  close();
+})
+
diff --git a/libgen/gdmo_gencpp.h b/libgen/gdmo_gencpp.h
new file mode 100644 (file)
index 0000000..c78fb29
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef GDMO_GENCPP_H
+#define GDMO_GENCPP_H
+
+class gencpp : public GDMO::generator
+{
+  public:    
+    gencpp(GDMO::generator::moduleList &l);
+
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) ;
+
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+    void gen_module_start(ADT::GDMO::module &m);
+    void gen_module_end(ADT::GDMO::module &m)  ;
+    void gen_oid(ADT::GDMO::construct *c);
+  protected:
+    void open(ADT::GDMO::templates &t);
+    void close();
+  public:
+    void gen_mo_package(ADT::GDMO::mo_tplt &mo,ADT::GDMO::package_tplt &t);
+    ADT::Adt  *lookup(const std::string &s);
+  protected:
+    std::fstream       m_os;
+    ADT::GDMO::module *m_cmodule;
+};
+#endif /*GDMO_GENASN1_H*/
diff --git a/libgen/gdmo_gencpp_action.cpp b/libgen/gdmo_gencpp_action.cpp
new file mode 100644 (file)
index 0000000..77efe40
--- /dev/null
@@ -0,0 +1,91 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_gencpp.h"
+
+using namespace ADT;
+using namespace ADT::GDMO;
+#include "gdmo_gencpp_action.h"
+
+
+/**
+ *
+ */ 
+gencpp_action::
+gencpp_action(std::ostream &os,gencpp &g,action_tplt &t)
+  : m_gen(g), m_tplt(t), m_os(os)
+{
+}
+
+void 
+gencpp_action::generate()
+{
+  gen_includes();
+  gen_ctors();  
+  gen_codec();  
+}
+
+
+/**
+ *
+ */ 
+void 
+gencpp_action::gen_includes()
+{
+  std::string mo = m_tplt.get_label().getName();
+  //mo_derived_from     *derived  = m_tplt.get_derived_from();
+  m_os<<"// Autamtic generated do not edit\n";
+  m_os<<"#include <iostream>\n";
+  m_os<<"#include <string>\n";
+  m_os<<"#include <map>\n";
+  // Need to include asn1 definitions 
+  m_os<<"#include \"asn1/asn1_rose.h\"\n";
+  m_os<<"#include \"cmip/CMIP_1.h\"\n";
+  
+  // Try to use a template visitor for this purpose
+  // Need to include parameters attributes actions notifications 
+  m_os<<"#include \"action/"<<mo<<".h\"\n";
+}
+
+void
+gencpp_action::gen_ctors()
+{
+  std::string mo = m_tplt.get_label().getName();
+  m_os<<"\n"<<mo<<"::"<<mo<<"()\n";
+  m_os<<"{\n";
+  m_os<<"\t// Initialize Id;\n";
+  m_os<<"}\n";
+  m_os<<"\n"<<mo<<"::"<<mo<<"(const "<<mo<<" &c)\n";
+  m_os<<"{\n";
+  m_os<<"}\n";
+  m_os<<"\n"<<mo<<"::~"<<mo<<"()\n{}\n";
+  // Create is a virtual method that needs to be implemented
+  m_os<<"\n"<<mo<<" *\n"<<mo<<"::"<<"Create()\n";
+  m_os<<"{\n";
+  m_os<<"\treturn new "<<mo<<"();\n";
+  m_os<<"}\n";
+}
+
+void
+gencpp_action::gen_codec()
+{
+  std::string mo = m_tplt.get_label().getName();
+  m_os<<"\nvoid\n"<<mo<<"::"<<"encode_Value(asn1::context &ctx)\n";
+  m_os<<"{\n";
+  m_os<<"\t// What do I encode? m_reply or m_info when both are present? \n";
+  m_os<<"}\n";
+  m_os<<"\n//\n";
+  m_os<<"int\n"<<mo<<"::"<<"decode_Value(asn1::context &ctx)\n";
+  m_os<<"{\n";
+  m_os<<"\t// What do I decode, \n";
+  m_os<<"\treturn asn1::ok;\n";
+  m_os<<"}\n";
+}
+
+void
+gencpp_action::gen_equal()
+{
+}
+
diff --git a/libgen/gdmo_gencpp_action.h b/libgen/gdmo_gencpp_action.h
new file mode 100644 (file)
index 0000000..186c654
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef GDMO_GENCPP_ACTION_H
+#define GDMO_GENCPP_ACTION_H
+
+/**
+ *
+ */ 
+class gencpp_action
+{
+  public: 
+    typedef void (gencpp_action::*fct_gen_ptr)(decl &l);
+
+    gencpp_action(std::ostream &os,gencpp &g,action_tplt &t);
+   
+    void generate();
+
+    action_tplt & tplt()
+    {
+      return m_tplt;  
+    }
+    gencpp & gen()
+    {
+      return m_gen;  
+    }
+  protected:
+    void gen_includes();
+    void gen_ctors();
+    void gen_codec();
+    void gen_equal();
+    void gen_attribute_include(decl &attr);
+    // setter / getter for attribute
+  protected:
+    std::string    m_inc_path;
+    gencpp         &m_gen;
+    action_tplt    &m_tplt;
+    std::ostream   &m_os;
+}
+;
+#endif /*GDMO_GENCPP_ATTRIBUTE_H*/
diff --git a/libgen/gdmo_gencpp_attribute.cpp b/libgen/gdmo_gencpp_attribute.cpp
new file mode 100644 (file)
index 0000000..7bf719f
--- /dev/null
@@ -0,0 +1,135 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_gencpp.h"
+
+using namespace ADT;
+using namespace ADT::GDMO;
+using namespace ::GDMO;
+#include "gdmo_gencpp_attribute.h"
+
+
+/**
+ *
+ */ 
+gencpp_attribute::
+gencpp_attribute(std::ostream &os,gencpp &g,attribute_tplt &t)
+  : m_gen(g), m_tplt(t), m_os(os)
+{
+}
+
+void 
+gencpp_attribute::generate()
+{
+  gen_includes();
+  gen_ctors();  
+  gen_codec();  
+}
+
+
+/**
+ *
+ */ 
+void 
+gencpp_attribute::gen_includes()
+{
+  std::string            mo      = m_tplt.get_label().getName();
+  ADT::GDMO::attr_syntax *syntax = m_tplt.get_syntax();
+  ADT::GDMO::typeref     *ref    = NULL;
+  ADT::GDMO::label       *lbl    = NULL;
+  
+  if (syntax)
+  {
+    ref = dynamic_cast<ADT::GDMO::typeref *>(syntax->get_decl());
+    lbl = dynamic_cast<ADT::GDMO::label *>(syntax->get_decl());
+  }
+    
+  //mo_derived_from     *derived  = m_tplt.get_derived_from();
+  m_os<<"// Autamtic generated do not edit\n";
+  m_os<<"#include <iostream>\n";
+  m_os<<"#include <string>\n";
+  m_os<<"#include <map>\n";
+  // Need to include asn1 definitions 
+  //m_os<<"#include \"asn1/asn1_rose.h\"\n";
+  //m_os<<"#include \"cmip/CMIP_1.h\"\n";
+  m_os<<"#include \"CMIP_1.h\"\n";
+  m_os<<"#include \"ACSE_1.h\"\n";
+  if (ref)
+  {
+    m_os<<"#include \""<<::GDMO::cpp(ref->get_asn1_module())<<".h\"\n";  
+    m_os<<"using namespace "<<::GDMO::cpp(ref->get_asn1_module())<<";\n";  
+  }
+  if (lbl)
+  {
+    // Missing syntax ...  
+    m_os<<"#include \"attribute/"<<lbl->getName()<<".h\"\n";  
+  }
+  // Try to use a template visitor for this purpose
+  // Need to include parameters attributes actions notifications 
+  m_os<<"#include \"attribute/"<<mo<<".h\"\n";
+}
+
+void
+gencpp_attribute::gen_ctors()
+{
+  std::string                 mo = m_tplt.get_label().getName();
+  ADT::GDMO::attr_registered *r  = m_tplt.get_registered();
+  m_os<<"\n"<<cpp(mo)<<"::"<<cpp(mo)<<"()\n{\n";
+  m_os<<"\t// Init _id with ";
+  m_gen.gen_oid(r);
+  m_os<<"\n}\n";
+  m_os<<"\n"<<cpp(mo)<<"::"<<cpp(mo)<<"(const "<<mo<<" &c)\n{}\n";
+  m_os<<"\n"<<cpp(mo)<<"::~"<<cpp(mo)<<"()\n{}\n";
+}
+
+void
+gencpp_attribute::gen_codec()
+{
+  std::string            mo      = m_tplt.get_label().getName();
+  ADT::GDMO::attr_syntax *syntax = m_tplt.get_syntax();
+  ADT::GDMO::typeref     *ref    = NULL;
+  
+  if (syntax)
+  {
+    ref = dynamic_cast<ADT::GDMO::typeref *>(syntax->get_decl());
+  }
+    
+  // encode function
+  m_os<<"\nvoid "<<mo<<"::encode_Value(asn1::context &ctx)\n{\n";
+  if (ref)
+  {
+    m_os<<"\tm_syntax.encode(ctx);\n";  
+  }
+  m_os<<"\n}\n";
+  // decode function
+  m_os<<"\nint "<<mo<<"::decode_Value(asn1::context &ctx)\n{\n";
+  if (ref)
+  {
+    m_os<<"\treturn m_syntax.decode(ctx);\n";  
+  }
+  m_os<<"\n}\n";
+
+  // setter and getter
+  if (ref)
+  {
+    // setter  
+    m_os<<"\tvoid "<<mo<<"::set_Value(const ";  
+    m_os<<::GDMO::cpp(ref->get_asn1_module())<<"::"<<ref->getName()<<" &v)\n{\n";
+    m_os<<"\tm_syntax = v;\n";
+    m_os<<"\n}\n";
+    // getter
+    m_os<<"\tint "<<mo<<"::get_Value(";  
+    m_os<<::GDMO::cpp(ref->get_asn1_module())<<"::"<<ref->getName()<<" &v)\n{\n";
+    m_os<<"\tv = m_syntax;\n";
+    m_os<<"\treturn true;\n";
+    m_os<<"\n}\n";
+  }
+}
+
+void
+gencpp_attribute::gen_equal()
+{
+}
+
diff --git a/libgen/gdmo_gencpp_attribute.h b/libgen/gdmo_gencpp_attribute.h
new file mode 100644 (file)
index 0000000..9547695
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef GDMO_GENCPP_ATTRIBUTE_H
+#define GDMO_GENCPP_ATTRIBUTE_H
+
+/**
+ *
+ */ 
+class gencpp_attribute
+{
+  public: 
+    typedef void (gencpp_attribute::*fct_gen_ptr)(decl &l);
+
+    gencpp_attribute(std::ostream &os,gencpp &g,attribute_tplt &t);
+   
+    void generate();
+
+    attribute_tplt & tplt()
+    {
+      return m_tplt;  
+    }
+    gencpp & gen()
+    {
+      return m_gen;  
+    }
+  protected:
+    void gen_includes();
+    void gen_ctors();
+    void gen_codec();
+    void gen_equal();
+    void gen_attribute_include(decl &attr);
+    // setter / getter for attribute
+  protected:
+    std::string    m_inc_path;
+    gencpp         &m_gen;
+    attribute_tplt &m_tplt;
+    std::ostream   &m_os;
+}
+;
+#endif /*GDMO_GENCPP_ATTRIBUTE_H*/
diff --git a/libgen/gdmo_gencpp_mo.cpp b/libgen/gdmo_gencpp_mo.cpp
new file mode 100644 (file)
index 0000000..8e88c4c
--- /dev/null
@@ -0,0 +1,328 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_gencpp.h"
+
+using namespace ADT;
+using namespace ADT::GDMO;
+#include "gdmo_gencpp_mo.h"
+
+/**
+ *
+ */ 
+struct do_package
+{
+  do_package(std::ostream &os,gencpp_mo &c)
+      : m_os(os),m_gen(c)
+  {
+  }
+  void  operator()(Adt &adt)
+  {
+       package_tplt *p = dynamic_cast<package_tplt *>(&(adt));
+       label        *l = dynamic_cast<label *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         ADT::Adt *d = m_gen.gen().lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           m_gen.gen_mo_package(m_gen.tplt(),*rp);
+         }
+       }
+       if (p)
+       {
+         m_gen.gen_mo_package(m_gen.tplt(),*p);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+};
+
+/**
+ *
+ */ 
+struct do_attribute
+{
+  do_attribute(std::ostream &os,gencpp_mo &c)
+      : m_os(os),m_gen(c)
+  {
+  }
+  void operator()(Adt &adt)
+  {
+       //label        *l = dynamic_cast<label *>(&(adt));
+       pkg_attribute  *l = dynamic_cast<pkg_attribute *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         m_gen.gen_attribute(*l);
+       } else
+       {
+           std::cerr<<"gencpp_mo::do_attribute failed dync"<<std::endl;  
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+};
+/**
+ *
+ */ 
+struct do_generic_package
+{
+  do_generic_package(std::ostream &os,gencpp_mo &c,gencpp_mo::fct_gen_ptr f)
+      : m_os(os),m_gen(c),m_fct(f)
+  {
+  }
+  void  operator()(Adt &adt)
+  {
+       package_tplt *p = dynamic_cast<package_tplt *>(&(adt));
+       label        *l = dynamic_cast<label *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         ADT::Adt *d = m_gen.gen().lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           m_gen.generic_package(*rp,m_fct);
+         }
+       }
+       if (p)
+       {
+         m_gen.generic_package(*p,m_fct);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+  gencpp_mo::fct_gen_ptr m_fct;   
+};
+
+
+/**
+ *
+ */ 
+struct do_generic_attribute
+{
+  do_generic_attribute( std::ostream &os
+                     , gencpp_mo &c,gencpp_mo::fct_gen_ptr f)
+      : m_os(os),m_gen(c),m_fct(f)
+  {
+  }
+  void operator()(Adt &adt)
+  {
+       decl       *l = dynamic_cast<decl *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         //m_gen.gen_attribute(*l);
+         (m_gen.*m_fct)(*l);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+  gencpp_mo::fct_gen_ptr m_fct;
+};
+
+
+/**
+ *
+ */ 
+gencpp_mo::
+gencpp_mo(std::ostream &os,gencpp &g,mo_tplt &t)
+  : m_gen(g), m_tplt(t), m_os(os)
+{
+}
+
+void 
+gencpp_mo::generate()
+{
+  mo_characterized_by *pkgs     = m_tplt.get_characterized_by();
+  mo_cond_packages    *cpkgs    = m_tplt.get_cond_packages();
+  gen_includes();
+  gen_ctors();  
+  if (pkgs)
+  {
+      std::for_each( pkgs->begin()
+                   , pkgs->end()
+                   , do_package(m_os,*this));  
+  }
+  if (cpkgs)
+  {
+      std::for_each( cpkgs->begin()
+                   , cpkgs->end()
+                   , do_package(m_os,*this));  
+  }
+}
+/**
+ *
+ *
+ */ 
+void gencpp_mo::gen_mo_package(mo_tplt &mo,ADT::GDMO::package_tplt &t)
+{
+  std::string cname = mo.get_label().getName();
+  ADT::GDMO::pkg_attributes  *attrs   = t.get_attributes();
+  if (attrs)
+  {
+    std::for_each( attrs->begin()
+                 , attrs->end()
+                 , do_attribute(m_os,*this)); 
+  }
+  m_os<<"// What about notifications and actions\n";
+    
+}
+
+void gencpp_mo::generic_package(ADT::GDMO::package_tplt &t,fct_gen_ptr f)
+{
+  std::string cname = m_tplt.get_label().getName();
+  ADT::GDMO::pkg_attributes    *attrs   = t.get_attributes();
+  ADT::GDMO::pkg_notifications *notif   = t.get_notifications();
+  ADT::GDMO::pkg_actions       *acts    = t.get_actions();
+  if (attrs)
+  {
+    m_inc_path ="attribute/";  
+    std::for_each( attrs->begin()
+                 , attrs->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+  if (notif)
+  {
+    m_inc_path ="notification/";  
+    std::for_each( notif->begin()
+                 , notif->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+  if (acts)
+  {
+    m_inc_path ="action/";  
+    std::for_each( acts->begin()
+                 , acts->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+    
+}
+
+
+/**
+ *
+ */ 
+void 
+gencpp_mo::gen_includes()
+{
+  std::string mo = m_tplt.get_label().getName();
+  mo_characterized_by *pkgs     = m_tplt.get_characterized_by();
+  mo_cond_packages    *cpkgs    = m_tplt.get_cond_packages();
+  mo_derived_from     *derived  = m_tplt.get_derived_from();
+  m_os<<"// Autamtic generated do not edit\n";
+  m_os<<"#include <iostream>\n";
+  m_os<<"#include <string>\n";
+  m_os<<"#include <map>\n";
+  // Need to include asn1 definitions 
+  m_os<<"#include \"managed_object.h\"\n";
+  m_os<<"#include \"CMIP_1.h\"\n";
+  m_os<<"#include \"ACSE_1.h\"\n";
+  m_os<<"#include \"Attribute_ASN1Module.h\"\n";
+  //
+  m_os<<"using namespace CMIP_1;\n";
+  m_os<<"using namespace Attribute_ASN1Module;\n";
+  // Try to use a template visitor for this purpose
+  if (pkgs)
+  {
+      std::for_each( pkgs->begin()
+                   , pkgs->end()
+                   , do_generic_package(m_os,*this,&gencpp_mo::gen_attribute_include));  
+  }
+  if (cpkgs)
+  {
+      std::for_each( cpkgs->begin()
+                   , cpkgs->end()
+                   , do_generic_package(m_os,*this,&gencpp_mo::gen_attribute_include));  
+  }
+  // Need to include parameters attributes actions notifications 
+  m_os<<"#include \"mo/"<<mo<<".h\"\n";
+}
+
+void
+gencpp_mo::gen_ctors()
+{
+  std::string mo = m_tplt.get_label().getName();
+  m_os<<"\n"<<mo<<"::"<<mo<<"()\n{}\n";
+  m_os<<"\n"<<mo<<"::"<<mo<<"(const "<<mo<<" &c)\n{}\n";
+  m_os<<"\n"<<mo<<"::~"<<mo<<"()\n{}\n";
+}
+
+void
+gencpp_mo::gen_codec()
+{
+}
+
+void
+gencpp_mo::gen_equal()
+{
+}
+
+// setter / getter for attribute
+void
+gencpp_mo::gen_attr(attribute_tplt &attr)
+{
+}
+
+/**
+ * type must change to something like
+ * pkg_attribute
+ *   that contains label and properties
+ */ 
+void
+gencpp_mo::gen_attribute(pkg_attribute &l)
+{
+  std::string cname = m_tplt.get_label().getName();
+#if 1
+  property *get_r = l.get_get_replace();
+  property *add_r = l.get_add_remove();
+#endif
+
+  m_os<<"\n// Setter and Getter "<<l.getName()<<" Missing properties\n";
+  if ( get_r)
+  {
+    if (get_r->flags.replace)
+    {
+      m_os<<"void\n"<<cname<<"::"<<l.getName()<<"_set(const "<<l.getName()<<" &e)\n";
+      m_os<<"{}\n"; 
+    }
+    if (get_r->flags.get)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_get("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+  }
+#if 1
+  if (add_r)
+  {
+    m_os<<"// ADD REMOVE "<<std::endl;
+    if (add_r->flags.add)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_add("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+    if (add_r->flags.remove)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_remove("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+  }
+#endif
+}
+/**
+ * type must change to something like
+ * pkg_attribute
+ *   that contains label and properties
+ */ 
+void
+gencpp_mo::gen_attribute_include(decl &l)
+{
+  if (pkg_attribute *pa = dynamic_cast<pkg_attribute *>(&l) )
+  {
+    m_os<<"#include \""<<m_inc_path<<l.getName()<<".h\"\n";
+  } else
+  {
+    m_os<<"#include \""<<m_inc_path<<l.getName()<<".h\" // decl\n";
+  }
+}
diff --git a/libgen/gdmo_gencpp_mo.h b/libgen/gdmo_gencpp_mo.h
new file mode 100644 (file)
index 0000000..872e3fb
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef GDMO_GENCPP_MO_H
+#define GDMO_GENCPP_MO_H
+
+/**
+ *
+ */ 
+class gencpp_mo
+{
+  public: 
+    typedef void (gencpp_mo::*fct_gen_ptr)(decl &l);
+
+    gencpp_mo(std::ostream &os,gencpp &g,mo_tplt &t);
+    void generate();
+
+    mo_tplt & tplt()
+    {
+      return m_tplt;  
+    }
+    gencpp & gen()
+    {
+      return m_gen;  
+    }
+    void gen_mo_package(mo_tplt &mo,ADT::GDMO::package_tplt &t);
+    void generic_package(ADT::GDMO::package_tplt &t,fct_gen_ptr);
+    void gen_attribute(pkg_attribute &attr);
+  protected:
+    void gen_includes();
+    void gen_ctors();
+    void gen_codec();
+    void gen_equal();
+    void gen_attribute_include(decl &attr);
+    // setter / getter for attribute
+    void gen_attr(attribute_tplt &attr);
+  protected:
+    std::string  m_inc_path;
+    gencpp       &m_gen;
+    mo_tplt      &m_tplt;
+    std::ostream &m_os;
+}
+;
+#endif /*GDMO_GENCPP_MO_H*/
diff --git a/libgen/gdmo_gencpp_parameter.cpp b/libgen/gdmo_gencpp_parameter.cpp
new file mode 100644 (file)
index 0000000..b608a71
--- /dev/null
@@ -0,0 +1,321 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_gencpp.h"
+
+using namespace ADT;
+using namespace ADT::GDMO;
+#include "gdmo_gencpp_mo.h"
+
+/**
+ *
+ */ 
+struct do_package
+{
+  do_package(std::ostream &os,gencpp_mo &c)
+      : m_os(os),m_gen(c)
+  {
+  }
+  void  operator()(Adt &adt)
+  {
+       package_tplt *p = dynamic_cast<package_tplt *>(&(adt));
+       label        *l = dynamic_cast<label *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         ADT::Adt *d = m_gen.gen().lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           m_gen.gen_mo_package(m_gen.tplt(),*rp);
+         }
+       }
+       if (p)
+       {
+         m_gen.gen_mo_package(m_gen.tplt(),*p);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+};
+
+/**
+ *
+ */ 
+struct do_attribute
+{
+  do_attribute(std::ostream &os,gencpp_mo &c)
+      : m_os(os),m_gen(c)
+  {
+  }
+  void operator()(Adt &adt)
+  {
+       //label        *l = dynamic_cast<label *>(&(adt));
+       pkg_attribute  *l = dynamic_cast<pkg_attribute *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         m_gen.gen_attribute(*l);
+       } else
+       {
+           std::cerr<<"gencpp_mo::do_attribute failed dync"<<std::endl;  
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+};
+/**
+ *
+ */ 
+struct do_generic_package
+{
+  do_generic_package(std::ostream &os,gencpp_mo &c,gencpp_mo::fct_gen_ptr f)
+      : m_os(os),m_gen(c),m_fct(f)
+  {
+  }
+  void  operator()(Adt &adt)
+  {
+       package_tplt *p = dynamic_cast<package_tplt *>(&(adt));
+       label        *l = dynamic_cast<label *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         ADT::Adt *d = m_gen.gen().lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           m_gen.generic_package(*rp,m_fct);
+         }
+       }
+       if (p)
+       {
+         m_gen.generic_package(*p,m_fct);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+  gencpp_mo::fct_gen_ptr m_fct;   
+};
+
+
+/**
+ *
+ */ 
+struct do_generic_attribute
+{
+  do_generic_attribute( std::ostream &os
+                     , gencpp_mo &c,gencpp_mo::fct_gen_ptr f)
+      : m_os(os),m_gen(c),m_fct(f)
+  {
+  }
+  void operator()(Adt &adt)
+  {
+       decl       *l = dynamic_cast<decl *>(&(adt));
+       if (l)
+       {
+         // resolve and call gen
+         //m_gen.gen_attribute(*l);
+         (m_gen.*m_fct)(*l);
+       }
+  }
+  gencpp_mo    &m_gen;
+  std::ostream &m_os;
+  gencpp_mo::fct_gen_ptr m_fct;
+};
+
+
+/**
+ *
+ */ 
+gencpp_mo::
+gencpp_mo(std::ostream &os,gencpp &g,mo_tplt &t)
+  : m_gen(g), m_tplt(t), m_os(os)
+{
+}
+
+void 
+gencpp_mo::generate()
+{
+  mo_characterized_by *pkgs     = m_tplt.get_characterized_by();
+  mo_cond_packages    *cpkgs    = m_tplt.get_cond_packages();
+  gen_includes();
+  gen_ctors();  
+  if (pkgs)
+  {
+      std::for_each( pkgs->begin()
+                   , pkgs->end()
+                   , do_package(m_os,*this));  
+  }
+  if (cpkgs)
+  {
+      std::for_each( cpkgs->begin()
+                   , cpkgs->end()
+                   , do_package(m_os,*this));  
+  }
+}
+/**
+ *
+ *
+ */ 
+void gencpp_mo::gen_mo_package(mo_tplt &mo,ADT::GDMO::package_tplt &t)
+{
+  std::string cname = mo.get_label().getName();
+  ADT::GDMO::pkg_attributes  *attrs   = t.get_attributes();
+  if (attrs)
+  {
+    std::for_each( attrs->begin()
+                 , attrs->end()
+                 , do_attribute(m_os,*this)); 
+  }
+  m_os<<"// What about notifications and actions\n";
+    
+}
+
+void gencpp_mo::generic_package(ADT::GDMO::package_tplt &t,fct_gen_ptr f)
+{
+  std::string cname = m_tplt.get_label().getName();
+  ADT::GDMO::pkg_attributes    *attrs   = t.get_attributes();
+  ADT::GDMO::pkg_notifications *notif   = t.get_notifications();
+  ADT::GDMO::pkg_actions       *acts    = t.get_actions();
+  if (attrs)
+  {
+    m_inc_path ="attribute/";  
+    std::for_each( attrs->begin()
+                 , attrs->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+  if (notif)
+  {
+    m_inc_path ="notification/";  
+    std::for_each( notif->begin()
+                 , notif->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+  if (acts)
+  {
+    m_inc_path ="action/";  
+    std::for_each( acts->begin()
+                 , acts->end()
+                 , do_generic_attribute(m_os,*this,f)); 
+  }
+    
+}
+
+
+/**
+ *
+ */ 
+void 
+gencpp_mo::gen_includes()
+{
+  std::string mo = m_tplt.get_label().getName();
+  mo_characterized_by *pkgs     = m_tplt.get_characterized_by();
+  mo_cond_packages    *cpkgs    = m_tplt.get_cond_packages();
+  mo_derived_from     *derived  = m_tplt.get_derived_from();
+  m_os<<"// Autamtic generated do not edit\n";
+  m_os<<"#include <iostream>\n";
+  m_os<<"#include <string>\n";
+  m_os<<"#include <map>\n";
+  // Need to include asn1 definitions 
+  // Try to use a template visitor for this purpose
+  if (pkgs)
+  {
+      std::for_each( pkgs->begin()
+                   , pkgs->end()
+                   , do_generic_package(m_os,*this,&gencpp_mo::gen_attribute_include));  
+  }
+  if (cpkgs)
+  {
+      std::for_each( cpkgs->begin()
+                   , cpkgs->end()
+                   , do_generic_package(m_os,*this,&gencpp_mo::gen_attribute_include));  
+  }
+  // Need to include parameters attributes actions notifications 
+  m_os<<"#include \"mo/"<<mo<<".h\"\n";
+}
+
+void
+gencpp_mo::gen_ctors()
+{
+  std::string mo = m_tplt.get_label().getName();
+  m_os<<"\n"<<mo<<"::"<<mo<<"()\n{}\n";
+  m_os<<"\n"<<mo<<"::"<<mo<<"(const "<<mo<<" &c)\n{}\n";
+  m_os<<"\n"<<mo<<"::~"<<mo<<"()\n{}\n";
+}
+
+void
+gencpp_mo::gen_codec()
+{
+}
+
+void
+gencpp_mo::gen_equal()
+{
+}
+
+// setter / getter for attribute
+void
+gencpp_mo::gen_attr(attribute_tplt &attr)
+{
+}
+
+/**
+ * type must change to something like
+ * pkg_attribute
+ *   that contains label and properties
+ */ 
+void
+gencpp_mo::gen_attribute(pkg_attribute &l)
+{
+  std::string cname = m_tplt.get_label().getName();
+#if 1
+  property *get_r = l.get_get_replace();
+  property *add_r = l.get_add_remove();
+#endif
+
+  m_os<<"\n// Setter and Getter "<<l.getName()<<" Missing properties\n";
+  if ( get_r)
+  {
+    if (get_r->flags.replace)
+    {
+      m_os<<"void\n"<<cname<<"::"<<l.getName()<<"_set(const "<<l.getName()<<" &e)\n";
+      m_os<<"{}\n"; 
+    }
+    if (get_r->flags.get)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_get("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+  }
+#if 1
+  if (add_r)
+  {
+    m_os<<"// ADD REMOVE "<<std::endl;
+    if (add_r->flags.add)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_add("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+    if (add_r->flags.remove)
+    {
+      m_os<<"\n//\nvoid\n"<<cname<<"::"<<l.getName()<<"_remove("<<l.getName()<<" &e)\n";
+      m_os<<"{}\n";
+    }
+  }
+#endif
+}
+/**
+ * type must change to something like
+ * pkg_attribute
+ *   that contains label and properties
+ */ 
+void
+gencpp_mo::gen_attribute_include(decl &l)
+{
+  if (pkg_attribute *pa = dynamic_cast<pkg_attribute *>(&l) )
+  {
+    m_os<<"#include \""<<m_inc_path<<l.getName()<<".h\"\n";
+  } else
+  {
+    m_os<<"#include \""<<m_inc_path<<l.getName()<<".h\" // decl\n";
+  }
+}
diff --git a/libgen/gdmo_gencpp_parameter.h b/libgen/gdmo_gencpp_parameter.h
new file mode 100644 (file)
index 0000000..872e3fb
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef GDMO_GENCPP_MO_H
+#define GDMO_GENCPP_MO_H
+
+/**
+ *
+ */ 
+class gencpp_mo
+{
+  public: 
+    typedef void (gencpp_mo::*fct_gen_ptr)(decl &l);
+
+    gencpp_mo(std::ostream &os,gencpp &g,mo_tplt &t);
+    void generate();
+
+    mo_tplt & tplt()
+    {
+      return m_tplt;  
+    }
+    gencpp & gen()
+    {
+      return m_gen;  
+    }
+    void gen_mo_package(mo_tplt &mo,ADT::GDMO::package_tplt &t);
+    void generic_package(ADT::GDMO::package_tplt &t,fct_gen_ptr);
+    void gen_attribute(pkg_attribute &attr);
+  protected:
+    void gen_includes();
+    void gen_ctors();
+    void gen_codec();
+    void gen_equal();
+    void gen_attribute_include(decl &attr);
+    // setter / getter for attribute
+    void gen_attr(attribute_tplt &attr);
+  protected:
+    std::string  m_inc_path;
+    gencpp       &m_gen;
+    mo_tplt      &m_tplt;
+    std::ostream &m_os;
+}
+;
+#endif /*GDMO_GENCPP_MO_H*/
diff --git a/libgen/gdmo_generator.cpp b/libgen/gdmo_generator.cpp
new file mode 100644 (file)
index 0000000..7f41670
--- /dev/null
@@ -0,0 +1,83 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <list>
+#include <map>
+#include <stack>
+#include <algorithm>
+
+#include "gdmo_config.h"
+#include "ADT/Adt.h"
+//#include "ast_builder.h"
+#include "gdmo_generator.h"
+
+
+static
+char  lop_substitute(char c)
+{
+        return (c == '-')?'_':c;
+}
+
+
+namespace GDMO
+{
+
+
+std::string cpp(const std::string &s)
+{
+  std::string tmp;
+  tmp.resize(s.size());
+  std::transform(s.begin(),s.end(),tmp.begin(),lop_substitute);
+  return tmp;
+}
+
+
+generator::generator(moduleList &m)
+  : m_modules(m)  
+{
+}
+
+void generator::foreach_template(ADT::GDMO::module &m)
+{
+  ADT::Module::iterator tit;  
+  for ( tit = m.begin()
+        ; tit != m.end()
+        ; ++tit)
+  {
+    switch((*tit).getClass())
+    {
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+      case ADT::Adt::cls##Class: \
+      { this->gen_##cls(dynamic_cast<ADT::GDMO::cls &>((*tit)));}; break;
+
+#define GDMO_CONSTRUCT_DECL(cls,p)
+#include  "ADT/gdmo/Gdmo.h.inc"      
+      default:
+      ;
+    }
+  }
+}
+
+
+void generator::foreach_module()
+{
+  moduleIterator mit;
+  for ( mit = m_modules.begin();
+        mit != m_modules.end();
+        ++mit)
+  {
+    this->gen_module_start(*(*mit));
+    this->foreach_template(*(*mit));
+    this->gen_module_end(*(*mit));
+  }
+}
+
+
+void 
+generator::generate()
+{
+  foreach_module();
+}
+
+}
diff --git a/libgen/gdmo_generator.h b/libgen/gdmo_generator.h
new file mode 100644 (file)
index 0000000..36ee075
--- /dev/null
@@ -0,0 +1,82 @@
+#ifndef GDMO_GENERATOR_H
+#define GDMO_GENERATOR_H
+
+namespace GDMO
+{
+
+#define config_params(eType)   \
+    eType(vf,asn1,bool,false)  \
+    eType(vs,debug,int,0)      \
+
+
+
+/**
+ * Config for the generators 
+ */ 
+struct config
+{
+#define members(v,nm,T,d) \
+  T m_ ## nm ;
+#define vf
+#define vs ,    
+
+#define init_const(v,nm,T,d) \
+  v m_## nm (d) 
+
+  config()
+   : config_params( init_const )
+  {
+  };
+
+  config_params(members)
+};
+
+#undef init_const
+#undef members
+#undef vf
+#undef vs
+
+/**
+ * Generic function used to converte model string into cpp strings
+ */ 
+std::string cpp(const std::string &s);
+
+/**
+ * Generic interface for code generators
+ */ 
+class generator
+{
+  public:
+    typedef std::list<ADT::GDMO::module *> moduleList;
+    typedef moduleList::iterator           moduleIterator;
+
+    generator(moduleList &_m);
+
+    virtual void generate();
+
+    void set_config(const config &c) 
+    {
+      m_config = c;  
+    }
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) {};
+
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+    virtual void gen_module_start(ADT::GDMO::module &m) {};
+    virtual void gen_module_end(ADT::GDMO::module &m) {} ;
+  protected:  
+    void foreach_template(ADT::GDMO::module &m);
+
+    void foreach_module();
+
+  protected:
+    config      m_config;
+    moduleList &m_modules;
+};
+
+}
+#endif /*GDMO_GENERATOR_H*/
diff --git a/libgen/gdmo_genhpp.cpp b/libgen/gdmo_genhpp.cpp
new file mode 100644 (file)
index 0000000..6ae6b28
--- /dev/null
@@ -0,0 +1,449 @@
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_generator.h"
+#include "gdmo_genhpp.h"
+
+using namespace ADT::GDMO;
+using namespace ::GDMO;
+
+genhpp::genhpp(GDMO::generator::moduleList &l)
+  : GDMO::generator(l)
+  , m_cmodule(NULL)   
+{
+  std::cout<<"Start generator hpp"<<std::endl; 
+}
+
+void 
+genhpp::gen_module_start(ADT::GDMO::module &m)
+{
+  m_cmodule = &m;
+
+}
+
+void 
+genhpp::gen_module_end(ADT::GDMO::module &m)
+{
+  m_cmodule = NULL;  
+}
+    
+void 
+genhpp::gen_oid(ADT::GDMO::construct *r)
+{
+  if (r)
+  {
+     ADT::Container::iterator i = r->begin();
+     m_os<<" {";
+     for ( ; i != r->end()
+           ; ++i)
+     {
+         ADT::GDMO::oid_item *oidi = dynamic_cast<ADT::GDMO::oid_item *>(&(*i));
+         m_os<<" "<<oidi->get_name();
+     } 
+     m_os<<"}";
+  }
+}
+
+void 
+genhpp::open(ADT::GDMO::templates &t)
+{
+  struct stat st;
+  std::string fn;
+  std::string tname = t.get_label().getName();
+  // Check if gLog directory exists
+#ifdef WIN32
+#define MKDIR(x)      mkdir(x);
+#else
+#define  MKDIR(x)     mkdir(x,0777);
+#endif
+
+#define CHECK_CREATE(x) \
+  if (stat (x,ast) == -1) \
+    MKDIR(x)
+
+#define TPLT(cls)  \
+    case  ADT::Adt::cls ## _tpltClass:  \
+      { MKDIR(#cls); fn.append(#cls) ; fn+="/";} break;
+  switch (t.getClass())
+  {
+    TPLT(mo)
+    TPLT(action)
+    TPLT(notification)
+    TPLT(parameter)
+    TPLT(attribute)
+    default:
+     ;   
+  };
+#undef TPLT
+#undef MKDIR
+#undef CHECK_CREATE
+
+  fn.append(tname);
+  fn += ".h";
+  if (m_os.is_open())
+      m_os.close();
+  m_os.open(fn.c_str(),std::fstream::out);   
+}
+
+void 
+genhpp::close()
+{
+  m_os.close();    
+}
+
+#undef GDMO_TPLT_DECL
+#define GDMO_TPLT_DECL(cls,parent)  \
+void genhpp::gen_## cls( ADT::GDMO::cls &c)      \
+{                                      \
+   parent                              \
+}
+
+/**
+ *
+ */ 
+
+/**
+ * Generate code for managed Object
+ */ 
+GDMO_TPLT_DECL(mo_tplt,
+{
+  std::string mo = c.get_label().getName();
+  open(c);
+  ADT::GDMO::mo_characterized_by *pkgs     = c.get_characterized_by();
+  ADT::GDMO::mo_cond_packages    *cpkgs    = c.get_cond_packages();
+  ADT::GDMO::mo_derived_from     *derived  = c.get_derived_from();
+  m_os<<"#ifndef "<<mo<<"_H__\n";
+  m_os<<"#define "<<mo<<"_H__\n";
+  if (! mo.compare("top"))
+  {
+    m_os<<"\n\nstruct "<<mo<<": public GDMO::managed_object \n{"<<std::endl;
+  } else
+  {
+    m_os<<"\n\nstruct "<<cpp(mo)<<": ";
+    ADT::Container::iterator i = derived->begin();
+    //m_os<<" {";
+    for ( ; i != derived->end()
+          ; ++i)
+    {
+       ADT::GDMO::label *oidi = dynamic_cast<ADT::GDMO::label *>(&(*i));
+       if (i != derived->begin())
+         m_os<<" , ";
+       m_os<<"public "<<cpp(oidi->get_name());
+    } 
+    m_os<<"\n{"<<std::endl;
+    m_os<<std::endl;
+  }
+  m_os<<"\tpublic:\n";
+  m_os<<"\t\t"<<cpp(mo)<<"();\n";
+  m_os<<"\t\t"<<cpp(mo)<<"(const "<<cpp(mo)<<" &c);\n";
+  m_os<<"\t\t~"<<cpp(mo)<<"();\n";
+  // OK go through packages now
+  //
+  if (pkgs)
+  {
+    ADT::Container::iterator i = pkgs->begin();
+    m_os<<"\t//packages size="<<pkgs->size()<<std::endl;
+    for ( ; i != pkgs->end()
+          ; ++i)
+    {
+       ADT::GDMO::package_tplt *p = dynamic_cast<ADT::GDMO::package_tplt *>(&(*i));
+       ADT::GDMO::label   *l = dynamic_cast<ADT::GDMO::label *>(&(*i));
+       if (l)
+       {
+         m_os<<"\t//package_label "<<l->getName()<<"\n";
+         // resolve and call gen
+         ADT::Adt *d = m_cmodule->lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           gen_mo_package(*rp);
+         }
+       }
+       if (p)
+       {
+         m_os<<"\t// call gen_mo_package "<<std::endl;
+         gen_mo_package(*p);
+       }
+    } 
+  }
+  // cond  
+  if (cpkgs)
+  {
+    ADT::Container::iterator i = cpkgs->begin();
+    m_os<<"\t//conditional packages size="<<cpkgs->size()<<std::endl;
+    for ( ; i != cpkgs->end()
+          ; ++i)
+    {
+       ADT::GDMO::package_tplt *p = dynamic_cast<ADT::GDMO::package_tplt *>(&(*i));
+       ADT::GDMO::label   *l = dynamic_cast<ADT::GDMO::label *>(&(*i));
+       if (l)
+       {
+         m_os<<"\t//package_label "<<l->getName()<<"\n";
+         // resolve and call gen
+         ADT::Adt *d = m_cmodule->lookup(l->getName());
+         if (package_tplt *rp = dynamic_cast<package_tplt *>(d))
+         {
+           gen_mo_package(*rp);
+         }
+       }
+       if (p)
+       {
+         m_os<<"\t// call gen_mo_package "<<p->get_label().getName()<<std::endl;
+         gen_mo_package(*p);
+       }
+    } 
+  }
+  m_os<<"};\n";
+  m_os<<"#endif\n";
+  close();
+})
+
+/**
+ *
+ */ 
+void genhpp::gen_mo_package(ADT::GDMO::package_tplt &t)
+{
+  ADT::GDMO::pkg_attributes  *attrs   = t.get_attributes();
+  if (attrs)
+  {
+    ADT::Container::iterator i = attrs->begin();
+    for ( ; i != attrs->end()
+          ; ++i)
+    {
+       ADT::GDMO::pkg_attribute *l = dynamic_cast<ADT::GDMO::pkg_attribute *>(&(*i));
+       if (l)
+       {
+         property *get_r = l->get_get_replace();
+          property *add_r = l->get_add_remove();
+         m_os<<"\t//\n";  
+         if (get_r)
+         {
+           if (get_r->flags.replace)
+           {
+             m_os<<"\tvoid "<<cpp(l->getName())<<"_set(const ";
+             m_os<<cpp(l->getName())<<" &e);\n";
+           }
+           if (get_r->flags.get)
+           {
+             m_os<<"\tvoid "<<cpp(l->getName())<<"_get(";
+             m_os<<cpp(l->getName())<<" &e);\n";
+           }
+         }
+         if (add_r)
+         {
+           if (add_r->flags.add)
+           {
+               m_os<<"\tvoid "<<cpp(l->getName())<<"_add(const ";
+               m_os<<cpp(l->getName())<<" &e);\n";
+           }
+           if (add_r->flags.remove)
+           {
+             m_os<<"\tvoid "<<cpp(l->getName())<<"_remove(";
+             m_os<<cpp(l->getName())<<" &e);\n";
+           }
+        }
+        // resolve and call gen
+       } else
+       {
+         m_os<<"\t//"<<"_xxx();\n";
+       }
+    } 
+  }
+    
+}
+
+GDMO_TPLT_DECL(package_tplt,
+{
+  // std::cout<<"genhpp::package_tplt "<<c.get_label().getName()<<std::endl;
+})
+
+GDMO_TPLT_DECL(name_binding_tplt,{})
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(attribute_tplt,
+{
+  std::string inherit("CMIP_1::ICMIP_ATTRIBUTE");
+  std::string attr = cpp(c.get_label().getName());
+  ADT::GDMO::attr_registered *r = c.get_registered();
+  ADT::GDMO::attr_syntax *syntax = c.get_syntax();
+  open(c);
+  m_os<<"#ifndef "<<attr<<"_H__\n";
+  m_os<<"#define "<<attr<<"_H__\n";
+  
+  //
+  m_os<<"\n\nstruct "<<cpp(attr)<<" :";
+  if (syntax)
+  {
+    if (ADT::GDMO::label *ref = dynamic_cast<ADT::GDMO::label *>(syntax->get_decl()))
+    {
+      inherit = cpp(ref->getName());
+    } 
+  } 
+  m_os<<"public "<<inherit<<"\n{\n"<<std::endl;
+  m_os<<"\tpublic:\n";
+  m_os<<"\t\t"<<attr<<"();\n";
+  m_os<<"\t\t"<<attr<<"(const "<<attr<<" &c);\n";
+  m_os<<"\t\t~"<<attr<<"();\n";
+  m_os<<"\n";
+  if (!r)
+  {
+    m_os<<"\n//\n// Abstract "<<attr<<" CMIP_1::CMIP_ATTRIBUTE "<<std::endl;
+    m_os<<"//"<<std::endl;
+  }
+  // NEEDED for ICMIP_ATTRIBUTE
+  m_os<<"\t\t"<<attr<<" *Create();\n";
+  //m_os<<"\t\tbool"<<" idEquals(CMIP_1::AttributeId &i);\n";
+  m_os<<"\t\tvoid"<<" encode_Value(asn1::context &c);\n";
+  m_os<<"\t\tint "<<" decode_Value(asn1::context &c);\n";
+  if (syntax)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(syntax->get_decl()))
+    {
+      //m_os<<"\t\t//\n";
+      m_os<<"\t\t//\n";
+      m_os<<"\t\tvoid set_Value(const ";
+      //m_os<<::GDMO::cpp(ref->get_asn1_module())<<"::"<<ref->getName()<<" &v);\n";
+      m_os<<ref->getName()<<" &v);\n";
+      m_os<<"\t\t//\n";
+      m_os<<"\t\tint get_Value(";
+      //m_os<<::GDMO::cpp(ref->get_asn1_module())<<"::"<<ref->getName()<<" &v);\n";
+      m_os<<ref->getName()<<" &v);\n";
+      m_os<<"\tprotected:\n";
+      m_os<<"\t\t"<<ref->getName()<<"\tm_syntax;\n";
+    }
+  }
+  m_os<<"\t//";
+  gen_oid(r);
+  m_os<<std::endl;
+  m_os<<"};\n"<<std::endl;
+  m_os<<"#endif\n";
+  close();
+})
+
+GDMO_TPLT_DECL(attribute_group_tplt,{})
+GDMO_TPLT_DECL(behaviour_tplt,{})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(action_tplt,
+{
+  std::string  act = c.get_label().getName(); 
+  ADT::GDMO::action_registered *r = c.get_registered();
+  ADT::GDMO::action_with_reply           *reply = c.get_with_reply();
+  ADT::GDMO::action_with_information     *info  = c.get_with_information();
+  open(c);
+  m_os<<"#ifndef "<<act<<"_H__\n";
+  m_os<<"#define "<<act<<"_H__\n";
+  
+  m_os<<"\n\nstruct "<<act;
+  m_os<<": public CMIP_1::ICMIP_ACTION\n{"<<std::endl;
+  m_os<<std::endl;
+  
+  m_os<<"\tpublic:\n";
+  m_os<<"\t\t"<<act<<"();\n";
+  m_os<<"\t\t"<<act<<"(const "<<act<<" &c);\n";
+  m_os<<"\t\t~"<<act<<"();\n";
+  m_os<<std::endl;
+  m_os<<"\t\t"<<act<<"* Create();\n";
+  m_os<<std::endl;
+  m_os<<"\t\tvoid encode_Value"<<"(asn1::context &ctx);\n";
+  m_os<<"//"<<std::endl;
+  m_os<<"\t\tint  decode_Value"<<"(asn1::context &ctx);\n";
+  if (r)
+  {
+    m_os<<"\t// OID m_oid ";
+    gen_oid(r);
+    m_os<<"\n";
+  } else
+  {
+    m_os<<"\n-- Abstract Action \n-- "<<c.get_label().getName()<<"\n--"<<std::endl;
+  }
+  //
+  if (reply)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(reply->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_reply;\n";
+    }
+  }
+  //
+  if (info)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(info->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_info;\n";
+    }
+  }
+  //
+  m_os<<std::endl;
+  m_os<<"};\n"<<std::endl;
+  m_os<<"#endif\n";
+  close();
+})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(parameter_tplt,
+{
+  ADT::GDMO::parameter_registered *r = c.get_registered();
+  open(c);
+  if (r)
+  {
+    m_os<<"-- Parameter need context\n";
+    m_os<<"-- "<<c.get_label().getName()<<" cxt ::= {"<<std::endl;
+  } else
+  {
+    m_os<<"\n-- Abstract parameter-- "<<c.get_label().getName()<<"\n--"<<std::endl;
+  }
+  close();
+})
+
+/**
+ *
+ */ 
+GDMO_TPLT_DECL(notification_tplt,
+{
+  std::string evt = c.get_label().getName();
+  ADT::GDMO::notification_registered *r = c.get_registered();
+  ADT::GDMO::notification_with_reply           *reply = c.get_with_reply();
+  ADT::GDMO::notification_with_information     *info  = c.get_with_information();
+  open(c);
+  m_os<<"#ifndef "<<evt<<"_H__\n";
+  m_os<<"#define "<<evt<<"_H__\n";
+  m_os<<"\n\nstruct "<<c.get_label().getName();
+  m_os<<" : public CMIP_1::ICMIP_EVENT\n{\n"<<std::endl;
+  
+  m_os<<"\tpublic:\n"<<std::endl;
+  m_os<<"\t\t"<<evt<<"();\n";
+  m_os<<"\t\t"<<evt<<"(const "<<evt<<" &e);\n";
+  m_os<<"\t\t~"<<evt<<"();\n";
+  m_os<<"\n\t\t"<<evt<<"* Create();\n";
+  m_os<<"\n\t\t"<<evt<<"* clone();\n";
+  //gen_oid(r);
+  m_os<<"\t\tvoid encode(asn1::context &ctx);\n";
+  m_os<<"\t\tint  decode(asn1::context &ctx);\n";
+  m_os<<std::endl;
+  m_os<<"\tprotected:\n"<<std::endl;
+  //
+  if (reply)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(reply->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_reply;\n";
+    }
+  }
+  //
+  if (info)
+  {
+    if (ADT::GDMO::typeref *ref = dynamic_cast<ADT::GDMO::typeref *>(info->get_decl()))
+    {
+      m_os<<"\t"<<ref->getName()<<"\tm_info;\n";
+    }
+  }
+  m_os<<"};\n"<<std::endl;
+  m_os<<"#endif\n";
+  close();
+})
+
diff --git a/libgen/gdmo_genhpp.h b/libgen/gdmo_genhpp.h
new file mode 100644 (file)
index 0000000..5daa6a3
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef GDMO_GENHPP_H
+#define GDMO_GENHPP_H
+
+class genhpp : public GDMO::generator
+{
+  public:    
+    genhpp(GDMO::generator::moduleList &l);
+
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) ;
+
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+    virtual void gen_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+    void gen_module_start(ADT::GDMO::module &m);
+    void gen_module_end(ADT::GDMO::module &m)  ;
+  protected:
+    void gen_oid(ADT::GDMO::construct *c);
+    void open(ADT::GDMO::templates &t);
+    void close();
+
+    void gen_mo_package(ADT::GDMO::package_tplt &t);  
+  protected:
+    std::fstream       m_os;
+    ADT::GDMO::module *m_cmodule;
+};
+#endif /*GDMO_GENASN1_H*/
diff --git a/libparser/CMakeLists.txt b/libparser/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0864b9f
--- /dev/null
@@ -0,0 +1,29 @@
+PROJECT(gdmoparser)
+
+
+IF (NOT CMAKE_BUILD_TYPE)
+  SET(CMAKE_BUILD_TYPE Debug)
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+# Only for Linux not MAC
+IF(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG ")
+ELSE(APPLE)
+  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -std=c++0x")
+  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++0x")
+ENDIF(APPLE)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
+INCLUDE(${rules_SOURCE_DIR}/flex.cmake)
+
+
+LEXGEN(gdmo.l   lgdmo.cpp)
+BISONGEN(gdmo.y pgdmo.cpp cpp)
+
+ADD_LIBRARY(gdmoparser 
+    lgdmo.cpp 
+    pgdmo.cpp
+    parser_listener.cpp
+    parser.cpp
+    ) 
diff --git a/libparser/gdmo.l b/libparser/gdmo.l
new file mode 100644 (file)
index 0000000..edd8705
--- /dev/null
@@ -0,0 +1,264 @@
+%{
+#include "gdmo_config.h"
+
+#include "ADT/Adt.h"
+#include "gdmo_parser.h"
+
+typedef  union
+{
+  ADT::GDMO::templates *tplt;
+  ADT::GDMO::decl      *decl;
+  ADT::GDMO::label     *label;
+  ADT::Container       *container;
+  ADT::GDMO::construct *construct;
+  long                  number; 
+} YYSTYPE;
+#define YYSTYPE_IS_DECLARED 1
+#define YY_DECL int gdmo_lex(YYSTYPE *yylval)
+
+#include "pgdmo.hpp"
+
+long
+gdmo_atoi(const char *ptr);
+
+void gdmo_error(const char *s) {
+  printf("Failed line: %d %s\n",yylineno,s);
+#if 1
+  exit(1);
+#endif
+};
+
+#define TOK(x) {return x;}
+#define REF_TF        { yylval->reference = new asn1::typefield_reference(yytext);return T_TYPEFIELDREFERENCE;}
+#define REF_VF        { yylval->reference = new asn1::valuefield_reference(yytext);return T_VALUEFIELDREFERENCE;}
+#define DECL_TOK(x)   { yylval->decl = ADT::GDMO::decl::Create(yytext);return x;}
+#define NUM_TOK(x)    { \
+                        yylval->number = gdmo_atoi(yytext);\
+                        return x;\
+                      }
+#define NUMV_TOK(x,val)    { \
+                        yylval->number = val;\
+                        return x;\
+                      }
+#define DOUBLE_TOK(x) { *yylval = new asn1::node(yytext);return x;}
+%}
+
+%option prefix="gdmo_"
+%option stack
+%option yylineno
+/*
+%option noyywrap stack
+%option debug
+*/
+%pointer
+
+%x dash_comment
+%x idash_comment
+%x cpp_comment
+%x quote
+%x opaque
+%x encoding_control
+%x with_syntax
+%x object
+
+/* */
+Digits          [0-9]+
+NDigits         -{Digits}
+
+Real            [-+]?[0-9]+[.]?([eE][-+]?)?[0-9]+
+
+
+
+Char            ([^\t\"\'\\])
+Char_Literal    "'"({Char}|\")"'"
+String_Literal  \"({Char}|"'")*\"
+HString         '[0-9A-F \r\r\v\f\n]+'H
+BString         '[01 \t\r\v\f\n]+'B
+Identifier      [a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)*
+CapitalReference    [A-Z][A-Z0-9]*([-][A-Z0-9]+)*
+TypeReference       [A-Z][A-Za-z0-9]*([-][A-Za-z0-9]+)*
+
+
+nl  [\r\n\v\f]
+
+wsp [\t\r\v\f\n ]
+
+%%
+
+-{3,}/[\r\n] /* Comment */
+
+<INITIAL,with_syntax>-- yy_push_state(dash_comment);
+<INITIAL,object>-- yy_push_state(dash_comment);
+
+<dash_comment>{ /* Very special to treat rules for dash_comment rules */
+    {nl}    yy_pop_state();
+    --      yy_pop_state();
+    -       /* single dash */
+    [^\r\v\f\n-]+ /* do nothing */
+}
+
+<INITIAL,cpp_comment>"/*" yy_push_state(cpp_comment);
+
+<cpp_comment>{
+    [^*/<]  /* skip */
+    "*/"    yy_pop_state();
+    .       /* skip */
+}
+
+ADD-REMOVE          TOK(T_ADD_REMOVE)
+ADD                 TOK(T_ADD)
+ACTIONS                                TOK(T_ACTIONS)
+ACTION                         TOK(T_ACTION)
+ACTION-INFO                    TOK(T_ACTION_INFO)
+ACTION-REPLY           TOK(T_ACTION_REPLY)
+AND                                TOK(T_AND)
+AS                                 TOK(T_AS)
+ATTRIBUTES                     TOK(T_ATTRIBUTES)
+ATTRIBUTE                      TOK(T_ATTRIBUTE)
+BEHAVIOUR                      TOK(T_BEHAVIOUR)
+BINDING                                TOK(T_BINDING)
+BY                                 TOK(T_BY)
+CHARACTERIZED          TOK(T_CHARACTERIZED)
+CLASS                          TOK(T_CLASS)
+COLON                          TOK(T_COLON)
+COMMA                          TOK(T_COMMA)
+CONDITIONAL                    TOK(T_CONDITIONAL)
+CONFIRMED                      TOK(T_CONFIRMED)
+CONTEXT                                TOK(T_CONTEXT)
+CREATE                         TOK(T_CREATE)
+DEFAULT                                TOK(T_DEFAULT)
+DEFINED                                TOK(T_DEFINED)
+DELETES-CONTAINED-OBJECTS                              TOK(T_DELETES_CONTAINED_OBJECTS)
+DELETE                         TOK(T_DELETE)
+DERIVATION          TOK(T_DERIVATION)
+DERIVED                                TOK(T_DERIVED)
+DESCRIPTION                    TOK(T_DESCRIPTION)
+DOT                                TOK(T_DOT)
+ELEMENTS                       TOK(T_ELEMENTS)
+EQUALITY                       TOK(T_EQUALITY)
+EVENT-INFO                     TOK(T_EVENT_INFO)
+EVENT-REPLY                    TOK(T_EVENT_REPLY)
+EXCLAMATION                    TOK(T_EXCLAMATION)
+FIXED                          TOK(T_FIXED)
+FOR                                TOK(T_FOR)
+FROM                           TOK(T_FROM)
+GET-REPLACE         TOK(T_GET_REPLACE)
+GET                 TOK(T_GET)
+GROUPS                         TOK(T_GROUPS)
+GROUP                          TOK(T_GROUP)
+IDS                                TOK(T_IDS)
+IF                                 TOK(T_IF)
+INFORMATION                    TOK(T_INFORMATION)
+INITIAL                                TOK(T_INITIAL)
+LBRACET                                TOK(T_LBRACET)
+LPARENT                                TOK(T_LPARENT)
+MANAGED                                TOK(T_MANAGED)
+MATCHES                                TOK(T_MATCHES)
+MODE                           TOK(T_MODE)
+NAMED                          TOK(T_NAMED)
+NAME                           TOK(T_NAME)
+NO-MODIFY           TOK(T_NO_MODIFY)
+NOTIFICATIONS          TOK(T_NOTIFICATIONS)
+NOTIFICATION           TOK(T_NOTIFICATION)
+OBJECT                         TOK(T_OBJECT)
+ONLY-IF-NO-CONTAINED-OBJECTS                           TOK(T_ONLY_IF_NO_CONTAINED_OBJECTS)
+ORDERING                       TOK(T_ORDERING)
+PACKAGE                                TOK(T_PACKAGE)
+PACKAGES                       TOK(T_PACKAGES)
+PARAMETER                      TOK(T_PARAMETER)
+PARAMETERS                     TOK(T_PARAMETERS)
+PERMITTED                  TOK(T_PERMITTED)
+PRESENT                                TOK(T_PRESENT)
+RBRACET                                TOK(T_RBRACET)
+REGISTERED                     TOK(T_REGISTERED)
+REMOVE              TOK(T_REMOVE)
+REPLACE-WITH-DEFAULT   TOK(T_REPLACE_WITH_DEFAULT)
+REPLY                          TOK(T_REPLY)
+REQUIRED                       TOK(T_REQUIRED)
+RPARENT                                TOK(T_RPARENT)
+RULE                TOK(T_RULE)
+SET-BY-CREATE          TOK(T_SET_BY_CREATE)
+SET-COMPARISON         TOK(T_SET_COMPARISON)
+SET-INTERSECTION       TOK(T_SET_INTERSECTION)
+SIMILICON                      TOK(T_SIMILICON)
+SPECIFIC-ERROR         TOK(T_SPECIFIC_ERROR)
+{String_Literal}       DECL_TOK(T_STRING)
+SUBCLASSES                     TOK(T_SUBCLASSES)
+SUBORDINATE                    TOK(T_SUBORDINATE)
+SUBSTRINGS                     TOK(T_SUBSTRINGS)
+SUPERIOR                       TOK(T_SUPERIOR)
+SYNTAX                                 TOK(T_SYNTAX )
+VALUES                         TOK(T_VALUES)
+VALUE                          TOK(T_VALUE)
+WITH                           TOK(T_WITH)
+WITH-AUTOMATIC-INSTANCE-NAMING         TOK(T_WITH_AUTOMATIC_INSTANCE_NAMING)
+WITH-REFERENCE-OBJECT                          TOK(T_WITH_REFERENCE_OBJECT)
+
+itu-t              NUMV_TOK(T_NUM,0)
+iso                NUMV_TOK(T_NUM,1)
+joint-iso-itu-t    NUMV_TOK(T_NUM,2)
+
+{Identifier}        DECL_TOK(T_IDENTIFIER)
+{TypeReference}     DECL_TOK(T_TYPEREF)
+{Digits}            NUM_TOK(T_NUM)
+
+
+"!"             TOK(T_EXCLAMATION)
+"{"             TOK(T_LBRACET)
+"}"             TOK(T_RBRACET)
+")"             TOK(T_RPARENT)
+"("             TOK(T_LPARENT)
+"."             TOK(T_DOT)
+","             TOK(T_COMMA)
+";"             TOK(T_SIMILICON)
+":"             TOK(T_COLON)
+{wsp}+  /* ignore whitespace*/
+
+
+%%
+
+void enable_with_syntax()
+{
+    yy_push_state(with_syntax);
+}
+void disable_with_syntax()
+{
+    yy_pop_state();
+}
+
+void enable_encoding_control()
+{
+    yy_push_state(encoding_control);
+}
+
+void enable_object()
+{
+    yy_push_state(object);
+}
+void disable_object()
+{
+    yy_pop_state();
+}
+
+
+
+long
+gdmo_atoi(const char *ptr)
+{
+    long ret;
+    return atol(ptr);
+}
+
+double
+gdmo_atod(const char *ptr)
+{
+    double ret;
+    errno = 0;
+    ret = strtod(ptr,0);
+    if (errno)
+    {
+        std::cerr<<" Value out range : "<<ptr<<std::endl;
+    }
+
+    return ret;
+}
diff --git a/libparser/gdmo.y b/libparser/gdmo.y
new file mode 100644 (file)
index 0000000..f69d73d
--- /dev/null
@@ -0,0 +1,1300 @@
+%{
+
+#include "gdmo_config.h"
+//#include "gdmo_node.h"
+#include "ADT/Adt.h"
+#include "gdmo_parser.h"
+
+
+typedef  union
+{
+  ADT::GDMO::templates *tplt;
+  ADT::GDMO::decl      *decl;
+  ADT::GDMO::label     *label;
+  ADT::Container       *container;
+  ADT::GDMO::construct *construct;
+  long                  number;
+} YYSTYPE;
+#define YYSTYPE_IS_DECLARED 1
+
+
+
+extern  void gdmo_error( const char *s);
+extern  int  gdmo_lex(YYSTYPE *yylval);
+
+extern void enable_with_syntax(void);
+extern void enable_encoding_control(void);
+extern void disable_with_syntax(void);
+extern void enable_object(void);
+extern void disable_object(void);
+
+
+#if defined(__GNUC__) && defined(DEBUG)
+#define GDMO_LOG_DEBUG(fmt,args...) do {\
+  char _lbuf[256]; \
+  if ( gLog.is_open()) { \
+    gLog<<"DEBUG "; \
+    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \
+    sprintf(_lbuf," (gdmo.y : %d)\n",__LINE__); gLog<<_lbuf; \
+  } else { \
+  fprintf(stderr,"gdmo_parser (DEBUG): "); \
+  fprintf(stderr,fmt,##args);\
+  fprintf(stderr," (gdmo.y : %d)\n",__LINE__);\
+  } \
+} while (0)
+
+#define GDMO_LOG_WARNING(fmt,args...) do {\
+  char _lbuf[256]; \
+  if (gLog.is_open()) { \
+    gLog<<"WARN "; \
+    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \
+    sprintf(_lbuf," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \
+  }  \
+  fprintf(stderr,"asn1_parser (WARNI): "); \
+  fprintf(stderr,fmt,##args);\
+  fprintf(stderr," (asn1.y : %d)\n",__LINE__);\
+} while (0)
+
+#define GDMO_LOG_ERROR(fmt,args...) do {\
+  char _lbuf[256]; \
+  if ( gLog.is_open()) { \
+    gLog<<"ERROR "; \
+    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \
+    sprintf(_lbuf," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \
+  }  \
+  fprintf(stderr,"asn1_parser (ERROR): "); \
+  fprintf(stderr,fmt,##args);\
+  fprintf(stderr," (asn1.y : %d)\n",__LINE__);\
+} while (0)
+
+static std::fstream gLog;
+
+void open_log(const std::string &fn)
+{
+  struct stat st;
+  // Check if gLog directory exists
+  if (stat("log",&st) == -1 ) {
+#ifdef WIN32
+      mkdir("log");
+#else
+      mkdir("log",0777);
+#endif
+  }
+  // 
+  std::string _logname("log/"); _logname.append(fn); _logname.append(".parser.log");
+  if ( gLog.is_open())
+  {
+    std::cerr<<"open_log "<<fn<<" already open ?"<<std::endl;
+  } else  
+  {
+    gLog.open(_logname.c_str(),std::fstream::out | std::fstream::app);
+  }
+}
+
+void close_log()
+{
+  if ( gLog.is_open() )
+    gLog.close();
+}
+#else
+  static std::fstream gLog;
+  void open_log(const std::string &fn)
+  {
+  }
+  void close_log() {
+  }
+  static inline void GDMO_LOG_DEBUG(const char *fmt,...) {(void)fmt;};
+  static inline void GDMO_LOG_ERROR(const char *fmt,...) {(void)fmt;};
+  static inline void GDMO_LOG_WARNING(const char *fmt,...) {(void)fmt;};
+#endif
+
+
+%}
+
+%token T_ACTION
+%token T_ACTIONS
+%token T_ACTION_INFO
+%token T_ACTION_REPLY
+%token T_ADD
+%token T_ADD_REMOVE
+%token T_AND
+%token T_AS
+%token T_ATTRIBUTE
+%token T_ATTRIBUTES
+%token T_BEHAVIOUR
+%token T_BINDING
+%token T_BY
+%token T_CHARACTERIZED
+%token T_CLASS
+%token T_COLON
+%token T_COMMA
+%token T_CONDITIONAL
+%token T_CONFIRMED
+%token T_CONTEXT
+%token T_CREATE
+%token T_DEFAULT
+%token T_DEFINED
+%token T_DELETE
+%token T_DELETES_CONTAINED_OBJECTS
+%token T_DERIVATION 
+%token T_DERIVED
+%token T_DESCRIPTION
+%token T_DOT
+%token T_ELEMENTS
+%token T_EQUALITY
+%token T_EVENT_INFO
+%token T_EVENT_REPLY
+%token T_EXCLAMATION
+%token T_FIXED
+%token T_FOR
+%token T_FROM
+%token T_GET
+%token T_GET_REPLACE
+%token T_GROUP
+%token T_GROUPS
+%token <decl>T_IDENTIFIER
+%token T_IDS
+%token T_IF
+%token T_INFORMATION
+%token T_INITIAL
+%token T_LBRACET
+%token T_LPARENT
+%token T_MANAGED
+%token T_MATCHES
+%token T_MODE
+%token T_NAMED
+%token T_NAME
+%token T_NO_MODIFY
+%token T_NOTIFICATION
+%token T_NOTIFICATIONS
+%token <number>T_NUM
+%token T_OBJECT
+%token T_ONLY_IF_NO_CONTAINED_OBJECTS
+%token T_ORDERING
+%token T_PACKAGE
+%token T_PACKAGES
+%token T_PARAMETER
+%token T_PARAMETERS
+%token T_PERMITTED
+%token T_PRESENT
+%token T_RBRACET
+%token T_REGISTERED
+%token T_REMOVE
+%token T_REPLACE
+%token T_REPLACE_WITH_DEFAULT
+%token T_REPLY
+%token T_REQUIRED
+%token T_RPARENT
+%token T_RULE
+%token T_SET_BY_CREATE
+%token T_SET_COMPARISON
+%token T_SET_INTERSECTION
+%token T_SIMILICON
+%token T_SPECIFIC_ERROR
+%token <decl>T_STRING
+%token T_SUBCLASSES
+%token T_SUBORDINATE
+%token T_SUBSTRINGS
+%token T_SUPERIOR
+%token T_SYNTAX 
+%token <decl>T_TYPEREF 
+%token T_VALUE
+%token T_VALUES
+%token T_WITH
+%token T_WITH_AUTOMATIC_INSTANCE_NAMING
+%token T_WITH_REFERENCE_OBJECT
+
+
+%type <label> label alias_label
+%type <tplt>  mo_header package_header behaviour_header attribute_header nbind_header
+%type <tplt>  attribute_group_header parameter_header action_header notification_header
+%type <decl>  mo_pkg_label present_if pkg_attribute pkg_notif_item
+%type <decl>  mo_conditional_pkg oid_item pkg_proplist_typeref pkg_action
+%type <container>  labels nbind_opt_params pkg_attributes 
+%type <container>  attr_parameters notif_parameters
+%type <container>  nbind_params mo_pkg_labels  pkg_notification pkg_actions
+%type <container>  mo_conditional_pkgs oid_list oid registered_as
+
+%type <construct>  pkg_opt_attrs
+%type <construct> mo_opt_characterized mo_opt_derived mo_opt_conditional_pkg
+
+%name-prefix="gdmo_"
+%pure_parser
+
+
+%%
+
+definition_files: template
+  {
+    GDMO_LOG_DEBUG("definition_files: got definition" );
+  }
+  |   definition_files template
+  {
+    GDMO_LOG_DEBUG("definition_files: got 1 definition" );
+  }
+;
+
+labels: label
+  {
+    $$ = ADT::Container::Create("");
+    $$->add($1);
+  }
+  | labels T_COMMA label
+  {
+
+    $1->add($3);
+  }
+;
+
+label: T_IDENTIFIER
+  {
+    GDMO_LOG_DEBUG("label: %s ",$1->get_name().c_str() );
+    $$ = GDMO::parser::instance()->create_label("",$<decl>1->get_name());
+    delete( $1 );
+  }
+  | alias_label
+;
+
+alias_label: T_STRING T_COLON label
+  {
+    GDMO_LOG_DEBUG("alias: label");
+    $3->set_scope($<decl>1->get_name());
+    delete( $1 );
+    $$ = $3;
+  }
+;
+
+template: mo_template
+  | package_template
+  | parameter_template
+  | nbind_template
+  | attribute_template
+  | attribute_group_template
+  | behaviour_template
+  | action_template
+  | notification_template
+
+;
+
+
+
+
+mo_template: mo_header mo_constructs registered_as T_SIMILICON
+  { 
+    GDMO_LOG_DEBUG("mo_template: got Managed Object Class");
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::mo_registeredClass,$3);
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+mo_header:label T_MANAGED T_OBJECT T_CLASS
+  {
+    GDMO_LOG_DEBUG("mo_header: create  Managed Object Header");
+    $$ =::GDMO::parser::instance()->create_mo(*($1));
+  }
+;
+
+registered_as: T_REGISTERED T_AS oid
+  {
+    GDMO_LOG_DEBUG("registered_as: got OID");
+    $$ = $3;
+  }
+;
+
+
+mo_constructs: mo_opt_derived
+             mo_opt_characterized
+             mo_opt_conditional_pkg
+  {
+    GDMO_LOG_DEBUG("mo_constructs: ");
+    if ($1)
+    {
+    }
+  }
+;
+
+
+mo_opt_derived: /*empty*/ 
+  {
+    $$ = NULL;
+  }
+  | T_DERIVED T_FROM labels T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("mo_opt_derived: ");
+    $$ = GDMO::parser::instance()->create_construct(
+           ADT::Adt::mo_derived_fromClass,$3);
+  }
+;
+
+mo_opt_characterized: /*empty*/
+  {
+    $<construct>$ = NULL;
+  }
+  | T_CHARACTERIZED T_BY mo_pkg_labels T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("mo_opt_charaterized: ");
+    $$ = GDMO::parser::instance()->create_construct(
+           ADT::Adt::mo_characterized_byClass,$3);
+  }
+;
+
+mo_pkg_labels: mo_pkg_label
+  {
+    GDMO_LOG_DEBUG("mo_pkg_labels: 1 package label");
+    $$ = ADT::Container::Create("packages");
+    $$->add($1);
+  }
+  | mo_pkg_labels T_COMMA mo_pkg_label
+  {
+    GDMO_LOG_DEBUG("mo_pkg_labels: list ");
+    $$=$1;
+    $$->add($3);
+  }
+;
+
+mo_pkg_label: label
+  {
+    GDMO_LOG_DEBUG("mo_pkg_label: label reference");
+  }
+  | package_template
+  {
+    GDMO_LOG_DEBUG("mo_pkg_label: template");
+  }
+;
+
+mo_opt_conditional_pkg: /* empty*/
+  {
+    $<container>$ = NULL;
+  }
+  | T_CONDITIONAL T_PACKAGES mo_conditional_pkgs T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("mo_opt_conditional: ");
+    $$ = GDMO::parser::instance()->create_construct(
+           ADT::Adt::mo_cond_packagesClass,$3);
+  }
+;
+
+mo_conditional_pkgs: mo_conditional_pkg
+  {
+    GDMO_LOG_DEBUG("mo_conditional_pkgs: 1 %s",$1->getName().c_str());
+    $$ = ADT::Container::Create("conditional packages");
+    $$->add($<decl>1);
+  }
+  | mo_conditional_pkgs T_COMMA mo_conditional_pkg
+  {
+    GDMO_LOG_DEBUG("mo_conditional_pkgs: 2 sz=%lu %s",$1->size(),$3->getName().c_str());
+    if ( ! $1->add($3) )
+    {
+      GDMO_LOG_DEBUG("mo_conditional_pkgs: 2 sz=%lu %s failed",$1->size(),$3->getName().c_str());
+    }
+    $$ = $1;
+  }
+;
+
+mo_conditional_pkg:  package_template present_if
+  {
+    GDMO_LOG_DEBUG("mo_conditional_pkg: template");
+    $$ = $<decl>1;
+  }
+  | label present_if
+  {
+    GDMO_LOG_DEBUG("mo_conditional_pkg: label");
+    $$ = $1;
+  }
+;
+
+present_if:  T_PRESENT T_IF T_STRING
+  {
+    GDMO_LOG_DEBUG("present if: ");
+    $$ = $3;
+  }
+;
+
+package_template: package_header pkg_constructs T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("package_template:");
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+package_header: label T_PACKAGE
+  {
+    GDMO_LOG_DEBUG("pakage_header: create");
+    $$ =::GDMO::parser::instance()->create_package(*($1));
+  }
+;
+pkg_constructs: pkg_opt_behaviour
+                pkg_opt_attrs
+                pkg_opt_attr_grp
+                pkg_opt_act
+                pkg_opt_notif
+                pkg_opt_registered
+  {
+    GDMO_LOG_DEBUG("pkg_constructs:");
+  }
+;
+
+pkg_opt_behaviour: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_BEHAVIOUR pkg_behaviour T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("pkg_opt_behaviour:");
+  }
+;
+
+pkg_behaviour: pkg_behaviour_def
+  {
+    GDMO_LOG_DEBUG("pkg_behaviour: 1");
+  }
+  | pkg_behaviour pkg_behaviour_def
+  {
+    GDMO_LOG_DEBUG("pkg_behaviour: list");
+  }
+;
+
+pkg_behaviour_def: T_IDENTIFIER 
+  {
+    GDMO_LOG_DEBUG("pkg_behaviour_def: label");
+  }
+  | behaviour_template 
+  {
+    GDMO_LOG_DEBUG("pkg_behaviour_def: template");
+  }
+;
+
+pkg_opt_attrs: /*empty */
+  {
+    $<construct>$ = NULL;
+  }
+  | T_ATTRIBUTES pkg_attributes T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("pkg_opt_attrs: template");
+    $$ = GDMO::parser::instance()->create_construct(
+           ADT::Adt::pkg_attributesClass,$2);
+  }
+;
+
+pkg_attributes:pkg_attribute
+  {
+    GDMO_LOG_DEBUG("pkg_attributes: ");
+    $$ = ADT::Container::Create("package attributes");
+    $$->add($1);
+  }
+  | pkg_attributes T_COMMA pkg_attribute
+  {
+    GDMO_LOG_DEBUG("pkg_attributes: ");
+    $1->add($3);
+    $$ = $1;
+  }
+;
+
+
+pkg_attribute:label 
+              {
+                $<decl>$ = GDMO::parser::instance()->create_pkg_attribute(
+                     *($1));
+              } pkg_attr_proplist pkg_attr_param_labels
+  {
+    GDMO_LOG_DEBUG("pkg_attribute: ");
+    ADT::GDMO::decl *d = $<decl>2;
+    GDMO::parser::instance()->pkg_attribute_complete(dynamic_cast<pkg_attribute &>(*d));
+    $$ =d;
+  }
+;
+
+
+pkg_attr_proplist: pkg_proplist_replace_default
+   pkg_proplist_default
+   pkg_proplist_initial
+   pkg_proplist_permitted
+   pkg_proplist_required
+   pkg_proplist_get_replace
+   pkg_proplist_add_remove
+   pkg_proplist_set_by_created
+   pkg_proplist_no_modify
+;
+
+pkg_proplist_replace_default: /* empty*/
+  | T_REPLACE_WITH_DEFAULT   pkg_proplist_default
+  {
+    GDMO_LOG_DEBUG("pkg_attribute: ");
+  }
+;
+
+pkg_proplist_default: /* empty */
+  | T_DEFAULT T_VALUE pkg_proplist_value_spec
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_default: ");
+  }
+;
+
+
+pkg_proplist_initial: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_INITIAL T_VALUE pkg_proplist_value_spec
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_initial: ");
+  }
+;
+
+pkg_proplist_value_spec: T_IDENTIFIER
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_value_spec: ");
+  }
+  | T_TYPEREF T_DOT T_IDENTIFIER
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_value_spec: 1 Value");
+  }
+  | T_TYPEREF T_DOT T_TYPEREF
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_value_spec: 2 Type");
+  }
+  | T_DERIVATION T_RULE 
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_value_spec: 3");
+  }
+;
+
+pkg_proplist_permitted: /**/
+  | T_PERMITTED T_VALUES pkg_proplist_typeref
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_permitted: ");
+  }
+;
+
+pkg_proplist_required: /**/
+  | T_REQUIRED T_VALUES pkg_proplist_typeref
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_required: ");
+  }
+;
+
+pkg_proplist_typeref: T_TYPEREF T_DOT T_TYPEREF
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_typeref: ");
+    $$ = ADT::GDMO::typeref::Create($1->getName(),$3->getName());
+    delete($1);
+    delete($3);
+  }
+;
+
+pkg_proplist_get_replace: /**/
+  | T_GET
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace: ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_get_replaceClass,NULL);
+    c->flags.get = true;       
+  }
+  | T_GET_REPLACE
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace:1 ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_get_replaceClass,NULL);
+    c->flags.replace = true;       
+    c->flags.get = true;       
+  }
+  | T_REPLACE
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace:2 ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_get_replaceClass,NULL);
+    c->flags.replace = true;       
+  }
+;
+
+pkg_proplist_add_remove: /**/
+  | T_ADD
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace:2 ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_add_removeClass,NULL);
+    c->flags.add = true;       
+  }
+  | T_REMOVE
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace:2 ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_add_removeClass,NULL);
+    c->flags.remove = true;       
+  }
+  | T_ADD_REMOVE
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_get_replace:2 ");
+    ADT::GDMO::property *c = GDMO::parser::instance()->create_property(
+           ADT::Adt::property_add_removeClass,NULL);
+    c->flags.add = true;       
+    c->flags.remove = true;       
+  }
+;
+
+pkg_proplist_set_by_created: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_SET_BY_CREATE
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_set_by_created: ");
+  }
+;
+
+pkg_proplist_no_modify: /* empty */
+  {
+    $<label>$ = NULL;
+  }
+  | T_NO_MODIFY
+  {
+    GDMO_LOG_DEBUG("pkg_proplist_no_modify: ");
+  }
+;
+
+pkg_attr_param_labels: /**/
+  | pkg_attr_param_label
+  {
+    GDMO_LOG_DEBUG("pkg_attr_param_labels: 1");
+  }
+  | pkg_attr_param_labels pkg_attr_param_label
+  {
+    GDMO_LOG_DEBUG("pkg_attr_param_labels: 2");
+  }
+;
+
+pkg_attr_param_label: label
+                     
+pkg_opt_attr_grp: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_ATTRIBUTE T_GROUP
+;
+
+pkg_opt_act: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_ACTIONS pkg_actions T_SIMILICON
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::pkg_actionsClass,$2);
+  }
+;
+
+pkg_actions:pkg_action
+  {
+    GDMO_LOG_DEBUG("pkg_actions: 1 package label");
+    $$ = ADT::Container::Create("pkg_actions");
+    $$->add($1);
+  }   
+  | pkg_actions T_COMMA pkg_action
+  {
+    $1->add($3);
+    $$ = $1;
+  }   
+;
+
+pkg_action: label pkg_attr_param_labels
+  {
+  }
+;
+
+pkg_opt_notif: /* empty */
+  {
+    $<decl>$ = NULL;
+  }
+  | T_NOTIFICATIONS  pkg_notification T_SIMILICON
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::pkg_notificationsClass,$2);
+  }
+;
+
+pkg_notification: pkg_notif_item
+  {
+    GDMO_LOG_DEBUG("pkg_notification: 1 package label");
+    $$ = ADT::Container::Create("pkg_notifications");
+    $$->add($1);
+  }    
+  | pkg_notification T_COMMA pkg_notif_item
+  {
+    $1->add($3);
+    $$ = $1;
+  }
+;
+
+pkg_notif_item: label pkg_attr_param_labels
+  {
+    $$ = $1;
+  }
+;
+
+pkg_opt_registered: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | registered_as
+  {
+    GDMO_LOG_DEBUG("pkg_opt_registered: ");
+  }
+;
+
+parameter_template: parameter_header
+  T_CONTEXT param_ctx_type T_SIMILICON
+  param_syntax_or_attr T_SIMILICON
+  param_opt_behaviour
+  param_opt_register T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("parameter_template: ");
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+parameter_header: label T_PARAMETER
+  {
+    GDMO_LOG_DEBUG("parameter_header: create");
+    $$ =::GDMO::parser::instance()->create_parameter(*($1));
+  }
+;      
+
+param_ctx_type: T_ACTION_INFO
+  | T_ACTION_REPLY
+  | T_EVENT_INFO
+  | T_EVENT_REPLY
+  | T_SPECIFIC_ERROR
+  | T_TYPEREF T_DOT T_IDENTIFIER
+;
+
+param_syntax_or_attr: 
+  T_WITH T_SYNTAX pkg_proplist_typeref 
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::parameter_syntaxClass,$3);
+  }
+  | T_ATTRIBUTE label
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::parameter_syntaxClass,$2);
+  }
+;
+
+param_opt_behaviour: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+ | T_BEHAVIOUR param_behaviours T_SIMILICON
+;
+
+param_behaviours:param_behaviour
+ | param_behaviours T_COMMA param_behaviour
+;
+
+param_behaviour: label
+  | behaviour_template
+;
+
+param_opt_register: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | registered_as
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::parameter_registeredClass,$1);
+  }
+;
+
+
+nbind_template: nbind_header nbind_core
+  {
+    GDMO_LOG_DEBUG("nbind_template: ");
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+nbind_header: label T_NAME T_BINDING
+  {
+    GDMO_LOG_DEBUG("nbind_header: create template");
+    $$ =::GDMO::parser::instance()->create_name_binding(*($1));
+  }
+;
+
+nbind_core: 
+  T_SUBORDINATE T_OBJECT T_CLASS label opt_subclass T_SIMILICON
+  T_NAMED T_BY T_SUPERIOR T_OBJECT T_CLASS label opt_subclass T_SIMILICON
+  T_WITH T_ATTRIBUTE nbind_attrs T_SIMILICON
+  nbind_opt_behavior
+  nbind_opt_create
+  nbind_opt_delete
+  registered_as T_SIMILICON
+;
+
+nbind_attrs: label
+  {
+    GDMO_LOG_DEBUG("nbind_attrs: ");
+  }
+;
+opt_subclass: /**/
+  | T_AND T_SUBCLASSES            
+  {
+    GDMO_LOG_DEBUG("nbind_opt_subclass: ");
+  }
+;
+
+nbind_opt_behavior: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_BEHAVIOUR nbind_behaviours T_SIMILICON                
+  {
+    GDMO_LOG_DEBUG("nbind_behaviour ");
+  }
+;
+
+nbind_behaviours: nbind_behaviour
+  | nbind_behaviours T_COMMA nbind_behaviour
+  {
+    GDMO_LOG_DEBUG("nbind_behaviours: ");
+  }
+;
+
+nbind_behaviour: label
+  {
+    GDMO_LOG_DEBUG("nbind_behaviour: ");
+  }
+  | behaviour_template
+  {
+    GDMO_LOG_DEBUG("nbind_behaviour: template");
+  }
+;
+
+nbind_opt_create: /* empty*/
+  {
+    $<label>$ = NULL;
+  }
+  | T_CREATE nbind_create_modifiers nbind_opt_params T_SIMILICON                
+  {
+    GDMO_LOG_DEBUG("nbind_opt_create: ");
+  }
+;
+
+nbind_opt_params: /*empty */
+  {
+    $$ = NULL;
+  }
+  |nbind_params 
+;
+
+nbind_params: label
+  {
+    $$ = ADT::Container::Create("name binding parameters");
+    $$->add($1);
+  }
+  | nbind_params   label
+  {
+    $1->add($2);
+  }
+;
+
+nbind_create_modifiers: nbind_create_modifier
+  | nbind_create_modifiers T_COMMA nbind_create_modifier
+;
+
+nbind_create_modifier: /* empty */
+  {
+    $<label>$ = NULL;
+  }
+  | T_WITH_REFERENCE_OBJECT
+  {
+    GDMO_LOG_DEBUG("nbind_create_modifier: ");
+  }
+  | T_WITH_AUTOMATIC_INSTANCE_NAMING
+  {
+    GDMO_LOG_DEBUG("nbind_create_modifier: ");
+  }
+;
+
+nbind_opt_delete: /* empty */
+  | T_DELETE nbind_del_modifier nbind_opt_params T_SIMILICON                
+  {
+    GDMO_LOG_DEBUG("nbind_opt_delete: ");
+  }
+;
+
+nbind_del_modifier: /* empty */
+  | T_ONLY_IF_NO_CONTAINED_OBJECTS
+  {
+    GDMO_LOG_DEBUG("nbind_del_modifier: ");
+  }
+  | T_DELETES_CONTAINED_OBJECTS
+  {
+    GDMO_LOG_DEBUG("nbind_del_modifier: ");
+  }
+;
+
+
+
+attribute_template: attribute_header
+  derive_or_syntax T_SIMILICON
+  attr_opt_match
+  attr_opt_behaviour
+  attr_opt_parameters
+  attr_opt_registered T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("attribute_template: ");
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+attribute_header: label T_ATTRIBUTE
+  {
+    GDMO_LOG_DEBUG("attribute_header: create");
+    $$ =::GDMO::parser::instance()->create_attribute(*($1));
+  }
+;
+
+derive_or_syntax: T_DERIVED T_FROM label
+  {
+    GDMO_LOG_DEBUG("derived_or_syntax: ");
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::attr_syntaxClass,$3);
+  }
+  | T_WITH T_ATTRIBUTE T_SYNTAX  pkg_proplist_typeref
+  {
+    GDMO_LOG_DEBUG("derived_or_syntax:  ");
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::attr_syntaxClass,$4);
+  }
+;
+
+attr_opt_match: /* empty */
+  | T_MATCHES T_FOR attr_qualifiers T_SIMILICON              
+;
+
+attr_qualifiers: attr_qualifier
+  | attr_qualifiers T_COMMA attr_qualifier
+;
+
+attr_qualifier:T_EQUALITY
+  | T_ORDERING
+  | T_SUBSTRINGS
+  | T_SET_COMPARISON
+  | T_SET_INTERSECTION
+;
+
+attr_opt_behaviour: /*empty*/
+  | T_BEHAVIOUR attr_behaviours T_SIMILICON                
+  {
+    GDMO_LOG_DEBUG("attr_opt_behaviour: ");
+  }
+;
+
+attr_behaviours: attr_behaviour
+  {
+    GDMO_LOG_DEBUG("attr_behaviours: ");
+  }
+  | attr_behaviours T_COMMA attr_behaviour
+  {
+    GDMO_LOG_DEBUG("attr_behaviours: ");
+  }
+;
+
+attr_behaviour: label
+  {
+    GDMO_LOG_DEBUG("attr_behaviour: ");
+  }
+  | behaviour_template
+  {
+    GDMO_LOG_DEBUG("attr_behaviour: template ");
+  }
+;
+
+attr_opt_parameters: /*empty */
+  | T_PARAMETERS attr_parameters  T_SIMILICON                
+;
+
+attr_parameters: label
+ {
+   $$ = ADT::Container::Create("parameters");
+   $$->add($1);
+ }
+ | attr_parameters T_COMMA label
+ {
+   $1->add($3);
+   $$ = $1;
+ }
+;
+
+attr_opt_registered: /* empty*/
+  | registered_as
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::attr_registeredClass,$1);
+  }
+;
+
+
+
+attribute_group_template: attribute_group_header
+  attr_grp_elems
+  attr_grp_fixed
+  attr_grp_desc
+  registered_as T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("attribute_group_template: ");
+    //ADT::Container *c = GDMO::parser::instance()->create_construct(
+    //       ADT::Adt::attribute_group_registeredClass,$1);
+  }
+;
+
+attribute_group_header: label T_ATTRIBUTE T_GROUP
+  {
+    GDMO_LOG_DEBUG("attribute_group_header: create");
+  }
+;
+
+attr_grp_elems: /* empty*/ 
+  | T_GROUP T_ELEMENTS labels T_SIMILICON
+;
+attr_grp_fixed: /* empty*/
+  | T_FIXED T_SIMILICON
+;
+attr_grp_desc: /* empty*/
+  | T_DESCRIPTION T_STRING T_SIMILICON
+;
+
+behaviour_template: behaviour_header behaviour_construct
+  {
+    GDMO_LOG_DEBUG("behaviour_template: ");
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+behaviour_header: label T_BEHAVIOUR
+  {
+    GDMO_LOG_DEBUG("behaviour_header: create");
+    $$ = ::GDMO::parser::instance()->create_behaviour(*($1));
+  }
+;
+
+behaviour_construct: T_DEFINED T_AS T_STRING T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("behaviour_construct: ");
+  }
+;
+
+action_template: action_header
+  act_opt_behaviour
+  act_opt_mode
+  act_opt_params
+  act_opt_with
+  act_opt_with
+  registered_as T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("action_template: ");
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::action_registeredClass,$7);
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+action_header: label T_ACTION
+  {
+    GDMO_LOG_DEBUG("action_header: create");
+    $$ =::GDMO::parser::instance()->create_action(*($1));
+  }
+;
+
+act_opt_behaviour: /*empty*/
+  | T_BEHAVIOUR act_behaviours T_SIMILICON                 
+;
+
+act_behaviours: act_behaviour
+  | act_behaviours T_COMMA act_behaviour
+;
+
+act_behaviour: label
+  {
+    GDMO_LOG_DEBUG("act_behaviour: label");
+  }
+  | behaviour_template
+  {
+    GDMO_LOG_DEBUG("act_behaviour: template");
+  }
+;
+
+act_opt_mode: /* empty */
+  | T_MODE T_CONFIRMED T_SIMILICON
+;
+act_opt_params: /* empty */ 
+  | T_PARAMETERS act_parameters T_SIMILICON
+;
+
+act_parameters: act_parameter
+  | act_parameters T_COMMA act_parameter
+;
+
+act_parameter: label
+  {
+    GDMO_LOG_DEBUG("act_parameter: label");
+  }
+  | parameter_template
+  {
+    GDMO_LOG_DEBUG("act_parameter: template");
+  }
+;
+
+act_opt_with: /* empty*/
+  | T_WITH act_with_info_reply
+;
+act_with_info_reply:
+  T_INFORMATION  T_SYNTAX pkg_proplist_typeref T_SIMILICON 
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::action_with_informationClass,$3);
+  }
+  | T_REPLY  T_SYNTAX pkg_proplist_typeref T_SIMILICON
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::action_with_replyClass,$3);
+  }
+;
+
+
+notification_template: notification_header
+  notif_opt_behaviour
+  notif_opt_params
+  notif_opt_with
+  registered_as T_SIMILICON
+  {
+    GDMO_LOG_DEBUG("notification_template: ");
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::notification_registeredClass,$5);
+    ::GDMO::parser::instance()->template_complete(*($1));
+  }
+;
+
+notification_header: label T_NOTIFICATION
+  {
+    GDMO_LOG_DEBUG("notification_header: create");
+    $$ = ::GDMO::parser::instance()->create_notification(*($1));
+  }   
+;
+notif_opt_behaviour: /* empty*/
+  | T_BEHAVIOUR notif_behaviours T_SIMILICON                   
+;
+notif_behaviours: notif_behaviour
+  | notif_behaviours T_COMMA notif_behaviour
+;
+
+notif_behaviour: label
+  {
+    GDMO_LOG_DEBUG("notif_behaviour: label");
+  }
+  | behaviour_template
+  {
+    GDMO_LOG_DEBUG("notif_behaviour: template");
+  }
+;
+
+notif_opt_params: /* empty */
+  | T_PARAMETERS notif_parameters T_SIMILICON                   
+;
+
+notif_parameters: label
+  {
+    $$ = ADT::Container::Create("notification parameters");
+    $$->add($1);
+  }
+  | notif_parameters T_COMMA label
+  {
+    $1->add($3);
+    $$ = $1; 
+  }
+;
+
+
+notif_opt_with: /* empty:*/
+  | T_WITH  notif_info_reply
+;
+
+notif_info_reply: 
+   T_INFORMATION T_SYNTAX  pkg_proplist_typeref
+    notif_opt_attr_id T_SIMILICON
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::notification_with_informationClass,$3);
+  } 
+  | T_WITH T_REPLY T_SYNTAX  pkg_proplist_typeref T_SIMILICON
+  {
+    ADT::GDMO::construct *c = GDMO::parser::instance()->create_construct(
+           ADT::Adt::notification_with_replyClass,$4);
+  }
+;
+
+notif_opt_attr_id: /* empty */
+  | T_AND T_ATTRIBUTE T_IDS notif_opt_fields
+;
+
+notif_opt_fields: /**/
+  | notif_fields
+;
+
+notif_fields: notif_field
+  | notif_fields T_COMMA notif_field
+;
+
+notif_field: T_IDENTIFIER label
+ ;
+
+
+
+
+oid: T_LBRACET oid_list T_RBRACET
+  {
+    $$ = $2;
+  }
+;
+
+oid_list: oid_item
+  {
+    GDMO_LOG_DEBUG("oid_list: item");
+    $$ = ADT::Container::Create("oid");
+    $$->add($1);
+  }
+  | oid_list oid_item
+  {
+    GDMO_LOG_DEBUG("oid_list: list");
+    $1->add($2);
+    $$ = $1;
+  }
+;
+
+oid_item: T_IDENTIFIER
+  {
+    GDMO_LOG_DEBUG("oid_item: ident <%s>",$1->getName().c_str());
+    $$ = ADT::GDMO::oid_item::Create($1->getName());
+    delete ($1);
+  }
+  | T_IDENTIFIER T_LPARENT  T_NUM T_RPARENT
+  {
+    GDMO_LOG_DEBUG("oid_item: ident <%s> (num %ld) "
+                  , $1->getName().c_str()
+                  , $<number>3);
+    $$ = ADT::GDMO::oid_item::Create($1->getName(),$<number>3);
+    delete ($1);
+  }
+  | T_NUM
+  {
+    GDMO_LOG_DEBUG("oid_item: num %ld",$<number>1);
+    $$ = ADT::GDMO::oid_item::Create("",$<number>1);
+  }
+;
+
+%%
+/*
+ * vim:et:sw=2:ts=2:
+ */
diff --git a/libparser/gdmo_parser.h b/libparser/gdmo_parser.h
new file mode 100644 (file)
index 0000000..4ce3269
--- /dev/null
@@ -0,0 +1,220 @@
+#ifndef GDMO_PARSER
+#define GDMO_PARSER
+
+using namespace ADT::GDMO;
+
+namespace  GDMO
+{
+  /**
+   * abstract interface
+   */ 
+  class parser_listener
+  {
+    public:
+      typedef void (parser_listener::*construct_ptr)(construct &t);        
+      parser_listener()
+      {} ;
+      
+      virtual ~parser_listener() {} ;
+      /*
+       * Add arguments
+       */ 
+#define GDMO_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p) \
+      virtual void on_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+     /*
+      * template  construct elements
+      */
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p) \
+      virtual void on_##cls(ADT::GDMO::cls &t) {};
+#define GDMO_PROPLIST_DECL(cls,p) \
+      virtual void on_##cls(ADT::GDMO::cls &t) {};
+#include  "ADT/gdmo/Gdmo.h.inc"      
+
+     /**
+      *
+      */  
+      virtual void on_module_start(ADT::GDMO::module &t)  {};
+      
+      virtual void on_module_end(ADT::GDMO::module &t)  {};
+
+      void on_construct(ADT::GDMO::construct *c);
+
+      virtual void on_template_start(ADT::GDMO::templates *t);
+      virtual void on_template(ADT::GDMO::templates &t);
+      //
+      virtual void on_pkg_attribute_start(pkg_attribute &pa);
+      virtual void on_pkg_attribute(pkg_attribute &pa);
+    protected:    
+  };
+  
+  /**
+   * Notify template start
+   */ 
+  struct do_template_start
+  {
+    do_template_start(ADT::GDMO::templates *t)
+      : m_template(t)
+    { }
+    
+    void operator ()(parser_listener *l)
+    {
+      l->on_template_start(m_template);  
+    }
+
+    ADT::GDMO::templates *m_template;
+  } ;
+  
+  /**
+   * Notify template complete
+   */ 
+  struct do_template_complete
+  {
+    do_template_complete(ADT::GDMO::templates &t)
+      : m_template(t)
+    { }
+    
+    void operator ()(parser_listener *l)
+    {
+      l->on_template(m_template);  
+    }
+
+    ADT::GDMO::templates &m_template;
+  } ;
+
+  /**
+   *
+   */ 
+  class parser
+  {
+    private:
+      parser()
+        :m_current_module(NULL)
+      {
+        ;
+      }      
+    public:
+      typedef std::list<parser_listener *>  listener_list;
+      typedef listener_list::iterator       listener_iterator;
+      typedef std::list<std::string>        string_list;
+
+      /**
+       *
+       */ 
+      static parser * instance()
+      {
+      if (m_instance == NULL)
+        m_instance = new parser();
+      return m_instance;
+      }
+      
+      /**
+       *
+       */ 
+      void register_listener(parser_listener *l)
+      {
+        m_listeners.push_back(l); 
+      }
+
+      /**
+       *
+       */ 
+      mo_tplt *create_mo(const label &l);
+      
+      /**
+       *
+       */ 
+      name_binding_tplt *create_name_binding(const label &l) ;
+      
+      action_tplt *create_action(const label &l) ;
+      
+      parameter_tplt *create_parameter(const label &l) ;
+      
+      notification_tplt *create_notification(const label &l) ;
+      
+      behaviour_tplt *create_behaviour(const label &l) ;
+      
+      /**
+       *
+       */ 
+      package_tplt *create_package(const label &l);
+      /**
+       *
+       */ 
+      pkg_attribute *create_pkg_attribute(const label &l);
+      void pkg_attribute_complete(pkg_attribute &p);
+      /**
+       *
+       */ 
+      attribute_tplt *create_attribute(const label &l) ;
+      
+      attribute_group_tplt *create_attribute_group(const label &l) ;
+
+      construct *create_construct(ADT::Adt::AdtClass c,ADT::Container *cont); 
+      
+      construct *create_construct(ADT::Adt::AdtClass c,ADT::GDMO::decl *d); 
+      
+      property *create_property(ADT::Adt::AdtClass c,ADT::GDMO::decl *d); 
+      /**
+       *
+       */ 
+      label *create_label(const std::string &scope,const std::string &name )
+      {
+        label  *l =  label::Create(scope,name); 
+        return l ;
+      }
+
+      module *create_module(const std::string &s);
+
+      void module_end(module *m);
+      /**
+       *
+       */ 
+      void template_complete(ADT::GDMO::templates &t)
+      {
+        do_template_complete complete(t);  
+        std::for_each( m_listeners.begin()
+                       , m_listeners.end()
+                       , complete); 
+      }
+      module * current_module() {return m_current_module;}
+      /**
+       *
+       */
+      int parse();
+      
+      //
+      inline string_list &includes() { return m_includes; }
+      //
+      inline string_list &files()    { return m_files;    }
+      //
+      void   set_file_mode(bool fm);
+      //
+      inline bool file_mode()        { return m_file_mode;} 
+    protected:  
+      void template_start(ADT::GDMO::templates *t)
+      {
+        do_template_start start(t);  
+        std::for_each( m_listeners.begin()
+                       , m_listeners.end()
+                       , start); 
+          
+      }
+    protected:
+      listener_list      m_listeners;
+      string_list        m_includes;
+      string_list        m_files;
+      ADT::GDMO::module *m_current_module;
+      bool               m_file_mode;
+    private:  
+      static parser *m_instance;    
+  };
+
+
+}
+#endif
diff --git a/libparser/parser.cpp b/libparser/parser.cpp
new file mode 100644 (file)
index 0000000..783b1b1
--- /dev/null
@@ -0,0 +1,385 @@
+#include "gdmo_config.h"
+#include "ADT/Adt.h"
+#include "gdmo_parser.h"
+
+extern void open_log(const std::string &s);
+extern void close_log();
+
+extern int gdmo_parse();
+extern FILE *gdmo_in;
+extern "C" int gdmo_wrap(void);
+
+GDMO::parser *
+GDMO::parser::m_instance         = NULL;
+
+
+/**
+ * wrap function to handle multiple file parsing other than through stdin
+ */
+int gdmo_wrap()
+{
+    GDMO::parser *gdmop = GDMO::parser::instance();
+    std::string fullname;
+    // If they are files to parse, return 0, but first, close the current in, and open the new one
+    if ((gdmop->file_mode() )  && gdmo_in != NULL)
+    {
+      fclose(gdmo_in);
+      gdmo_in = NULL;
+      if (gdmop->current_module())
+      {
+          GDMO::parser::instance()->module_end(NULL);
+          //currentModule = NULL;
+      }
+    } else if (!gdmop->file_mode())
+    {
+        std::cout<<"gdmo_wrap() not file_mode"<<std::endl;
+        return 1;
+    }
+    // Only process files if specified
+    if (gdmop->files().size() > 0)
+    {
+      if (gdmop->includes().size() > 0)
+      {
+        std::list<std::string>::iterator it;
+        for ( it = gdmop->includes().begin()
+            ; it != gdmop->includes().end(); ++it)
+        {
+            fullname = (*it) + gdmop->files().back();
+            if (access(fullname.c_str(),F_OK)) 
+                break;
+        }
+      }
+      if (fullname.size() > 0)
+      {
+        gdmo_in = fopen(fullname.c_str(),"r");
+        if (gdmo_in != NULL)
+        {
+            gdmop->create_module(gdmop->files().back());
+            gdmop->files().pop_back();
+            
+            return  0;
+        } else {
+            return 1;
+        }
+      } else 
+          return 1;
+    } else
+    {
+        //std::cout<<"gdmo_wrap() array file empty"<<std::endl;
+    }
+    return 1;
+}
+
+
+
+
+namespace GDMO
+{
+
+  /**
+   * Notify template start
+   */ 
+  struct notif_module
+  {
+    enum ntype { M_START,M_END} mode;  
+    notif_module(ntype _m ,ADT::GDMO::module *t)
+      : m_mod(t) , mode(_m)
+    { }
+    
+    void operator ()(parser_listener *l)
+    {
+      if ( mode == M_START)  
+      {
+        l->on_module_start(*m_mod);
+      } else
+        l->on_module_end(*m_mod);
+    }
+
+    ADT::GDMO::module *m_mod;
+  } ;
+
+  /**
+   * Notify creation of construct part
+   */
+  template <typename T>  
+  struct notif_construct
+  {
+    typedef void (parser_listener::*ptr)(T &t);          
+    notif_construct(T &c,ptr p )
+      : m_mod(c) , m_ptr(p)
+    { }
+    
+    void operator ()(parser_listener *l)
+    {
+        (*l.*m_ptr)(m_mod);
+    }
+
+    T &m_mod;
+    ptr m_ptr;
+  } ;
+
+
+
+module *
+parser::create_module(const std::string &_mod)
+{
+  m_current_module = module::Create(_mod);
+  
+  open_log(_mod);
+  notif_module notif(notif_module::M_START,m_current_module);  
+  
+  std::for_each( m_listeners.begin()
+               , m_listeners.end()
+               , notif); 
+  return m_current_module;
+}
+
+void 
+parser::module_end(module *m)
+{
+  notif_module notif(notif_module::M_END,m_current_module);  
+  std::for_each( m_listeners.begin()
+               , m_listeners.end()
+               , notif); 
+  close_log();
+  m_current_module = NULL;
+}
+
+/**
+ *
+ */ 
+mo_tplt *
+parser::create_mo(const label &l)
+{
+  mo_tplt *mo =  mo_tplt::Create(l); 
+  template_start(mo);
+  return   mo;
+}
+  
+/**
+ *
+ */ 
+package_tplt *
+parser::create_package(const label &l)
+{
+  package_tplt *mo =  package_tplt::Create(l); 
+  template_start(mo);
+  return   mo;
+}
+
+/**
+ *
+ */ 
+name_binding_tplt *
+parser::create_name_binding(const label &l)
+{
+  name_binding_tplt *t = name_binding_tplt::Create(l);
+  template_start(t);
+  return   t;
+}
+
+/**
+ *
+ */ 
+attribute_tplt *
+parser::create_attribute(const label &l)
+{
+  attribute_tplt *tmp =  attribute_tplt::Create(l);
+  template_start(tmp);
+  return   tmp;
+}
+
+/**
+ *
+ */ 
+attribute_group_tplt *
+parser::create_attribute_group(const label &l)
+{
+  attribute_group_tplt *tmp =  attribute_group_tplt::Create(l);
+  template_start(tmp);
+  return   tmp;
+}
+
+
+/**
+ *
+ */ 
+parameter_tplt *
+parser::create_parameter(const label &l)
+{
+  parameter_tplt *t = parameter_tplt::Create(l);
+  template_start(t);
+  return   t;
+}
+
+/**
+ *
+ */ 
+behaviour_tplt *
+parser::create_behaviour(const label &l)
+{
+  behaviour_tplt *t = behaviour_tplt::Create(l);
+  template_start(t);
+  return   t;
+}
+
+/**
+ *
+ */ 
+action_tplt *
+parser::create_action(const label &l)
+{
+  action_tplt *tmp =  action_tplt::Create(l);
+  template_start(tmp);
+  return   tmp;
+}
+
+
+/**
+ *
+ */ 
+notification_tplt *
+parser::create_notification(const label &l)
+{
+  notification_tplt *tmp =  notification_tplt::Create(l);
+  template_start(tmp);
+  return   tmp;
+}
+
+construct *
+parser::create_construct(ADT::Adt::AdtClass c,ADT::Container *cont)
+{
+  construct *result = NULL;
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p)   \
+    case ADT::Adt::cls##Class : \
+      { result = cls::Create(cont); \
+        notif_construct<cls> notif(dynamic_cast<cls &>(*result)  \
+                                  ,&parser_listener::on_##cls); \
+        std::for_each( m_listeners.begin() \
+               , m_listeners.end()         \
+               , notif);                   \
+      } break;
+
+
+  switch (c)
+  {
+#include  "ADT/gdmo/Gdmo.h.inc"      
+    default:
+        std::cerr<<"on_template UNKNOWN TEMPLATE"<<std::endl;  
+     ;   
+  }
+  return result;
+}
+
+construct *
+parser::create_construct(ADT::Adt::AdtClass c,ADT::GDMO::decl *cont)
+{
+  construct *result = NULL;
+#if 1
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p)   \
+    case ADT::Adt::cls##Class : \
+      { result = cls::Create(cont); \
+        notif_construct<cls> notif(dynamic_cast<cls &>(*result)  \
+                                  ,&parser_listener::on_##cls); \
+        std::for_each( m_listeners.begin() \
+               , m_listeners.end()         \
+               , notif);                   \
+      } break;
+
+
+  switch (c)
+  {
+#include  "ADT/gdmo/Gdmo.h.inc"      
+    default:
+        std::cerr<<"on_template UNKNOWN TEMPLATE"<<std::endl;  
+     ;   
+  }
+#endif
+  return result;
+}
+
+ADT::GDMO::property*
+parser::create_property(ADT::Adt::AdtClass c,ADT::GDMO::decl *cont)
+{
+  property *result = NULL;
+#if 1
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p)   
+#define GDMO_PROPLIST_DECL(cls,p)   \
+    case ADT::Adt::cls##Class : \
+      { result = cls::Create(cont); \
+        notif_construct<cls> notif(dynamic_cast<cls &>(*result)  \
+           ,&parser_listener::on_##cls); \
+        std::for_each( m_listeners.begin() \
+               , m_listeners.end()         \
+               , notif);                   \
+      } break;
+
+
+  switch (c)
+  {
+#include  "ADT/gdmo/Gdmo.h.inc"      
+    default:
+        std::cerr<<"on_property UNKNOWN "<<std::endl;  
+     ;   
+  }
+#endif
+  return result;
+}
+
+
+
+/**
+*
+*/ 
+pkg_attribute *
+parser::create_pkg_attribute(const label &l)
+{
+  pkg_attribute *pa  = pkg_attribute::Create(l.get_name());   
+  notif_construct<pkg_attribute> notif(*pa  
+           ,&parser_listener::on_pkg_attribute_start);
+
+  std::for_each( m_listeners.begin() 
+               , m_listeners.end()         
+               , notif);
+  return pa;
+}
+
+void 
+parser::pkg_attribute_complete(pkg_attribute &p)
+{
+  notif_construct<pkg_attribute> notif(p  
+           ,&parser_listener::on_pkg_attribute);
+
+  std::for_each( m_listeners.begin() 
+               , m_listeners.end()         
+               , notif);
+}
+
+void
+parser::set_file_mode(bool fm)
+{
+  m_file_mode = fm;
+  if (fm)
+    gdmo_in = NULL;
+}
+
+int
+parser::parse()
+{
+  if ( !gdmo_wrap() )
+  {
+    gdmo_parse();
+    return 0;
+  } else
+  {
+    return 1;
+  }
+}
+
+}
diff --git a/libparser/parser_listener.cpp b/libparser/parser_listener.cpp
new file mode 100644 (file)
index 0000000..e96e2f8
--- /dev/null
@@ -0,0 +1,77 @@
+#include "gdmo_config.h"
+#include "ADT/Adt.h"
+#include "gdmo_parser.h"
+
+
+namespace GDMO
+{
+
+/**
+ * Creation of a new template
+ */ 
+void
+parser_listener::on_template_start(ADT::GDMO::templates *t)
+{
+}
+
+/**
+ * template complete
+ */ 
+void
+parser_listener::on_template(ADT::GDMO::templates &t)
+{
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)   \
+    case ADT::Adt::cls##Class : \
+      { on_##cls(dynamic_cast<cls &>(t)) ; } break;
+
+  switch (t.getClass())
+  {
+#if 1
+#include  "ADT/gdmo/Gdmo.h.inc"      
+#else
+    case ADT::Adt::attribute_tpltClass:
+        { on_attribute_tplt(dynamic_cast<attribute_tplt &>(t));}
+        break;
+#endif
+    default:
+        std::cerr<<"on_template UNKNOWN TEMPLATE"<<std::endl;  
+     ;   
+  }
+}
+
+
+void 
+parser_listener::on_construct(ADT::GDMO::construct *_cls)
+{
+#define GDMO_DECL(cls,p)
+#define GDMO_TPLT_DECL(cls,p)
+#define GDMO_CONSTRUCT_DECL(cls,p)   \
+    case ADT::Adt::cls##Class : \
+      { on_##cls(dynamic_cast<cls &>(*_cls)) ; } break;
+
+
+  switch (_cls->getClass())
+  {
+#include  "ADT/gdmo/Gdmo.h.inc"      
+    default:
+        std::cerr<<"on_template UNKNOWN TEMPLATE"<<std::endl;  
+     ;   
+  }
+}
+
+void
+parser_listener::on_pkg_attribute_start(ADT::GDMO::pkg_attribute &pa)
+{
+}
+
+void
+parser_listener::on_pkg_attribute(ADT::GDMO::pkg_attribute &pa)
+{
+}
+
+
+}
+/*
+ * :vim:et:sw=2:ts=2:
+ */ 
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..a8ea9ae
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,262 @@
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string.h>
+#include <map>
+#include <list>
+#include <set>
+#include <stack>
+
+#include <gdmo_config.h>
+// For open / close
+#include <fcntl.h>
+// for access function I need unistd
+#include "ADT/Adt.h"
+#include "libparser/gdmo_parser.h"
+#include "ast/ast_builder.h"
+
+#include "libgen/gdmo_generator.h"
+#include "libgen/gdmo_genasn1.h"
+#include "libgen/gdmo_genhpp.h"
+#include "libgen/gdmo_gencpp.h"
+
+
+#include "optionparser.h"
+
+/**
+ * Global Variables for the parser / lexer
+ */
+
+std::list<std::string>  asn1_files;
+
+enum optionIndex {UNKNOWN, HELP, JAVASCRIPT,F_ASN1,BER,XER,PER,JER,FICHIER,OUTPUT,INCLUDE,NESTED,COMMENT,OPT_END};
+const option::Descriptor usage[] = {
+ {UNKNOWN,      0, "", "", option::Arg::None,"Usage gdmo [options]\n\texample: gdmo  -f toto.gdmo -I[path]\n"},
+ {HELP,         0, "h",  "help",option::Arg::None,"--help,-h \tPrint help and quit."},
+ {JAVASCRIPT,   0, "j", "javascript",option::Arg::Optional,"--javascript,-j \tGenerate javascript parser."},
+ {F_ASN1,       0, "a", "asn1",  option::Arg::Optional,"--asn1,-a \tAsn1 input file to parse"},
+ {BER,          0, "b", "ber",  option::Arg::None,"--ber,-b \tGenerate BER encode/decode code"},
+ {XER,          0, "x", "xer",  option::Arg::None,"--xer,-x \tGenerate XER encode/decode code"},
+ {PER,          0, "p", "per",  option::Arg::None,"--per,-p \tGenerate PER encode/decode code"},
+ {JER,          0, "J", "jer",  option::Arg::None,"--jer,-J \tGenerate JER (json) encode/decode code"},
+ {FICHIER,      0, "f", "file", option::Arg::Required,"--file,-f \tGDMO input file to parse"},
+ {OUTPUT,       0, "o", "ouput", option::Arg::Required,"--output,-o \toutput file without extension to be generated"},
+ {INCLUDE,      0, "I", "include",     option::Arg::Required,"--include,-I\tInclude path to look for other asn1 files."},
+ {NESTED,       0, "n", "nested",     option::Arg::Required,"--nested,-n\ttrue/false should structures be nested or not"},
+ {COMMENT,      0, "c", "comment",     option::Arg::Required,"--comment,-n\ttrue/false generate comment in source def true"},
+ {0,0,0,0,0,0}
+};
+
+
+/**
+ * Simple listener
+ */ 
+class test : public GDMO::parser_listener
+{
+  public:
+    struct counters
+    {
+      counters() 
+       : m_mo(0), m_attributes(0), m_notif(0), m_action(0)
+       , m_param(0)
+      {
+      }
+      long m_attributes;
+      long m_mo;
+      long m_notif;
+      long m_action;
+      long m_param;
+    };
+    test()
+     : m_mo(0), m_attributes(0), m_notif(0), m_action(0)
+       , m_param(0)
+       , m_counters()
+    {
+    }
+    ~test()
+    {
+    }
+    void display()
+    {
+      std::cout<<"Stats :\n";
+      std::cout<<"\tNb managed objects = "<<m_counters.m_mo<<std::endl;
+      std::cout<<"\tNb attributes      = "<<m_counters.m_attributes<<std::endl;  
+      std::cout<<"\tNb actions         = "<<m_counters.m_action<<std::endl;  
+      std::cout<<"\tNb notifications   = "<<m_counters.m_notif<<std::endl;  
+      std::cout<<"\tNb parameter       = "<<m_counters.m_param<<std::endl;  
+    }
+  void on_mo_tplt(mo_tplt &)
+  {
+    m_counters.m_mo++;  
+  }
+
+  void on_attribute_tplt(attribute_tplt &)
+  {
+    m_counters.m_attributes++;  
+  }
+  //
+  void on_action_tplt(action_tplt &)
+  { m_counters.m_action++;  }
+  //
+  void on_notification_tplt(notification_tplt &)
+  { m_counters.m_notif++;  }
+  //
+  void on_parameter_tplt(parameter_tplt &)
+  { m_counters.m_param++;  }
+
+  void on_module_end(module &m)
+  {
+    size_t l = m.getName().size();
+    std::cout<<"Got module "<<m.getName()<<std::endl;
+    display();
+    memset(&m_counters,0x00,sizeof(counters));  
+  }
+
+  protected:
+    counters m_counters;
+    long m_attributes;
+    long m_mo;
+    long m_notif;
+    long m_action;
+    long m_param;
+};
+
+
+/**
+ * Main entry point
+ */
+int main(int argc,char **argv)
+{
+    std::map<std::string,std::string> module_map;
+    GDMO::parser *p = GDMO::parser::instance();
+    
+    // Option stuff must go here
+    option::Stats   stats(usage,argc-1,&argv[1]);
+    const int      max(stats.options_max);
+    option::Option  options[OPT_END*3],buffer[OPT_END*4];
+    option::Parser  parser(usage,argc-1,&argv[1],options,buffer);
+    ast_builder builder;  
+    test listener;
+    p->register_listener(&listener);
+    p->register_listener(builder.get_listener());
+
+    if (parser.error()) {
+        return 1;
+    }
+    if (options[HELP] )
+    {
+        option::printUsage(std::cout,usage);
+        return 1;
+    }
+    if (options[INCLUDE])
+    {
+        for (option::Option *opts = options[INCLUDE] ;opts; opts = opts->next()) {
+            if (opts->arg)
+                p->includes().push_back(std::string(opts->arg));
+        }
+    }
+    if (options[COMMENT])
+    {
+        for (option::Option *opts = options[COMMENT] ;opts; opts = opts->next()) {
+            if (opts->arg && ! strcmp(opts->arg,"false"))
+            {
+              //g_config.with_source_comment(false);  
+            }
+        }
+    }
+    if (options[F_ASN1] )
+    {
+        for (option::Option *opts = options[F_ASN1] ;opts; opts = opts->next()) {
+            if (opts->arg)
+                asn1_files.push_back(std::string(opts->arg));
+        }
+    } else
+    if (options[FICHIER] )
+    {
+        for (option::Option *opts = options[FICHIER] ;opts; opts = opts->next()) {
+            if (opts->arg)
+                p->files().push_back(std::string(opts->arg));
+        }
+       p->set_file_mode(true);
+        std::cout<<"Main: start with wrap feature"<<std::endl;
+        
+        if (p->parse())
+        {
+          std::cout<<"Main: start with wrap failed "<<std::endl;
+        }
+    } else
+    {
+      // Only file mode is available   
+      option::printUsage(std::cout,usage);
+      return 1;
+    }
+#if 0
+        if ( asn1_files.size() > 0 && !_asn1_wrap() )
+        {
+            !asn1_parse();
+        } else {
+          std::cout<<"Main: Failed parsing ASN1 files"<<std::endl;
+        }
+#endif
+    
+    genasn1 asn1gen(builder.get_modules());
+    asn1gen.generate();
+
+    genhpp hppgen(builder.get_modules());
+    hppgen.generate();
+    
+    gencpp cppgen(builder.get_modules());
+    cppgen.generate();
+#if 0 
+    for ( it = p->begin(); it != p->end(); it++ )
+    {
+      std::fstream os;
+      std::string fname = (*it)->cpp_name() + std::string(".h");
+      std::string fcname = (*it)->name() + std::string(".cpp");
+      std::string jsname = (*it)->name() + std::string(".js");
+      asn1::gen_auto_tag gen_auto((*it),p->modules());
+
+      // If OUTPUT option is set, only generate the specified module
+      if (options[OUTPUT] && (options[OUTPUT].arg != NULL )) {
+        if ((*it)->name().compare(options[OUTPUT].arg)  )
+                continue;
+      }
+      if (options[JAVASCRIPT])  
+      {
+          os.open(jsname.c_str(),std::fstream::out);
+          std::cout<<"\n*\n*Process javascript generation for Definition :"<<(*it)->name()<<"\n*"<<std::endl;
+          generate_js gen((*it),p->modules());
+          // Generate automatic tag. This class goes through the module for automatic tagging
+          gen_auto.gen(std::cout,".auto");
+          gen.gen(os,".js");
+          os.close();
+          
+      } else {
+          os.open(fname.c_str(),std::fstream::out);
+          std::cout<<"\n*\n*Process cpp generation for Definition :"<<(*it)->name()<<"\n*"<<std::endl;
+          // Generate automatic tag. This class goes through the module for automatic tagging
+          gen_auto.gen(std::cout,".auto1");
+          generate_header gen((*it),p->modules());
+          gen.set_config(g_config);
+          gen.gen(os,".hpp");
+          os.close();
+          
+          // Reset generated flag
+          asn1::node::iterator nit = (*it)->begin();
+          for (; nit != (*it)->end() ; nit++) 
+          {
+              //std::cout<<"Reset:"<<(*nit)->name()<<std::endl;
+              (*nit)->set_generated(false);
+          }
+          // Generate codec cod
+          os.open(fcname.c_str(),std::fstream::out);
+          generate_codec_cpp genc((*it),p->modules());
+          genc.set_config(g_config);
+          genc.gen(os,".cpp");
+          os.close();
+      }
+    }
+#endif
+    std::cout<<"Bye "<<argv[0]<<std::endl;
+
+}
diff --git a/pgdmo/GDMOTemplates.py b/pgdmo/GDMOTemplates.py
new file mode 100644 (file)
index 0000000..ad798ec
--- /dev/null
@@ -0,0 +1,5 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 filetype=python list
+
+
diff --git a/pgdmo/GDMOUtils.py b/pgdmo/GDMOUtils.py
new file mode 100644 (file)
index 0000000..5d14820
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 filetype=python list
+
+class Asn1ObjectIdentifier(object):
+    _oid_list = ()
+    def __init__(self,oidl):
+        self._oid_list = oidl
+
+    def __str__(self):
+        s = ",".join([ str(arc) for arc in self._oid_list ])
+        return "{ %s }" % (s)
+        
+    def resolve(self,parent):
+        self.gdmo = parent
+
+    def encode(self,oid):
+        first_octet = 40 * oid[0] + oid[1]
+        rest = ""
+        length = 1
+        for v in range(2, len(oid)):
+            if oid[v] < 127:
+                rest += chr(oid[v])
+                length += 1
+            else:
+                r = self.base126_encode(oid[v])
+                length += length(r)
+                rest = rest.append(r)
+        rest = chr(first_octet) + rest
+        return rest 
+
+
+    def base128_encode(n): # int/long to byte string
+        if n > 0:
+            arr = []
+            while n:
+                n, rem = divmod(n, 128)
+                arr.append(chr(rem))
+            return ''.join(reversed(arr))
+        elif n == 0:
+            return '\x00'
+        else:
+            raise ValueError
+
diff --git a/pgdmo/Generators/__init__.py b/pgdmo/Generators/__init__.py
new file mode 100644 (file)
index 0000000..862bb09
--- /dev/null
@@ -0,0 +1,7 @@
+
+from common import Common
+from db import GenDbPub
+from db import GenDbAttributeConstant
+from db import GenDbManagedObjectConstant
+from asn1 import Asn1Objects
+from mocpp import CPPMObjects
diff --git a/pgdmo/Generators/asn1.py b/pgdmo/Generators/asn1.py
new file mode 100644 (file)
index 0000000..e4bbfeb
--- /dev/null
@@ -0,0 +1,88 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 list
+
+from ply import *
+from gdmoparse import *
+import sys, os.path
+from Generators import Common
+
+
+attribute_object='''--
+-- Attribute %(attribute)s
+--
+%(attribute)s CMIP-ATTRIBUTE ::= { 
+     TYPE %(attribute_type)s
+     ID  %(form)s : { %(oid)s }
+}
+'''
+
+action_object='''--
+-- Action %(action)s
+--
+%(action)s CMIP-ACTION ::= { 
+     TYPE %(action_type)s
+     ID  %(form)s : { %(oid)s } 
+  }
+'''
+
+asn1_imports='''IMPORTS
+  CMIP-ATTRIBUTE, AttributeSet, DistinguishedName, CMISFilter, Attribute,
+    BaseManagedObjectId, AttributeId, ObjectInstance, ObjectClass, EventTypeId
+    FROM CMIP-1 {joint-iso-itu-t ms(9) cmip(1) modules(0) protocol(3)}
+      ;
+'''
+
+class Asn1Objects(Common): 
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+
+    def gen_attlist(self,f):
+        '''Loop over attribute list and generate code in f'''
+        for attribute in self.gdmoAST.attlist:
+            oid = attribute.getOid()
+            if oid is None:
+                continue
+            oid = " ".join([str(p) for p in attribute.getOid() ]  )
+            if attribute is None:
+                continue
+            
+            params= { 'attribute'     : str(attribute.getName())
+                    , 'attribute_type' : str(attribute.getSyntax(self.gdmoAST))
+                    , 'form'          : "globalForm"
+                    , 'oid'           : oid
+                    }
+            result = attribute_object % params
+            f.write(result)
+
+
+    def gen_actions(self,f):
+        '''Loop over action list and generate code in f'''
+        for action in self.gdmoAST.actions:
+            if oid is None:
+                continue
+            oid = " ".join([str(p) for p in action.getOid() ]  )
+            params= { 'action'     : str(action.getName())
+                    , 'action_type' : str(action.getWithInfoSyntax())
+                    , 'form'          : "globalForm"
+                    , 'oid'           : oid
+                    }
+            result =action_object % params
+            f.write(result)
+            print "TODO ACTION"
+
+    def gen_prolog(self,f):
+        f.write("Gdmo-Model {joint-iso-itu-t ms(9) }\n")
+        f.write("DEFINITIONS IMPLICIT TAGS ::=\n")
+        f.write("BEGIN\n")
+        f.write(asn1_imports)
+
+    def gen_epilog(self,f):
+        f.write("END")
+
+    def generate(self,output_file = "gdmo_objects.asn1" ):
+        with open(output_file,'w') as self.file:
+            self.gen_prolog(self.file)
+            self.gen_attlist(self.file)
+            self.gen_actions(self.file)
+            self.gen_epilog(self.file)
diff --git a/pgdmo/Generators/common.py b/pgdmo/Generators/common.py
new file mode 100644 (file)
index 0000000..4be57b7
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 list
+
+from ply import *
+import gdmolex,gdmoparse
+from gdmoparse import *
+import sys, os.path
+
+
+class Common(object):
+    ''' Generic class with help methods to travel through the AST tree '''
+    def __init__(self,ast):
+        self.gdmoAST = ast
+    
+    def real_package(self,p):
+        if p.kind == 'package_template':
+            return p
+        return self.gdmoAST.getName(p.name)
+    
+    def real_attribute(self,attr):
+        if attr.kind == 'attribute_template':
+            return p
+        return self.gdmoAST.getName(attr.name)
+
+    def ofile(self,odir,filename):
+        ''' Compute absolute path from odir and filename'''
+        if odir is not None:
+            self.outputdir = odir
+            return os.path.join(odir,filename)
+        self.outputdir = "./"
+        return filename
+
+    def generateInDir(self,odir,outputfile):
+        self.generate(self.ofile(odir,outputfile))
diff --git a/pgdmo/Generators/db.py b/pgdmo/Generators/db.py
new file mode 100755 (executable)
index 0000000..fd7a521
--- /dev/null
@@ -0,0 +1,261 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 list
+
+from ply import *
+import gdmolex,gdmoparse
+from gdmoparse import *
+import sys, os.path
+from Generators import Common
+
+
+#
+# GenDbPub class generates dbi file
+#
+class GenDbPub(Common):
+
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+
+    def get_type(self,attr):
+        real_attr = attr
+        if (attr.kind == 'attribute'):
+            try:
+                real_attr = self.gdmoAST.getName(attr.name)
+            except Exception , err:
+                print err
+                return "long"
+        #Check if syntax or derived 
+        return real_attr.getSyntax(GDMO)
+
+    def gen_attribute(self,attr,ofd):
+        ofd.write(" %s\t\t%s; \t\t/* %s*/\n" % (self.get_type(attr).getType(),attr.name.getName().lower(),
+                                               self.get_type(attr)))
+
+
+    def gen_mo(self):
+        self.union_table = "\nunion {\n unsigned char *ptr_on_mo[MAX_MANAGED_OBJECT_CLASS];\n"
+        self.union_table += " struct {\n"
+        for mo in self.gdmoAST.mo:
+            name = mo.name.getName().lower()
+            self.union_table += "  cmi_%s *%s_table;\n" %(name,name)
+            self.file.write("struct _%s \n{\n" % name)
+            print ("GenDbPub Proce MO %s" % name )
+            # Handle Derivations 
+            if mo.derives is not None:
+                for d in mo.derives:
+                    dname = d.getName().lower()
+                    self.file.write(" long mo_%s; /* Parent Object index */\n" % (dname  ))
+            # Handle packages
+            for attr ,na in mo.attributes():
+                self.gen_attribute(attr,self.file)
+
+            self.file.write("} cmi_%s;\n\n" % name)
+
+        self.union_table += "  } type_ptr;\n"
+        self.union_table += "} p_on_mo;\n\n"
+        self.file.write(self.union_table)
+    
+    def generate(self,filename="db_pub.db"):
+        ga = GenDbAttributeDescription(self.gdmoAST)
+
+        with open(filename,'w') as self.file:
+            self.gen_mo()
+            self.file.write(ga.generate())
+#
+# Attribute constants
+#
+attr_const='''#define CMIP_%(attr)s\t\t\t(%(val)d)\n'''
+
+class GenDbAttributeConstant(Common):
+    '''Generate  Attribute constants'''
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+        self.count = 0
+
+    def gen_mo(self):
+        for  mo in self.gdmoAST.mo:
+            name = mo .name.getName().upper()
+            self.file.write(attr_const % {'attr' : name, 'val' : self.count  })
+            self.count +=1
+            for attr , na  in mo.attributes():
+                name =  attr.name.getName().upper()
+                self.file.write(attr_const % {'attr' : name, 'val' : self.count  })
+                self.count +=1
+
+
+    def generate(self,filename="g_attribute.db"):
+        with open(filename,'w') as self.file:
+            self.gen_mo()
+
+
+#
+# Managed Object constants
+#
+mo_const='''#define %s\t\t(%d)\n'''
+d_mo_name_header="""/**
+ *  Generated file by pgdmo DO NOT EDIT
+ */
+"""
+
+class GenDbManagedObjectConstant(Common):
+    '''Generate  Managed Object constants'''
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+        self.count = 0
+
+    def gen_mo(self,db_fd):
+        for  mo in self.gdmoAST.mo:
+            name = mo .name.getName().upper()
+            db_fd.write(mo_const % (name,self.count) )
+            self.count +=1
+        db_fd.write(mo_const % ("MAX_MANAGED_OBJECT_CLASS",self.count))
+        db_fd.close()
+
+
+    def generate(self,filename="db_mo_name.dbi"):
+        with open(filename,'w') as db_fd:
+            db_fd.write(d_mo_name_header)
+            self.gen_mo(db_fd)
+            db_fd.close()
+
+#
+# Attributes Decription Table....
+#
+attribute_header='''
+struct attribute_description$
+{
+    unsigned int               mo;  /* Managed Object INDEX CMI_.... */
+    long                      default_value, min_value, max_value;
+    unsigned char             attribute_type; /*                     */
+    unsigned int              corr_attribute; /* in ldd definition. From Name Binding IF EXISTS   */
+    unsigned int              next_attr_in_entity;
+    dword                     dyn_add;        /* Offset of attr in mo*/
+    byte                kind;
+    word                length;
+    byte                dummy[5]; /* -> sizeof adt is a power of 2 */
+};
+        
+#define attribute_offset(mo,attr) &((((mo)*)0)->attr)
+static struct attribute_description const adt[]  = 
+{
+'''
+attribute_mo='''/****************
+ * %(mo)s
+ ***************/
+'''
+
+attribute_item='''  {    %(mo)s
+     , %(default)s, %(min)s , %(max)s
+     , CMIP_%(attr)s
+     , %(corr_attr)s
+     , CMIP_%(next_attr)s
+     , attribute_offset(cmi_%(mot)s,%(attr_type)s) 
+     , %(kind)s
+     , sizeof(%(attr_type)s) 
+  },
+'''
+
+class GenDbAttributeDescription(Common):
+    '''Generate  Attribute table for all attributes '''
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+
+    
+
+
+    def gen_mo(self):
+        result = "".join(attribute_header)
+
+        for mo in self.gdmoAST.mo:
+            fa = mo.first_attribute()
+            result +=attribute_mo % {'mo' : mo.name}
+            params = { 'mo'        : mo.name.getName().upper()
+                       ,'default'  : "0"
+                       ,'min'      : "0"
+                       ,'max'      : "0"
+                       ,'attr_type': fa.name.getName().lower() if fa is not None else "NIL"
+                       ,'corr_attr': "NIL_ATTR_NAME"
+                       ,'next_attr': fa.name.getName().upper() if fa is not None else "NIL"
+                       ,'mot'      : mo.name.getName().lower()
+                       ,'attr'     : "NIL" 
+                       ,'kind'     : "BASIC_KIND"
+                       }
+            result += attribute_item % params
+            for a,na in mo.attributes():
+                params = { 'mo'        : mo.name.getName().upper()
+                           ,'default'  : "0"
+                           ,'min'      : "0"
+                           ,'max'      : "0"
+                           ,'attr_type': a.name.getName().lower()
+                           ,'corr_attr': "NIL_ATTR_NAME"
+                           ,'next_attr':  na.name.getName().upper() if na is not None else "NIL"
+                           ,'mot'      : mo.name.getName().lower()
+                           ,'attr'     : a.name.getName().upper()
+                           ,'kind'     : "BASIC_KIND"
+                           }
+                result += attribute_item % params
+        return result
+
+    def generate(self):
+        return self.gen_mo()
+
+
+#
+# Main netry point
+#
+
+
+def ofile(odir,filename):
+    if odir is not None:
+        return os.path.join(odir,filename)
+    return filename
+
+if __name__ == '__main__':
+    from optparse import OptionParser
+    o = OptionParser()
+    o.add_option('-I',action='append',dest='incdirs',default=['.'],
+                 help="Directory to search for imported files")
+
+    o.add_option('-D',dest='outdir',default=None,
+                 help="Directory to generate files")
+
+    o.add_option('-d',action='store_true', dest='debug', default=False,
+                help='Set Debug for parser')
+
+    o.add_option('-f',dest='files',action = 'append', default=[],
+                 help="Files to parse")
+
+    options,args = o.parse_args()
+
+    if options.outdir is not None:
+        if not os.path.isdir(options.outdir):
+            os.mkdir(options.outdir)
+
+    if options.files is None:
+        print >>sys.stderr, "-f file required"
+        sys.exit(1)
+
+    print "Parsing %s" % options.files
+    p = GDMOParser()
+
+    GDMO = p.parse_files(options.files, 1 if options.debug else 0);
+
+    filename = ofile(options.outdir,"db_mo_name.dbi")
+    
+    with open(filename,'w') as db_fd:
+        db_fd.write(d_mo_name_header)
+        count = 0
+        for mo in GDMO.mo:
+            db_fd.write("#define %s\t\t(%d)\n" % (mo.name.getName().upper(),count) )
+            count+=1
+
+        db_fd.write("#define %s\t\t(%d)\n" % ("MAX_MANAGED_OBJECT_CLASS",count))
+
+        db_fd.close()
+
+    pub = GenDbPub(GDMO)
+    pub.generate(ofile(options.outdir,"db_pub.dbi"))
+
+    ac = GenDbAttributeConstant(GDMO)
+    ac.generate(ofile(options.outdir,"g_attribute.db"))
diff --git a/pgdmo/Generators/mocpp.py b/pgdmo/Generators/mocpp.py
new file mode 100644 (file)
index 0000000..18633e0
--- /dev/null
@@ -0,0 +1,269 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 list
+
+from ply import *
+from gdmoparse import *
+import sys, os.path
+from Generators import Common
+
+
+attribute_object='''--
+-- Attribute %(attribute)s
+--
+%(attribute)s CMIP-ATTRIBUTE ::= { 
+     TYPE %(attribute_type)s
+     ID  %(form)s : { %(oid)s }
+}
+'''
+
+action_object='''--
+-- Action %(action)s
+--
+%(action)s CMIP-ACTION ::= { 
+     TYPE %(action_type)s
+     ID  %(form)s : { %(oid)s } 
+  }
+'''
+
+h_header='''#ifndef __%(name)s_H__
+#define __%(name)s_H__
+'''
+h_ctors='''    ///
+    %(name)s();
+    ///
+    %(name)s(const %(name)s &c);
+    ///
+    virtual ~%(name)s();
+'''
+
+h_get='''
+    /**
+     * Lookup for the right attribute and set _attr accordingly.
+     *  The main difficulty is to find the right attribute and
+     *   call the appropriate function
+     *  returns an error if the attribbute is not found or access denied
+     */
+    int getAttribute(CMIP_1::AttributeId &_id,CMIP_1::IATTRIBUTE **_attr);
+
+'''
+
+cpp_get='''
+/**
+ *  returns an error if the attribbute is not found or access denied
+ */
+int
+%(name)s::getAttribute(CMIP_1::AttributeId &_id,CMIP_1::IATTRIBUTE **_attr)
+'''
+
+h_set='''
+    /**
+     * Lookup for the right attribute and set _attr accordingly.
+     *  The main difficulty is to find the right attribute and
+     *   call the appropriate function
+     *  returns an error if the attribbute is not found or access denied
+     */
+    int setAttribute(CMIP_1::IATTRIBUTE &_attr);
+
+'''
+
+cpp_set='''
+/**
+ * Lookup for the right attribute and set _attr accordingly.
+ *  The main difficulty is to find the right attribute and
+ *   call the appropriate function
+ *  returns an error if the attribbute is not found or access denied
+ */
+int
+%s(name)::setAttribute(CMIP_1::IATTRIBUTE &_attr)
+'''
+
+cpp_cast_attribute_ptr='''
+  %(attribute)s *%(var)s = static_cast<%attribute *>(%(parameter)s);
+'''
+cpp_cast_attribute_ref='''
+  %(attribute)s &%(var)s = static_cast<%attribute &>(%(parameter)s);
+'''
+
+h_attribute_set='''    //void %(attr)s_get(CMIP_1::IATTRIBUTE &a);
+    void %(attr)s_get(%(scope)s::%(attr_type)s &_a);
+'''
+cpp_attribute_set='''
+void
+%(oname)s::%(attr)s_get(%(scope)s::%(attr_type)s &_a)
+{
+  std::cout<<"%(oname)s::"<<__FUNCTION__<<"TODO"<<std::endl;
+}
+'''
+
+
+cpp_header='''#include <iostream>
+#include <string>
+#include <map>
+#include "Remote_Operations_Generic_ROS_PDUs.h"
+#include "ACSE_1.h"
+#include "CMIP_1.h"
+#include "CMIP_1.hpp"
+
+#include "rtasn1/asn1_codec.h"
+#include "rtasn1/asn1_codec_ber.h"
+
+'''
+
+
+class CPPMObjects(Common): 
+    def __init__(self,ast):
+        Common.__init__(self,ast)
+
+    def get_type(self,attr):
+        real_attr = attr
+        if (attr.kind == 'attribute'):
+            try:
+                real_attr = self.gdmoAST.getName(attr.name)
+            except Exception , err:
+                print err
+                return "long"
+        #Check if syntax or derived 
+        return real_attr.getSyntax(GDMO)
+
+    def gen_attlist(self,f):
+        '''Loop over attribute list and generate code in f'''
+        for attribute in self.gdmoAST.attlist:
+            oid = attribute.getOid()
+            if oid is None:
+                continue
+            oid = " ".join([str(p) for p in attribute.getOid() ]  )
+            if attribute is None:
+                continue
+            
+            params= { 'attribute'     : str(attribute.getName())
+                    , 'attribute_type' : str(attribute.getSyntax(self.gdmoAST))
+                    , 'form'          : "globalForm"
+                    , 'oid'           : oid
+                    }
+            result = attribute_object % params
+            f.write(result)
+
+    def gen_get_attribute(self,mo,cppf,hf):
+        '''Generate code for get GetAttribute Function'''
+        def attr_case(attr):
+            blk='''
+  if (_id.get_Id.Equals(%(oid)s))
+  {
+    %(name)s *a = new %(name)s();
+    *_attr = a;
+    %(name)s_get(a->getValue());
+    return 0;
+  }
+'''
+            return blk % {'name' : attr.name
+                         , 'oid' : attr.getOid()
+                         }
+
+        name = mo.name.getName()
+        hf.write(h_get)
+        hf.write(h_set)
+        cppf.write(cpp_get
+                    % { 'name' : name })
+        cppf.write("{\n")
+        # Handle packages
+        for attr ,na in mo.attributes():
+            cppf.write(attr_case(attr))
+
+        cppf.write("\n}\n")
+
+    def gen_attribute(self,mo_name,attr,cppf,hf):
+        ''' Why is attr of type AttributeTemplate ?'''
+        aname = attr.name.getName()
+        _type = self.get_type(attr)
+        atype = _type.getType()
+        scope = _type.getScope().replace("-","_")
+
+        if attr.prop_get:
+            hf.write("\n")
+            hf.write(h_attribute_set %
+                        { 'attr' : aname
+                        , 'scope': scope
+                        , 'attr_type' : atype } )
+            cppf.write(cpp_attribute_set %
+                    { 'oname'     : mo_name
+                    , 'attr'      : aname
+                    , 'scope'     : scope
+                    , 'attr_type' : atype} )
+
+        if attr.prop_replace:
+            hf.write("    void %s_set(const %s::%s &_a);\n" %
+                         (aname,scope,atype) )
+            cppf.write("\nvoid\n%s::%s_set(const %s::%s &_a)\n{\n}\n" %
+                        (mo_name,aname,scope,atype) )
+
+        if attr.prop_add:
+            hf.write("    void %s_add(const %s::%s &_a);\n" %
+                         (aname,scope,atype) )
+            cppf.write("\nvoid\n%s::%s_add(const %s::%s &_a)\n{\n}\n" %
+                        (mo_name,aname,scope,atype) )
+
+    def gen_actions(self,f):
+        '''Loop over action list and generate code in f'''
+        for action in self.gdmoAST.actions:
+            if oid is None:
+                continue
+            oid = " ".join([str(p) for p in action.getOid() ]  )
+            params= { 'action'     : str(action.getName())
+                    , 'action_type' : str(action.getWithInfoSyntax())
+                    , 'form'          : "globalForm"
+                    , 'oid'           : oid
+                    }
+            result =action_object % params
+            f.write(result)
+            print "TODO ACTION"
+
+    def gen_prolog(self,mo,cppf,hf):
+        cppf.write(cpp_header)
+        inc = "\n".join( "#include \"%s.h\"" % i for i in self.gdmoAST.scopes)
+        cppf.write(inc+"\n")
+        if mo.derives is not None:
+            herit = "\n".join([ "#include \"%s.h\"" % 
+                                    str(d) for d in mo.derives ]  )
+            cppf.write(herit+"\n")
+        hf.write(h_header % { 'name' : mo.name.getName().upper() })
+
+    def gen_epilog(self,mo,cppf,hf):
+        cppf.write("/* vim: et sw=2 ts=2: */")
+        hf.write("#endif\n/* vim: et sw=2 ts=2: */")
+
+    def gen_mo(self,mo,cppf,hf):
+        ''' Entry point for Managed Object C++ code generation '''
+        name = mo.name.getName()
+        hf.write("struct %s " % name)
+        print ("CPPMObjects Process MO %s" % name )
+        # Handle Derivations 
+        if mo.derives is not None:
+            herit = " , ".join([ "public %s" % str(d) for d in mo.derives ]  )
+            hf.write(" : "+herit)
+
+        hf.write("\n{\n\n  public:\n" )
+
+        cppf.write("#include \"%s.h\"\n\n" % (name) )
+        # Default ctors
+        hf.write(h_ctors % { "name" : name } )
+        cppf.write("%s::%s()\n{\n}\n" % (name,name) )
+        #
+        self.gen_get_attribute(mo,cppf,hf)
+        # Handle packages
+        for attr ,na in mo.attributes(False):
+            self.gen_attribute(name,attr,cppf,hf)
+
+        hf.write("} ;\n\n" )
+
+
+
+    def generate(self,output_dir = "Out/" ):
+        for mo in self.gdmoAST.mo:
+            name = mo.name.getName()
+            cpp_file = self.ofile(output_dir,name + ".cpp")
+            h_file = self.ofile(output_dir,name + ".h")
+            with open(cpp_file,'w') as cppf , open(h_file,'w') as hf:
+                self.gen_prolog(mo,cppf,hf)
+                self.gen_mo(mo,cppf,hf)
+                self.gen_epilog(mo,cppf,hf)
diff --git a/pgdmo/__init__.py b/pgdmo/__init__.py
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/pgdmo/gdmolex.py b/pgdmo/gdmolex.py
new file mode 100644 (file)
index 0000000..465afcb
--- /dev/null
@@ -0,0 +1,234 @@
+# My first gdmo lexer in python. I hope it will work
+
+from ply import *
+
+keywords = [
+  'ADD'
+  ,'ACTIONS'
+  ,'ACTION'
+  ,'AND'
+  ,'AS'
+  ,'ATTRIBUTES'
+  ,'ATTRIBUTE'
+  ,'BEHAVIOUR'
+  ,'BINDING'
+  ,'BY'
+  ,'CHARACTERIZED'
+  ,'CLASS'
+  ,'CONDITIONAL'
+  ,'CONFIRMED'
+  ,'CONTEXT'
+  ,'CREATE'
+  ,'DEFAULT'
+  ,'DEFINED'
+  ,'DELETE'
+  ,'DERIVATION'
+  ,'DERIVED'
+  ,'DESCRIPTION'
+  ,'ELEMENTS'
+  ,'EQUALITY'
+  ,'FIXED'
+  ,'FOR'
+  ,'FROM'
+  ,'GET'
+  ,'GROUPS'
+  ,'GROUP'
+  ,'IDS'
+  ,'IF'
+  ,'INFORMATION'
+  ,'INITIAL'
+  ,'MANAGED'
+  ,'MATCHES'
+  ,'MODE'
+  ,'NAMED'
+  ,'NAME'
+  ,'NOTIFICATIONS'
+  ,'NOTIFICATION'
+  ,'OBJECT'
+  ,'ORDERING'
+  ,'PACKAGE'
+  ,'PACKAGES'
+  ,'PARAMETER'
+  ,'PARAMETERS'
+  ,'PERMITTED'
+  ,'PRESENT'
+  ,'REGISTERED'
+  ,'REMOVE'
+  ,'REPLACE'
+  ,'REPLY'
+  ,'REQUIRED'
+  ,'RULE'
+  ,'SUBCLASSES'
+  ,'SUBORDINATE'
+  ,'SUBSTRINGS'
+  ,'SUPERIOR'
+  ,'SYNTAX'
+  ,'VALUES'
+  ,'VALUE'
+  ,'WITH'
+]
+
+special_keywords = {
+    'ADD-REMOVE' : 'ADD_REMOVE'
+  ,'ACTION-INFO' :'ACTION_INFO'
+  ,'ACTION-REPLY' :'ACTION_REPLY'
+  ,'DELETES-CONTAINED-OBJECTS' :'DELETES_CONTAINED_OBJECTS'
+  ,'EVENT-INFO' :'EVENT_INFO'
+  ,'EVENT-REPLY' :'EVENT_REPLY'
+  ,'GET-REPLACE' :'GET_REPLACE'
+  ,'ONLY-IF-NO-CONTAINED-OBJECTS' :'ONLY_IF_NO_CONTAINED_OBJECTS'
+  ,'NO-MODIFY' :'NO_MODIFY'
+  ,'REPLACE-WITH-DEFAULT' :'REPLACE_WITH_DEFAULT'
+  ,'SET-BY-CREATE' :'SET_BY_CREATE'
+  ,'SET-COMPARISON' :'SET_COMPARISON'
+  ,'SET-INTERSECTION' :'SET_INTERSECTION'
+  ,'SPECIFIC-ERROR' :'SPECIFIC_ERROR'
+  ,'WITH-AUTOMATIC-INSTANCE-NAMING' :'WITH_AUTOMATIC_INSTANCE_NAMING'
+  ,'WITH-REFERENCE-OBJECT' : 'WITH_REFERENCE_OBJECT'
+}
+
+
+tokens = keywords + [ 'DOCUMENT','ALIAS','STRING', 'LBRACET', 'RBRACET', 'LPARENT', 'RPARENT', 'DOT', 'COMMA'
+        ,'SIMILICON' , 'COLON','TYPEREF','IDENTIFIER','NUM']
+
+tokens.extend(special_keywords.values())
+# Comment skip states
+states = (
+           ( 'dashc' , 'exclusive' ),
+           ( 'gdmo'  , 'exclusive' )
+        )
+
+def t_STRING(t):
+    r'(\"(?s).*?\")|(!(?s).*?!)'
+    t.lexer.lineno += t.value.count("\n")
+    return t
+
+def t_TYPEREF(t):
+    r'[A-Z][A-Za-z0-9]*([-][a-zA-Z0-9]+)*'
+    # Check if in special keywords
+    if (special_keywords.get(t.value,'') != ''):
+        t.type = special_keywords.get(t.value)
+    
+    if t.value in keywords:
+        t.type = t.value
+    return t
+
+def t_IDENTIFIER(t):
+    r'[a-z][A-Za-z0-9]*([-][a-zA-Z0-9]+)*'
+    if t.value in keywords:
+        t.type = t.value
+    return t
+
+def t_NEWLINE(t):
+    r'[\n\r]'
+    t.lexer.lineno += 1
+    pass
+
+
+def t_error(t):
+    print("Illegal character line: %d <%s >" % (t.lexer.lineno , t.value[0]))
+    t.lexer.skip(1)
+
+def t_dashdd(t):
+    r'--'
+    t.lexer.begin('dashc')
+
+def t_eof(t):
+    if len(t.lexer.files) > 0:
+        t.lexer.filename = t.lexer.files.pop()
+        fd = open(t.lexer.parser.search_file(t.lexer.filename))
+        data = fd.read()
+        fd.close()
+        t.lexer.input(data)
+        return t.lexer.token()
+    return None
+
+
+# Comment rules
+def t_dashc_NEWLINE(t):
+    r'\n'
+    t.lexer.lineno += 1
+    t.lexer.begin('INITIAL')
+    pass
+
+def t_dashc_dash(t):
+    r'-'
+    pass
+
+def t_dashc_alias(t):
+    r'<GDMO.Alias'
+    t.lexer.begin('gdmo')
+    t.type = 'ALIAS' 
+    return t
+
+def t_dashc_document(t):
+    r'<GDMO.Document'
+    t.lexer.begin('gdmo')
+    t.type = 'DOCUMENT' 
+    return t
+
+def t_dashc_string(t):
+    r'(\"(?s).*?\")|(!(?s).*?!)'
+    t.lexer.lineno += t.value.count("\n")
+    pass
+    #return t
+
+def t_dashc_comment(t):
+    r'.[^\n]*'
+    #t.lexer.lineno += 1
+    t.lexer.begin('INITIAL')
+    pass
+
+def t_dashc_error(t):
+    print("Illegal state dashc character line %d %s" % (t.lexer.lineno,t.value[0]) )
+    t.lexer.skip(1)
+
+t_dashc_ignore = ' =.()\t\r'
+
+#
+# GDMO State
+#
+def t_gdmo_string(t):
+    r'(\"(?s).*?\")|(!(?s).*?!)'
+    t.lexer.lineno += t.value.count("\n")
+    t.type = 'STRING'
+    return t
+
+def t_gdmo_comma(t):
+    r',|--'
+    pass
+
+def t_gdmo_end(t):
+    r'>--\n'
+    t.lexer.lineno += 1
+    t.lexer.begin('INITIAL')
+    pass
+
+def t_gdmo_NEWLINE(t):
+    r'\n'
+    t.lexer.lineno += 1
+    pass
+
+def t_gdmo_error(t):
+    print("Illegal state gdmo character line %d %s" % (t.lexer.lineno,t.value[0]) )
+    t.lexer.skip(1)
+
+t_gdmo_ignore = ' \t'
+
+
+t_ignore = ' \t'
+
+t_NUM = r'\d+'
+t_LBRACET = r'\{'
+t_RBRACET = r'\}'
+t_RPARENT = r'\)'
+t_LPARENT = r'\('
+t_DOT = r'\.'
+t_COMMA = r','
+t_SIMILICON = r';'
+t_COLON = r':'
+
+def GDMOLexer(outdir = '',dbg = 0):
+    return lex.lex(debug=dbg
+                   , outputdir = outdir
+                   , lextab='gdmolex')
diff --git a/pgdmo/gdmoparse.py b/pgdmo/gdmoparse.py
new file mode 100755 (executable)
index 0000000..7d830f0
--- /dev/null
@@ -0,0 +1,1559 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 list
+from ply import *
+import gdmolex
+import sys, os.path
+from os.path import exists, join,abspath
+import hashlib
+from gdmolex import *
+from GDMOUtils import *
+
+class Label(object):
+    kind = 'label'
+    name = ""
+    def __init__(self,reference,name,location):
+        self.name      = name
+        self.reference = reference
+        self.location  = location
+
+    def __eq__(self,other):
+        return self.name == other.name
+
+    def getName(self):
+        return self.name
+
+    def __str__(self):
+        if self.reference == None:
+            return "%s" % (self.name)
+        return "%s:%s" % (self.reference, self.name)
+
+    def __hash__(self):
+        return hash(self.name) 
+
+class Typeref(object):
+    def __init__(self,ref1,ref2):
+        self.ref1 = ref1
+        self.ref2 = ref2
+    def getType(self):
+        return self.ref2
+    
+    def getScope(self):
+        return self.ref1
+
+    def __str__(self):
+        return "%s.%s" % (self.ref1, self.ref2)
+
+
+class Template(object):
+    kind = 'package'
+
+    def __init__(self,label,oid):
+        self.name = label
+        self.oid  = oid
+
+    def real_package(self,p):
+        if p.kind == 'package_template':
+            return p
+        return self.gdmo.getName(p.name)
+
+    def real_attribute(self,attr):
+        if attr.kind == 'attribute_template':
+            return p
+        return self.gdmo.getName(attr.name)
+
+    def __eq__(self,other):
+        return self.name == other.name and self.oid == other.oid
+
+    def getName(self):
+        return self.name
+
+    def getOid(self):
+        return self.oid
+
+    def isRegistered(self):
+        return self.oid != None
+
+class MObject(Template):
+    kind = 'managed_object_template'
+
+    def __init__(self,label,derives,packages,cond_pkgs,oid):
+        Template.__init__(self,label,oid)
+        self.packages      = packages
+        self.derives       = derives
+        self.cond_packages = cond_pkgs
+
+    def attributes(self,template = True):
+        ''' Get All attributes supported by the managed object class'''
+        def invar(obj,lst):
+            for p in lst:
+                rp     = self.real_package(p)
+                np_idx = lst.index(p)
+                np     = lst[np_idx + 1] if np_idx + 1 < len(lst) else None
+                if rp.attributes is not None:
+                    for a in rp.attributes:
+                        idx  = rp.attributes.index(a)
+                        next = rp.attributes[idx + 1] if idx + 1 < len(rp.attributes) else None
+                        if not next and np:
+                            nrp = self.real_package(np)
+                            if nrp.attributes is not None:
+                                next = nrp.attributes[0]
+                        if template:
+                            yield ( self.real_attribute(a) , next)
+                        else:
+                            yield ( a , next)
+        pkgs = []
+        if self.packages is not None:
+            pkgs += self.packages
+
+
+        if self.cond_packages is not None:
+            pkgs += self.cond_packages
+
+        for i in invar(self,pkgs):
+                yield  i
+
+
+    def first_attribute(self):
+        for a,n in self.attributes():
+            return a
+
+    def resolve(self,parent):
+        parent.setName(self)
+        self.gdmo = parent
+
+    def __str__(self):
+        sc = "\n\tCONDITIONAL PACKAGES "
+        if (self.cond_packages != None):
+            sc = sc + "\n\t, ".join([str(p) for p in self.cond_packages])
+        else:
+            sc = ""
+        sp = "\n\tCHARACTERIZED BY\n\t"
+        if (self.packages != None):
+            sp = sp + "\n\t ".join([str(p) for p in self.packages])
+        else:
+            so = ""
+        sd = "\n\tDERIVED FROM "
+        if (self.derives != None):
+            sd = sd + ", ".join([str(p) for p in self.derives])
+
+        return "%s MANAGED OBJECT CLASS  %s %s;%s\n" % (self.name ,sd, sp,sc)
+
+class Package(object):
+    kind = 'package'
+
+    def __init__(self,label , presentif = None):
+        self.name       = label
+        self.present_if = presentif
+
+    def isConditional(self):
+        return self.present_if != None
+
+    def setPresentIf(selft , presentif):
+        selft.present_if = presentif
+
+    def __str__(self):
+        return "Pkg %s" % ( str(self.name) )
+
+class PackageTemplate(Template):
+    kind = 'package_template'
+
+
+    def __init__(self,label,attrs,behav,attr_grp,actions,notif,oid):
+        Template.__init__(self,label,oid)
+        self.attributes    = attrs
+        self.behaviours    = behav
+        self.attr_group    = attr_grp
+        self.actions       = actions
+        self.notifications = notif
+        self.present_id    = None
+
+    def resolve(self,parent):
+        parent.setName(self)
+
+    def __str__(self):
+        sa = "\n\tACTIONS "
+        if (self.actions != None):
+            sa = sa + "\n\t ".join([str(p) for p in self.actions])
+        else:
+            sa = ""
+        sattr = "\n\tATTRIBUTES "
+        if (self.attributes != None):
+            sattr = sattr + "\n, ".join([str(p) for p in self.attributes])
+        else:
+            sattr = ""
+            
+        sb = "\n\tBEHAVIOUR "
+        if (self.behaviours != None):
+            sb = sb + "\n ".join([str(p) for p in self.behaviours])
+        else:
+            sb = ""
+        sb+=";"    
+        return "%s PACKAGE %s %s %s ;"  % ( str(self.name) ,sb, sattr,sa  )
+
+    def setPresentIf(selft , presentif):
+        selft.present_if = presentif
+
+    def isConditional(self):
+        return self.present_if != None
+#
+# There is a difference between an Attribute and Attribute Template
+#
+class Attribute(object):
+    kind = 'attribute'
+    prop_get     = False
+    prop_replace = False
+    prop_add     = False
+    prop_remove  = False
+
+    def __init__(self,label,props = None,params = None ):
+        self.name = label
+        self.properties = props
+        self.parameters = params
+        if (self.properties != None):
+            p = self.properties['get_replace']
+            #print ("Property : %s " % (p))
+            if ( p == "GET"):
+                self.prop_get = True
+            if (p == "REPLACE"):
+                self.prop_replace = True
+            if ( p == "GET-REPLACE"):
+                self.prop_replace = True
+                self.prop_get = True
+
+            p = self.properties['add_remove']
+            if ( p == "ADD-REMOVE"):
+                self.prop_add = True
+                self.prop_remove = True
+
+
+    def __str__(self):
+        prop = ""
+        if (self.prop_get):
+            prop = prop + "GET"
+        if (self.prop_replace):
+            prop = prop + " REPLACE"
+        return "%s %s" % ( str(self.name) , prop )
+
+class AttributeTemplate(Template):
+    kind = 'attribute_template'
+    
+    def __init__(self,label,typ,match,behav,params,oid):
+        Template.__init__(self,label,oid)
+        self.type  = typ
+        self.match = match
+        self.behaviours  = behav
+        self.parameters  = params
+    
+    def resolve(self,parent):
+        parent.setName(self)
+        if self.hasSyntax():
+            parent.scopes.add(self.getSyntax(parent).getScope())
+    
+    def hasSyntax(self):
+        return self.type['syntax'] is not None
+    
+    def hasDerivedSyntax(self):
+        return self.type['derived'] is not None
+    
+    def getDerived(self):
+        return self.type['derived']
+
+    def getSyntax(self,model):
+        if (self.hasDerivedSyntax()):
+            par = model.getName(self.getDerived())
+            return par.getSyntax(model)
+        return self.type['syntax']
+
+
+    def __str__(self):
+        sTy = ""
+        if (self.type['syntax'] != None):
+            sTy = "WITH ATTRIBUTE SYNTAX " + str(self.type['syntax'])
+        else:
+            sTy = "DERIVED FROM " + str(self.type['derived'])
+
+        return "%s ATTRIBUTE\n\t %s " % ( str(self.name) , sTy)
+
+class AttributeGroupeTemplate(Template):
+    kind = 'attribute_groupe_template'
+    
+    def __init__(self,label,elements,fixed,desc,oid):
+        Template.__init__(self,label,oid)
+        self.elements = elements
+        self.fixed    = fixed
+        self.desc     = desc
+    
+    def resolve(self,parent):
+        parent.setName(self)
+    
+    def __str__(self):
+        se = "\n\tELEMENTS\n\t"
+        if (self.elements != None):
+            se = se + "\n\t, ".join([str(p) for p in self.elements])
+        return "%s ATTRIBUTE GROUP %s" % ( str(self.name),se )
+
+
+class ParameterTemplate(Template):
+    kind = 'parameter_template'
+    
+    def __init__(self,label,ctx,type,behavior,oid):
+        Template.__init__(self,label,oid)
+        self.context = ctx
+        self.type    = type
+        self.behavior= behavior
+    
+    def resolve(self,parent):
+        parent.setName(self)
+    
+    def __str__(self):
+        return "%s PARAMETER ;" % ( str(self.name) )
+
+class Parameter(object):
+    kind = 'parameter'
+    
+    def __init__(self,label):
+        # Missing parameters
+        self.name = label
+
+
+# Action & Action Template
+class Action(object):
+    kind = 'action'
+    
+    def __init__(self,label):
+        # Missing parameters
+        self.name = label
+    def __str__(self):
+        return "ACT(%s)" % ( str(self.name) )
+
+
+class ActionTemplate(Template):
+    kind = 'action_template'
+    
+    def __init__(self,label,behaviour,mode,params,wi,wr,oid):
+        Template.__init__(self,label,oid)
+        self.behaviour  = behaviour
+        self.mode       = mode
+        self.parameters = params
+        self.with_info  = wi
+        self.with_reply = wr
+    
+    def resolve(self,parent):
+        parent.setName(self)
+    
+    def hasWithInfoSyntax(self):
+        return self.wi['INFORMATION'] is not None
+    
+    def hasWithReplySyntax(self):
+        return self.wr['REPLY'] is not None
+    
+    def getWithInfoSyntax(self):
+        return self.wi['INFORMATION']
+    
+    def getWithReplySyntax(self):
+        return self.wi['INFORMATION']
+
+    
+    def __str__(self):
+        return "%s ACTION ;" % ( str(self.name) )
+
+# NameBinding Template
+class NameBindingTemplate(Template):
+    kind = 'namebinding_template'
+
+    def __init__(self,label,sup,sub,attr,behav,create,delete,oid):
+        Template.__init__(self,label,oid)
+        self.subordinate  = sub['label']
+        self.superior     = sup['label']
+        self.attribute    = attr
+        self.behaviour    = behav
+        self.create       = create
+        self.delete       = delete
+
+    def __str__(self):
+        ssoc = "SUBORDINATE OBJECT CLASS " + str(self.subordinate)
+        ssup = "SUPERIOR OBJECT CLASS " + str(self.superior)
+        swa  = "WITH ATTRIBUTE " + str(self.attribute)
+        return "%s NAME BINDING\n %s;\n NAME BY\n\t%s;\n\t%s;\n " % ( str(self.name) ,ssoc ,ssup,swa )
+
+    def resolve(self,parent):
+        parent.setName(self)
+
+# Behaviour and BehaviourTemplate
+
+class Behaviour(object):
+    kind = 'behaviour'
+
+    def __init__(self,label):
+        self.name =label
+
+    def __str__(self):
+        return "BehaviourTplt(%s)" % ( str(self.name) )
+
+class BehaviourTemplate(Template):
+    kind = 'behavior_template'
+
+    def __init__(self,label,str):
+        Template.__init__(self,label,None)
+        self.message = str
+
+    def resolve(self,parent):
+        parent.setName(self)
+
+    def __str__(self):
+        return "%s BEHAVIOUR\n\tDEFINED AS %s;\n" % ( str(self.name),self.message )
+
+class ObjectIdentifier(object):
+
+    def __init__(self,ids):
+        self.ids = ids
+
+
+class NotificationTemplate(Template):
+    kind = 'notification_template'
+
+    def __init__(self,label,behaviours,params,syntax,reply,oid):
+        Template.__init__(self,label,oid)
+        self.behaviours = behaviours
+        self.params     = params
+        self.syntax     = syntax
+        self.reply      = reply
+
+    def resolve(self,parent):
+        parent.setName(self)
+
+    def __str__(self):
+        return "%s NOTIFICATION" %  str(self.name)
+
+class Notification(object):
+    kind = 'notification'
+    
+    def __init__(self,label):
+        self.name = label
+    
+    def __str__(self):
+        return "Noti(%s)" % ( str(self.name) )
+
+# Map of names and Objects 
+class NameMap(object):
+    def __init__(self):
+        self._d = {}
+
+    def __getitem__(self,key):
+        #print("NameMap(%d).__getitem__ <%s> type de key %s" % (len(self._d), key,type(key)))
+        #for i in self._d.keys():
+        #    print "NameMap has key %s type = %s" %  (i , type(i))
+        return self._d[key]
+
+    def __iter__(self):
+        return self._d.itervalues()
+
+    def __contains__(self,key):
+        return key in self._d
+
+    def __len__(self):
+        return len(self._d)
+
+    def set(self,object):
+        if object.name in self._d:
+            print "NameMap Object Allready in map: <%s>" % object.name
+            pass
+        else:
+            self._d[ object.name ] = object
+
+    def get(self,id):
+        print "NameMap get : %s" % id
+        try:
+            return self[id]
+        except:
+            raise GDMOError('NameMap get error ')
+
+# Missing Location
+class Location(object):
+    _line = False
+
+    def __init__(self,lexer,lineno,lexpos):
+        self._lineno  = lineno
+        self._lexpos  = lexpos
+        self._lexdata = lexer.lexdata
+        self._file    = getattr(lexer,'filename','<unknown>')
+
+    def pointerline(self):
+        def i():
+            for i in xrange(0,self._colno):
+                yield " "
+            yield "^"
+
+        return "".join(i())
+
+    def resolve(self):
+        if (self._line):
+            return
+
+        startofline = self._lexdata.rfind('\n',0,self._lexpos) + 1
+        endofline   = self._lexdata.find('\n',self._lexpos,self._lexpos + 80)
+        self._line  = self._lexdata[startofline:endofline]
+        self._colno = self._lexpos - startofline
+
+    def __str__(self):
+        self.resolve()
+        return "%s: line %s:%s\n%s\n%s" % (self._file,self._lineno,self._colno
+                                  ,self._line,self.pointerline())
+
+class GDMOError(Exception):
+    def __init__(self,message,lineno = 0,warning = False):
+        self.message  = message
+        self.warning = warning
+        self.lineno  = lineno
+
+    def __str__(self):
+        return "GDMO %s (%d): %s " % ( self.warning and 'warning' or 'error' ,self.lineno, self.message)
+
+class TranslationUnit(object):
+    templates = []
+    document  = ""
+    alias     = []
+    imports   = []
+
+    def __init__(self,header,template):
+        self.templates.append(template)
+
+    def addTemplate(self, template):
+        self.templates.append(template)
+
+    def resolve(self,parent):
+        self.gdmo = parent
+        for t in self.templates:
+            if t.kind is 'managed_object_template':
+                parent.mo.append(t)
+            if t.kind is 'attribute_template':
+                parent.attlist.append(t)
+            if t.kind is 'action_template':
+                parent.actions.append(t)
+            if t.kind is 'package_template':
+                parent.packages.append(t)
+            if t.kind is 'notification_template':
+                parent.notifs.append(t)
+            if t.kind is 'namebinding_template':
+                parent.nbindings.append(t)
+            # Needs to be changed
+            t.resolve(parent)
+
+#
+# Object Returned my parser.
+#
+class GDMO(object):
+    templates = []
+    def __init__(self,files):
+        self.files      = files
+        self.mo         = []
+        self.attlist    = []
+        self.actions    = []
+        self.packages   = []
+        self.notifs     = []
+        self.nbindings  = []
+        # namespaces for asn1 types
+        self.scopes     = set()
+    def setName(self,object):
+        self.namemap.set(object)
+
+    def getName(self,key):
+        try:
+            return self.namemap[key]
+        except KeyError:
+            raise GDMOError("GDMO.getName type %s not found\n%s " % (key,str(key.location )))
+
+    def hasName(self,id):
+        print ("GDMO.hasName %s length de namemap = %d" % (id,len(self.namemap)))
+        return id in self.namemap
+
+    def resolve(self):
+        print "GDMO.resolve resolving ..."
+        self.namemap = NameMap()
+
+        for f in self.files:
+            f.resolve(self)
+
+        print "GDMO.resolve Done"
+        print "\n\tTU %d\n\tMO %d\n\tAT %d\n\tAC %d\n\tNO %d\n" % \
+                (len(self.files),len(self.mo),len(self.attlist),len(self.actions),len(self.notifs))
+    def __str__(self):
+        return  "".join([str(p) for p in self.templates])
+
+
+
+#
+# GDMOParser Function. May be I should transform it into a class
+#
+#
+
+class GDMOParser(object):
+
+    tokens = gdmolex.tokens
+
+    def p_gdmo(self,p):
+        '''gdmo : definition_files'''
+        p[0] = GDMO(p[1])
+        p[0].resolve()
+
+    def p_definition_files_init(self,p):
+        '''definition_files : empty'''
+        print ("GDMOParser start empty")
+        p[0] = []
+
+    def p_definition_files_start(self,p):
+        '''definition_files : file'''
+        p[0] = [p[1]]
+
+    def p_definition_files_continue(self,p):
+        '''definition_files : definition_files file'''
+        print "New File "
+        p[0] = list(p[1])
+        p[0].append(p[2])
+
+    def p_file(self,p):
+        '''file : opt_gdmo_header template'''
+        header,template = p[1:]
+        p[0] = TranslationUnit(header,template)
+
+    def p_file_cont(self,p):
+        '''file : file template'''
+        p[0] = p[1]
+        p[0].addTemplate(p[2])
+
+    def p_opt_gdmo_header(self,p):
+        '''opt_gdmo_header : empty
+                           | opt_alias gdmo_doc opt_alias'''
+        if len(p) > 2:
+            p[0] = { 'alias' : p[1] , 'document' : p[2] , 'imports' : p[3] }
+
+    def p_opt_alias(self,p):
+        '''opt_alias : empty
+                     | gdmo_aliases'''
+        p[0] = p[1]
+
+    def p_gdmo_aliases_start(self,p):
+        '''gdmo_aliases : gdmo_alias'''
+        p[0] = [p[1]]
+
+    def p_gdmo_aliases_next(self,p):
+        '''gdmo_aliases : gdmo_aliases gdmo_alias'''
+        p[0] = list(p[1]) 
+        p[0].append(p[2])
+
+    def p_gdmo_alias_start(self,p):
+        '''gdmo_alias : ALIAS STRING'''
+        p[0] = [p[2]]
+
+    def p_gdmo_alias_next(self,p):
+        '''gdmo_alias : gdmo_alias STRING'''
+        p[0] = list(p[1]) 
+        p[0].append(p[2])
+
+    def p_gdmo_doc(self,p):
+        '''gdmo_doc : DOCUMENT STRING'''
+        p[0] = p[2]
+
+    def p_labels_start(self,p):
+        '''labels : label'''
+        p[0] = [p[1]]
+
+    def p_labels_continue(self,p):    
+        '''labels : labels COMMA label '''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_label(self,p):
+        '''label : IDENTIFIER'''
+        p[0] = Label(None,p[1],self.getLocation(p,1))
+
+    def p_label_alias(self,p):    
+        '''label : alias_label'''
+        p[0] = p[1] 
+
+    def p_alias_label(self,p):
+        '''alias_label : STRING COLON IDENTIFIER'''
+        p[0] = Label(p[1],p[3], self.getLocation(p,1) )
+        
+    def p_template(self,p):
+        '''template : mo_template
+        | package_template
+        | parameter_template
+        | nbind_template
+        | attribute_template
+        | attribute_group_template
+        | behaviour_template
+        | action_template
+        | notification_template'''
+        p[0] = p[1]
+
+    def p_mo_template(self,p):
+        '''mo_template : mo_header mo_constructs registered_as SIMILICON'''
+        c = p[2]
+        p[0] = MObject(p[1],c['derived'],c['pkgs'],c['cond_pkgs'],p[3])
+
+    def p_mo_header(self,p):   
+        ''' mo_header : label MANAGED OBJECT CLASS'''
+        p[0] = p[1]
+
+    def p_registered_as(self,p):
+        '''registered_as : REGISTERED AS oid'''
+        p[0]  = Asn1ObjectIdentifier(p[3])
+
+    def p_mo_constructs(self,p):
+        '''mo_constructs : mo_opt_derived \
+                 mo_opt_characterized \
+                 mo_opt_conditional_pkg '''
+        p[0] = {'derived' : p[1] , 'pkgs' : p[2] , 'cond_pkgs' : p[3]}
+
+    def p_mo_opt_derived(self,p):
+        '''mo_opt_derived : empty
+                          | DERIVED FROM labels SIMILICON '''
+        if (len(p)> 3):
+            p[0] = list(p[3])
+
+    def p_mo_opt_characterized(self,p):
+        '''mo_opt_characterized : empty
+      | CHARACTERIZED BY mo_pkgs SIMILICON '''
+        if (len(p) > 3):
+            p[0] = list(p[3])
+
+    def p_mo_pkgs_start(self,p):
+        '''mo_pkgs : mo_pkg'''
+        p[0] = [p[1]]
+
+    def p_mo_pkgs_cont(self,p):
+        '''mo_pkgs : mo_pkgs COMMA mo_pkg '''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_mo_pkg_label(self,p):
+        '''mo_pkg : label'''
+        p[0] = Package(p[1])
+
+    def p_mo_pkg_tplt(self,p):
+        '''mo_pkg :  package_template'''
+        p[0] = p[1]
+
+    def p_mo_opt_conditional_pkg(self,p):
+        '''mo_opt_conditional_pkg : empty
+             | CONDITIONAL PACKAGES mo_conditional_pkgs SIMILICON'''
+        if (len(p) > 3):
+            p[0] = list(p[3])
+
+    def p_mo_conditional_pkgs_start(self,p):
+        '''mo_conditional_pkgs : mo_conditional_pkg'''
+        p[0] = [p[1]]
+
+    def p_mo_conditional_pkgs_cont(self,p):
+        '''mo_conditional_pkgs : mo_conditional_pkgs COMMA mo_conditional_pkg'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_mo_conditional_pkg(self,p):
+        '''mo_conditional_pkg :  package_template present_if'''
+        p[1].setPresentIf(p[2])
+        p[0] = p[1]
+
+    def p_mo_conditional_pkg_lbl(self,p):
+        '''mo_conditional_pkg   : label present_if'''
+        p[0] = Package(p[1],p[2])
+        p[0].setPresentIf(p[2])
+        
+    def p_present_if(self,p):
+        '''present_if :  PRESENT IF STRING'''
+        p[0]  = p[3]
+
+    def p_package_template(self,p):
+        '''package_template : package_header pkg_constructs SIMILICON'''
+        c= p[2]
+        p[0] = PackageTemplate(p[1] \
+                ,c['attrs']         \
+                ,c['behavior']      \
+                ,c['attr_grp']      \
+                ,c['actions']       \
+                ,c['notifications'] \
+                ,c['oid']           \
+                )
+
+    def p_package_header(self,p):
+        '''package_header : label PACKAGE'''
+        p[0] = p[1]
+
+    def p_pkg_constructs(self,p):
+        '''pkg_constructs : pkg_opt_behaviour \
+                    pkg_opt_attrs \
+                    pkg_opt_attr_grp \
+                    pkg_opt_act \
+                    pkg_opt_notif \
+                    pkg_opt_registered'''
+        behavior,attrs,attr_grp,actions,notif,registered = p[1:]  
+        p[0] = {  'attrs'        : attrs      \
+                , 'behavior'     : behavior   \
+                , 'attr_grp'     : attr_grp   \
+                , 'actions'      : actions    \
+                , 'notifications': notif      \
+                , 'oid'          : registered \
+                }
+
+    def p_pkg_opt_behaviour(self,p):
+        '''pkg_opt_behaviour : empty
+           | BEHAVIOUR pkg_behaviour SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_pkg_behaviour_start(self,p):
+        '''pkg_behaviour : pkg_behaviour_def'''
+        p[0] = [p[1]]
+
+    def p_pkg_behaviour_cont(self,p):
+        '''pkg_behaviour :  pkg_behaviour COMMA pkg_behaviour_def'''
+        p[0] = list(p[1])
+        p[0].append(p[2])
+
+    def p_pkg_behaviour_def(self,p):
+        '''pkg_behaviour_def : label 
+                             | behaviour_template'''
+        p[0] = p[1]
+
+    def p_pkg_opt_attrs(self,p):
+        '''pkg_opt_attrs : empty
+      | ATTRIBUTES pkg_attributes SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_pkg_attributes_start(self,p):
+        '''pkg_attributes : pkg_attribute'''
+        p[0] = [p[1]]
+
+    def p_pkg_attributes_cont(self,p):
+        '''pkg_attributes : pkg_attributes COMMA pkg_attribute'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_pkg_attribute(self,p):
+        '''pkg_attribute : label pkg_attr_proplist pkg_attr_param_labels'''
+        p[0] = Attribute(p[1],p[2],p[3])
+
+    def p_pkg_attr_proplist(self,p):
+        '''pkg_attr_proplist : pkg_proplist_replace_default \
+       pkg_proplist_default \
+       pkg_proplist_initial \
+       pkg_proplist_permitted \
+       pkg_proplist_required \
+       pkg_proplist_get_replace \
+       pkg_proplist_add_remove \
+       pkg_proplist_set_by_created \
+       pkg_proplist_no_modify'''
+        p[0] = { 'default'        : p[2] \
+               , 'replace_default': p[1] \
+               , 'initial'        : p[3] \
+               , 'permitted'      : p[4] \
+               , 'required'       : p[5] \
+               , 'get_replace'    : p[6] \
+               , 'add_remove'     : p[7] \
+               , 'set_by_created' : p[8] \
+               , 'set_no_modify'  : p[9] \
+               }
+
+    def p_pkg_proplist_replace_default(self,p):
+        '''pkg_proplist_replace_default : empty
+      | REPLACE_WITH_DEFAULT   pkg_proplist_default'''
+
+    def p_pkg_proplist_default(self,p):
+        '''pkg_proplist_default : empty
+      | DEFAULT VALUE pkg_proplist_value_spec'''
+        if (len(p) > 2):
+            p[0] = p[3]
+
+    def p_pkg_proplist_initial(self,p):
+        '''pkg_proplist_initial : empty
+      | INITIAL VALUE pkg_proplist_value_spec'''
+        if (len(p) > 2):
+            p[0] = p[3]
+
+    def p_pkg_proplist_value_spec_ident(self,p):
+        '''pkg_proplist_value_spec : IDENTIFIER'''
+        p[0] = p[1]
+
+    def p_pkg_proplist_value_spec_tv(self,p):
+        '''pkg_proplist_value_spec : TYPEREF DOT IDENTIFIER'''
+
+    def p_pkg_proplist_value_spec_tt(self,p):
+        '''pkg_proplist_value_spec : TYPEREF DOT TYPEREF'''
+        p[0] = Typeref(p[1],p[3])
+
+    def p_pkg_proplist_value_spec_dr(self,p):
+        '''pkg_proplist_value_spec : DERIVATION RULE'''
+        p[0] = p[1]
+
+    def p_pkg_proplist_permitted(self,p):
+        '''pkg_proplist_permitted : empty
+      | PERMITTED VALUES pkg_proplist_typeref '''
+        if (len(p) > 2):
+            p[0] = p[3]
+
+    def p_pkg_proplist_required(self,p):
+        '''pkg_proplist_required : empty
+      | REQUIRED VALUES pkg_proplist_typeref'''
+        if (len(p) > 2):
+            p[0] = p[3]
+
+    def p_pkg_proplist_typeref(self,p):
+        '''pkg_proplist_typeref : TYPEREF DOT TYPEREF'''
+        p[0] = Typeref(p[1],p[3])
+
+
+    def p_pkg_proplist_get_replace(self,p):
+        '''pkg_proplist_get_replace : empty
+      | GET
+      | GET_REPLACE
+      | REPLACE'''
+        p[0] = p[1]
+
+    def p_pkg_proplist_add_remove(self,p):
+        '''pkg_proplist_add_remove : empty
+      | ADD
+      | REMOVE
+      | ADD_REMOVE'''
+        p[0] = p[1]
+
+    def p_pkg_proplist_set_by_created(self,p):
+        '''pkg_proplist_set_by_created : empty
+      | SET_BY_CREATE'''
+        p[0] = p[1]
+
+    def p_pkg_proplist_no_modify(self,p):
+        '''pkg_proplist_no_modify : empty
+      | NO_MODIFY'''
+        p[0] = p[1]
+
+    def p_pkg_attr_param_labels_empty(self,p):
+        '''pkg_attr_param_labels : empty'''
+        p[0] = None
+
+    def p_pkg_attr_param_labels_start(self,p):
+        '''pkg_attr_param_labels : pkg_attr_param_label'''
+        p[0] = [p[1]]
+
+    def p_pkg_attr_param_labels_cont(self,p):
+        '''pkg_attr_param_labels : pkg_attr_param_labels pkg_attr_param_label'''
+        p[0] = list(p[1])
+        p[0].append(p[2])
+
+    def p_pkg_attr_param_label(self,p):
+        '''pkg_attr_param_label : label '''
+        p[0] = Parameter(p[1])
+
+    def p_pkg_opt_attr_grp(self,p):
+        '''pkg_opt_attr_grp : empty
+           | ATTRIBUTE GROUP'''
+
+    def p_pkg_opt_act(self,p):
+        '''pkg_opt_act : empty
+           | ACTIONS pkg_actions SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_pkg_actions_start(self,p):
+        '''pkg_actions : pkg_action'''
+        p[0] = [p[1]]
+
+    def p_pkg_actions_cont(self,p):
+        '''pkg_actions : pkg_actions COMMA pkg_action'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_pkg_action(self,p):
+        '''pkg_action : label pkg_attr_param_labels'''
+        p[0] = Action(p[1])
+
+    def p_pkg_opt_notif(self,p):
+        '''pkg_opt_notif : empty
+           | NOTIFICATIONS  pkg_notification SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_pkg_notification_start(self,p):
+        '''pkg_notification : pkg_notif_item'''
+        p[0] = [p[1]]
+
+    def p_pkg_notification_cont(self,p):
+        '''pkg_notification : pkg_notification COMMA pkg_notif_item'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_pkg_notif_item(self,p):
+        '''pkg_notif_item : label pkg_attr_param_labels'''
+        p[0] = Notification(p[1])
+
+    def p_pkg_opt_registered(self,p):
+        '''pkg_opt_registered : empty
+      | registered_as'''
+
+    def p_parameter_template(self,p):
+        '''parameter_template : parameter_header CONTEXT param_ctx_type SIMILICON \
+                                  param_syntax_or_attr SIMILICON \
+                                  param_opt_behaviour \
+                                  param_opt_register SIMILICON'''
+        label,CTX,ctx,SIMI,type,SIMI1,behavior,oid,SIMI2 = p[1:]
+        p[0] = ParameterTemplate(label,ctx,type,behavior,oid)
+
+    def p_parameter_header(self,p):
+        '''parameter_header : label PARAMETER'''
+        p[0] = p[1]
+
+    def p_param_ctx_type(self,p):
+        '''param_ctx_type : ACTION_INFO
+          | ACTION_REPLY
+          | EVENT_INFO
+          | EVENT_REPLY
+          | SPECIFIC_ERROR
+          | TYPEREF DOT IDENTIFIER'''
+        if (len (p) > 2):
+            p[0] = Typeref(p[1],p[3])
+            print "Error param_ctx_type to sovle"
+        else:
+            p[0] = p[1]
+
+    def p_param_syntax_or_attr(self,p):
+        '''param_syntax_or_attr : WITH SYNTAX pkg_proplist_typeref 
+                                | ATTRIBUTE label ''';
+        if (len (p) > 2):
+            p[0] = p[3]
+        else:
+            p[0] = Attribute(p[2])
+
+    def p_param_opt_behaviour(self,p):
+        '''param_opt_behaviour : empty
+     | BEHAVIOUR param_behaviours SIMILICON'''
+        if (len(p) > 2 ):
+            p[0] = p[2]
+
+    def p_param_behaviours_start(self,p):
+        '''param_behaviours : param_behaviour'''
+        p[0] = [p[1]]
+
+    def p_param_behaviours_cont(self,p):
+        '''param_behaviours : param_behaviours COMMA param_behaviour'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_param_behaviour_lbl(self,p):
+        '''param_behaviour : label'''
+        p[0] = Behaviour(p[1])
+
+    def p_param_behaviour(self,p):
+        '''param_behaviour : behaviour_template'''
+        p[0] = p[1]
+
+    def p_param_opt_register(self,p):
+        '''param_opt_register : empty
+      | registered_as'''
+        p[0] = p[1]
+
+    def p_nbind_template(self,p):
+        '''nbind_template : nbind_header nbind_core'''
+        c = p[2]
+        # Missing oid and the rest
+        p[0] = NameBindingTemplate(p[1],
+                                   c['superior'],
+                                   c['subordinate'],
+                                   c['attribute'],
+                                   c['behavior'],
+                                   c['create'],
+                                   c['delete'],
+                                   c['oid'])
+
+    def p_nbind_header(self,p):
+        '''nbind_header : label NAME BINDING'''
+        p[0] = p[1]
+
+    def p_nbind_core(self,p):
+        '''nbind_core : SUBORDINATE OBJECT CLASS label opt_subclass SIMILICON \
+      NAMED BY SUPERIOR OBJECT CLASS label opt_subclass SIMILICON \
+      WITH ATTRIBUTE nbind_attrs SIMILICON \
+      nbind_opt_behavior \
+      nbind_opt_create \
+      nbind_opt_delete \
+      registered_as SIMILICON'''
+        p[0] = { 'subordinate' : { 'label' : p[4]  ,'subclasses' : p[5]  } \
+              ,'superior'    : { 'label' : p[12] ,'subclasses' : p[13] } \
+              ,'attribute'   : p[17] \
+              ,'behavior'    : p[19] \
+              ,'create'      : p[20] \
+              ,'delete'      : p[21] \
+              ,'oid'         : p[22] \
+             }
+
+    def p_nbind_attrs(self,p):
+        '''nbind_attrs : label'''
+        p[0] = Attribute(p[1])
+
+    def p_opt_subclass(self,p):
+        '''opt_subclass : empty
+      | AND SUBCLASSES'''
+
+    def p_nbind_opt_behavior(self,p):
+        '''nbind_opt_behavior : empty
+           | BEHAVIOUR nbind_behaviours SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_nbind_behaviours(self,p):
+        '''nbind_behaviours : nbind_behaviour
+                            | nbind_behaviours COMMA nbind_behaviour'''
+
+    def p_nbind_behaviour_lbl(self,p):
+        '''nbind_behaviour : label'''
+        p[0] = Behaviour(p[1])
+
+    def p_nbind_behaviour_bhv(self,p):
+        '''nbind_behaviour : behaviour_template'''
+        p[0] = p[1]
+
+    def p_nbind_opt_create(self,p):
+        '''nbind_opt_create : empty
+                            | CREATE nbind_create_modifiers nbind_opt_params SIMILICON'''
+        if ( len(p) > 3 ):
+            p[0] = { 'modifiers' : p[2] , 'parameters' : p[3] }
+
+    def p_nbind_opt_params(self,p):
+        '''nbind_opt_params : empty
+                            | nbind_params'''
+        p[0] = p[1]
+
+    def p_nbind_params_start(self,p):
+        '''nbind_params : label'''
+        p[0] = [Parameter(p[1])]
+
+    def p_nbind_params(self,p):
+        '''nbind_params : nbind_params   label'''
+        p[0] = list(p[1])
+        p[0].append(Parameter(p[2]))
+
+    def p_nbind_create_modifiers_start(self,p):
+        '''nbind_create_modifiers : nbind_create_modifier'''
+        p[0] = [p[1]]
+
+    def p_nbind_create_modifiers(self,p):
+        '''nbind_create_modifiers : nbind_create_modifiers COMMA nbind_create_modifier'''
+        p[0] = list(p[1])
+        if p[3] != None:
+            p[0].append(p[3])
+
+    def p_nbind_create_modifier(self,p):
+        '''nbind_create_modifier : empty
+      | WITH_REFERENCE_OBJECT
+      | WITH_AUTOMATIC_INSTANCE_NAMING'''
+        p[0] = [p[1]]
+
+    def p_nbind_opt_delete(self,p):
+        '''nbind_opt_delete : empty
+                            | DELETE nbind_del_modifier nbind_opt_params SIMILICON'''
+        if ( len(p) > 3 ):
+            p[0] = { 'modifiers' : p[2] , 'parameters' : p[3] }
+
+    def p_nbind_del_modifier(self,p):
+        '''nbind_del_modifier : empty
+      | ONLY_IF_NO_CONTAINED_OBJECTS
+      | DELETES_CONTAINED_OBJECTS'''
+        p[0] = [p[1]]
+
+    def p_attribute_template(self,p):
+        '''attribute_template : attribute_header derive_or_syntax SIMILICON \
+                                attr_opt_match attr_opt_behaviour attr_opt_parameters \
+                                attr_opt_registered SIMILICON'''
+        p[0] = AttributeTemplate(p[1],p[2],p[4],p[5],p[6],p[7])
+
+    def p_attribute_header(self,p):
+        '''attribute_header : label ATTRIBUTE'''
+        p[0] = p[1]
+
+    def p_derive_or_syntax(self,p):
+        '''derive_or_syntax : DERIVED FROM label
+           | WITH ATTRIBUTE SYNTAX  pkg_proplist_typeref'''
+        if (len(p) > 4):
+            p[0] = {'derived' : None , 'syntax' : p[4] }
+        else:
+            p[0] = {'derived' : p[3] , 'syntax' : None }
+
+    def p_attr_opt_match(self,p):
+        '''attr_opt_match : empty
+           | MATCHES FOR attr_qualifiers SIMILICON'''
+        if (len(p) > 3):
+            p[0] = p[3]
+
+    def p_attr_qualifiers_start(self,p):
+        '''attr_qualifiers : attr_qualifier'''
+        p[0] = [p[1]]
+
+    def p_attr_qualifiers_cont(self,p):
+        '''attr_qualifiers :  attr_qualifiers COMMA attr_qualifier'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_attr_qualifier(self,p):
+        '''attr_qualifier : EQUALITY
+      | ORDERING
+      | SUBSTRINGS
+      | SET_COMPARISON
+      | SET_INTERSECTION'''
+        p[0] = p[1]
+
+    def p_attr_opt_behaviour(self,p):
+        '''attr_opt_behaviour : empty
+      | BEHAVIOUR attr_behaviours SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_attr_behaviours_start(self,p):
+        '''attr_behaviours : attr_behaviour'''
+        p[0] = [p[1]]
+
+    def p_attr_behaviours_cont(self,p):
+        '''attr_behaviours : attr_behaviours COMMA attr_behaviour'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_attr_behaviour_lbl(self,p):
+        '''attr_behaviour : label'''
+        p[0] = Behaviour(p[1])
+
+    def p_attr_behaviour_bh(self,p):
+        '''attr_behaviour : behaviour_template'''
+        p[0] = p[1]
+
+    def p_attr_opt_parameters(self,p):
+        '''attr_opt_parameters : empty
+      | PARAMETERS attr_parameters  SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_attr_parameters_start(self,p):
+        '''attr_parameters : label'''
+        p[0] = [p[1]]
+    def p_attr_parameters_cont(self,p):
+        '''attr_parameters : attr_parameters COMMA label'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_attr_opt_registered(self,p):
+        '''attr_opt_registered : empty
+           | registered_as'''
+        p[0] = p[1]
+
+    def p_attribute_group_template(self,p):
+        '''attribute_group_template : attribute_group_header attr_grp_elems attr_grp_fixed attr_grp_desc registered_as SIMILICON'''
+        name , elements,fixed,desc,oid ,SIM = p[1:]
+        p[0] = AttributeGroupeTemplate(name,elements,fixed,desc,oid)
+
+    def p_attribute_group_header(self,p):
+        '''attribute_group_header : label ATTRIBUTE GROUP'''
+        p[0] = p[1]
+
+    def p_attr_grp_elems(self,p):
+        '''attr_grp_elems : empty
+      | GROUP ELEMENTS labels SIMILICON'''
+        if (len(p) > 3):
+            p[0] = p[3]
+
+    def p_attr_grp_fixed(self,p):
+        '''attr_grp_fixed : empty
+                          | FIXED SIMILICON '''
+        p[0] = p[1]
+
+    def p_attr_grp_desc(self,p):
+        '''attr_grp_desc : empty
+           | DESCRIPTION STRING SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_behaviour_template(self,p):
+        '''behaviour_template : behaviour_header behaviour_construct'''
+        p[0] = BehaviourTemplate(p[1],p[2])
+
+    def p_behaviour_header(self,p):
+        '''behaviour_header : label BEHAVIOUR'''
+        p[0] = p[1]
+
+    def p_behaviour_construct(self,p):
+        '''behaviour_construct : DEFINED AS STRING SIMILICON'''
+        p[0] = p[3]
+
+    def p_action_template(self,p):
+        '''action_template : action_header act_opt_behaviour act_opt_mode act_opt_params act_opt_with act_opt_with registered_as SIMILICON'''
+        label,behaviour,mode,params,wi,wr,oid,SIM = p[1:]
+        p[0] = ActionTemplate(label,behaviour,mode,params,wi,wr,oid)
+
+    def p_action_header(self,p):
+        '''action_header : label ACTION'''
+        p[0] = p[1]
+
+    def p_act_opt_behaviour(self,p):
+        '''act_opt_behaviour : empty
+        | BEHAVIOUR act_behaviours SIMILICON'''
+        if (len(p) > 2):
+            p[0] = p[2]
+
+    def p_act_behaviours_start(self,p):
+        '''act_behaviours : act_behaviour'''
+        p[0] = [p[1]]
+
+    def p_act_behaviours_cont(self,p):
+        '''act_behaviours : act_behaviours COMMA act_behaviour'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_act_behaviour_lbl(self,p):
+        '''act_behaviour : label'''
+        p[0] = Behaviour(p[1])
+
+    def p_act_behaviour_tlpt(self,p):
+        '''act_behaviour : behaviour_template'''
+        p[0] = p[1]
+
+    def p_act_opt_mode(self,p):
+        '''act_opt_mode : empty
+      | MODE CONFIRMED SIMILICON'''
+
+    def p_act_opt_params(self,p):
+        '''act_opt_params : empty
+      | PARAMETERS act_parameters SIMILICON'''
+        if (len(p)>2):
+            p[0] = p[2]
+
+    def p_act_parameters_start(self,p):
+        '''act_parameters : act_parameter'''
+        p[0] = [p[1]]
+
+    def p_act_parameters_cont(self,p):
+        '''act_parameters : act_parameters COMMA act_parameter'''
+        p[0] = list(p[1])
+        p[0].append(p[3])
+
+    def p_act_parameter_lbl(self,p):
+        '''act_parameter : label'''
+        p[0] = Parameter(p[1])
+
+    def p_act_parameter_tplt(self,p):
+        '''act_parameter : parameter_template'''
+        p[0] = p[1]
+
+    def p_act_opt_with(self,p):
+        '''act_opt_with : empty
+           | WITH act_with_info_reply'''
+        if (len(p)>2):
+            p[0] = p[2]
+
+    def p_act_with_info_reply_info(self,p):
+        '''act_with_info_reply : INFORMATION  SYNTAX pkg_proplist_typeref SIMILICON'''
+        p[0] = { p[1] : p[3] }
+
+    def p_act_with_info_reply_reply(self,p):
+        '''act_with_info_reply : REPLY  SYNTAX pkg_proplist_typeref SIMILICON'''
+        p[0] = { p[1] : p[3] }
+
+    def p_notification_template(self,p):
+        '''notification_template : notification_header notif_opt_behaviour notif_opt_params\
+                                   notif_opt_with \
+                                   opt_notif_reply registered_as SIMILICON'''
+        behav,params,syntax,reply,oid,SIM = p[2:] 
+        p[0] = NotificationTemplate(p[1],behav,params,syntax,reply,oid)
+
+    def p_notification_header(self,p):
+        '''notification_header : label NOTIFICATION'''
+        p[0]  = p[1]
+
+    def p_notif_opt_behaviour(self,p):
+        '''notif_opt_behaviour : empty
+      | BEHAVIOUR notif_behaviours SIMILICON'''
+        if (len(p)>2):
+            p[0] = p[2]
+
+    def p_notif_behaviours_start(self,p):
+        '''notif_behaviours : notif_behaviour'''
+        p[0] = [p[1]]
+
+    def p_notif_behaviours_cont(self,p):
+        '''notif_behaviours : notif_behaviours COMMA notif_behaviour'''
+        p[0] = list(P[1])
+        p[0].append(p[3])
+
+    def p_notif_behaviour_lbl(self,p):
+        '''notif_behaviour : label'''
+        p[0] = Behaviour(p[1])
+
+    def p_notif_behaviour_bh(self,p):
+        '''notif_behaviour :  behaviour_template'''
+        p[0] = p[1]
+
+    def p_notif_opt_params(self,p):
+        '''notif_opt_params : empty
+           | PARAMETERS notif_parameters SIMILICON'''
+        if (len(p)>2):
+            p[0] = p[2]
+
+    def p_notif_parameters_start(self,p):
+        '''notif_parameters : label'''
+        p[0] = [Parameter(p[1])]
+
+    def p_notif_parameters_cont(self,p):
+        '''notif_parameters : notif_parameters COMMA label'''
+        p[0] = list(P[1])
+        p[0].append(Parameter(p[3]))
+
+    def p_notif_opt_with(self,p):
+        '''notif_opt_with : empty
+                          | WITH  notif_info'''
+        if ( len(p ) > 1):
+            p[0] = p[2]
+
+    def p_notif_info(self,p):
+        '''notif_info : INFORMATION SYNTAX  pkg_proplist_typeref notif_opt_attr_id SIMILICON'''
+        p[0] = {'syntax' : p[3] , 'attributes' : p[4] }
+
+    def p_opt_notif_reply(self,p):
+        '''opt_notif_reply  : empty
+                            | WITH REPLY SYNTAX  pkg_proplist_typeref SIMILICON'''
+        if ( len(p) > 4):
+            p[0] = p[4]
+
+    def p_notif_opt_attr_id(self,p):
+        '''notif_opt_attr_id : empty
+           | AND ATTRIBUTE IDS notif_opt_fields'''
+        if (len(p) > 3):
+            p[0] = p[4]
+
+    def p_notif_opt_fields(self,p):
+        '''notif_opt_fields : empty
+                            | notif_fields'''
+        p[0] = p[1]
+
+    def p_notif_fields_start(self,p):
+        '''notif_fields : notif_field'''
+        p[0] = [p[1]]
+
+    def p_notif_fields_cont(self,p):
+        '''notif_fields : notif_fields COMMA notif_field '''
+        p[0] = list(p[1])
+        p[0].append(p[2])
+
+    def p_notif_field(self,p):
+        '''notif_field : IDENTIFIER label'''
+        p[0] = p[1]
+
+    def p_oid(self,p):
+        '''oid : LBRACET oid_list RBRACET'''
+        p[0] = p[2]
+
+    def p_oid_list_start(self,p):
+        '''oid_list : oid_item'''
+        p[0] = [p[1]]
+
+    def p_oid_list_cont(self,p):
+        '''oid_list : oid_list oid_item'''
+        p[0] = list(p[1])
+        p[0].append(p[2])
+
+    def p_oid_item_id(self,p):
+        '''oid_item : IDENTIFIER'''
+        p[0] = p[1]
+
+    def p_oid_item_idnum(self,p):
+        '''oid_item : IDENTIFIER LPARENT NUM RPARENT'''
+        p[0] = p[3]
+
+    def p_oid_item_num(self,p):
+        '''oid_item : NUM'''
+        p[0] = p[1]
+
+    def p_oid_item_module_dot_ident(self,p):
+        '''oid_item : TYPEREF DOT IDENTIFIER '''
+        p[0] = p[1]
+
+    def p_empty(self,t):
+       'empty :'
+       pass
+
+    # Catastrophic error handler
+
+    def p_error(self,p):
+        if not p:
+            raise GDMOError(" parser SYNTAX ERROR AT EOF")
+        print "p_error ERROR at line:%d %s\n" % (p.lineno,p.value)
+
+        raise GDMOError(" Syntax error ",p.lineno )
+
+    def __init__(self,outputdir='',debug = 0):
+        self.lexer  = gdmolex.GDMOLexer(outputdir,debug)
+
+        self.parser = yacc.yacc(module    = self,
+                                debug     = debug,
+                                outputdir = outputdir,
+                                tabmodule ='gdmoparseryacc')
+
+    def search_file(self,filename):
+        found = 0
+        for path in self.incdirs:
+            if exists(join(path,filename)):
+                found = 1
+                break
+        if found:
+            return abspath(join(path,filename))
+        return None
+
+    def parse(self,data, debug=0):
+        self.parser.error = 0
+        p = self.parser.parse(data, debug=debug)
+        if self.parser.error:
+            return None
+        return p
+
+    def parse_files(self,files,incdirs,debug = 0):
+        self.parser.error = 0
+        self.incdirs = incdirs
+        first = files.pop()
+        self.lexer.filename = first
+        self.lexer.files    = files
+        self.lexer.parser   = self
+        fd = open(self.search_file(first))
+        p = self.parser.parse(fd.read(), debug=debug)
+        fd.close()
+        if self.parser.error:
+            return None
+        return p
+
+    def getLocation(self,p,i):
+        return Location(self.lexer,p.lineno(i),p.lexpos(i))
+
+
+if __name__ == '__main__':
+    from optparse import OptionParser
+    o = OptionParser()
+    o.add_option('-I',action='append',dest='incdirs',default=['.'],
+                 help="Directory to search for imported files")
+
+    o.add_option('-D',dest='outdir',default=None,
+                 help="Directory to generate files")
+
+    o.add_option('-d',action='store_true', dest='debug', default=False,
+                help='Set Debug for parser')
+
+    o.add_option('-f',action="append",dest='files', default=[],
+                 help="File to parse")
+
+    options,args = o.parse_args()
+
+    if options.outdir is not None:
+        if not os.path.isdir(options.outdir):
+            os.mkdir(options.outdir)
+
+    if options.files is None:
+        print >>sys.stderr, "-f file required"
+        sys.exit(1)
+
+    print "GDMO Parsing Start"
+    p = GDMOParser()
+    p.parse_files(options.files,0);
diff --git a/pgdmo/pgdom b/pgdmo/pgdom
new file mode 100755 (executable)
index 0000000..9e333fb
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/env python2.7
+#  First implementation in Python for GDMO syntax parsing
+#  vim: et sw=4 sws=4 ts=4 filetype=python list
+
+from ply import *
+import gdmolex,gdmoparse
+from gdmoparse import *
+
+from pgdmo.Generators import *
+
+import sys, os.path
+
+
+''' Main entry point that will process all
+     Option regarding GDMO parsing.
+'''
+if __name__ == '__main__':
+    from optparse import OptionParser
+    usage= "Usage : %prog -f <gdmo file> -g asn1 -f <generator>"
+    o = OptionParser(usage = usage)
+    o.add_option('-I',action='append',dest='incdirs',default=['.'],
+                 help="Directory to search for imported files")
+
+    o.add_option('-D',"--directory",dest='outdir',default=None,
+                 help="Directory to generate files")
+
+    o.add_option('-d',action='store_true', dest='debug', default=False,
+                help='Set Debug for parser')
+
+    o.add_option('-f',dest='files',action = 'append', default=[],
+                 help="Files to parse required option")
+    
+    o.add_option('-g',"--generator",dest='generator', default="asn1",
+            help="Generator : asn1, db, sql, typelib, \
+                        mgr, agent, cppmo [default: %default] " )
+
+    (options,args ) = o.parse_args()
+
+    if options.outdir is not None:
+        if not os.path.isdir(options.outdir):
+            os.mkdir(options.outdir)
+
+    if len(options.files) == 0  :
+        o.print_help()
+        print >>sys.stderr, "at least one file required"
+        sys.exit(1)
+
+    print "PGDMO Parsing %s" % options.files
+    p = GDMOParser()
+
+    GDMO = p.parse_files( options.files
+                        , options.incdirs
+                        , 1 if options.debug else 0)
+
+    if options.generator == 'asn1':
+        print "PGDMO Generate asn1 files for Attributes, Actions"
+        g = Asn1Objects(GDMO)
+        g.generateInDir(options.outdir,"asn1_objects.asn1")
+    
+    if options.generator == 'cppmo':
+        print "PGDMO Generate asn1 files for Attributes, Actions"
+        g = CPPMObjects(GDMO)
+        g.generate(options.outdir)
+
+    if options.generator == 'db':
+        print "PGDMO Generate db files for Managed Object. Allows creation of native C database"
+        pub = GenDbPub(GDMO)
+        pub.generateInDir(options.outdir,"db_pub.dbi")
+        # Constant Attributes
+        ac = GenDbAttributeConstant(GDMO)
+        ac.generateInDir(options.outdir,"g_attribute.db")
+        mo = GenDbManagedObjectConstant(GDMO)
+        mo.generateInDir(options.outdir,"db_mo_name.dbi")
+    
+    if options.generator == 'typelib':
+        print "PGDMO Generate type library to be used by a Manager"
diff --git a/rt/managed_object.h b/rt/managed_object.h
new file mode 100644 (file)
index 0000000..7a4261e
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef MANAGED_OBJECT_H
+#define MANAGED_OBJECT_H
+
+namespace GDMO
+{
+
+/**
+ *
+ */ 
+class managed_object
+{
+  public:
+    managed_object();
+    ~managed_object();
+
+  protected: 
+    managed_object  *m_parent;
+};
+
+}
+#endif /*MANAGED_OBJECT_H*/