Modify folders to improve SAM score 98/219198/5
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 3 Dec 2019 06:23:29 +0000 (15:23 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 3 Dec 2019 09:00:01 +0000 (18:00 +0900)
Change-Id: Iee13089dcb077c017dd0a2d37a612d7fed7ae14f
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
173 files changed:
idlc/CMakeLists.txt
idlc/ast/attribute.cc [new file with mode: 0644]
idlc/ast/attribute.h [new file with mode: 0644]
idlc/ast/block.cc [new file with mode: 0644]
idlc/ast/block.h [new file with mode: 0644]
idlc/ast/declaration.cc [new file with mode: 0644]
idlc/ast/declaration.h [new file with mode: 0644]
idlc/ast/document.cc [new file with mode: 0644]
idlc/ast/document.h [new file with mode: 0644]
idlc/ast/element.cc [new file with mode: 0644]
idlc/ast/element.h [new file with mode: 0644]
idlc/ast/interface.cc [new file with mode: 0644]
idlc/ast/interface.h [new file with mode: 0644]
idlc/ast/location.hh [new file with mode: 0644]
idlc/ast/parameter.cc [new file with mode: 0644]
idlc/ast/parameter.h [new file with mode: 0644]
idlc/ast/parser.cc [new file with mode: 0644]
idlc/ast/parser.h [new file with mode: 0644]
idlc/ast/position.hh [new file with mode: 0644]
idlc/ast/structure.cc [new file with mode: 0644]
idlc/ast/structure.h [new file with mode: 0644]
idlc/ast/tidlc.ll [new file with mode: 0644]
idlc/ast/tidlc.yy [new file with mode: 0644]
idlc/ast/tidlc_l.cpp [new file with mode: 0644]
idlc/ast/tidlc_y.cpp [new file with mode: 0644]
idlc/ast/tidlc_y.hpp [new file with mode: 0644]
idlc/ast/type.cc [new file with mode: 0644]
idlc/ast/type.h [new file with mode: 0644]
idlc/attribute.cc [deleted file]
idlc/attribute.h [deleted file]
idlc/block.cc [deleted file]
idlc/block.h [deleted file]
idlc/c_gen/c_body_gen_base.cc [deleted file]
idlc/c_gen/c_body_gen_base.h [deleted file]
idlc/c_gen/c_body_gen_base_cb.h [deleted file]
idlc/c_gen/c_gen_base.cc [deleted file]
idlc/c_gen/c_gen_base.h [deleted file]
idlc/c_gen/c_gen_base_cb.h [deleted file]
idlc/c_gen/c_header_gen_base.cc [deleted file]
idlc/c_gen/c_header_gen_base.h [deleted file]
idlc/c_gen/c_header_gen_base_cb.h [deleted file]
idlc/c_gen/c_proxy_body_gen.cc [deleted file]
idlc/c_gen/c_proxy_body_gen.h [deleted file]
idlc/c_gen/c_proxy_body_gen_cb.h [deleted file]
idlc/c_gen/c_proxy_header_gen.cc [deleted file]
idlc/c_gen/c_proxy_header_gen.h [deleted file]
idlc/c_gen/c_proxy_header_gen_cb.h [deleted file]
idlc/c_gen/c_stub_body_gen.cc [deleted file]
idlc/c_gen/c_stub_body_gen.h [deleted file]
idlc/c_gen/c_stub_body_gen_cb.h [deleted file]
idlc/c_gen/c_stub_header_gen.cc [deleted file]
idlc/c_gen/c_stub_header_gen.h [deleted file]
idlc/c_gen/c_stub_header_gen_cb.h [deleted file]
idlc/cpp_gen/cpp_gen_base.cc [deleted file]
idlc/cpp_gen/cpp_gen_base.h [deleted file]
idlc/cpp_gen/cpp_gen_base_cb.h [deleted file]
idlc/cpp_gen/cpp_proxy_body_gen.cc [deleted file]
idlc/cpp_gen/cpp_proxy_body_gen.h [deleted file]
idlc/cpp_gen/cpp_proxy_body_gen_cb.h [deleted file]
idlc/cpp_gen/cpp_proxy_header_gen.cc [deleted file]
idlc/cpp_gen/cpp_proxy_header_gen.h [deleted file]
idlc/cpp_gen/cpp_proxy_header_gen_cb.h [deleted file]
idlc/cpp_gen/cpp_stub_body_gen.cc [deleted file]
idlc/cpp_gen/cpp_stub_body_gen.h [deleted file]
idlc/cpp_gen/cpp_stub_body_gen_cb.h [deleted file]
idlc/cpp_gen/cpp_stub_header_gen.cc [deleted file]
idlc/cpp_gen/cpp_stub_header_gen.h [deleted file]
idlc/cpp_gen/cpp_stub_header_gen_cb.h [deleted file]
idlc/cs_gen/cs_cb_interop.h [deleted file]
idlc/cs_gen/cs_cb_rpc_port.h [deleted file]
idlc/cs_gen/cs_cb_version.h [deleted file]
idlc/cs_gen/cs_gen_base.cc [deleted file]
idlc/cs_gen/cs_gen_base.h [deleted file]
idlc/cs_gen/cs_gen_base_cb.h [deleted file]
idlc/cs_gen/cs_lib_gen.cc [deleted file]
idlc/cs_gen/cs_lib_gen.h [deleted file]
idlc/cs_gen/cs_proxy_gen.cc [deleted file]
idlc/cs_gen/cs_proxy_gen.h [deleted file]
idlc/cs_gen/cs_proxy_gen_cb.h [deleted file]
idlc/cs_gen/cs_stub_gen.cc [deleted file]
idlc/cs_gen/cs_stub_gen.h [deleted file]
idlc/cs_gen/cs_stub_gen_cb.h [deleted file]
idlc/declaration.cc [deleted file]
idlc/declaration.h [deleted file]
idlc/document.cc [deleted file]
idlc/document.h [deleted file]
idlc/element.cc [deleted file]
idlc/element.h [deleted file]
idlc/gen/c_body_gen_base.cc [new file with mode: 0644]
idlc/gen/c_body_gen_base.h [new file with mode: 0644]
idlc/gen/c_body_gen_base_cb.h [new file with mode: 0644]
idlc/gen/c_gen_base.cc [new file with mode: 0644]
idlc/gen/c_gen_base.h [new file with mode: 0644]
idlc/gen/c_gen_base_cb.h [new file with mode: 0644]
idlc/gen/c_header_gen_base.cc [new file with mode: 0644]
idlc/gen/c_header_gen_base.h [new file with mode: 0644]
idlc/gen/c_header_gen_base_cb.h [new file with mode: 0644]
idlc/gen/c_proxy_body_gen.cc [new file with mode: 0644]
idlc/gen/c_proxy_body_gen.h [new file with mode: 0644]
idlc/gen/c_proxy_body_gen_cb.h [new file with mode: 0644]
idlc/gen/c_proxy_header_gen.cc [new file with mode: 0644]
idlc/gen/c_proxy_header_gen.h [new file with mode: 0644]
idlc/gen/c_proxy_header_gen_cb.h [new file with mode: 0644]
idlc/gen/c_stub_body_gen.cc [new file with mode: 0644]
idlc/gen/c_stub_body_gen.h [new file with mode: 0644]
idlc/gen/c_stub_body_gen_cb.h [new file with mode: 0644]
idlc/gen/c_stub_header_gen.cc [new file with mode: 0644]
idlc/gen/c_stub_header_gen.h [new file with mode: 0644]
idlc/gen/c_stub_header_gen_cb.h [new file with mode: 0644]
idlc/gen/cpp_gen_base.cc [new file with mode: 0644]
idlc/gen/cpp_gen_base.h [new file with mode: 0644]
idlc/gen/cpp_gen_base_cb.h [new file with mode: 0644]
idlc/gen/cpp_proxy_body_gen.cc [new file with mode: 0644]
idlc/gen/cpp_proxy_body_gen.h [new file with mode: 0644]
idlc/gen/cpp_proxy_body_gen_cb.h [new file with mode: 0644]
idlc/gen/cpp_proxy_header_gen.cc [new file with mode: 0644]
idlc/gen/cpp_proxy_header_gen.h [new file with mode: 0644]
idlc/gen/cpp_proxy_header_gen_cb.h [new file with mode: 0644]
idlc/gen/cpp_stub_body_gen.cc [new file with mode: 0644]
idlc/gen/cpp_stub_body_gen.h [new file with mode: 0644]
idlc/gen/cpp_stub_body_gen_cb.h [new file with mode: 0644]
idlc/gen/cpp_stub_header_gen.cc [new file with mode: 0644]
idlc/gen/cpp_stub_header_gen.h [new file with mode: 0644]
idlc/gen/cpp_stub_header_gen_cb.h [new file with mode: 0644]
idlc/gen/cs_cb_interop.h [new file with mode: 0644]
idlc/gen/cs_cb_rpc_port.h [new file with mode: 0644]
idlc/gen/cs_cb_version.h [new file with mode: 0644]
idlc/gen/cs_gen_base.cc [new file with mode: 0644]
idlc/gen/cs_gen_base.h [new file with mode: 0644]
idlc/gen/cs_gen_base_cb.h [new file with mode: 0644]
idlc/gen/cs_lib_gen.cc [new file with mode: 0644]
idlc/gen/cs_lib_gen.h [new file with mode: 0644]
idlc/gen/cs_proxy_gen.cc [new file with mode: 0644]
idlc/gen/cs_proxy_gen.h [new file with mode: 0644]
idlc/gen/cs_proxy_gen_cb.h [new file with mode: 0644]
idlc/gen/cs_stub_gen.cc [new file with mode: 0644]
idlc/gen/cs_stub_gen.h [new file with mode: 0644]
idlc/gen/cs_stub_gen_cb.h [new file with mode: 0644]
idlc/gen/generator.cc [new file with mode: 0644]
idlc/gen/generator.h [new file with mode: 0644]
idlc/generator.cc [deleted file]
idlc/generator.h [deleted file]
idlc/interface.cc [deleted file]
idlc/interface.h [deleted file]
idlc/location.hh [deleted file]
idlc/main.cc
idlc/parameter.cc [deleted file]
idlc/parameter.h [deleted file]
idlc/parser.cc [deleted file]
idlc/parser.h [deleted file]
idlc/position.hh [deleted file]
idlc/structure.cc [deleted file]
idlc/structure.h [deleted file]
idlc/tidlc.ll [deleted file]
idlc/tidlc.yy [deleted file]
idlc/tidlc_l.cpp [deleted file]
idlc/tidlc_y.cpp [deleted file]
idlc/tidlc_y.hpp [deleted file]
idlc/type.cc [deleted file]
idlc/type.h [deleted file]
unit_tests/CMakeLists.txt
unit_tests/attribute_unittest.cc
unit_tests/block_unittest.cc
unit_tests/cs_gen/cs_proxy_gen_unittest.cc
unit_tests/cs_gen/cs_stub_gen_unittest.cc
unit_tests/declaration_unittest.cc
unit_tests/document_unittest.cc
unit_tests/element_unittest.cc
unit_tests/generator_unittest.cc
unit_tests/interface_unittest.cc
unit_tests/parser_unittest.cc
unit_tests/structure_unittest.cc
unit_tests/type_unittest.cc

index 05077256e384f9c0a5f1a0b17497f6aa2c1496b7..1d60f9f2ca6926f3fd3a0cf20fdce15f70a8ebaa 100644 (file)
@@ -25,19 +25,17 @@ SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/cs_gen CS_GEN_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/c_gen C_GEN_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/cpp_gen CPP_GEN_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ast AST_GEN_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/gen GEN_SOURCES)
 
-BISON_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/tidlc.yy ${CMAKE_CURRENT_SOURCE_DIR}/tidlc_y.cpp)
-FLEX_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/tidlc.ll ${CMAKE_CURRENT_SOURCE_DIR}/tidlc_l.cpp)
+BISON_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/ast/tidlc.yy ${CMAKE_CURRENT_SOURCE_DIR}/ast/tidlc_y.cpp)
+FLEX_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/ast/tidlc.ll ${CMAKE_CURRENT_SOURCE_DIR}/ast/tidlc_l.cpp)
 
 ADD_EXECUTABLE(${PROJECT_NAME}
+       ${AST_GEN_SOURCES}
        ${BISON_TIDLC_OUTPUTS}
        ${FLEX_TIDLC_OUTPUTS}
-       ${CS_GEN_SOURCES}
-       ${C_GEN_SOURCES}
-       ${CPP_GEN_SOURCES}
+       ${GEN_SOURCES}
        ${SOURCES}
        )
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBPKGS_LIBRARIES} ${EXE_STATIC})
diff --git a/idlc/ast/attribute.cc b/idlc/ast/attribute.cc
new file mode 100644 (file)
index 0000000..6fcf86d
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/attribute.h"
+
+namespace tidl {
+
+Attribute::Attribute(std::string key, std::string value, unsigned line)
+    : key_(std::move(key)), value_(std::move(value)), line_(line) {
+}
+
+const std::string& Attribute::GetKey() const {
+  return key_;
+}
+
+const std::string& Attribute::GetValue() const {
+  return value_;
+}
+
+const unsigned Attribute::GetLine() const {
+  return line_;
+}
+
+void Attributes::Add(Attribute* attr) {
+  attrs_.emplace_back(attr);
+}
+
+const std::list<std::unique_ptr<Attribute>>& Attributes::GetAttrs() const {
+  return attrs_;
+}
+
+bool Attributes::Exist(Attribute* attr) const {
+  for (auto& a : attrs_) {
+    if (a->GetKey() == attr->GetKey() &&
+        a->GetValue() == attr->GetValue())
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/attribute.h b/idlc/ast/attribute.h
new file mode 100644 (file)
index 0000000..360348e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_ATTRIBUTE_H_
+#define IDLC_ATTRIBUTE_H_
+
+#include <string>
+#include <list>
+#include <memory>
+
+namespace tidl {
+
+class Attribute {
+ public:
+  Attribute(std::string key, std::string value, unsigned line);
+
+  const std::string& GetKey() const;
+  const std::string& GetValue() const;
+  const unsigned GetLine() const;
+
+ private:
+  std::string key_;
+  std::string value_;
+  unsigned line_;
+};
+
+class Attributes {
+ public:
+  void Add(Attribute* attr);
+  const std::list<std::unique_ptr<Attribute>>& GetAttrs() const;
+  bool Exist(Attribute* attr) const;
+
+ private:
+  std::list<std::unique_ptr<Attribute>> attrs_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_ATTRIBUTE_H_
diff --git a/idlc/ast/block.cc b/idlc/ast/block.cc
new file mode 100644 (file)
index 0000000..3630155
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/block.h"
+
+namespace tidl {
+
+Block::Block(std::string id, Block::Type type,
+             std::string comments, unsigned line)
+    : id_(std::move(id)), type_(type), comments_(std::move(comments)),
+      line_(line) {}
+
+const std::string& Block::GetID() const {
+  return id_;
+}
+
+const Block::Type& Block::GetType() const {
+  return type_;
+}
+
+const unsigned Block::GetLine() const {
+  return line_;
+}
+
+const std::string& Block::GetComments() const {
+  return comments_;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/block.h b/idlc/ast/block.h
new file mode 100644 (file)
index 0000000..ea2e19d
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_BLOCK_H_
+#define IDLC_BLOCK_H_
+
+#include <string>
+#include <memory>
+
+#include "idlc/ast/declaration.h"
+
+namespace tidl {
+
+class Block {
+ public:
+  enum Type {
+    TYPE_INTERFACE = 0,
+    TYPE_STRUCTURE,
+  };
+
+  Block(std::string id, Block::Type type, std::string comments,
+        unsigned line);
+  virtual ~Block() = default;
+
+  const std::string& GetID() const;
+  const Block::Type& GetType() const;
+  const unsigned GetLine() const;
+  const std::string& GetComments() const;
+
+ private:
+  std::string id_;
+  Block::Type type_;
+  std::string comments_;
+  unsigned line_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_BLOCK_H_
+
diff --git a/idlc/ast/declaration.cc b/idlc/ast/declaration.cc
new file mode 100644 (file)
index 0000000..400225a
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+
+namespace tidl {
+
+Declaration::Declaration(std::string id, BaseType* ret_type,
+                         Parameters* params, std::string comments,
+                         unsigned line, MethodType mtype)
+    : id_(std::move(id)),
+      ret_type_(ret_type),
+      params_(params),
+      comments_(std::move(comments)),
+      line_(line),
+      mtype_(mtype) {}
+
+const std::string& Declaration::GetID() const {
+  return id_;
+}
+
+const BaseType& Declaration::GetType() const {
+  return *ret_type_;
+}
+
+const Parameters& Declaration::GetParameters() const {
+  return *params_;
+}
+
+const unsigned Declaration::GetLine() const {
+  return line_;
+}
+
+const std::string& Declaration::GetComments() const {
+  return comments_;
+}
+
+void Declarations::Add(Declaration* decl) {
+  decls_.emplace_back(decl);
+}
+
+const std::list<std::unique_ptr<Declaration>>& Declarations::GetDecls() const {
+  return decls_;
+}
+
+bool Declarations::Exist(Declaration* decl) const {
+  for (auto& d : decls_) {
+    if (d->GetID() == decl->GetID())
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/declaration.h b/idlc/ast/declaration.h
new file mode 100644 (file)
index 0000000..13f81dd
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_DECLARATION_H_
+#define IDLC_DECLARATION_H_
+
+#include <string>
+#include <list>
+#include <memory>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+
+namespace tidl {
+
+class Declaration {
+ public:
+  enum class MethodType {
+    SYNC,
+    ASYNC,
+    DELEGATE
+  };
+
+  Declaration(std::string id, BaseType* ret_type, Parameters* params,
+              std::string comments, unsigned line,
+              MethodType mtype = MethodType::SYNC);
+
+  const std::string& GetID() const;
+  const BaseType& GetType() const;
+  const Parameters& GetParameters() const;
+  MethodType GetMethodType() const { return mtype_; }
+  const unsigned GetLine() const;
+  const std::string& GetComments() const;
+
+ private:
+  std::string id_;
+  std::unique_ptr<BaseType> ret_type_;
+  std::unique_ptr<Parameters> params_;
+  std::string comments_;
+  unsigned line_;
+  MethodType mtype_;
+};
+
+class Declarations {
+ public:
+  void Add(Declaration* decl);
+  const std::list<std::unique_ptr<Declaration>>& GetDecls() const;
+  bool Exist(Declaration* decl) const;
+
+ private:
+  std::list<std::unique_ptr<Declaration>> decls_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_DECLARATION_H_
diff --git a/idlc/ast/document.cc b/idlc/ast/document.cc
new file mode 100644 (file)
index 0000000..d59e1bb
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/ast/document.h"
+#include "idlc/ast/block.h"
+
+namespace tidl {
+
+Document::Document() {}
+
+void Document::AddBlock(Block* block) {
+  blocks_.emplace_back(block);
+}
+
+const std::list<std::unique_ptr<Block>>& Document::GetBlocks() const {
+  return blocks_;
+}
+
+bool Document::ExistBlock(Block* block) const {
+  for (auto& b : blocks_) {
+    if (b->GetType() == block->GetType() &&
+        b->GetID() == block->GetID())
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/document.h b/idlc/ast/document.h
new file mode 100644 (file)
index 0000000..2c8a3d6
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_DOCUMENT_H_
+#define IDLC_DOCUMENT_H_
+
+#include <list>
+#include <memory>
+
+#include "idlc/ast/interface.h"
+
+namespace tidl {
+
+class Document {
+ public:
+  Document();
+
+  void AddBlock(Block* block);
+  const std::list<std::unique_ptr<Block>>& GetBlocks() const;
+  bool ExistBlock(Block* block) const;
+
+ private:
+  std::list<std::unique_ptr<Block>> blocks_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_DOCUMENT_H_
diff --git a/idlc/ast/element.cc b/idlc/ast/element.cc
new file mode 100644 (file)
index 0000000..1594a2a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/element.h"
+#include "idlc/ast/type.h"
+
+namespace tidl {
+
+Element::Element(std::string id, BaseType* type,
+                 std::string comments, unsigned line)
+    : id_(std::move(id)), type_(type), comments_(std::move(comments)),
+      line_(line) {}
+
+const std::string& Element::GetID() const {
+  return id_;
+}
+
+const BaseType& Element::GetType() const {
+  return *type_;
+}
+
+const unsigned Element::GetLine() const {
+  return line_;
+}
+
+const std::string& Element::GetComments() const {
+  return comments_;
+}
+
+void Elements::Add(Element* elm) {
+  elms_.emplace_back(elm);
+}
+
+const std::list<std::unique_ptr<Element>>& Elements::GetElms() const {
+  return elms_;
+}
+
+bool Elements::Exist(Element* elm) const {
+  for (auto& e : elms_) {
+    if (e->GetID() == elm->GetID())
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/element.h b/idlc/ast/element.h
new file mode 100644 (file)
index 0000000..ca1b56c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_ELEMENT_H_
+#define IDLC_ELEMENT_H_
+
+#include <string>
+#include <list>
+#include <memory>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+
+namespace tidl {
+
+class Element {
+ public:
+  Element(std::string id, BaseType* type,
+          std::string comments, unsigned line);
+
+  const std::string& GetID() const;
+  const BaseType& GetType() const;
+  const unsigned GetLine() const;
+  const std::string& GetComments() const;
+
+ private:
+  std::string id_;
+  std::unique_ptr<BaseType> type_;
+  std::string comments_;
+  unsigned line_;
+};
+
+class Elements {
+ public:
+  void Add(Element* elm);
+  const std::list<std::unique_ptr<Element>>& GetElms() const;
+  bool Exist(Element* elm) const;
+
+ private:
+  std::list<std::unique_ptr<Element>> elms_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_ELEMENT_H_
diff --git a/idlc/ast/interface.cc b/idlc/ast/interface.cc
new file mode 100644 (file)
index 0000000..40587a2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/attribute.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/block.h"
+
+namespace tidl {
+
+Interface::Interface(std::string id, Declarations* decls, std::string comments,
+                     Attributes* attrs, unsigned line)
+    : Block::Block(std::move(id), Block::TYPE_INTERFACE,
+                   std::move(comments), line),
+      decls_(decls),
+      attrs_(attrs) {}
+
+const Declarations& Interface::GetDeclarations() const {
+  return *decls_;
+}
+
+const Attributes& Interface::GetAttributes() const {
+  return *attrs_;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/interface.h b/idlc/ast/interface.h
new file mode 100644 (file)
index 0000000..d7463f7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_INTERFACE_H_
+#define IDLC_INTERFACE_H_
+
+#include <string>
+#include <memory>
+
+#include "idlc/ast/block.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/attribute.h"
+
+namespace tidl {
+
+class Interface : public Block {
+ public:
+  Interface(std::string id, Declarations* decls, std::string comments,
+            Attributes* attrs, unsigned line);
+
+  const Declarations& GetDeclarations() const;
+  const Attributes& GetAttributes() const;
+
+ private:
+  std::unique_ptr<Declarations> decls_;
+  std::unique_ptr<Attributes> attrs_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_INTERFACE_H_
+
diff --git a/idlc/ast/location.hh b/idlc/ast/location.hh
new file mode 100644 (file)
index 0000000..b7c1b5f
--- /dev/null
@@ -0,0 +1,163 @@
+// A Bison parser, made by GNU Bison 3.0.2.
+
+// Locations for Bison parsers in C++
+
+// Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton.  Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file /home/gogo/work/next/tidl/idlc/ast/location.hh
+ ** Define the yy::location class.
+ */
+
+#ifndef YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_LOCATION_HH_INCLUDED
+# define YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_LOCATION_HH_INCLUDED
+
+# include "position.hh"
+
+
+namespace yy {
+#line 46 "/home/gogo/work/next/tidl/idlc/ast/location.hh" // location.cc:291
+  /// Abstract a location.
+  class location
+  {
+  public:
+
+    /// Initialization.
+    void initialize (std::string* f = YY_NULLPTR,
+                     unsigned int l = 1u,
+                     unsigned int c = 1u)
+    {
+      begin.initialize (f, l, c);
+      end = begin;
+    }
+
+    /** \name Line and Column related manipulators
+     ** \{ */
+  public:
+    /// Reset initial location to final location.
+    void step ()
+    {
+      begin = end;
+    }
+
+    /// Extend the current location to the COUNT next columns.
+    void columns (int count = 1)
+    {
+      end += count;
+    }
+
+    /// Extend the current location to the COUNT next lines.
+    void lines (int count = 1)
+    {
+      end.lines (count);
+    }
+    /** \} */
+
+
+  public:
+    /// Beginning of the located region.
+    position begin;
+    /// End of the located region.
+    position end;
+  };
+
+  /// Join two location objects to create a location.
+  inline location operator+ (location res, const location& end)
+  {
+    res.end = end.end;
+    return res;
+  }
+
+  /// Change end position in place.
+  inline location& operator+= (location& res, int width)
+  {
+    res.columns (width);
+    return res;
+  }
+
+  /// Change end position.
+  inline location operator+ (location res, int width)
+  {
+    return res += width;
+  }
+
+  /// Change end position in place.
+  inline location& operator-= (location& res, int width)
+  {
+    return res += -width;
+  }
+
+  /// Change end position.
+  inline location operator- (const location& begin, int width)
+  {
+    return begin + -width;
+  }
+
+  /// Compare two location objects.
+  inline bool
+  operator== (const location& loc1, const location& loc2)
+  {
+    return loc1.begin == loc2.begin && loc1.end == loc2.end;
+  }
+
+  /// Compare two location objects.
+  inline bool
+  operator!= (const location& loc1, const location& loc2)
+  {
+    return !(loc1 == loc2);
+  }
+
+  /** \brief Intercept output stream redirection.
+   ** \param ostr the destination output stream
+   ** \param loc a reference to the location to redirect
+   **
+   ** Avoid duplicate information.
+   */
+  template <typename YYChar>
+  inline std::basic_ostream<YYChar>&
+  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
+  {
+    unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
+    ostr << loc.begin// << "(" << loc.end << ") "
+;
+    if (loc.end.filename
+        && (!loc.begin.filename
+            || *loc.begin.filename != *loc.end.filename))
+      ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
+    else if (loc.begin.line < loc.end.line)
+      ostr << '-' << loc.end.line << '.' << end_col;
+    else if (loc.begin.column < end_col)
+      ostr << '-' << end_col;
+    return ostr;
+  }
+
+
+} // yy
+#line 163 "/home/gogo/work/next/tidl/idlc/ast/location.hh" // location.cc:291
+#endif // !YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_LOCATION_HH_INCLUDED
diff --git a/idlc/ast/parameter.cc b/idlc/ast/parameter.cc
new file mode 100644 (file)
index 0000000..31633ef
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/type.h"
+
+namespace tidl {
+
+Parameter::Parameter(std::string id, ParameterType* type, unsigned line)
+    : type_(type), id_(std::move(id)), line_(line) {}
+
+const std::string& Parameter::GetID() const {
+  return id_;
+}
+
+const ParameterType& Parameter::GetParameterType() const {
+  return *type_;
+}
+
+const unsigned Parameter::GetLine() const {
+  return line_;
+}
+
+void Parameters::Add(Parameter* param) {
+  params_.emplace_back(param);
+}
+
+const std::list<std::unique_ptr<Parameter>>& Parameters::GetParams() const {
+  return params_;
+}
+
+bool Parameters::Exist(Parameter* param) const {
+  for (auto& p : params_) {
+    if (p->GetID() == param->GetID())
+      return true;
+  }
+
+  return false;
+}
+
+}  // namespace tidl
+
diff --git a/idlc/ast/parameter.h b/idlc/ast/parameter.h
new file mode 100644 (file)
index 0000000..830d397
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_PARAMETER_H_
+#define IDLC_PARAMETER_H_
+
+#include <string>
+#include <list>
+#include <memory>
+
+#include "idlc/ast/type.h"
+
+namespace tidl {
+
+class Parameter {
+ public:
+  Parameter(std::string id, ParameterType* type, unsigned line);
+
+  const std::string& GetID() const;
+  const ParameterType& GetParameterType() const;
+  const unsigned GetLine() const;
+
+ private:
+  std::unique_ptr<ParameterType> type_;
+  std::string id_;
+  unsigned line_;
+};
+
+class Parameters {
+ public:
+  void Add(Parameter* param);
+  const std::list<std::unique_ptr<Parameter>>& GetParams() const;
+  bool Exist(Parameter* param) const;
+
+ private:
+  std::list<std::unique_ptr<Parameter>> params_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_PARAMETER_H_
diff --git a/idlc/ast/parser.cc b/idlc/ast/parser.cc
new file mode 100644 (file)
index 0000000..7635efb
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <fstream>
+#include <string>
+
+#include "idlc/ast/parser.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/tidlc_y.hpp"
+
+struct yy_buffer_state;
+yy_buffer_state* yy_scan_buffer(char*, size_t, void*);
+void yylex_init(void**);
+void yylex_destroy(void*);
+
+namespace tidl {
+
+Parser::Parser() : scanner_(nullptr), error_(false) {
+  yylex_init(&scanner_);
+}
+
+Parser::~Parser() {
+  yylex_destroy(scanner_);
+}
+
+void Parser::SetDoc(Document* doc) {
+  doc_ = std::shared_ptr<Document>(doc);
+}
+
+std::shared_ptr<Document> Parser::GetDoc() {
+  return doc_;
+}
+
+bool Parser::Parse(const std::string& input) {
+  std::string in = input;
+  error_ = false;
+
+  in.append(2u, '\0');
+  yy_scan_buffer(&in[0], in.length(), scanner_);
+  if (yy::parser(this).parse() != 0 || error_ != false) {
+    std::cerr << "[TIDL:Parser] error" << std::endl;
+    return false;
+  }
+
+  return true;
+}
+
+bool Parser::ParseFromFile(const std::string& path) {
+  std::ifstream inFile(path);
+  std::string str((std::istreambuf_iterator<char>(inFile)),
+      std::istreambuf_iterator<char>());
+  path_ = path;
+  return Parse(str);
+}
+
+void Parser::ReportError(const std::string& err, unsigned line) {
+  std::cerr << path_ << ":" << line << ": " << err << std::endl;
+  error_ = true;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/parser.h b/idlc/ast/parser.h
new file mode 100644 (file)
index 0000000..6981c6e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_PARSER_H_
+#define IDLC_PARSER_H_
+
+#include <memory>
+#include <string>
+#include <list>
+
+#include "idlc/ast/document.h"
+
+namespace tidl {
+
+class Parser {
+ public:
+  Parser();
+  ~Parser();
+
+  void* Scanner() const { return scanner_; }
+  bool Parse(const std::string& input);
+  bool ParseFromFile(const std::string& path);
+  void SetDoc(Document* doc);
+  std::shared_ptr<Document> GetDoc();
+  void ReportError(const std::string& err, unsigned line);
+
+ private:
+  void* scanner_;
+  std::shared_ptr<Document> doc_;
+  std::string path_;
+  bool error_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_PARSER_H_
diff --git a/idlc/ast/position.hh b/idlc/ast/position.hh
new file mode 100644 (file)
index 0000000..b980804
--- /dev/null
@@ -0,0 +1,169 @@
+// A Bison parser, made by GNU Bison 3.0.2.
+
+// Positions for Bison parsers in C++
+
+// Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton.  Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file /home/gogo/work/next/tidl/idlc/ast/position.hh
+ ** Define the yy::position class.
+ */
+
+#ifndef YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_POSITION_HH_INCLUDED
+# define YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_POSITION_HH_INCLUDED
+
+# include <algorithm> // std::max
+# include <iostream>
+# include <string>
+
+# ifndef YY_NULLPTR
+#  if defined __cplusplus && 201103L <= __cplusplus
+#   define YY_NULLPTR nullptr
+#  else
+#   define YY_NULLPTR 0
+#  endif
+# endif
+
+
+namespace yy {
+#line 56 "/home/gogo/work/next/tidl/idlc/ast/position.hh" // location.cc:291
+  /// Abstract a position.
+  class position
+  {
+  public:
+    /// Initialization.
+    void initialize (std::string* fn = YY_NULLPTR,
+                     unsigned int l = 1u,
+                     unsigned int c = 1u)
+    {
+      filename = fn;
+      line = l;
+      column = c;
+    }
+
+    /** \name Line and Column related manipulators
+     ** \{ */
+    /// (line related) Advance to the COUNT next lines.
+    void lines (int count = 1)
+    {
+      if (count)
+        {
+          column = 1u;
+          line = add_ (line, count, 1);
+        }
+    }
+
+    /// (column related) Advance to the COUNT next columns.
+    void columns (int count = 1)
+    {
+      column = add_ (column, count, 1);
+    }
+    /** \} */
+
+    /// File name to which this position refers.
+    std::string* filename;
+    /// Current line number.
+    unsigned int line;
+    /// Current column number.
+    unsigned int column;
+
+  private:
+    /// Compute max(min, lhs+rhs) (provided min <= lhs).
+    static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
+    {
+      return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
+              ? rhs + lhs
+              : min);
+    }
+  };
+
+  /// Add and assign a position.
+  inline position&
+  operator+= (position& res, int width)
+  {
+    res.columns (width);
+    return res;
+  }
+
+  /// Add two position objects.
+  inline position
+  operator+ (position res, int width)
+  {
+    return res += width;
+  }
+
+  /// Add and assign a position.
+  inline position&
+  operator-= (position& res, int width)
+  {
+    return res += -width;
+  }
+
+  /// Add two position objects.
+  inline position
+  operator- (position res, int width)
+  {
+    return res -= width;
+  }
+
+  /// Compare two position objects.
+  inline bool
+  operator== (const position& pos1, const position& pos2)
+  {
+    return (pos1.line == pos2.line
+            && pos1.column == pos2.column
+            && (pos1.filename == pos2.filename
+                || (pos1.filename && pos2.filename
+                    && *pos1.filename == *pos2.filename)));
+  }
+
+  /// Compare two position objects.
+  inline bool
+  operator!= (const position& pos1, const position& pos2)
+  {
+    return !(pos1 == pos2);
+  }
+
+  /** \brief Intercept output stream redirection.
+   ** \param ostr the destination output stream
+   ** \param pos a reference to the position to redirect
+   */
+  template <typename YYChar>
+  inline std::basic_ostream<YYChar>&
+  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
+  {
+    if (pos.filename)
+      ostr << *pos.filename << ':';
+    return ostr << pos.line << '.' << pos.column;
+  }
+
+
+} // yy
+#line 169 "/home/gogo/work/next/tidl/idlc/ast/position.hh" // location.cc:291
+#endif // !YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_POSITION_HH_INCLUDED
diff --git a/idlc/ast/structure.cc b/idlc/ast/structure.cc
new file mode 100644 (file)
index 0000000..5e7eae6
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <utility>
+
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/block.h"
+
+namespace tidl {
+
+Structure::Structure(std::string id, Elements* elms, std::string comments,
+                     unsigned line)
+    : Block::Block(std::move(id), Block::TYPE_STRUCTURE,
+                   std::move(comments), line), elms_(elms) {}
+
+const Elements& Structure::GetElements() const {
+  return *elms_;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/structure.h b/idlc/ast/structure.h
new file mode 100644 (file)
index 0000000..f9b93b8
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_STRUCTURE_H_
+#define IDLC_STRUCTURE_H_
+
+#include <string>
+#include <memory>
+
+#include "idlc/ast/block.h"
+#include "idlc/ast/element.h"
+
+namespace tidl {
+
+class Structure : public Block {
+ public:
+  Structure(std::string id, Elements* elms, std::string comments,
+            unsigned line);
+
+  const Elements& GetElements() const;
+
+ private:
+  std::unique_ptr<Elements> elms_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_STRUCTURE_H_
+
diff --git a/idlc/ast/tidlc.ll b/idlc/ast/tidlc.ll
new file mode 100644 (file)
index 0000000..226315d
--- /dev/null
@@ -0,0 +1,140 @@
+%{
+#include <stdio.h>
+#include <string>
+
+#include "idlc/ast/parser.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/block.h"
+#include "idlc/ast/attribute.h"
+#include "idlc/ast/tidlc_y.hpp"
+
+#define YY_USER_ACTION yylloc->columns(yyleng);
+%}
+
+%x COMMENT VALUE
+
+%option yylineno
+%option noyywrap
+%option reentrant
+%option bison-bridge
+%option bison-locations
+
+%%
+%{
+  std::string comments;
+  std::string values;
+%}
+
+"/*"                    { comments += yytext; BEGIN(COMMENT); }
+<COMMENT>"*/"+\/        { comments += yytext; yylloc->step(); BEGIN(INITIAL); }
+<COMMENT>"*/"           { comments += yytext; comments += "\n"; BEGIN(INITIAL); }
+<COMMENT>"*/"\n+        { comments += yytext; yylloc->step(); BEGIN(INITIAL); }
+<COMMENT>\n+            { comments += yytext; yylloc->lines(yyleng); }
+<COMMENT>([^*]\n)+|.    { comments += yytext; yylloc->step(); }
+<COMMENT><<EOF>>        { return 0; }
+
+"//".*\n                { comments += yytext; yylloc->step(); }
+
+"\""                    { BEGIN(VALUE); }
+<VALUE>"\""             {
+                          BEGIN(INITIAL);
+                          yylval->token = new tidl::Token(values, comments);
+                          return yy::parser::token::T_VALUE;
+                        }
+<VALUE>([^*]\n)+|.      { values += yytext; yylloc->step(); }
+
+[\n]+                   { yylloc->lines(yyleng); yylloc->step(); }
+
+[ \t\r\n] ; // ignore all whitespace
+","                     { return yy::parser::token::T_COMMA; }
+"{"                     { return yy::parser::token::T_BRACE_OPEN; }
+"}"                     { return yy::parser::token::T_BRACE_CLOSE; }
+"("                     { return yy::parser::token::T_LEFT; }
+")"                     { return yy::parser::token::T_RIGHT; }
+";"                     { return yy::parser::token::T_SEMICOLON; }
+"void"                  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_VOID;
+                        }
+"char"                  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_CHAR;
+                        }
+"short"                 {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SHORT;
+                        }
+"int"                   {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_INT;
+                        }
+"long"                  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_LONG;
+                        }
+"float"                 {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_FLOAT;
+                        }
+"double"                {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_DOUBLE;
+                        }
+"bundle"                {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_BUNDLE;
+                        }
+"string"                {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_STRING;
+                        }
+"bool"                  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_BOOL;
+                        }
+"in"                    { return yy::parser::token::T_IN; }
+"out"                   { return yy::parser::token::T_OUT; }
+"ref"                   { return yy::parser::token::T_REF; }
+"async"                 { return yy::parser::token::T_ASYNC; }
+"delegate"              { return yy::parser::token::T_DELEGATE; }
+"<"                     { return yy::parser::token::T_META_OPEN; }
+">"                     { return yy::parser::token::T_META_CLOSE; }
+"list"                  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_LIST;
+                        }
+"array"                 {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_ARRAY;
+                        }
+"struct"                {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_STRUCTURE;
+                        }
+"interface"             {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_INTERFACE;
+                        }
+[A-Za-z_][A-Za-z0-9_]*  {
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_ID;
+                        }
+"["                     { // Square Bracket
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SB_OPEN;
+                        }
+"]"                     { // Square Bracket
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SB_CLOSE;
+                        }
+"="                     { return yy::parser::token::T_EQUAL; }
+.                       { return yy::parser::token::T_UNKNOWN; }
+
+%%
+
diff --git a/idlc/ast/tidlc.yy b/idlc/ast/tidlc.yy
new file mode 100644 (file)
index 0000000..557d5ec
--- /dev/null
@@ -0,0 +1,476 @@
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "idlc/ast/parser.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/block.h"
+#include "idlc/ast/attribute.h"
+#include "idlc/ast/tidlc_y.hpp"
+
+int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
+
+#define lex_scanner ps->Scanner()
+
+%}
+
+%parse-param { tidl::Parser* ps }
+%lex-param { void *lex_scanner }
+
+%token T_LEFT T_RIGHT T_COMMA T_SEMICOLON T_BRACE_OPEN T_BRACE_CLOSE
+%token T_IN T_OUT T_REF T_ASYNC
+%token T_META_OPEN T_META_CLOSE
+%token T_EQUAL T_DELEGATE T_UNKNOWN
+
+
+%start start
+
+%skeleton "glr.cc"
+
+%union {
+  tidl::Document* doc;
+  tidl::Interface* interf;
+  tidl::Declaration* decl;
+  tidl::Declarations* decls;
+  tidl::BaseType* b_type;
+  tidl::ParameterType* p_type;
+  tidl::Token* direction;
+  tidl::Parameter* param;
+  tidl::Parameters* params;
+  tidl::Token* token;
+  tidl::Structure* structure;
+  tidl::Element* elm;
+  tidl::Elements* elms;
+  tidl::Block* blk;
+  tidl::Attribute* attr;
+  tidl::Attributes* attrs;
+}
+
+%token<token> T_ID
+%token<token> T_STRUCTURE
+%token<token> T_INTERFACE
+%token<token> T_CHAR
+%token<token> T_SHORT
+%token<token> T_INT
+%token<token> T_LONG
+%token<token> T_FLOAT
+%token<token> T_DOUBLE
+%token<token> T_VOID
+%token<token> T_BUNDLE
+%token<token> T_STRING
+%token<token> T_BOOL
+%token<token> T_LIST
+%token<token> T_ARRAY
+%token<token> T_VALUE
+%token<token> T_SB_OPEN
+%token<token> T_SB_CLOSE
+%type<doc> blocks
+%type<blk> block
+%type<structure> structure_block
+%type<interf> interface_block
+%type<decls> declarations
+%type<decl> declaration
+%type<p_type> parameter_type
+%type<b_type> base_type
+%type<b_type> container_type
+%type<param> parameter
+%type<params> parameter_list
+%type<direction> direction_specifier
+%type<token> container_type_name
+%type<elm> element
+%type<elms> elements
+%type<attr> attribute
+%type<attrs> attributes
+
+%%
+
+start: blocks {
+     ps->SetDoc($1);
+  }
+;
+
+blocks: block {
+    $$ = new tidl::Document();
+    if ($1 != NULL)
+      $$->AddBlock($1);
+  }
+  | blocks block {
+    $$ = $1;
+
+    if ($2 != NULL) {
+      if ($$->ExistBlock($2)) {
+        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
+        delete $2;
+      } else {
+        $$->AddBlock($2);
+      }
+    }
+  }
+;
+
+block: interface_block {
+    $$ = $1;
+  }
+  | structure_block {
+    $$ = $1;
+  }
+;
+
+structure_block: T_STRUCTURE T_ID T_BRACE_OPEN elements T_BRACE_CLOSE {
+    $$ = new tidl::Structure($2->ToString(), $4, $1->GetComments(),
+        @1.begin.line);
+    delete $1;
+    delete $2;
+  }
+  | T_STRUCTURE T_BRACE_OPEN elements T_BRACE_CLOSE {
+    ps->ReportError("syntax error. \"No identifier\".", @1.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+  | T_STRUCTURE error T_BRACE_OPEN elements T_BRACE_CLOSE {
+    ps->ReportError("syntax error. \"Please check it before an open brace.\"",
+        @2.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+  | T_STRUCTURE error T_BRACE_CLOSE {
+    ps->ReportError("syntax error in structure declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+;
+
+elements: element {
+    $$ = new (std::nothrow) tidl::Elements();
+    if ($$ != nullptr) {
+      $$->Add($1);
+    }
+  }
+  | elements element {
+    $$ = $1;
+    if ($2 != nullptr) {
+      if ($$->Exist($2)) {
+        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
+        delete $2;
+      } else {
+        $$->Add($2);
+      }
+    }
+  }
+  | elements error T_SEMICOLON {
+    ps->ReportError("syntax error in elements declarations.", @1.begin.line);
+    $$ = $1;
+  }
+;
+
+element: base_type T_ID T_SEMICOLON {
+    $$ = new tidl::Element($2->ToString(), $1, $1->GetComments(),
+        @1.begin.line);
+    delete $2;
+  }
+  | base_type T_SEMICOLON {
+    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
+    $$ = NULL;
+  }
+  | base_type error T_SEMICOLON {
+    ps->ReportError("syntax error in element declaration.", @2.begin.line);
+    $$ = NULL;
+  }
+  | error {
+    ps->ReportError("syntax error in element declaration.", @1.begin.line);
+    $$ = NULL;
+  }
+;
+
+attributes: attribute {
+    $$ = new (std::nothrow) tidl::Attributes();
+    if ($$ != nullptr) {
+      $$->Add($1);
+    }
+  }
+  | attributes T_COMMA attribute {
+    $$ = $1;
+    if ($3 != nullptr) {
+      if ($$->Exist($3)) {
+        ps->ReportError("syntax error. \"Already Exist\".", $3->GetLine());
+        delete $3;
+      } else {
+        $$->Add($3);
+      }
+    }
+  }
+  | error {
+    ps->ReportError("syntax error in attributes", @1.begin.line);
+    $$ = new tidl::Attributes();
+  }
+;
+
+attribute: T_ID T_EQUAL T_VALUE {
+    $$ = new tidl::Attribute($1->ToString(), $3->ToString(), @1.begin.line);
+    delete $1;
+    delete $3;
+  }
+  | T_ID error T_VALUE  {
+    ps->ReportError("syntax error in attribute declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $1;
+    delete $3;
+  }
+  | T_ID T_EQUAL error {
+    ps->ReportError("syntax error in attribute declaration.", @3.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+;
+
+interface_block: T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE {
+    $$ = new tidl::Interface($2->ToString(), $4, $1->GetComments(),
+        new tidl::Attributes(), @1.begin.line);
+    delete $1;
+    delete $2;
+  }
+  | T_SB_OPEN attributes T_SB_CLOSE T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE {
+    $$ = new tidl::Interface($5->ToString(), $7, $1->GetComments(), $2,
+        @1.begin.line);
+    delete $1;
+    delete $3;
+    delete $4;
+    delete $5;
+  }
+  | T_INTERFACE T_BRACE_OPEN declarations T_BRACE_CLOSE {
+    ps->ReportError("syntax error. \"No identifier\".", @1.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+  | T_INTERFACE error T_BRACE_OPEN declarations T_BRACE_CLOSE {
+    ps->ReportError("syntax error in interface declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+  | T_INTERFACE error T_BRACE_CLOSE {
+    ps->ReportError("syntax error in interface declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $1;
+  }
+;
+
+declarations: declaration {
+    $$ = new (std::nothrow) tidl::Declarations();
+    if ($$ != nullptr) {
+      $$->Add($1);
+    }
+  }
+  | declarations declaration {
+    $$ = $1;
+    if ($2 != nullptr) {
+      if ($$->Exist($2)) {
+        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
+        delete $2;
+      } else {
+        $$->Add($2);
+      }
+    }
+  }
+  | declarations error T_SEMICOLON {
+    ps->ReportError("syntax error in methods declaration.", @2.begin.line);
+    $$ = $1;
+  }
+;
+
+declaration: base_type T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON {
+    $$ = new tidl::Declaration($2->ToString(), $1, $4, $1->GetComments(),
+        @1.begin.line, tidl::Declaration::MethodType::SYNC);
+    delete $2;
+  }
+  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
+    $$ = new tidl::Declaration($2->ToString(),
+        new tidl::BaseType("void", $1->GetComments()), $4,
+        $1->GetComments(), @1.begin.line, tidl::Declaration::MethodType::ASYNC);
+    delete $1;
+    delete $2;
+  }
+  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
+    $$ = new tidl::Declaration($2->ToString(),
+        new tidl::BaseType("void", $1->GetComments()), $4,
+        $1->GetComments(), @1.begin.line,
+        tidl::Declaration::MethodType::DELEGATE);
+    delete $1;
+    delete $2;
+  }
+  | base_type T_ID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
+    ps->ReportError("syntax error in method declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $2;
+  }
+  | base_type T_ID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
+    ps->ReportError("syntax error in method declaration.", @2.begin.line);
+    $$ = NULL;
+    delete $2;
+  }
+  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON {
+    ps->ReportError("syntax error. \"No async\".", @6.begin.line);
+    $$ = NULL;
+    delete $2;
+  }
+  | base_type T_LEFT parameter_list T_RIGHT T_SEMICOLON {
+    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
+    $$ = NULL;
+  }
+  | T_VOID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
+    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
+    $$ = NULL;
+  }
+  | T_VOID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
+    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
+    $$ = NULL;
+  }
+  | base_type error T_SEMICOLON {
+    ps->ReportError("syntax error in method declaration.", @2.begin.line);
+    $$ = NULL;
+  }
+  | T_VOID error T_SEMICOLON {
+    ps->ReportError("syntax error in method declaration.", @2.begin.line);
+    $$ = NULL;
+  }
+;
+
+parameter_list: parameter {
+    $$ = new tidl::Parameters();
+    if ($1 != nullptr) {
+      $$->Add($1);
+    }
+  }
+  | parameter_list T_COMMA parameter {
+    $$ = $1;
+    if ($3 != nullptr) {
+      if ($$->Exist($3)) {
+        ps->ReportError("syntax error. \"Already Exists\".", $3->GetLine());
+        delete $3;
+      } else {
+        $$->Add($3);
+      }
+    }
+  }
+  | error {
+    ps->ReportError("syntax error in parameter list", @1.begin.line);
+    $$ = new tidl::Parameters();
+  }
+;
+
+direction_specifier: T_IN {
+    $$ = new tidl::Token("in", "");
+  }
+  | T_OUT {
+    $$ = new tidl::Token("out", "");
+  }
+  | T_REF {
+    $$ = new tidl::Token("ref", "");
+  }
+;
+
+parameter: {
+    $$ = nullptr;
+  }
+  | T_VOID {
+    $$ = nullptr;
+    delete $1;
+  }
+  | parameter_type T_ID {
+    $$ = new tidl::Parameter($2->ToString(), $1, @1.begin.line);
+    delete $2;
+  }
+;
+
+parameter_type: base_type {
+      $$ = new tidl::ParameterType($1);
+    }
+    | direction_specifier base_type {
+      $$ = new tidl::ParameterType($2, $1->ToString());
+      delete $1;
+    }
+;
+
+base_type: container_type {
+      $$ = $1;
+    }
+    | T_VOID {
+      $$ = new tidl::BaseType("void", $1->GetComments());
+      delete $1;
+    }
+    | T_CHAR {
+      $$ = new tidl::BaseType("char", $1->GetComments());
+      delete $1;
+    }
+    | T_SHORT {
+      $$ = new tidl::BaseType("short", $1->GetComments());
+      delete $1;
+    }
+    | T_INT {
+      $$ = new tidl::BaseType("int", $1->GetComments());
+      delete $1;
+    }
+    | T_LONG {
+      $$ = new tidl::BaseType("long", $1->GetComments());
+      delete $1;
+    }
+    | T_FLOAT {
+      $$ = new tidl::BaseType("float", $1->GetComments());
+      delete $1;
+    }
+    | T_DOUBLE {
+      $$ = new tidl::BaseType("double", $1->GetComments());
+      delete $1;
+    }
+    | T_BUNDLE {
+      $$ = new tidl::BaseType("bundle", $1->GetComments());
+      delete $1;
+    }
+    | T_STRING {
+      $$ = new tidl::BaseType("string", $1->GetComments());
+      delete $1;
+    }
+    | T_BOOL {
+      $$ = new tidl::BaseType("bool", $1->GetComments());
+      delete $1;
+    }
+    | T_ID {
+      $$ = new tidl::BaseType($1->ToString(), $1->GetComments(), true);
+      delete $1;
+    }
+;
+
+container_type: container_type_name T_META_OPEN base_type T_META_CLOSE {
+      $$ = new tidl::BaseType($1->ToString(), $1->GetComments());
+      $$->SetMetaType($3);
+      delete $1;
+    }
+;
+
+container_type_name: T_LIST {
+      $$ = new tidl::Token("list", $1->GetComments());
+      delete $1;
+    }
+    | T_ARRAY {
+      $$ = new tidl::Token("array", $1->GetComments());
+      delete $1;
+    }
+;
+
+%%
+
+#include <ctype.h>
+#include <stdio.h>
+
+void yy::parser::error(const yy::parser::location_type& l,
+                       const std::string& errstr) {
+  ps->ReportError(errstr, l.begin.line);
+}
+
+
diff --git a/idlc/ast/tidlc_l.cpp b/idlc/ast/tidlc_l.cpp
new file mode 100644 (file)
index 0000000..f8c6386
--- /dev/null
@@ -0,0 +1,2414 @@
+#line 2 "/home/gogo/work/next/tidl/idlc/ast/tidlc_l.cpp"
+
+#line 4 "/home/gogo/work/next/tidl/idlc/ast/tidlc_l.cpp"
+
+#define  YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 39
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with  platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types. 
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t; 
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN               (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN              (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN              (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX               (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX              (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX              (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX              (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX             (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX             (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else  /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index.  If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+   are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Enter a start condition.  This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state.  The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+    /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
+     *       access to the local variable yy_act. Since yyless() is a macro, it would break
+     *       existing scanners that call yyless() from OUTSIDE yylex. 
+     *       One obvious solution it to make yy_act a global. I tried that, and saw
+     *       a 5% performance hit in a non-yylineno scanner, because yy_act is
+     *       normally declared as a register variable-- so it is not worth it.
+     */
+    #define  YY_LESS_LINENO(n) \
+            do { \
+                int yyl;\
+                for ( yyl = n; yyl < yyleng; ++yyl )\
+                    if ( yytext[yyl] == '\n' )\
+                        --yylineno;\
+            }while(0)
+    #define YY_LINENO_REWIND_TO(dst) \
+            do {\
+                const char *p;\
+                for ( p = yy_cp-1; p >= (dst); --p)\
+                    if ( *p == '\n' )\
+                        --yylineno;\
+            }while(0)
+    
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+       do \
+               { \
+               /* Undo effects of setting up yytext. */ \
+        int yyless_macro_arg = (n); \
+        YY_LESS_LINENO(yyless_macro_arg);\
+               *yy_cp = yyg->yy_hold_char; \
+               YY_RESTORE_YY_MORE_OFFSET \
+               yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+               YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+               } \
+       while ( 0 )
+
+#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+       {
+       FILE *yy_input_file;
+
+       char *yy_ch_buf;                /* input buffer */
+       char *yy_buf_pos;               /* current position in input buffer */
+
+       /* Size of input buffer in bytes, not including room for EOB
+        * characters.
+        */
+       yy_size_t yy_buf_size;
+
+       /* Number of characters read into yy_ch_buf, not including EOB
+        * characters.
+        */
+       yy_size_t yy_n_chars;
+
+       /* Whether we "own" the buffer - i.e., we know we created it,
+        * and can realloc() it to grow it, and should free() it to
+        * delete it.
+        */
+       int yy_is_our_buffer;
+
+       /* Whether this is an "interactive" input source; if so, and
+        * if we're using stdio for input, then we want to use getc()
+        * instead of fread(), to make sure we stop fetching input after
+        * each newline.
+        */
+       int yy_is_interactive;
+
+       /* Whether we're considered to be at the beginning of a line.
+        * If so, '^' rules will be active on the next match, otherwise
+        * not.
+        */
+       int yy_at_bol;
+
+    int yy_bs_lineno; /**< The line count. */
+    int yy_bs_column; /**< The column count. */
+    
+       /* Whether to try to fill the input buffer when we reach the
+        * end of it.
+        */
+       int yy_fill_buffer;
+
+       int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+       /* When an EOF's been seen but there's still some text to process
+        * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+        * shouldn't try reading from the input source any more.  We might
+        * still have a bunch of tokens to match, though, because of
+        * possible backing-up.
+        *
+        * When we actually see the EOF, we change the status to "new"
+        * (via yyrestart()), so that the user can continue scanning by
+        * just pointing yyin at a new input file.
+        */
+#define YY_BUFFER_EOF_PENDING 2
+
+       };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+                          : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void yypop_buffer_state (yyscan_t yyscanner );
+
+static void yyensure_buffer_stack (yyscan_t yyscanner );
+static void yy_load_buffer_state (yyscan_t yyscanner );
+static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
+
+void *yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+       { \
+       if ( ! YY_CURRENT_BUFFER ){ \
+        yyensure_buffer_stack (yyscanner); \
+               YY_CURRENT_BUFFER_LVALUE =    \
+            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+       } \
+       YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+       }
+
+#define yy_set_bol(at_bol) \
+       { \
+       if ( ! YY_CURRENT_BUFFER ){\
+        yyensure_buffer_stack (yyscanner); \
+               YY_CURRENT_BUFFER_LVALUE =    \
+            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+       } \
+       YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+       }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define yywrap(yyscanner) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state  ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+       yyg->yytext_ptr = yy_bp; \
+       yyleng = (size_t) (yy_cp - yy_bp); \
+       yyg->yy_hold_char = *yy_cp; \
+       *yy_cp = '\0'; \
+       yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 45
+#define YY_END_OF_BUFFER 46
+/* This struct is not used in this scanner,
+   but its presence is necessary. */
+struct yy_trans_info
+       {
+       flex_int32_t yy_verify;
+       flex_int32_t yy_nxt;
+       };
+static yyconst flex_int16_t yy_accept[129] =
+    {   0,
+        0,    0,    0,    0,    0,    0,   46,   44,   12,   11,
+        8,   16,   17,   13,   44,   18,   34,   43,   35,   40,
+       41,   42,   40,   40,   40,   40,   40,   40,   40,   40,
+       40,   40,   40,   14,   15,    6,    5,    6,   10,   45,
+        9,   10,   11,    1,    0,   40,   40,   40,   40,   40,
+       40,   40,   40,   40,   29,   40,   40,   40,   40,   40,
+       40,   40,    6,    5,    3,   10,    0,    7,   40,   40,
+       40,   40,   40,   40,   40,   40,   22,   40,   40,   30,
+       31,   40,   40,   40,    0,    5,    4,    0,    2,    0,
+       40,   40,   28,   40,   20,   40,   40,   40,   40,   36,
+
+       23,   40,   40,   40,   19,    0,   37,   32,   40,   40,
+       40,   24,   40,   21,   40,   40,   26,   40,   25,   40,
+       27,   38,   40,   40,   33,   40,   39,    0
+    } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
+        1,    1,    2,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    2,    1,    4,    1,    1,    1,    1,    1,    5,
+        6,    7,    1,    8,    1,    1,    9,   10,   10,   10,
+       10,   10,   10,   10,   10,   10,   10,    1,   11,   12,
+       13,   14,    1,    1,   15,   15,   15,   15,   15,   15,
+       15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
+       15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
+       16,    1,   17,    1,   15,    1,   18,   19,   20,   21,
+
+       22,   23,   24,   25,   26,   15,   15,   27,   15,   28,
+       29,   15,   15,   30,   31,   32,   33,   34,   15,   15,
+       35,   15,   36,    1,   37,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1
+    } ;
+
+static yyconst flex_int32_t yy_meta[38] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    2,    1,    1,    3,
+        1,    1,    1,    1,    3,    1,    1,    3,    3,    3,
+        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
+        3,    3,    3,    3,    3,    1,    1
+    } ;
+
+static yyconst flex_int16_t yy_base[135] =
+    {   0,
+        0,    0,   35,   36,   37,   42,  153,  154,  154,  149,
+      154,  154,  154,  154,   41,  154,  154,  154,  154,    0,
+      154,  154,   21,   24,  126,   25,  123,  121,   29,  115,
+      125,   31,  117,  154,  154,  142,  141,  134,  139,  138,
+      137,  154,  136,  154,  135,    0,  107,  101,  106,  106,
+      115,  105,   98,  101,   97,   97,   99,   94,  102,   95,
+       93,   96,    0,  118,   57,    0,  117,  154,  101,   90,
+       90,   95,   85,   92,   94,   94,   89,   78,   85,    0,
+        0,   78,   35,   86,  103,  102,  101,   94,  154,   99,
+       66,   80,    0,   72,    0,   74,   70,   64,   65,    0,
+
+        0,   62,   65,   72,    0,   58,    0,    0,   69,   72,
+       67,    0,   65,    0,   63,   54,    0,   53,    0,   66,
+        0,    0,   60,   59,    0,   40,    0,  154,   68,   71,
+       56,   74,   77,   80
+    } ;
+
+static yyconst flex_int16_t yy_def[135] =
+    {   0,
+      128,    1,  129,  129,  130,  130,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  131,
+      128,  128,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  132,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  133,  133,  128,  134,  132,  128,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  128,  128,  128,  128,  128,  128,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+
+      131,  131,  131,  131,  131,  128,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,    0,  128,  128,
+      128,  128,  128,  128
+    } ;
+
+static yyconst flex_int16_t yy_nxt[192] =
+    {   0,
+        8,    9,   10,   11,   12,   13,    8,   14,   15,    8,
+       16,   17,   18,   19,   20,   21,   22,   23,   24,   25,
+       26,   20,   27,   20,   20,   28,   29,   20,   30,   31,
+       32,   20,   20,   33,   20,   34,   35,   37,   37,   40,
+       41,   38,   38,   42,   40,   41,   52,   44,   42,   45,
+       47,   48,   49,   53,   56,   60,   50,   57,   46,   87,
+      103,  127,   61,   88,   88,   89,   89,  104,   36,   36,
+       36,   39,   39,   39,   67,   67,   67,   85,  126,   85,
+       90,  125,   90,  124,  123,  122,  121,  120,  119,  118,
+      117,  116,  115,  114,  113,  112,  111,  110,  109,  108,
+
+      107,   66,  106,   87,   64,   63,  105,  102,  101,  100,
+       99,   98,   97,   96,   95,   94,   93,   92,   91,   68,
+       86,   84,   83,   82,   81,   80,   79,   78,   77,   76,
+       75,   74,   73,   72,   71,   70,   69,   68,   43,   66,
+       66,   66,   65,   64,   63,   62,   59,   58,   55,   54,
+       51,   43,  128,    7,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128
+
+    } ;
+
+static yyconst flex_int16_t yy_chk[192] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    3,    4,    5,
+        5,    3,    4,    5,    6,    6,   26,   15,    6,   15,
+       23,   23,   24,   26,   29,   32,   24,   29,  131,   65,
+       83,  126,   32,   65,  106,   65,  106,   83,  129,  129,
+      129,  130,  130,  130,  132,  132,  132,  133,  124,  133,
+      134,  123,  134,  120,  118,  116,  115,  113,  111,  110,
+      109,  104,  103,  102,   99,   98,   97,   96,   94,   92,
+
+       91,   90,   88,   87,   86,   85,   84,   82,   79,   78,
+       77,   76,   75,   74,   73,   72,   71,   70,   69,   67,
+       64,   62,   61,   60,   59,   58,   57,   56,   55,   54,
+       53,   52,   51,   50,   49,   48,   47,   45,   43,   41,
+       40,   39,   38,   37,   36,   33,   31,   30,   28,   27,
+       25,   10,    7,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
+      128
+
+    } ;
+
+/* Table of booleans, true if rule could match eol. */
+static yyconst flex_int32_t yy_rule_can_match_eol[46] =
+    {   0,
+0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0,     };
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+#line 2 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+#include <stdio.h>
+#include <string>
+
+#include "idlc/ast/parser.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/block.h"
+#include "idlc/ast/attribute.h"
+#include "idlc/ast/tidlc_y.hpp"
+
+#define YY_USER_ACTION yylloc->columns(yyleng);
+
+#line 572 "/home/gogo/work/next/tidl/idlc/ast/tidlc_l.cpp"
+
+#define INITIAL 0
+#define COMMENT 1
+#define VALUE 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+    {
+
+    /* User-defined. Not touched by flex. */
+    YY_EXTRA_TYPE yyextra_r;
+
+    /* The rest are the same as the globals declared in the non-reentrant scanner. */
+    FILE *yyin_r, *yyout_r;
+    size_t yy_buffer_stack_top; /**< index of top of stack. */
+    size_t yy_buffer_stack_max; /**< capacity of stack. */
+    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
+    char yy_hold_char;
+    yy_size_t yy_n_chars;
+    yy_size_t yyleng_r;
+    char *yy_c_buf_p;
+    int yy_init;
+    int yy_start;
+    int yy_did_buffer_switch_on_eof;
+    int yy_start_stack_ptr;
+    int yy_start_stack_depth;
+    int *yy_start_stack;
+    yy_state_type yy_last_accepting_state;
+    char* yy_last_accepting_cpos;
+
+    int yylineno_r;
+    int yy_flex_debug_r;
+
+    char *yytext_r;
+    int yy_more_flag;
+    int yy_more_len;
+
+    YYSTYPE * yylval_r;
+
+    YYLTYPE * yylloc_r;
+
+    }; /* end struct yyguts_t */
+
+static int yy_init_globals (yyscan_t yyscanner );
+
+    /* This must go here because YYSTYPE and YYLTYPE are included
+     * from bison output in section 1.*/
+    #    define yylval yyg->yylval_r
+    
+    #    define yylloc yyg->yylloc_r
+    
+int yylex_init (yyscan_t* scanner);
+
+int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+   These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy (yyscan_t yyscanner );
+
+int yyget_debug (yyscan_t yyscanner );
+
+void yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner );
+
+void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *yyget_in (yyscan_t yyscanner );
+
+void yyset_in  (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *yyget_out (yyscan_t yyscanner );
+
+void yyset_out  (FILE * out_str ,yyscan_t yyscanner );
+
+yy_size_t yyget_leng (yyscan_t yyscanner );
+
+char *yyget_text (yyscan_t yyscanner );
+
+int yyget_lineno (yyscan_t yyscanner );
+
+void yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+int yyget_column  (yyscan_t yyscanner );
+
+void yyset_column (int column_no ,yyscan_t yyscanner );
+
+YYSTYPE * yyget_lval (yyscan_t yyscanner );
+
+void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
+
+       YYLTYPE *yyget_lloc (yyscan_t yyscanner );
+    
+        void yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
+    
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap (yyscan_t yyscanner );
+#else
+extern int yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+    static void yyunput (int c,char *buf_ptr  ,yyscan_t yyscanner);
+    
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+       if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+               { \
+               int c = '*'; \
+               size_t n; \
+               for ( n = 0; n < max_size && \
+                            (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+                       buf[n] = (char) c; \
+               if ( c == '\n' ) \
+                       buf[n++] = (char) c; \
+               if ( c == EOF && ferror( yyin ) ) \
+                       YY_FATAL_ERROR( "input in flex scanner failed" ); \
+               result = n; \
+               } \
+       else \
+               { \
+               errno=0; \
+               while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+                       { \
+                       if( errno != EINTR) \
+                               { \
+                               YY_FATAL_ERROR( "input in flex scanner failed" ); \
+                               break; \
+                               } \
+                       errno=0; \
+                       clearerr(yyin); \
+                       } \
+               }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int yylex \
+               (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
+
+#define YY_DECL int yylex \
+               (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+       YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+       register yy_state_type yy_current_state;
+       register char *yy_cp, *yy_bp;
+       register int yy_act;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+    yylval = yylval_param;
+
+    yylloc = yylloc_param;
+
+       if ( !yyg->yy_init )
+               {
+               yyg->yy_init = 1;
+
+#ifdef YY_USER_INIT
+               YY_USER_INIT;
+#endif
+
+               if ( ! yyg->yy_start )
+                       yyg->yy_start = 1;      /* first start state */
+
+               if ( ! yyin )
+                       yyin = stdin;
+
+               if ( ! yyout )
+                       yyout = stdout;
+
+               if ( ! YY_CURRENT_BUFFER ) {
+                       yyensure_buffer_stack (yyscanner);
+                       YY_CURRENT_BUFFER_LVALUE =
+                               yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+               }
+
+               yy_load_buffer_state(yyscanner );
+               }
+
+       {
+#line 28 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+
+
+  std::string comments;
+  std::string values;
+
+
+#line 862 "/home/gogo/work/next/tidl/idlc/ast/tidlc_l.cpp"
+
+       while ( 1 )             /* loops until end-of-file is reached */
+               {
+               yy_cp = yyg->yy_c_buf_p;
+
+               /* Support of yytext. */
+               *yy_cp = yyg->yy_hold_char;
+
+               /* yy_bp points to the position in yy_ch_buf of the start of
+                * the current run.
+                */
+               yy_bp = yy_cp;
+
+               yy_current_state = yyg->yy_start;
+yy_match:
+               do
+                       {
+                       register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
+                       if ( yy_accept[yy_current_state] )
+                               {
+                               yyg->yy_last_accepting_state = yy_current_state;
+                               yyg->yy_last_accepting_cpos = yy_cp;
+                               }
+                       while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+                               {
+                               yy_current_state = (int) yy_def[yy_current_state];
+                               if ( yy_current_state >= 129 )
+                                       yy_c = yy_meta[(unsigned int) yy_c];
+                               }
+                       yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+                       ++yy_cp;
+                       }
+               while ( yy_base[yy_current_state] != 154 );
+
+yy_find_action:
+               yy_act = yy_accept[yy_current_state];
+               if ( yy_act == 0 )
+                       { /* have to back up */
+                       yy_cp = yyg->yy_last_accepting_cpos;
+                       yy_current_state = yyg->yy_last_accepting_state;
+                       yy_act = yy_accept[yy_current_state];
+                       }
+
+               YY_DO_BEFORE_ACTION;
+
+               if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
+                       {
+                       yy_size_t yyl;
+                       for ( yyl = 0; yyl < yyleng; ++yyl )
+                               if ( yytext[yyl] == '\n' )
+                                          
+    do{ yylineno++;
+        yycolumn=0;
+    }while(0)
+;
+                       }
+
+do_action:     /* This label is used only to access EOF actions. */
+
+               switch ( yy_act )
+       { /* beginning of action switch */
+                       case 0: /* must back up */
+                       /* undo the effects of YY_DO_BEFORE_ACTION */
+                       *yy_cp = yyg->yy_hold_char;
+                       yy_cp = yyg->yy_last_accepting_cpos;
+                       yy_current_state = yyg->yy_last_accepting_state;
+                       goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 34 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; BEGIN(COMMENT); }
+       YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 35 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; yylloc->step(); BEGIN(INITIAL); }
+       YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 36 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; comments += "\n"; BEGIN(INITIAL); }
+       YY_BREAK
+case 4:
+/* rule 4 can match eol */
+YY_RULE_SETUP
+#line 37 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; yylloc->step(); BEGIN(INITIAL); }
+       YY_BREAK
+case 5:
+/* rule 5 can match eol */
+YY_RULE_SETUP
+#line 38 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; yylloc->lines(yyleng); }
+       YY_BREAK
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 39 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; yylloc->step(); }
+       YY_BREAK
+case YY_STATE_EOF(COMMENT):
+#line 40 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return 0; }
+       YY_BREAK
+case 7:
+/* rule 7 can match eol */
+YY_RULE_SETUP
+#line 42 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ comments += yytext; yylloc->step(); }
+       YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 44 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ BEGIN(VALUE); }
+       YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 45 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          BEGIN(INITIAL);
+                          yylval->token = new tidl::Token(values, comments);
+                          return yy::parser::token::T_VALUE;
+                        }
+       YY_BREAK
+case 10:
+/* rule 10 can match eol */
+YY_RULE_SETUP
+#line 50 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ values += yytext; yylloc->step(); }
+       YY_BREAK
+case 11:
+/* rule 11 can match eol */
+YY_RULE_SETUP
+#line 52 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ yylloc->lines(yyleng); yylloc->step(); }
+       YY_BREAK
+case 12:
+/* rule 12 can match eol */
+YY_RULE_SETUP
+#line 54 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+; // ignore all whitespace
+       YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 55 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_COMMA; }
+       YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 56 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_BRACE_OPEN; }
+       YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 57 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_BRACE_CLOSE; }
+       YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 58 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_LEFT; }
+       YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 59 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_RIGHT; }
+       YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 60 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_SEMICOLON; }
+       YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 61 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_VOID;
+                        }
+       YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 65 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_CHAR;
+                        }
+       YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 69 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SHORT;
+                        }
+       YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 73 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_INT;
+                        }
+       YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 77 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_LONG;
+                        }
+       YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 81 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_FLOAT;
+                        }
+       YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 85 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_DOUBLE;
+                        }
+       YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 89 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_BUNDLE;
+                        }
+       YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 93 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_STRING;
+                        }
+       YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 97 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_BOOL;
+                        }
+       YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 101 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_IN; }
+       YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 102 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_OUT; }
+       YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 103 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_REF; }
+       YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 104 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_ASYNC; }
+       YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 105 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_DELEGATE; }
+       YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 106 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_META_OPEN; }
+       YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 107 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_META_CLOSE; }
+       YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 108 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_LIST;
+                        }
+       YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 112 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_ARRAY;
+                        }
+       YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 116 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_STRUCTURE;
+                        }
+       YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 120 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_INTERFACE;
+                        }
+       YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 124 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_ID;
+                        }
+       YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 128 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ // Square Bracket
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SB_OPEN;
+                        }
+       YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 132 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ // Square Bracket
+                          yylval->token = new tidl::Token(yytext, comments);
+                          return yy::parser::token::T_SB_CLOSE;
+                        }
+       YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 136 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_EQUAL; }
+       YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 137 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+{ return yy::parser::token::T_UNKNOWN; }
+       YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 139 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+ECHO;
+       YY_BREAK
+#line 1222 "/home/gogo/work/next/tidl/idlc/ast/tidlc_l.cpp"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(VALUE):
+       yyterminate();
+
+       case YY_END_OF_BUFFER:
+               {
+               /* Amount of text matched not including the EOB char. */
+               int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+               /* Undo the effects of YY_DO_BEFORE_ACTION. */
+               *yy_cp = yyg->yy_hold_char;
+               YY_RESTORE_YY_MORE_OFFSET
+
+               if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+                       {
+                       /* We're scanning a new file or input source.  It's
+                        * possible that this happened because the user
+                        * just pointed yyin at a new source and called
+                        * yylex().  If so, then we have to assure
+                        * consistency between YY_CURRENT_BUFFER and our
+                        * globals.  Here is the right place to do so, because
+                        * this is the first action (other than possibly a
+                        * back-up) that will match for the new input source.
+                        */
+                       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+                       YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+                       YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+                       }
+
+               /* Note that here we test for yy_c_buf_p "<=" to the position
+                * of the first EOB in the buffer, since yy_c_buf_p will
+                * already have been incremented past the NUL character
+                * (since all states make transitions on EOB to the
+                * end-of-buffer state).  Contrast this with the test
+                * in input().
+                */
+               if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+                       { /* This was really a NUL. */
+                       yy_state_type yy_next_state;
+
+                       yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+                       yy_current_state = yy_get_previous_state( yyscanner );
+
+                       /* Okay, we're now positioned to make the NUL
+                        * transition.  We couldn't have
+                        * yy_get_previous_state() go ahead and do it
+                        * for us because it doesn't know how to deal
+                        * with the possibility of jamming (and we don't
+                        * want to build jamming into it because then it
+                        * will run more slowly).
+                        */
+
+                       yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+                       yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+                       if ( yy_next_state )
+                               {
+                               /* Consume the NUL. */
+                               yy_cp = ++yyg->yy_c_buf_p;
+                               yy_current_state = yy_next_state;
+                               goto yy_match;
+                               }
+
+                       else
+                               {
+                               yy_cp = yyg->yy_c_buf_p;
+                               goto yy_find_action;
+                               }
+                       }
+
+               else switch ( yy_get_next_buffer( yyscanner ) )
+                       {
+                       case EOB_ACT_END_OF_FILE:
+                               {
+                               yyg->yy_did_buffer_switch_on_eof = 0;
+
+                               if ( yywrap(yyscanner ) )
+                                       {
+                                       /* Note: because we've taken care in
+                                        * yy_get_next_buffer() to have set up
+                                        * yytext, we can now set up
+                                        * yy_c_buf_p so that if some total
+                                        * hoser (like flex itself) wants to
+                                        * call the scanner after we return the
+                                        * YY_NULL, it'll still work - another
+                                        * YY_NULL will get returned.
+                                        */
+                                       yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+                                       yy_act = YY_STATE_EOF(YY_START);
+                                       goto do_action;
+                                       }
+
+                               else
+                                       {
+                                       if ( ! yyg->yy_did_buffer_switch_on_eof )
+                                               YY_NEW_FILE;
+                                       }
+                               break;
+                               }
+
+                       case EOB_ACT_CONTINUE_SCAN:
+                               yyg->yy_c_buf_p =
+                                       yyg->yytext_ptr + yy_amount_of_matched_text;
+
+                               yy_current_state = yy_get_previous_state( yyscanner );
+
+                               yy_cp = yyg->yy_c_buf_p;
+                               yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+                               goto yy_match;
+
+                       case EOB_ACT_LAST_MATCH:
+                               yyg->yy_c_buf_p =
+                               &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+                               yy_current_state = yy_get_previous_state( yyscanner );
+
+                               yy_cp = yyg->yy_c_buf_p;
+                               yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+                               goto yy_find_action;
+                       }
+               break;
+               }
+
+       default:
+               YY_FATAL_ERROR(
+                       "fatal flex scanner internal error--no action found" );
+       } /* end of action switch */
+               } /* end of scanning one token */
+       } /* end of user's declarations */
+} /* end of yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ *     EOB_ACT_LAST_MATCH -
+ *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ *     EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+       register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+       register char *source = yyg->yytext_ptr;
+       register int number_to_move, i;
+       int ret_val;
+
+       if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+               YY_FATAL_ERROR(
+               "fatal flex scanner internal error--end of buffer missed" );
+
+       if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+               { /* Don't try to fill the buffer, so this is an EOF. */
+               if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+                       {
+                       /* We matched a single character, the EOB, so
+                        * treat this as a final EOF.
+                        */
+                       return EOB_ACT_END_OF_FILE;
+                       }
+
+               else
+                       {
+                       /* We matched some text prior to the EOB, first
+                        * process it.
+                        */
+                       return EOB_ACT_LAST_MATCH;
+                       }
+               }
+
+       /* Try to read more data. */
+
+       /* First move last chars to start of buffer. */
+       number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+       for ( i = 0; i < number_to_move; ++i )
+               *(dest++) = *(source++);
+
+       if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+               /* don't do the read, it's not guaranteed to return an EOF,
+                * just force an EOF
+                */
+               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+       else
+               {
+                       yy_size_t num_to_read =
+                       YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+               while ( num_to_read <= 0 )
+                       { /* Not enough room in the buffer - grow it. */
+
+                       /* just a shorter name for the current buffer */
+                       YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+                       int yy_c_buf_p_offset =
+                               (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
+
+                       if ( b->yy_is_our_buffer )
+                               {
+                               yy_size_t new_size = b->yy_buf_size * 2;
+
+                               if ( new_size <= 0 )
+                                       b->yy_buf_size += b->yy_buf_size / 8;
+                               else
+                                       b->yy_buf_size *= 2;
+
+                               b->yy_ch_buf = (char *)
+                                       /* Include room in for 2 EOB chars. */
+                                       yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+                               }
+                       else
+                               /* Can't grow it, we don't own it. */
+                               b->yy_ch_buf = 0;
+
+                       if ( ! b->yy_ch_buf )
+                               YY_FATAL_ERROR(
+                               "fatal error - scanner input buffer overflow" );
+
+                       yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+                       num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+                                               number_to_move - 1;
+
+                       }
+
+               if ( num_to_read > YY_READ_BUF_SIZE )
+                       num_to_read = YY_READ_BUF_SIZE;
+
+               /* Read in more data. */
+               YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+                       yyg->yy_n_chars, num_to_read );
+
+               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+               }
+
+       if ( yyg->yy_n_chars == 0 )
+               {
+               if ( number_to_move == YY_MORE_ADJ )
+                       {
+                       ret_val = EOB_ACT_END_OF_FILE;
+                       yyrestart(yyin  ,yyscanner);
+                       }
+
+               else
+                       {
+                       ret_val = EOB_ACT_LAST_MATCH;
+                       YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+                               YY_BUFFER_EOF_PENDING;
+                       }
+               }
+
+       else
+               ret_val = EOB_ACT_CONTINUE_SCAN;
+
+       if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+               /* Extend the array by 50%, plus the number we really need. */
+               yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+               YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+               if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+                       YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+       }
+
+       yyg->yy_n_chars += number_to_move;
+       YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+       YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+       yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+       return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+       register yy_state_type yy_current_state;
+       register char *yy_cp;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       yy_current_state = yyg->yy_start;
+
+       for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+               {
+               register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+               if ( yy_accept[yy_current_state] )
+                       {
+                       yyg->yy_last_accepting_state = yy_current_state;
+                       yyg->yy_last_accepting_cpos = yy_cp;
+                       }
+               while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+                       {
+                       yy_current_state = (int) yy_def[yy_current_state];
+                       if ( yy_current_state >= 129 )
+                               yy_c = yy_meta[(unsigned int) yy_c];
+                       }
+               yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+               }
+
+       return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ *     next_state = yy_try_NUL_trans( current_state );
+ */
+    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+       register int yy_is_jam;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
+       register char *yy_cp = yyg->yy_c_buf_p;
+
+       register YY_CHAR yy_c = 1;
+       if ( yy_accept[yy_current_state] )
+               {
+               yyg->yy_last_accepting_state = yy_current_state;
+               yyg->yy_last_accepting_cpos = yy_cp;
+               }
+       while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+               {
+               yy_current_state = (int) yy_def[yy_current_state];
+               if ( yy_current_state >= 129 )
+                       yy_c = yy_meta[(unsigned int) yy_c];
+               }
+       yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+       yy_is_jam = (yy_current_state == 128);
+
+       (void)yyg;
+       return yy_is_jam ? 0 : yy_current_state;
+}
+
+    static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
+{
+       register char *yy_cp;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+    yy_cp = yyg->yy_c_buf_p;
+
+       /* undo effects of setting up yytext */
+       *yy_cp = yyg->yy_hold_char;
+
+       if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+               { /* need to shift things up to make room */
+               /* +2 for EOB chars. */
+               register yy_size_t number_to_move = yyg->yy_n_chars + 2;
+               register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+                                       YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+               register char *source =
+                               &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+               while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+                       *--dest = *--source;
+
+               yy_cp += (int) (dest - source);
+               yy_bp += (int) (dest - source);
+               YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+                       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+               if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+                       YY_FATAL_ERROR( "flex scanner push-back overflow" );
+               }
+
+       *--yy_cp = (char) c;
+
+    if ( c == '\n' ){
+        --yylineno;
+    }
+
+       yyg->yytext_ptr = yy_bp;
+       yyg->yy_hold_char = *yy_cp;
+       yyg->yy_c_buf_p = yy_cp;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+    static int yyinput (yyscan_t yyscanner)
+#else
+    static int input  (yyscan_t yyscanner)
+#endif
+
+{
+       int c;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+       if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+               {
+               /* yy_c_buf_p now points to the character we want to return.
+                * If this occurs *before* the EOB characters, then it's a
+                * valid NUL; if not, then we've hit the end of the buffer.
+                */
+               if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+                       /* This was really a NUL. */
+                       *yyg->yy_c_buf_p = '\0';
+
+               else
+                       { /* need more input */
+                       yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+                       ++yyg->yy_c_buf_p;
+
+                       switch ( yy_get_next_buffer( yyscanner ) )
+                               {
+                               case EOB_ACT_LAST_MATCH:
+                                       /* This happens because yy_g_n_b()
+                                        * sees that we've accumulated a
+                                        * token and flags that we need to
+                                        * try matching the token before
+                                        * proceeding.  But for input(),
+                                        * there's no matching to consider.
+                                        * So convert the EOB_ACT_LAST_MATCH
+                                        * to EOB_ACT_END_OF_FILE.
+                                        */
+
+                                       /* Reset buffer status. */
+                                       yyrestart(yyin ,yyscanner);
+
+                                       /*FALLTHROUGH*/
+
+                               case EOB_ACT_END_OF_FILE:
+                                       {
+                                       if ( yywrap(yyscanner ) )
+                                               return EOF;
+
+                                       if ( ! yyg->yy_did_buffer_switch_on_eof )
+                                               YY_NEW_FILE;
+#ifdef __cplusplus
+                                       return yyinput(yyscanner);
+#else
+                                       return input(yyscanner);
+#endif
+                                       }
+
+                               case EOB_ACT_CONTINUE_SCAN:
+                                       yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+                                       break;
+                               }
+                       }
+               }
+
+       c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+       *yyg->yy_c_buf_p = '\0';        /* preserve yytext */
+       yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+       if ( c == '\n' )
+                  
+    do{ yylineno++;
+        yycolumn=0;
+    }while(0)
+;
+
+       return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+    void yyrestart  (FILE * input_file , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       if ( ! YY_CURRENT_BUFFER ){
+        yyensure_buffer_stack (yyscanner);
+               YY_CURRENT_BUFFER_LVALUE =
+            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+       }
+
+       yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+       yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+    void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       /* TODO. We should be able to replace this entire function body
+        * with
+        *              yypop_buffer_state();
+        *              yypush_buffer_state(new_buffer);
+     */
+       yyensure_buffer_stack (yyscanner);
+       if ( YY_CURRENT_BUFFER == new_buffer )
+               return;
+
+       if ( YY_CURRENT_BUFFER )
+               {
+               /* Flush out information for old buffer. */
+               *yyg->yy_c_buf_p = yyg->yy_hold_char;
+               YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+               }
+
+       YY_CURRENT_BUFFER_LVALUE = new_buffer;
+       yy_load_buffer_state(yyscanner );
+
+       /* We don't actually know whether we did this switch during
+        * EOF (yywrap()) processing, but the only time this flag
+        * is looked at is after yywrap() is called, so it's safe
+        * to go ahead and always set it.
+        */
+       yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void yy_load_buffer_state  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+       yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+       yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+       yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+    YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
+{
+       YY_BUFFER_STATE b;
+    
+       b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+       if ( ! b )
+               YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+       b->yy_buf_size = size;
+
+       /* yy_ch_buf has to be 2 characters longer than the size given because
+        * we need to put in 2 end-of-buffer characters.
+        */
+       b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner );
+       if ( ! b->yy_ch_buf )
+               YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+       b->yy_is_our_buffer = 1;
+
+       yy_init_buffer(b,file ,yyscanner);
+
+       return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+    void yy_delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       if ( ! b )
+               return;
+
+       if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+               YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+       if ( b->yy_is_our_buffer )
+               yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+       yyfree((void *) b ,yyscanner );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+    static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)
+
+{
+       int oerrno = errno;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       yy_flush_buffer(b ,yyscanner);
+
+       b->yy_input_file = file;
+       b->yy_fill_buffer = 1;
+
+    /* If b is the current buffer, then yy_init_buffer was _probably_
+     * called from yyrestart() or through yy_get_next_buffer.
+     * In that case, we don't want to reset the lineno or column.
+     */
+    if (b != YY_CURRENT_BUFFER){
+        b->yy_bs_lineno = 1;
+        b->yy_bs_column = 0;
+    }
+
+        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+    
+       errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+    void yy_flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+       if ( ! b )
+               return;
+
+       b->yy_n_chars = 0;
+
+       /* We always need two end-of-buffer characters.  The first causes
+        * a transition to the end-of-buffer state.  The second causes
+        * a jam in that state.
+        */
+       b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+       b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+       b->yy_buf_pos = &b->yy_ch_buf[0];
+
+       b->yy_at_bol = 1;
+       b->yy_buffer_status = YY_BUFFER_NEW;
+
+       if ( b == YY_CURRENT_BUFFER )
+               yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ *  the current state. This function will allocate the stack
+ *  if necessary.
+ *  @param new_buffer The new state.
+ *  @param yyscanner The scanner object.
+ */
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+       if (new_buffer == NULL)
+               return;
+
+       yyensure_buffer_stack(yyscanner);
+
+       /* This block is copied from yy_switch_to_buffer. */
+       if ( YY_CURRENT_BUFFER )
+               {
+               /* Flush out information for old buffer. */
+               *yyg->yy_c_buf_p = yyg->yy_hold_char;
+               YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+               }
+
+       /* Only push if top exists. Otherwise, replace top. */
+       if (YY_CURRENT_BUFFER)
+               yyg->yy_buffer_stack_top++;
+       YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+       /* copied from yy_switch_to_buffer. */
+       yy_load_buffer_state(yyscanner );
+       yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ *  The next element becomes the new top.
+ *  @param yyscanner The scanner object.
+ */
+void yypop_buffer_state (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+       if (!YY_CURRENT_BUFFER)
+               return;
+
+       yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+       YY_CURRENT_BUFFER_LVALUE = NULL;
+       if (yyg->yy_buffer_stack_top > 0)
+               --yyg->yy_buffer_stack_top;
+
+       if (YY_CURRENT_BUFFER) {
+               yy_load_buffer_state(yyscanner );
+               yyg->yy_did_buffer_switch_on_eof = 1;
+       }
+}
+
+/* Allocates the stack if it does not exist.
+ *  Guarantees space for at least one push.
+ */
+static void yyensure_buffer_stack (yyscan_t yyscanner)
+{
+       yy_size_t num_to_alloc;
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+       if (!yyg->yy_buffer_stack) {
+
+               /* First allocation is just for 2 elements, since we don't know if this
+                * scanner will even need a stack. We use 2 instead of 1 to avoid an
+                * immediate realloc on the next call.
+         */
+               num_to_alloc = 1;
+               yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
+                                                               (num_to_alloc * sizeof(struct yy_buffer_state*)
+                                                               , yyscanner);
+               if ( ! yyg->yy_buffer_stack )
+                       YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+                                                                 
+               memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+                               
+               yyg->yy_buffer_stack_max = num_to_alloc;
+               yyg->yy_buffer_stack_top = 0;
+               return;
+       }
+
+       if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+               /* Increase the buffer to prepare for a possible push. */
+               int grow_size = 8 /* arbitrary grow size */;
+
+               num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
+               yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
+                                                               (yyg->yy_buffer_stack,
+                                                               num_to_alloc * sizeof(struct yy_buffer_state*)
+                                                               , yyscanner);
+               if ( ! yyg->yy_buffer_stack )
+                       YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+               /* zero only the new slots.*/
+               memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+               yyg->yy_buffer_stack_max = num_to_alloc;
+       }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object. 
+ */
+YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
+{
+       YY_BUFFER_STATE b;
+    
+       if ( size < 2 ||
+            base[size-2] != YY_END_OF_BUFFER_CHAR ||
+            base[size-1] != YY_END_OF_BUFFER_CHAR )
+               /* They forgot to leave room for the EOB's. */
+               return 0;
+
+       b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+       if ( ! b )
+               YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+       b->yy_buf_size = size - 2;      /* "- 2" to take care of EOB's */
+       b->yy_buf_pos = b->yy_ch_buf = base;
+       b->yy_is_our_buffer = 0;
+       b->yy_input_file = 0;
+       b->yy_n_chars = b->yy_buf_size;
+       b->yy_is_interactive = 0;
+       b->yy_at_bol = 1;
+       b->yy_fill_buffer = 0;
+       b->yy_buffer_status = YY_BUFFER_NEW;
+
+       yy_switch_to_buffer(b ,yyscanner );
+
+       return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ *       yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+{
+    
+       return yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len , yyscan_t yyscanner)
+{
+       YY_BUFFER_STATE b;
+       char *buf;
+       yy_size_t n;
+       yy_size_t i;
+    
+       /* Get memory for full buffer, including space for trailing EOB's. */
+       n = _yybytes_len + 2;
+       buf = (char *) yyalloc(n ,yyscanner );
+       if ( ! buf )
+               YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+       for ( i = 0; i < _yybytes_len; ++i )
+               buf[i] = yybytes[i];
+
+       buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+       b = yy_scan_buffer(buf,n ,yyscanner);
+       if ( ! b )
+               YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+       /* It's okay to grow etc. this buffer, and we should throw it
+        * away when we're done.
+        */
+       b->yy_is_our_buffer = 1;
+
+       return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+{
+       (void) fprintf( stderr, "%s\n", msg );
+       exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+       do \
+               { \
+               /* Undo effects of setting up yytext. */ \
+        int yyless_macro_arg = (n); \
+        YY_LESS_LINENO(yyless_macro_arg);\
+               yytext[yyleng] = yyg->yy_hold_char; \
+               yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+               yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+               *yyg->yy_c_buf_p = '\0'; \
+               yyleng = yyless_macro_arg; \
+               } \
+       while ( 0 )
+
+/* Accessor  methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE yyget_extra  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int yyget_lineno  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    
+        if (! YY_CURRENT_BUFFER)
+            return 0;
+    
+    return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int yyget_column  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    
+        if (! YY_CURRENT_BUFFER)
+            return 0;
+    
+    return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *yyget_in  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *yyget_out  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+yy_size_t yyget_leng  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *yyget_text  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void yyset_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void yyset_lineno (int  line_number , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+        /* lineno is only valid if an input buffer exists. */
+        if (! YY_CURRENT_BUFFER )
+           YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
+    
+    yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void yyset_column (int  column_no , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+        /* column is only valid if an input buffer exists. */
+        if (! YY_CURRENT_BUFFER )
+           YY_FATAL_ERROR( "yyset_column called with no buffer" );
+    
+    yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see yy_switch_to_buffer
+ */
+void yyset_in (FILE *  in_str , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yyin = in_str ;
+}
+
+void yyset_out (FILE *  out_str , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yyout = out_str ;
+}
+
+int yyget_debug  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yy_flex_debug;
+}
+
+void yyset_debug (int  bdebug , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+YYSTYPE * yyget_lval  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yylval;
+}
+
+void yyset_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yylval = yylval_param;
+}
+
+YYLTYPE *yyget_lloc  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    return yylloc;
+}
+    
+void yyset_lloc (YYLTYPE *  yylloc_param , yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    yylloc = yylloc_param;
+}
+    
+/* User-visible API */
+
+/* yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+    if (ptr_yy_globals == NULL){
+        errno = EINVAL;
+        return 1;
+    }
+
+    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+    if (*ptr_yy_globals == NULL){
+        errno = ENOMEM;
+        return 1;
+    }
+
+    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
+    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+    return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* yylex_init_extra has the same functionality as yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to yyalloc in
+ * the yyextra field.
+ */
+
+int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
+
+{
+    struct yyguts_t dummy_yyguts;
+
+    yyset_extra (yy_user_defined, &dummy_yyguts);
+
+    if (ptr_yy_globals == NULL){
+        errno = EINVAL;
+        return 1;
+    }
+       
+    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+       
+    if (*ptr_yy_globals == NULL){
+        errno = ENOMEM;
+        return 1;
+    }
+    
+    /* By setting to 0xAA, we expose bugs in
+    yy_init_globals. Leave at 0x00 for releases. */
+    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+    
+    yyset_extra (yy_user_defined, *ptr_yy_globals);
+    
+    return yy_init_globals ( *ptr_yy_globals );
+}
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+    /* Initialization is the same as for the non-reentrant scanner.
+     * This function is called from yylex_destroy(), so don't allocate here.
+     */
+
+    yyg->yy_buffer_stack = 0;
+    yyg->yy_buffer_stack_top = 0;
+    yyg->yy_buffer_stack_max = 0;
+    yyg->yy_c_buf_p = (char *) 0;
+    yyg->yy_init = 0;
+    yyg->yy_start = 0;
+
+    yyg->yy_start_stack_ptr = 0;
+    yyg->yy_start_stack_depth = 0;
+    yyg->yy_start_stack =  NULL;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+    yyin = stdin;
+    yyout = stdout;
+#else
+    yyin = (FILE *) 0;
+    yyout = (FILE *) 0;
+#endif
+
+    /* For future reference: Set errno on error, since we are called by
+     * yylex_init()
+     */
+    return 0;
+}
+
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int yylex_destroy  (yyscan_t yyscanner)
+{
+    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+    /* Pop the buffer stack, destroying each element. */
+       while(YY_CURRENT_BUFFER){
+               yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+               YY_CURRENT_BUFFER_LVALUE = NULL;
+               yypop_buffer_state(yyscanner);
+       }
+
+       /* Destroy the stack itself. */
+       yyfree(yyg->yy_buffer_stack ,yyscanner);
+       yyg->yy_buffer_stack = NULL;
+
+    /* Destroy the start condition stack. */
+        yyfree(yyg->yy_start_stack ,yyscanner );
+        yyg->yy_start_stack = NULL;
+
+    /* Reset the globals. This is important in a non-reentrant scanner so the next time
+     * yylex() is called, initialization will occur. */
+    yy_init_globals( yyscanner);
+
+    /* Destroy the main struct (reentrant only). */
+    yyfree ( yyscanner , yyscanner );
+    yyscanner = NULL;
+    return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+       register int i;
+       for ( i = 0; i < n; ++i )
+               s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+       register int n;
+       for ( n = 0; s[n]; ++n )
+               ;
+
+       return n;
+}
+#endif
+
+void *yyalloc (yy_size_t  size , yyscan_t yyscanner)
+{
+       return (void *) malloc( size );
+}
+
+void *yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
+{
+       /* The cast to (char *) in the following accommodates both
+        * implementations that use char* generic pointers, and those
+        * that use void* generic pointers.  It works with the latter
+        * because both ANSI C and C++ allow castless assignment from
+        * any pointer type to void*, and deal with argument conversions
+        * as though doing an assignment.
+        */
+       return (void *) realloc( (char *) ptr, size );
+}
+
+void yyfree (void * ptr , yyscan_t yyscanner)
+{
+       free( (char *) ptr );   /* see yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 138 "/home/gogo/work/next/tidl/idlc/ast/tidlc.ll"
+
+
+
+
diff --git a/idlc/ast/tidlc_y.cpp b/idlc/ast/tidlc_y.cpp
new file mode 100644 (file)
index 0000000..5c9f624
--- /dev/null
@@ -0,0 +1,3648 @@
+// A Bison parser, made by GNU Bison 3.0.2.
+
+// Skeleton implementation for Bison GLR parsers in C
+
+// Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton.  Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/* C GLR parser skeleton written by Paul Hilfinger.  */
+
+/* Identify Bison output.  */
+#define YYBISON 1
+
+/* Bison version.  */
+#define YYBISON_VERSION "3.0.2"
+
+/* Skeleton name.  */
+#define YYSKELETON_NAME "glr.cc"
+
+/* Pure parsers.  */
+#define YYPURE 1
+
+
+
+
+
+
+/* First part of user declarations.  */
+#line 1 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:207
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "idlc/ast/parser.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/element.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/block.h"
+#include "idlc/ast/attribute.h"
+#include "idlc/ast/tidlc_y.hpp"
+
+int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
+
+#define lex_scanner ps->Scanner()
+
+
+#line 77 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:207
+
+# ifndef YY_NULLPTR
+#  if defined __cplusplus && 201103L <= __cplusplus
+#   define YY_NULLPTR nullptr
+#  else
+#   define YY_NULLPTR 0
+#  endif
+# endif
+
+#include "tidlc_y.hpp"
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Default (constant) value used for initialization for null
+   right-hand sides.  Unlike the standard yacc.c template, here we set
+   the default value of $$ to a zeroed-out value.  Since the default
+   value is undefined, this behavior is technically correct.  */
+static YYSTYPE yyval_default;
+static YYLTYPE yyloc_default
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+  = { 1, 1, 1, 1 }
+# endif
+;
+
+/* Copy the second part of user declarations.  */
+#line 109 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:230
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
+
+# ifndef YYLLOC_DEFAULT
+#  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+    do                                                                  \
+      if (N)                                                            \
+        {                                                               \
+          (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
+          (Current).end    = YYRHSLOC (Rhs, N).end;                     \
+        }                                                               \
+      else                                                              \
+        {                                                               \
+          (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
+        }                                                               \
+    while (/*CONSTCOND*/ false)
+# endif
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
+static void yyerror (const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps, const char* msg);
+#line 131 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:230
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+#  if ENABLE_NLS
+#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+#  endif
+# endif
+# ifndef YY_
+#  define YY_(Msgid) Msgid
+# endif
+#endif
+
+#ifndef YYFREE
+# define YYFREE free
+#endif
+#ifndef YYMALLOC
+# define YYMALLOC malloc
+#endif
+#ifndef YYREALLOC
+# define YYREALLOC realloc
+#endif
+
+#define YYSIZEMAX ((size_t) -1)
+
+#ifdef __cplusplus
+   typedef bool yybool;
+#else
+   typedef unsigned char yybool;
+#endif
+#define yytrue 1
+#define yyfalse 0
+
+#ifndef YYSETJMP
+# include <setjmp.h>
+# define YYJMP_BUF jmp_buf
+# define YYSETJMP(Env) setjmp (Env)
+/* Pacify clang.  */
+# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
+#endif
+
+#ifndef YY_ATTRIBUTE
+# if (defined __GNUC__                                               \
+      && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
+     || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
+#  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
+# else
+#  define YY_ATTRIBUTE(Spec) /* empty */
+# endif
+#endif
+
+#ifndef YY_ATTRIBUTE_PURE
+# define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
+#endif
+
+#ifndef YY_ATTRIBUTE_UNUSED
+# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
+#endif
+
+#if !defined _Noreturn \
+     && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
+# if defined _MSC_VER && 1200 <= _MSC_VER
+#  define _Noreturn __declspec (noreturn)
+# else
+#  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E.  */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(E) ((void) (E))
+#else
+# define YYUSE(E) /* empty */
+#endif
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+    _Pragma ("GCC diagnostic push") \
+    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+    _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
+
+#ifndef YYASSERT
+# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
+#endif
+
+/* YYFINAL -- State number of the termination state.  */
+#define YYFINAL  19
+/* YYLAST -- Last index in YYTABLE.  */
+#define YYLAST   409
+
+/* YYNTOKENS -- Number of terminals.  */
+#define YYNTOKENS  36
+/* YYNNTS -- Number of nonterminals.  */
+#define YYNNTS  19
+/* YYNRULES -- Number of rules.  */
+#define YYNRULES  68
+/* YYNRULES -- Number of states.  */
+#define YYNSTATES  133
+/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule.  */
+#define YYMAXRHS 8
+/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
+   accessed by $0, $-1, etc., in any rule.  */
+#define YYMAXLEFT 0
+
+/* YYTRANSLATE(X) -- Bison symbol number corresponding to X.  */
+#define YYUNDEFTOK  2
+#define YYMAXUTOK   290
+
+#define YYTRANSLATE(YYX)                                                \
+  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+static const unsigned char yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
+       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
+      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
+      35
+};
+
+#if YYDEBUG
+/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+static const unsigned short int yyrline[] =
+{
+       0,    94,    94,    99,   104,   118,   121,   126,   132,   137,
+     143,   150,   156,   167,   173,   178,   182,   186,   192,   198,
+     209,   215,   220,   226,   233,   239,   247,   252,   257,   264,
+     270,   281,   287,   292,   299,   307,   312,   317,   322,   326,
+     330,   334,   338,   344,   350,   361,   367,   370,   373,   378,
+     381,   385,   391,   394,   400,   403,   407,   411,   415,   419,
+     423,   427,   431,   435,   439,   443,   449,   456,   460
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || 0
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
+static const char *const yytname[] =
+{
+  "$end", "error", "$undefined", "T_LEFT", "T_RIGHT", "T_COMMA",
+  "T_SEMICOLON", "T_BRACE_OPEN", "T_BRACE_CLOSE", "T_IN", "T_OUT", "T_REF",
+  "T_ASYNC", "T_META_OPEN", "T_META_CLOSE", "T_EQUAL", "T_DELEGATE",
+  "T_UNKNOWN", "T_ID", "T_STRUCTURE", "T_INTERFACE", "T_CHAR", "T_SHORT",
+  "T_INT", "T_LONG", "T_FLOAT", "T_DOUBLE", "T_VOID", "T_BUNDLE",
+  "T_STRING", "T_BOOL", "T_LIST", "T_ARRAY", "T_VALUE", "T_SB_OPEN",
+  "T_SB_CLOSE", "$accept", "start", "blocks", "block", "structure_block",
+  "elements", "element", "attributes", "attribute", "interface_block",
+  "declarations", "declaration", "parameter_list", "direction_specifier",
+  "parameter", "parameter_type", "base_type", "container_type",
+  "container_type_name", YY_NULLPTR
+};
+#endif
+
+#define YYPACT_NINF -68
+#define YYTABLE_NINF -56
+
+  // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+  // STATE-NUM.
+static const short int yypact[] =
+{
+      26,     6,    13,    41,    10,    26,   -68,   -68,   -68,    40,
+     323,    31,    55,   362,    43,   -68,    42,     1,   -68,   -68,
+     -68,   323,   -68,   -68,   -68,   -68,   -68,   -68,   -68,   -68,
+     -68,   -68,   -68,   -68,   -68,   -68,   -68,   116,   -68,    15,
+     -68,     4,   323,   362,   -68,    22,   148,   -68,    38,   362,
+     -11,     2,    36,    47,   180,    72,   -68,   -68,    73,   -68,
+      74,   377,   212,   244,    75,    84,    79,    78,   -68,   -68,
+      80,    84,    87,   276,   -68,   -68,   -68,   -68,    59,   -68,
+     -68,   -68,   -68,    83,   -68,   -68,   -68,   -68,   -68,   -68,
+     -68,    81,    61,   377,   -68,    82,   -68,    84,   -68,   -68,
+      65,    84,   -68,    85,   -68,    37,   347,   -68,   -68,    68,
+      92,    71,   362,    95,    97,   -68,     3,   -68,    52,   308,
+     -68,   -68,   -68,    98,   112,   -68,   113,   114,   -68,   -68,
+     -68,   -68,   -68
+};
+
+  // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+  // Performed when YYTABLE does not specify something else to do.  Zero
+  // means the default is an error.
+static const unsigned char yydefact[] =
+{
+       0,     0,     0,     0,     0,     2,     3,     6,     5,     0,
+       0,     0,     0,     0,     0,    20,     0,     0,    18,     1,
+       4,     0,    10,    17,    65,    56,    57,    58,    59,    60,
+      61,    55,    62,    63,    64,    67,    68,     0,    11,     0,
+      54,     0,     0,     0,    28,     0,     0,    29,     0,     0,
+       0,     0,     0,     0,     0,    17,     8,    12,     0,    15,
+       0,     0,     0,     0,     0,     0,     0,     0,    26,    30,
+       0,     0,     0,     0,    22,    23,    21,    19,     0,     9,
+      13,    16,    14,     0,     7,    27,    42,    45,    46,    47,
+      48,    50,     0,     0,    43,     0,    52,     0,    31,    41,
+       0,     0,    24,     0,    66,     0,    49,    53,    51,     0,
+       0,     0,     0,     0,     0,    44,     0,    38,     0,     0,
+      39,    40,    37,     0,     0,    32,     0,     0,    25,    33,
+      34,    35,    36
+};
+
+  // YYPGOTO[NTERM-NUM].
+static const signed char yypgoto[] =
+{
+     -68,   -68,   -68,   117,   -68,   -16,   -25,   -68,    69,   -68,
+     -41,   -45,   -67,   -68,    17,   -68,   -10,   -68,   -68
+};
+
+  // YYDEFGOTO[NTERM-NUM].
+static const signed char yydefgoto[] =
+{
+      -1,     4,     5,     6,     7,    37,    38,    17,    18,     8,
+      46,    47,    92,    93,    94,    95,    48,    40,    41
+};
+
+  // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
+  // positive, shift that token.  If negative, reduce the rule whose
+  // number is the opposite.  If YYTABLE_NINF, syntax error.
+static const short int yytable[] =
+{
+      39,    69,    63,    75,   100,    54,    52,     9,    73,   122,
+      19,    39,    57,    10,    12,   123,    58,    61,    69,   124,
+      13,    59,    74,    64,    11,    65,    62,    39,    69,    57,
+     109,    14,    39,    60,   111,    76,    53,    57,    42,    70,
+      66,    71,    15,    50,    39,     1,     2,    21,    22,   113,
+      49,    83,    39,   114,    16,    96,    72,    51,   125,    16,
+       3,    96,    43,    44,   126,   105,   106,    78,   127,   110,
+     106,   119,   116,   106,    69,   118,   106,   103,    80,    81,
+      82,    86,    97,   107,    98,    87,    99,    96,   -49,   -49,
+     101,    96,   112,    88,    89,    90,    96,   104,   117,   -55,
+     108,   120,    24,   121,   129,    25,    26,    27,    28,    29,
+      30,    91,    32,    33,    34,    35,    36,    55,   130,   131,
+     132,    77,    20,   115,    56,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,    24,     0,     0,    25,    26,    27,
+      28,    29,    30,    31,    32,    33,    34,    35,    36,    67,
+       0,     0,     0,     0,     0,     0,    68,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,    24,     0,     0,    25,
+      26,    27,    28,    29,    30,    45,    32,    33,    34,    35,
+      36,    55,     0,     0,     0,     0,     0,     0,    79,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,    24,     0,
+       0,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    55,     0,     0,     0,     0,     0,     0,
+      84,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+      24,     0,     0,    25,    26,    27,    28,    29,    30,    31,
+      32,    33,    34,    35,    36,    67,     0,     0,     0,     0,
+       0,     0,    85,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,    24,     0,     0,    25,    26,    27,    28,    29,
+      30,    45,    32,    33,    34,    35,    36,    67,     0,     0,
+       0,     0,     0,     0,   102,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,    24,     0,     0,    25,    26,    27,
+      28,    29,    30,    45,    32,    33,    34,    35,    36,    67,
+       0,     0,     0,     0,     0,     0,   128,     0,     0,     0,
+       0,     0,     0,     0,    23,     0,    24,     0,     0,    25,
+      26,    27,    28,    29,    30,    45,    32,    33,    34,    35,
+      36,    24,     0,     0,    25,    26,    27,    28,    29,    30,
+      31,    32,    33,    34,    35,    36,    88,    89,    90,     0,
+       0,     0,     0,     0,     0,    24,     0,     0,    25,    26,
+      27,    28,    29,    30,    91,    32,    33,    34,    35,    36,
+      24,     0,     0,    25,    26,    27,    28,    29,    30,    45,
+      32,    33,    34,    35,    36,    24,     0,     0,    25,    26,
+      27,    28,    29,    30,    31,    32,    33,    34,    35,    36
+};
+
+static const signed char yycheck[] =
+{
+      10,    46,    43,     1,    71,    21,     5,     1,    49,     6,
+       0,    21,    37,     7,     1,    12,     1,    13,    63,    16,
+       7,     6,    33,     1,    18,     3,    42,    37,    73,    54,
+      97,    18,    42,    18,   101,    33,    35,    62,     7,     1,
+      18,     3,     1,     1,    54,    19,    20,     7,     8,    12,
+       7,    61,    62,    16,    18,    65,    18,    15,     6,    18,
+      34,    71,     7,     8,    12,     4,     5,    20,    16,     4,
+       5,   112,     4,     5,   119,     4,     5,    18,     6,     6,
+       6,     6,     3,    93,     6,     1,     6,    97,     4,     5,
+       3,   101,     7,     9,    10,    11,   106,    14,     6,    18,
+      18,     6,    18,     6,     6,    21,    22,    23,    24,    25,
+      26,    27,    28,    29,    30,    31,    32,     1,     6,     6,
+       6,    52,     5,   106,     8,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,     1,
+      -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    18,    -1,    -1,    21,
+      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
+      32,     1,    -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    18,    -1,
+      -1,    21,    22,    23,    24,    25,    26,    27,    28,    29,
+      30,    31,    32,     1,    -1,    -1,    -1,    -1,    -1,    -1,
+       8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      18,    -1,    -1,    21,    22,    23,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,     1,    -1,    -1,    -1,    -1,
+      -1,    -1,     8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    18,    -1,    -1,    21,    22,    23,    24,    25,
+      26,    27,    28,    29,    30,    31,    32,     1,    -1,    -1,
+      -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,     1,
+      -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,
+      -1,    -1,    -1,    -1,     1,    -1,    18,    -1,    -1,    21,
+      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
+      32,    18,    -1,    -1,    21,    22,    23,    24,    25,    26,
+      27,    28,    29,    30,    31,    32,     9,    10,    11,    -1,
+      -1,    -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,
+      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
+      18,    -1,    -1,    21,    22,    23,    24,    25,    26,    27,
+      28,    29,    30,    31,    32,    18,    -1,    -1,    21,    22,
+      23,    24,    25,    26,    27,    28,    29,    30,    31,    32
+};
+
+  // YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+  // symbol of state STATE-NUM.
+static const unsigned char yystos[] =
+{
+       0,    19,    20,    34,    37,    38,    39,    40,    45,     1,
+       7,    18,     1,     7,    18,     1,    18,    43,    44,     0,
+      39,     7,     8,     1,    18,    21,    22,    23,    24,    25,
+      26,    27,    28,    29,    30,    31,    32,    41,    42,    52,
+      53,    54,     7,     7,     8,    27,    46,    47,    52,     7,
+       1,    15,     5,    35,    41,     1,     8,    42,     1,     6,
+      18,    13,    41,    46,     1,     3,    18,     1,     8,    47,
+       1,     3,    18,    46,    33,     1,    33,    44,    20,     8,
+       6,     6,     6,    52,     8,     8,     6,     1,     9,    10,
+      11,    27,    48,    49,    50,    51,    52,     3,     6,     6,
+      48,     3,     8,    18,    14,     4,     5,    52,    18,    48,
+       4,    48,     7,    12,    16,    50,     4,     6,     4,    46,
+       6,     6,     6,    12,    16,     6,    12,    16,     8,     6,
+       6,     6,     6
+};
+
+  // YYR1[YYN] -- Symbol number of symbol that rule YYN derives.
+static const unsigned char yyr1[] =
+{
+       0,    36,    37,    38,    38,    39,    39,    40,    40,    40,
+      40,    41,    41,    41,    42,    42,    42,    42,    43,    43,
+      43,    44,    44,    44,    45,    45,    45,    45,    45,    46,
+      46,    46,    47,    47,    47,    47,    47,    47,    47,    47,
+      47,    47,    47,    48,    48,    48,    49,    49,    49,    50,
+      50,    50,    51,    51,    52,    52,    52,    52,    52,    52,
+      52,    52,    52,    52,    52,    52,    53,    54,    54
+};
+
+  // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.
+static const unsigned char yyr2[] =
+{
+       0,     2,     1,     1,     2,     1,     1,     5,     4,     5,
+       3,     1,     2,     3,     3,     2,     3,     1,     1,     3,
+       1,     3,     3,     3,     5,     8,     4,     5,     3,     1,
+       2,     3,     6,     7,     7,     7,     7,     6,     5,     6,
+       6,     3,     3,     1,     3,     1,     1,     1,     1,     0,
+       1,     2,     1,     2,     1,     1,     1,     1,     1,     1,
+       1,     1,     1,     1,     1,     1,     4,     1,     1
+};
+
+
+/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none).  */
+static const unsigned char yydprec[] =
+{
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0
+};
+
+/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM.  */
+static const unsigned char yymerger[] =
+{
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0
+};
+
+/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
+   in the case of predicates.  */
+static const yybool yyimmediate[] =
+{
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0
+};
+
+/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
+   list of conflicting reductions corresponding to action entry for
+   state STATE-NUM in yytable.  0 means no conflicts.  The list in
+   yyconfl is terminated by a rule number of 0.  */
+static const unsigned char yyconflp[] =
+{
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0
+};
+
+/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
+   0, pointed into by YYCONFLP.  */
+static const short int yyconfl[] =
+{
+       0
+};
+
+/* Error token number */
+#define YYTERROR 1
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
+
+# ifndef YYLLOC_DEFAULT
+#  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+    do                                                                  \
+      if (N)                                                            \
+        {                                                               \
+          (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
+          (Current).end    = YYRHSLOC (Rhs, N).end;                     \
+        }                                                               \
+      else                                                              \
+        {                                                               \
+          (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
+        }                                                               \
+    while (/*CONSTCOND*/ false)
+# endif
+
+# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
+
+
+
+#undef yynerrs
+#define yynerrs (yystackp->yyerrcnt)
+#undef yychar
+#define yychar (yystackp->yyrawchar)
+#undef yylval
+#define yylval (yystackp->yyval)
+#undef yylloc
+#define yylloc (yystackp->yyloc)
+
+
+static const int YYEOF = 0;
+static const int YYEMPTY = -2;
+
+typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
+
+#define YYCHK(YYE)                              \
+  do {                                          \
+    YYRESULTTAG yychk_flag = YYE;               \
+    if (yychk_flag != yyok)                     \
+      return yychk_flag;                        \
+  } while (0)
+
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  define YYFPRINTF fprintf
+# endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+   This macro was not mandated originally: define only if we know
+   we won't break user code: when these are the locations we know.  */
+
+#ifndef YY_LOCATION_PRINT
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+
+/* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
+
+YY_ATTRIBUTE_UNUSED
+static unsigned
+yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
+{
+  unsigned res = 0;
+  int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+  if (0 <= yylocp->first_line)
+    {
+      res += YYFPRINTF (yyo, "%d", yylocp->first_line);
+      if (0 <= yylocp->first_column)
+        res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
+    }
+  if (0 <= yylocp->last_line)
+    {
+      if (yylocp->first_line < yylocp->last_line)
+        {
+          res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
+          if (0 <= end_col)
+            res += YYFPRINTF (yyo, ".%d", end_col);
+        }
+      else if (0 <= end_col && yylocp->first_column < end_col)
+        res += YYFPRINTF (yyo, "-%d", end_col);
+    }
+  return res;
+ }
+
+#  define YY_LOCATION_PRINT(File, Loc)          \
+  yy_location_print_ (File, &(Loc))
+
+# else
+#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+# define YYDPRINTF(Args)                        \
+  do {                                          \
+    if (yydebug)                                \
+      YYFPRINTF Args;                           \
+  } while (0)
+
+
+/*--------------------.
+| Print this symbol.  |
+`--------------------*/
+
+static void
+yy_symbol_print (FILE *, int yytype, const yy::parser::semantic_type *yyvaluep, const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  YYUSE (yyparser);
+  YYUSE (ps);
+  yyparser.yy_symbol_print_ (yytype, yyvaluep, yylocationp);
+}
+
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                  \
+  do {                                                                  \
+    if (yydebug)                                                        \
+      {                                                                 \
+        YYFPRINTF (stderr, "%s ", Title);                               \
+        yy_symbol_print (stderr, Type, Value, Location, yyparser, ps);        \
+        YYFPRINTF (stderr, "\n");                                       \
+      }                                                                 \
+  } while (0)
+
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+
+struct yyGLRStack;
+static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
+  YY_ATTRIBUTE_UNUSED;
+static void yypdumpstack (struct yyGLRStack* yystackp)
+  YY_ATTRIBUTE_UNUSED;
+
+#else /* !YYDEBUG */
+
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+
+#endif /* !YYDEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+/* Minimum number of free items on the stack allowed after an
+   allocation.  This is to allow allocation and initialization
+   to be completed by functions that call yyexpandGLRStack before the
+   stack is expanded, thus insuring that all necessary pointers get
+   properly redirected to new data.  */
+#define YYHEADROOM 2
+
+#ifndef YYSTACKEXPANDABLE
+#  define YYSTACKEXPANDABLE 1
+#endif
+
+#if YYSTACKEXPANDABLE
+# define YY_RESERVE_GLRSTACK(Yystack)                   \
+  do {                                                  \
+    if (Yystack->yyspaceLeft < YYHEADROOM)              \
+      yyexpandGLRStack (Yystack);                       \
+  } while (0)
+#else
+# define YY_RESERVE_GLRSTACK(Yystack)                   \
+  do {                                                  \
+    if (Yystack->yyspaceLeft < YYHEADROOM)              \
+      yyMemoryExhausted (Yystack);                      \
+  } while (0)
+#endif
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystpcpy
+#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+{
+  char *yyd = yydest;
+  const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+   quotes and backslashes, so that it's suitable for yyerror.  The
+   heuristic is that double-quoting is unnecessary unless the string
+   contains an apostrophe, a comma, or backslash (other than
+   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
+   null, do not copy; instead, return the length of what the result
+   would have been.  */
+static size_t
+yytnamerr (char *yyres, const char *yystr)
+{
+  if (*yystr == '"')
+    {
+      size_t yyn = 0;
+      char const *yyp = yystr;
+
+      for (;;)
+        switch (*++yyp)
+          {
+          case '\'':
+          case ',':
+            goto do_not_strip_quotes;
+
+          case '\\':
+            if (*++yyp != '\\')
+              goto do_not_strip_quotes;
+            /* Fall through.  */
+          default:
+            if (yyres)
+              yyres[yyn] = *yyp;
+            yyn++;
+            break;
+
+          case '"':
+            if (yyres)
+              yyres[yyn] = '\0';
+            return yyn;
+          }
+    do_not_strip_quotes: ;
+    }
+
+  if (! yyres)
+    return strlen (yystr);
+
+  return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+/** State numbers, as in LALR(1) machine */
+typedef int yyStateNum;
+
+/** Rule numbers, as in LALR(1) machine */
+typedef int yyRuleNum;
+
+/** Grammar symbol */
+typedef int yySymbol;
+
+/** Item references, as in LALR(1) machine */
+typedef short int yyItemNum;
+
+typedef struct yyGLRState yyGLRState;
+typedef struct yyGLRStateSet yyGLRStateSet;
+typedef struct yySemanticOption yySemanticOption;
+typedef union yyGLRStackItem yyGLRStackItem;
+typedef struct yyGLRStack yyGLRStack;
+
+struct yyGLRState {
+  /** Type tag: always true.  */
+  yybool yyisState;
+  /** Type tag for yysemantics.  If true, yysval applies, otherwise
+   *  yyfirstVal applies.  */
+  yybool yyresolved;
+  /** Number of corresponding LALR(1) machine state.  */
+  yyStateNum yylrState;
+  /** Preceding state in this stack */
+  yyGLRState* yypred;
+  /** Source position of the last token produced by my symbol */
+  size_t yyposn;
+  union {
+    /** First in a chain of alternative reductions producing the
+     *  non-terminal corresponding to this state, threaded through
+     *  yynext.  */
+    yySemanticOption* yyfirstVal;
+    /** Semantic value for this state.  */
+    YYSTYPE yysval;
+  } yysemantics;
+  /** Source location for this state.  */
+  YYLTYPE yyloc;
+};
+
+struct yyGLRStateSet {
+  yyGLRState** yystates;
+  /** During nondeterministic operation, yylookaheadNeeds tracks which
+   *  stacks have actually needed the current lookahead.  During deterministic
+   *  operation, yylookaheadNeeds[0] is not maintained since it would merely
+   *  duplicate yychar != YYEMPTY.  */
+  yybool* yylookaheadNeeds;
+  size_t yysize, yycapacity;
+};
+
+struct yySemanticOption {
+  /** Type tag: always false.  */
+  yybool yyisState;
+  /** Rule number for this reduction */
+  yyRuleNum yyrule;
+  /** The last RHS state in the list of states to be reduced.  */
+  yyGLRState* yystate;
+  /** The lookahead for this reduction.  */
+  int yyrawchar;
+  YYSTYPE yyval;
+  YYLTYPE yyloc;
+  /** Next sibling in chain of options.  To facilitate merging,
+   *  options are chained in decreasing order by address.  */
+  yySemanticOption* yynext;
+};
+
+/** Type of the items in the GLR stack.  The yyisState field
+ *  indicates which item of the union is valid.  */
+union yyGLRStackItem {
+  yyGLRState yystate;
+  yySemanticOption yyoption;
+};
+
+struct yyGLRStack {
+  int yyerrState;
+  /* To compute the location of the error token.  */
+  yyGLRStackItem yyerror_range[3];
+
+  int yyerrcnt;
+  int yyrawchar;
+  YYSTYPE yyval;
+  YYLTYPE yyloc;
+
+  YYJMP_BUF yyexception_buffer;
+  yyGLRStackItem* yyitems;
+  yyGLRStackItem* yynextFree;
+  size_t yyspaceLeft;
+  yyGLRState* yysplitPoint;
+  yyGLRState* yylastDeleted;
+  yyGLRStateSet yytops;
+};
+
+#if YYSTACKEXPANDABLE
+static void yyexpandGLRStack (yyGLRStack* yystackp);
+#endif
+
+static _Noreturn void
+yyFail (yyGLRStack* yystackp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps, const char* yymsg)
+{
+  if (yymsg != YY_NULLPTR)
+    yyerror (yylocp, yyparser, ps, yymsg);
+  YYLONGJMP (yystackp->yyexception_buffer, 1);
+}
+
+static _Noreturn void
+yyMemoryExhausted (yyGLRStack* yystackp)
+{
+  YYLONGJMP (yystackp->yyexception_buffer, 2);
+}
+
+#if YYDEBUG || YYERROR_VERBOSE
+/** A printable representation of TOKEN.  */
+static inline const char*
+yytokenName (yySymbol yytoken)
+{
+  if (yytoken == YYEMPTY)
+    return "";
+
+  return yytname[yytoken];
+}
+#endif
+
+/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
+ *  at YYVSP[YYLOW0].yystate.yypred.  Leaves YYVSP[YYLOW1].yystate.yypred
+ *  containing the pointer to the next state in the chain.  */
+static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED;
+static void
+yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
+{
+  int i;
+  yyGLRState *s = yyvsp[yylow0].yystate.yypred;
+  for (i = yylow0-1; i >= yylow1; i -= 1)
+    {
+#if YYDEBUG
+      yyvsp[i].yystate.yylrState = s->yylrState;
+#endif
+      yyvsp[i].yystate.yyresolved = s->yyresolved;
+      if (s->yyresolved)
+        yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
+      else
+        /* The effect of using yysval or yyloc (in an immediate rule) is
+         * undefined.  */
+        yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;
+      yyvsp[i].yystate.yyloc = s->yyloc;
+      s = yyvsp[i].yystate.yypred = s->yypred;
+    }
+}
+
+/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1.  Otherwise, fill in
+ * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
+ * For convenience, always return YYLOW1.  */
+static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
+     YY_ATTRIBUTE_UNUSED;
+static inline int
+yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
+{
+  if (!yynormal && yylow1 < *yylow)
+    {
+      yyfillin (yyvsp, *yylow, yylow1);
+      *yylow = yylow1;
+    }
+  return yylow1;
+}
+
+/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
+ *  and top stack item YYVSP.  YYLVALP points to place to put semantic
+ *  value ($$), and yylocp points to place for location information
+ *  (@$).  Returns yyok for normal return, yyaccept for YYACCEPT,
+ *  yyerr for YYERROR, yyabort for YYABORT.  */
+static YYRESULTTAG
+yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
+              yyGLRStack* yystackp,
+              YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
+  int yylow;
+  YYUSE (yyvalp);
+  YYUSE (yylocp);
+  YYUSE (yyparser);
+  YYUSE (ps);
+  YYUSE (yyrhslen);
+# undef yyerrok
+# define yyerrok (yystackp->yyerrState = 0)
+# undef YYACCEPT
+# define YYACCEPT return yyaccept
+# undef YYABORT
+# define YYABORT return yyabort
+# undef YYERROR
+# define YYERROR return yyerrok, yyerr
+# undef YYRECOVERING
+# define YYRECOVERING() (yystackp->yyerrState != 0)
+# undef yyclearin
+# define yyclearin (yychar = YYEMPTY)
+# undef YYFILL
+# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
+# undef YYBACKUP
+# define YYBACKUP(Token, Value)                                              \
+  return yyerror (yylocp, yyparser, ps, YY_("syntax error: cannot back up")),     \
+         yyerrok, yyerr
+
+  yylow = 1;
+  if (yyrhslen == 0)
+    *yyvalp = yyval_default;
+  else
+    *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
+  YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
+  yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
+
+  switch (yyn)
+    {
+        case 2:
+#line 94 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+     ps->SetDoc((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.doc));
+  }
+#line 1096 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 3:
+#line 99 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).doc) = new tidl::Document();
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk) != NULL)
+      ((*yyvalp).doc)->AddBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk));
+  }
+#line 1106 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 4:
+#line 104 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).doc) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.doc);
+
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk) != NULL) {
+      if (((*yyvalp).doc)->ExistBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk))) {
+        ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk)->GetLine());
+        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk);
+      } else {
+        ((*yyvalp).doc)->AddBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk));
+      }
+    }
+  }
+#line 1123 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 5:
+#line 118 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).blk) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.interf);
+  }
+#line 1131 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 6:
+#line 121 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).blk) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.structure);
+  }
+#line 1139 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 7:
+#line 126 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).structure) = new tidl::Structure((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.elms), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->GetComments(),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+  }
+#line 1150 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 8:
+#line 132 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+    ((*yyvalp).structure) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+  }
+#line 1160 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 9:
+#line 137 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"Please check it before an open brace.\"",
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+    ((*yyvalp).structure) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+  }
+#line 1171 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 10:
+#line 143 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in structure declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).structure) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
+  }
+#line 1181 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 11:
+#line 150 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).elms) = new (std::nothrow) tidl::Elements();
+    if (((*yyvalp).elms) != nullptr) {
+      ((*yyvalp).elms)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm));
+    }
+  }
+#line 1192 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 12:
+#line 156 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).elms) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.elms);
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm) != nullptr) {
+      if (((*yyvalp).elms)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm))) {
+        ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm)->GetLine());
+        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm);
+      } else {
+        ((*yyvalp).elms)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm));
+      }
+    }
+  }
+#line 1208 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 13:
+#line 167 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in elements declarations.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
+    ((*yyvalp).elms) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.elms);
+  }
+#line 1217 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 14:
+#line 173 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).elm) = new tidl::Element((((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.b_type)->GetComments(),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.token);
+  }
+#line 1227 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 15:
+#line 178 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).elm) = NULL;
+  }
+#line 1236 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 16:
+#line 182 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in element declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).elm) = NULL;
+  }
+#line 1245 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 17:
+#line 186 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in element declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).elm) = NULL;
+  }
+#line 1254 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 18:
+#line 192 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).attrs) = new (std::nothrow) tidl::Attributes();
+    if (((*yyvalp).attrs) != nullptr) {
+      ((*yyvalp).attrs)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr));
+    }
+  }
+#line 1265 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 19:
+#line 198 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).attrs) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.attrs);
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr) != nullptr) {
+      if (((*yyvalp).attrs)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr))) {
+        ps->ReportError("syntax error. \"Already Exist\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr)->GetLine());
+        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr);
+      } else {
+        ((*yyvalp).attrs)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr));
+      }
+    }
+  }
+#line 1281 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 20:
+#line 209 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in attributes", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).attrs) = new tidl::Attributes();
+  }
+#line 1290 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 21:
+#line 215 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).attr) = new tidl::Attribute((((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+  }
+#line 1300 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 22:
+#line 220 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in attribute declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).attr) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+  }
+#line 1311 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 23:
+#line 226 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in attribute declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).attr) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
+  }
+#line 1321 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 24:
+#line 233 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).interf) = new tidl::Interface((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->GetComments(),
+        new tidl::Attributes(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+  }
+#line 1332 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 25:
+#line 239 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).interf) = new tidl::Interface((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls), (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.attrs),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+  }
+#line 1345 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 26:
+#line 247 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+    ((*yyvalp).interf) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+  }
+#line 1355 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 27:
+#line 252 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in interface declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+    ((*yyvalp).interf) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+  }
+#line 1365 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 28:
+#line 257 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in interface declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).interf) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
+  }
+#line 1375 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 29:
+#line 264 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).decls) = new (std::nothrow) tidl::Declarations();
+    if (((*yyvalp).decls) != nullptr) {
+      ((*yyvalp).decls)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl));
+    }
+  }
+#line 1386 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 30:
+#line 270 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).decls) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls);
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl) != nullptr) {
+      if (((*yyvalp).decls)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl))) {
+        ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl)->GetLine());
+        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl);
+      } else {
+        ((*yyvalp).decls)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl));
+      }
+    }
+  }
+#line 1402 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 31:
+#line 281 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in methods declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).decls) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.decls);
+  }
+#line 1411 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 32:
+#line 287 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.params), (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.b_type)->GetComments(),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line, tidl::Declaration::MethodType::SYNC);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+  }
+#line 1421 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 33:
+#line 292 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString(),
+        new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments()), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.params),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yyloc).begin.line, tidl::Declaration::MethodType::ASYNC);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
+  }
+#line 1433 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 34:
+#line 299 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString(),
+        new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments()), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.params),
+        (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yyloc).begin.line,
+        tidl::Declaration::MethodType::DELEGATE);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
+  }
+#line 1446 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 35:
+#line 307 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
+  }
+#line 1456 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 36:
+#line 312 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
+  }
+#line 1466 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 37:
+#line 317 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No async\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
+  }
+#line 1476 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 38:
+#line 322 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+  }
+#line 1485 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 39:
+#line 326 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+  }
+#line 1494 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 40:
+#line 330 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+  }
+#line 1503 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 41:
+#line 334 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+  }
+#line 1512 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 42:
+#line 338 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    ((*yyvalp).decl) = NULL;
+  }
+#line 1521 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 43:
+#line 344 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).params) = new tidl::Parameters();
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param) != nullptr) {
+      ((*yyvalp).params)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param));
+    }
+  }
+#line 1532 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 44:
+#line 350 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).params) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.params);
+    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param) != nullptr) {
+      if (((*yyvalp).params)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param))) {
+        ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param)->GetLine());
+        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param);
+      } else {
+        ((*yyvalp).params)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param));
+      }
+    }
+  }
+#line 1548 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 45:
+#line 361 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ps->ReportError("syntax error in parameter list", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
+    ((*yyvalp).params) = new tidl::Parameters();
+  }
+#line 1557 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 46:
+#line 367 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).direction) = new tidl::Token("in", "");
+  }
+#line 1565 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 47:
+#line 370 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).direction) = new tidl::Token("out", "");
+  }
+#line 1573 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 48:
+#line 373 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).direction) = new tidl::Token("ref", "");
+  }
+#line 1581 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 49:
+#line 378 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).param) = nullptr;
+  }
+#line 1589 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 50:
+#line 381 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).param) = nullptr;
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+  }
+#line 1598 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 51:
+#line 385 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+    ((*yyvalp).param) = new tidl::Parameter((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.p_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
+    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+  }
+#line 1607 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 52:
+#line 391 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).p_type) = new tidl::ParameterType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type));
+    }
+#line 1615 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 53:
+#line 394 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).p_type) = new tidl::ParameterType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.direction)->ToString());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.direction);
+    }
+#line 1624 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 54:
+#line 400 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type);
+    }
+#line 1632 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 55:
+#line 403 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1641 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 56:
+#line 407 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("char", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1650 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 57:
+#line 411 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("short", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1659 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 58:
+#line 415 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("int", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1668 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 59:
+#line 419 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("long", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1677 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 60:
+#line 423 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("float", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1686 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 61:
+#line 427 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("double", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1695 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 62:
+#line 431 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("bundle", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1704 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 63:
+#line 435 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("string", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1713 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 64:
+#line 439 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType("bool", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1722 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 65:
+#line 443 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments(), true);
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1731 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 66:
+#line 449 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).b_type) = new tidl::BaseType((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->GetComments());
+      ((*yyvalp).b_type)->SetMetaType((((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.b_type));
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
+    }
+#line 1741 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 67:
+#line 456 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).token) = new tidl::Token("list", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1750 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+  case 68:
+#line 460 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:783
+    {
+      ((*yyvalp).token) = new tidl::Token("array", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
+      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
+    }
+#line 1759 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+    break;
+
+
+#line 1763 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:783
+      default: break;
+    }
+
+  return yyok;
+# undef yyerrok
+# undef YYABORT
+# undef YYACCEPT
+# undef YYERROR
+# undef YYBACKUP
+# undef yyclearin
+# undef YYRECOVERING
+}
+
+
+static void
+yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
+{
+  YYUSE (yy0);
+  YYUSE (yy1);
+
+  switch (yyn)
+    {
+
+      default: break;
+    }
+}
+
+                              /* Bison grammar-table manipulation.  */
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
+
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  YYUSE (yyvaluep);
+  YYUSE (yylocationp);
+  YYUSE (yyparser);
+  YYUSE (ps);
+  if (!yymsg)
+    yymsg = "Deleting";
+  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+  YYUSE (yytype);
+  YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+/** Number of symbols composing the right hand side of rule #RULE.  */
+static inline int
+yyrhsLength (yyRuleNum yyrule)
+{
+  return yyr2[yyrule];
+}
+
+static void
+yydestroyGLRState (char const *yymsg, yyGLRState *yys, yy::parser& yyparser, tidl::Parser* ps)
+{
+  if (yys->yyresolved)
+    yydestruct (yymsg, yystos[yys->yylrState],
+                &yys->yysemantics.yysval, &yys->yyloc, yyparser, ps);
+  else
+    {
+#if YYDEBUG
+      if (yydebug)
+        {
+          if (yys->yysemantics.yyfirstVal)
+            YYFPRINTF (stderr, "%s unresolved", yymsg);
+          else
+            YYFPRINTF (stderr, "%s incomplete", yymsg);
+          YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULLPTR, &yys->yyloc);
+        }
+#endif
+
+      if (yys->yysemantics.yyfirstVal)
+        {
+          yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
+          yyGLRState *yyrh;
+          int yyn;
+          for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
+               yyn > 0;
+               yyrh = yyrh->yypred, yyn -= 1)
+            yydestroyGLRState (yymsg, yyrh, yyparser, ps);
+        }
+    }
+}
+
+/** Left-hand-side symbol for rule #YYRULE.  */
+static inline yySymbol
+yylhsNonterm (yyRuleNum yyrule)
+{
+  return yyr1[yyrule];
+}
+
+#define yypact_value_is_default(Yystate) \
+  (!!((Yystate) == (-68)))
+
+/** True iff LR state YYSTATE has only a default reduction (regardless
+ *  of token).  */
+static inline yybool
+yyisDefaultedState (yyStateNum yystate)
+{
+  return yypact_value_is_default (yypact[yystate]);
+}
+
+/** The default reduction for YYSTATE, assuming it has one.  */
+static inline yyRuleNum
+yydefaultAction (yyStateNum yystate)
+{
+  return yydefact[yystate];
+}
+
+#define yytable_value_is_error(Yytable_value) \
+  0
+
+/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
+ *  Result R means
+ *    R < 0:  Reduce on rule -R.
+ *    R = 0:  Error.
+ *    R > 0:  Shift to state R.
+ *  Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
+ *  of conflicting reductions.
+ */
+static inline void
+yygetLRActions (yyStateNum yystate, int yytoken,
+                int* yyaction, const short int** yyconflicts)
+{
+  int yyindex = yypact[yystate] + yytoken;
+  if (yypact_value_is_default (yypact[yystate])
+      || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
+    {
+      *yyaction = -yydefact[yystate];
+      *yyconflicts = yyconfl;
+    }
+  else if (! yytable_value_is_error (yytable[yyindex]))
+    {
+      *yyaction = yytable[yyindex];
+      *yyconflicts = yyconfl + yyconflp[yyindex];
+    }
+  else
+    {
+      *yyaction = 0;
+      *yyconflicts = yyconfl + yyconflp[yyindex];
+    }
+}
+
+/** Compute post-reduction state.
+ * \param yystate   the current state
+ * \param yysym     the nonterminal to push on the stack
+ */
+static inline yyStateNum
+yyLRgotoState (yyStateNum yystate, yySymbol yysym)
+{
+  int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
+  if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
+    return yytable[yyr];
+  else
+    return yydefgoto[yysym - YYNTOKENS];
+}
+
+static inline yybool
+yyisShiftAction (int yyaction)
+{
+  return 0 < yyaction;
+}
+
+static inline yybool
+yyisErrorAction (int yyaction)
+{
+  return yyaction == 0;
+}
+
+                                /* GLRStates */
+
+/** Return a fresh GLRStackItem in YYSTACKP.  The item is an LR state
+ *  if YYISSTATE, and otherwise a semantic option.  Callers should call
+ *  YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
+ *  headroom.  */
+
+static inline yyGLRStackItem*
+yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
+{
+  yyGLRStackItem* yynewItem = yystackp->yynextFree;
+  yystackp->yyspaceLeft -= 1;
+  yystackp->yynextFree += 1;
+  yynewItem->yystate.yyisState = yyisState;
+  return yynewItem;
+}
+
+/** Add a new semantic action that will execute the action for rule
+ *  YYRULE on the semantic values in YYRHS to the list of
+ *  alternative actions for YYSTATE.  Assumes that YYRHS comes from
+ *  stack #YYK of *YYSTACKP. */
+static void
+yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
+                     yyGLRState* yyrhs, yyRuleNum yyrule)
+{
+  yySemanticOption* yynewOption =
+    &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
+  YYASSERT (!yynewOption->yyisState);
+  yynewOption->yystate = yyrhs;
+  yynewOption->yyrule = yyrule;
+  if (yystackp->yytops.yylookaheadNeeds[yyk])
+    {
+      yynewOption->yyrawchar = yychar;
+      yynewOption->yyval = yylval;
+      yynewOption->yyloc = yylloc;
+    }
+  else
+    yynewOption->yyrawchar = YYEMPTY;
+  yynewOption->yynext = yystate->yysemantics.yyfirstVal;
+  yystate->yysemantics.yyfirstVal = yynewOption;
+
+  YY_RESERVE_GLRSTACK (yystackp);
+}
+
+                                /* GLRStacks */
+
+/** Initialize YYSET to a singleton set containing an empty stack.  */
+static yybool
+yyinitStateSet (yyGLRStateSet* yyset)
+{
+  yyset->yysize = 1;
+  yyset->yycapacity = 16;
+  yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
+  if (! yyset->yystates)
+    return yyfalse;
+  yyset->yystates[0] = YY_NULLPTR;
+  yyset->yylookaheadNeeds =
+    (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
+  if (! yyset->yylookaheadNeeds)
+    {
+      YYFREE (yyset->yystates);
+      return yyfalse;
+    }
+  return yytrue;
+}
+
+static void yyfreeStateSet (yyGLRStateSet* yyset)
+{
+  YYFREE (yyset->yystates);
+  YYFREE (yyset->yylookaheadNeeds);
+}
+
+/** Initialize *YYSTACKP to a single empty stack, with total maximum
+ *  capacity for all stacks of YYSIZE.  */
+static yybool
+yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
+{
+  yystackp->yyerrState = 0;
+  yynerrs = 0;
+  yystackp->yyspaceLeft = yysize;
+  yystackp->yyitems =
+    (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
+  if (!yystackp->yyitems)
+    return yyfalse;
+  yystackp->yynextFree = yystackp->yyitems;
+  yystackp->yysplitPoint = YY_NULLPTR;
+  yystackp->yylastDeleted = YY_NULLPTR;
+  return yyinitStateSet (&yystackp->yytops);
+}
+
+
+#if YYSTACKEXPANDABLE
+# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
+  &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
+
+/** If *YYSTACKP is expandable, extend it.  WARNING: Pointers into the
+    stack from outside should be considered invalid after this call.
+    We always expand when there are 1 or fewer items left AFTER an
+    allocation, so that we can avoid having external pointers exist
+    across an allocation.  */
+static void
+yyexpandGLRStack (yyGLRStack* yystackp)
+{
+  yyGLRStackItem* yynewItems;
+  yyGLRStackItem* yyp0, *yyp1;
+  size_t yynewSize;
+  size_t yyn;
+  size_t yysize = yystackp->yynextFree - yystackp->yyitems;
+  if (YYMAXDEPTH - YYHEADROOM < yysize)
+    yyMemoryExhausted (yystackp);
+  yynewSize = 2*yysize;
+  if (YYMAXDEPTH < yynewSize)
+    yynewSize = YYMAXDEPTH;
+  yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
+  if (! yynewItems)
+    yyMemoryExhausted (yystackp);
+  for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
+       0 < yyn;
+       yyn -= 1, yyp0 += 1, yyp1 += 1)
+    {
+      *yyp1 = *yyp0;
+      if (*(yybool *) yyp0)
+        {
+          yyGLRState* yys0 = &yyp0->yystate;
+          yyGLRState* yys1 = &yyp1->yystate;
+          if (yys0->yypred != YY_NULLPTR)
+            yys1->yypred =
+              YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
+          if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR)
+            yys1->yysemantics.yyfirstVal =
+              YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
+        }
+      else
+        {
+          yySemanticOption* yyv0 = &yyp0->yyoption;
+          yySemanticOption* yyv1 = &yyp1->yyoption;
+          if (yyv0->yystate != YY_NULLPTR)
+            yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
+          if (yyv0->yynext != YY_NULLPTR)
+            yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
+        }
+    }
+  if (yystackp->yysplitPoint != YY_NULLPTR)
+    yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
+                                      yystackp->yysplitPoint, yystate);
+
+  for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
+    if (yystackp->yytops.yystates[yyn] != YY_NULLPTR)
+      yystackp->yytops.yystates[yyn] =
+        YYRELOC (yystackp->yyitems, yynewItems,
+                 yystackp->yytops.yystates[yyn], yystate);
+  YYFREE (yystackp->yyitems);
+  yystackp->yyitems = yynewItems;
+  yystackp->yynextFree = yynewItems + yysize;
+  yystackp->yyspaceLeft = yynewSize - yysize;
+}
+#endif
+
+static void
+yyfreeGLRStack (yyGLRStack* yystackp)
+{
+  YYFREE (yystackp->yyitems);
+  yyfreeStateSet (&yystackp->yytops);
+}
+
+/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
+ *  splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
+ *  YYS.  */
+static inline void
+yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
+{
+  if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys)
+    yystackp->yysplitPoint = yys;
+}
+
+/** Invalidate stack #YYK in *YYSTACKP.  */
+static inline void
+yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
+{
+  if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
+    yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
+  yystackp->yytops.yystates[yyk] = YY_NULLPTR;
+}
+
+/** Undelete the last stack in *YYSTACKP that was marked as deleted.  Can
+    only be done once after a deletion, and only when all other stacks have
+    been deleted.  */
+static void
+yyundeleteLastStack (yyGLRStack* yystackp)
+{
+  if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0)
+    return;
+  yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
+  yystackp->yytops.yysize = 1;
+  YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
+  yystackp->yylastDeleted = YY_NULLPTR;
+}
+
+static inline void
+yyremoveDeletes (yyGLRStack* yystackp)
+{
+  size_t yyi, yyj;
+  yyi = yyj = 0;
+  while (yyj < yystackp->yytops.yysize)
+    {
+      if (yystackp->yytops.yystates[yyi] == YY_NULLPTR)
+        {
+          if (yyi == yyj)
+            {
+              YYDPRINTF ((stderr, "Removing dead stacks.\n"));
+            }
+          yystackp->yytops.yysize -= 1;
+        }
+      else
+        {
+          yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
+          /* In the current implementation, it's unnecessary to copy
+             yystackp->yytops.yylookaheadNeeds[yyi] since, after
+             yyremoveDeletes returns, the parser immediately either enters
+             deterministic operation or shifts a token.  However, it doesn't
+             hurt, and the code might evolve to need it.  */
+          yystackp->yytops.yylookaheadNeeds[yyj] =
+            yystackp->yytops.yylookaheadNeeds[yyi];
+          if (yyj != yyi)
+            {
+              YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
+                          (unsigned long int) yyi, (unsigned long int) yyj));
+            }
+          yyj += 1;
+        }
+      yyi += 1;
+    }
+}
+
+/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
+ * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
+ * value *YYVALP and source location *YYLOCP.  */
+static inline void
+yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
+            size_t yyposn,
+            YYSTYPE* yyvalp, YYLTYPE* yylocp)
+{
+  yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
+
+  yynewState->yylrState = yylrState;
+  yynewState->yyposn = yyposn;
+  yynewState->yyresolved = yytrue;
+  yynewState->yypred = yystackp->yytops.yystates[yyk];
+  yynewState->yysemantics.yysval = *yyvalp;
+  yynewState->yyloc = *yylocp;
+  yystackp->yytops.yystates[yyk] = yynewState;
+
+  YY_RESERVE_GLRSTACK (yystackp);
+}
+
+/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
+ *  state YYLRSTATE, at input position YYPOSN, with the (unresolved)
+ *  semantic value of YYRHS under the action for YYRULE.  */
+static inline void
+yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
+                 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
+{
+  yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
+  YYASSERT (yynewState->yyisState);
+
+  yynewState->yylrState = yylrState;
+  yynewState->yyposn = yyposn;
+  yynewState->yyresolved = yyfalse;
+  yynewState->yypred = yystackp->yytops.yystates[yyk];
+  yynewState->yysemantics.yyfirstVal = YY_NULLPTR;
+  yystackp->yytops.yystates[yyk] = yynewState;
+
+  /* Invokes YY_RESERVE_GLRSTACK.  */
+  yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
+}
+
+#if !YYDEBUG
+# define YY_REDUCE_PRINT(Args)
+#else
+# define YY_REDUCE_PRINT(Args)          \
+do {                                    \
+  if (yydebug)                          \
+    yy_reduce_print Args;               \
+} while (0)
+
+/*----------------------------------------------------------------------.
+| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
+`----------------------------------------------------------------------*/
+
+static inline void
+yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
+                 yyRuleNum yyrule, yy::parser& yyparser, tidl::Parser* ps)
+{
+  int yynrhs = yyrhsLength (yyrule);
+  int yylow = 1;
+  int yyi;
+  YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
+             (unsigned long int) yyk, yyrule - 1,
+             (unsigned long int) yyrline[yyrule]);
+  if (! yynormal)
+    yyfillin (yyvsp, 1, -yynrhs);
+  /* The symbols being reduced.  */
+  for (yyi = 0; yyi < yynrhs; yyi++)
+    {
+      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
+      yy_symbol_print (stderr,
+                       yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
+                       &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
+                       , &(((yyGLRStackItem const *)yyvsp)[YYFILL ((yyi + 1) - (yynrhs))].yystate.yyloc)                       , yyparser, ps);
+      if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
+        YYFPRINTF (stderr, " (unresolved)");
+      YYFPRINTF (stderr, "\n");
+    }
+}
+#endif
+
+/** Pop the symbols consumed by reduction #YYRULE from the top of stack
+ *  #YYK of *YYSTACKP, and perform the appropriate semantic action on their
+ *  semantic values.  Assumes that all ambiguities in semantic values
+ *  have been previously resolved.  Set *YYVALP to the resulting value,
+ *  and *YYLOCP to the computed location (if any).  Return value is as
+ *  for userAction.  */
+static inline YYRESULTTAG
+yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
+            YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  int yynrhs = yyrhsLength (yyrule);
+
+  if (yystackp->yysplitPoint == YY_NULLPTR)
+    {
+      /* Standard special case: single stack.  */
+      yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
+      YYASSERT (yyk == 0);
+      yystackp->yynextFree -= yynrhs;
+      yystackp->yyspaceLeft += yynrhs;
+      yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
+      YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule, yyparser, ps));
+      return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
+                           yyvalp, yylocp, yyparser, ps);
+    }
+  else
+    {
+      int yyi;
+      yyGLRState* yys;
+      yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
+      yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
+        = yystackp->yytops.yystates[yyk];
+      if (yynrhs == 0)
+        /* Set default location.  */
+        yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;
+      for (yyi = 0; yyi < yynrhs; yyi += 1)
+        {
+          yys = yys->yypred;
+          YYASSERT (yys);
+        }
+      yyupdateSplit (yystackp, yys);
+      yystackp->yytops.yystates[yyk] = yys;
+      YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule, yyparser, ps));
+      return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
+                           yystackp, yyvalp, yylocp, yyparser, ps);
+    }
+}
+
+/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
+ *  and push back on the resulting nonterminal symbol.  Perform the
+ *  semantic action associated with YYRULE and store its value with the
+ *  newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
+ *  unambiguous.  Otherwise, store the deferred semantic action with
+ *  the new state.  If the new state would have an identical input
+ *  position, LR state, and predecessor to an existing state on the stack,
+ *  it is identified with that existing state, eliminating stack #YYK from
+ *  *YYSTACKP.  In this case, the semantic value is
+ *  added to the options for the existing state's semantic value.
+ */
+static inline YYRESULTTAG
+yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
+             yybool yyforceEval, yy::parser& yyparser, tidl::Parser* ps)
+{
+  size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
+
+  if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
+    {
+      YYSTYPE yysval;
+      YYLTYPE yyloc;
+
+      YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval, &yyloc, yyparser, ps);
+      if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
+        {
+          YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
+                     (unsigned long int) yyk, yyrule - 1));
+        }
+      if (yyflag != yyok)
+        return yyflag;
+      YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
+      yyglrShift (yystackp, yyk,
+                  yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
+                                 yylhsNonterm (yyrule)),
+                  yyposn, &yysval, &yyloc);
+    }
+  else
+    {
+      size_t yyi;
+      int yyn;
+      yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
+      yyStateNum yynewLRState;
+
+      for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
+           0 < yyn; yyn -= 1)
+        {
+          yys = yys->yypred;
+          YYASSERT (yys);
+        }
+      yyupdateSplit (yystackp, yys);
+      yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
+      YYDPRINTF ((stderr,
+                  "Reduced stack %lu by rule #%d; action deferred.  "
+                  "Now in state %d.\n",
+                  (unsigned long int) yyk, yyrule - 1, yynewLRState));
+      for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
+        if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
+          {
+            yyGLRState *yysplit = yystackp->yysplitPoint;
+            yyGLRState *yyp = yystackp->yytops.yystates[yyi];
+            while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
+              {
+                if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
+                  {
+                    yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
+                    yymarkStackDeleted (yystackp, yyk);
+                    YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
+                                (unsigned long int) yyk,
+                                (unsigned long int) yyi));
+                    return yyok;
+                  }
+                yyp = yyp->yypred;
+              }
+          }
+      yystackp->yytops.yystates[yyk] = yys;
+      yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
+    }
+  return yyok;
+}
+
+static size_t
+yysplitStack (yyGLRStack* yystackp, size_t yyk)
+{
+  if (yystackp->yysplitPoint == YY_NULLPTR)
+    {
+      YYASSERT (yyk == 0);
+      yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
+    }
+  if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
+    {
+      yyGLRState** yynewStates;
+      yybool* yynewLookaheadNeeds;
+
+      yynewStates = YY_NULLPTR;
+
+      if (yystackp->yytops.yycapacity
+          > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
+        yyMemoryExhausted (yystackp);
+      yystackp->yytops.yycapacity *= 2;
+
+      yynewStates =
+        (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
+                                  (yystackp->yytops.yycapacity
+                                   * sizeof yynewStates[0]));
+      if (yynewStates == YY_NULLPTR)
+        yyMemoryExhausted (yystackp);
+      yystackp->yytops.yystates = yynewStates;
+
+      yynewLookaheadNeeds =
+        (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
+                             (yystackp->yytops.yycapacity
+                              * sizeof yynewLookaheadNeeds[0]));
+      if (yynewLookaheadNeeds == YY_NULLPTR)
+        yyMemoryExhausted (yystackp);
+      yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
+    }
+  yystackp->yytops.yystates[yystackp->yytops.yysize]
+    = yystackp->yytops.yystates[yyk];
+  yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
+    = yystackp->yytops.yylookaheadNeeds[yyk];
+  yystackp->yytops.yysize += 1;
+  return yystackp->yytops.yysize-1;
+}
+
+/** True iff YYY0 and YYY1 represent identical options at the top level.
+ *  That is, they represent the same rule applied to RHS symbols
+ *  that produce the same terminal symbols.  */
+static yybool
+yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
+{
+  if (yyy0->yyrule == yyy1->yyrule)
+    {
+      yyGLRState *yys0, *yys1;
+      int yyn;
+      for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
+           yyn = yyrhsLength (yyy0->yyrule);
+           yyn > 0;
+           yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
+        if (yys0->yyposn != yys1->yyposn)
+          return yyfalse;
+      return yytrue;
+    }
+  else
+    return yyfalse;
+}
+
+/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
+ *  alternative semantic values for the RHS-symbols of YYY1 and YYY0.  */
+static void
+yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
+{
+  yyGLRState *yys0, *yys1;
+  int yyn;
+  for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
+       yyn = yyrhsLength (yyy0->yyrule);
+       yyn > 0;
+       yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
+    {
+      if (yys0 == yys1)
+        break;
+      else if (yys0->yyresolved)
+        {
+          yys1->yyresolved = yytrue;
+          yys1->yysemantics.yysval = yys0->yysemantics.yysval;
+        }
+      else if (yys1->yyresolved)
+        {
+          yys0->yyresolved = yytrue;
+          yys0->yysemantics.yysval = yys1->yysemantics.yysval;
+        }
+      else
+        {
+          yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
+          yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
+          while (yytrue)
+            {
+              if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR)
+                break;
+              else if (*yyz0p == YY_NULLPTR)
+                {
+                  *yyz0p = yyz1;
+                  break;
+                }
+              else if (*yyz0p < yyz1)
+                {
+                  yySemanticOption* yyz = *yyz0p;
+                  *yyz0p = yyz1;
+                  yyz1 = yyz1->yynext;
+                  (*yyz0p)->yynext = yyz;
+                }
+              yyz0p = &(*yyz0p)->yynext;
+            }
+          yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
+        }
+    }
+}
+
+/** Y0 and Y1 represent two possible actions to take in a given
+ *  parsing state; return 0 if no combination is possible,
+ *  1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred.  */
+static int
+yypreference (yySemanticOption* y0, yySemanticOption* y1)
+{
+  yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
+  int p0 = yydprec[r0], p1 = yydprec[r1];
+
+  if (p0 == p1)
+    {
+      if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
+        return 0;
+      else
+        return 1;
+    }
+  if (p0 == 0 || p1 == 0)
+    return 0;
+  if (p0 < p1)
+    return 3;
+  if (p1 < p0)
+    return 2;
+  return 0;
+}
+
+static YYRESULTTAG yyresolveValue (yyGLRState* yys,
+                                   yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps);
+
+
+/** Resolve the previous YYN states starting at and including state YYS
+ *  on *YYSTACKP. If result != yyok, some states may have been left
+ *  unresolved possibly with empty semantic option chains.  Regardless
+ *  of whether result = yyok, each state has been left with consistent
+ *  data so that yydestroyGLRState can be invoked if necessary.  */
+static YYRESULTTAG
+yyresolveStates (yyGLRState* yys, int yyn,
+                 yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  if (0 < yyn)
+    {
+      YYASSERT (yys->yypred);
+      YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp, yyparser, ps));
+      if (! yys->yyresolved)
+        YYCHK (yyresolveValue (yys, yystackp, yyparser, ps));
+    }
+  return yyok;
+}
+
+/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
+ *  user action, and return the semantic value and location in *YYVALP
+ *  and *YYLOCP.  Regardless of whether result = yyok, all RHS states
+ *  have been destroyed (assuming the user action destroys all RHS
+ *  semantic values if invoked).  */
+static YYRESULTTAG
+yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
+                 YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
+  int yynrhs = yyrhsLength (yyopt->yyrule);
+  YYRESULTTAG yyflag =
+    yyresolveStates (yyopt->yystate, yynrhs, yystackp, yyparser, ps);
+  if (yyflag != yyok)
+    {
+      yyGLRState *yys;
+      for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
+        yydestroyGLRState ("Cleanup: popping", yys, yyparser, ps);
+      return yyflag;
+    }
+
+  yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
+  if (yynrhs == 0)
+    /* Set default location.  */
+    yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;
+  {
+    int yychar_current = yychar;
+    YYSTYPE yylval_current = yylval;
+    YYLTYPE yylloc_current = yylloc;
+    yychar = yyopt->yyrawchar;
+    yylval = yyopt->yyval;
+    yylloc = yyopt->yyloc;
+    yyflag = yyuserAction (yyopt->yyrule, yynrhs,
+                           yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
+                           yystackp, yyvalp, yylocp, yyparser, ps);
+    yychar = yychar_current;
+    yylval = yylval_current;
+    yylloc = yylloc_current;
+  }
+  return yyflag;
+}
+
+#if YYDEBUG
+static void
+yyreportTree (yySemanticOption* yyx, int yyindent)
+{
+  int yynrhs = yyrhsLength (yyx->yyrule);
+  int yyi;
+  yyGLRState* yys;
+  yyGLRState* yystates[1 + YYMAXRHS];
+  yyGLRState yyleftmost_state;
+
+  for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
+    yystates[yyi] = yys;
+  if (yys == YY_NULLPTR)
+    {
+      yyleftmost_state.yyposn = 0;
+      yystates[0] = &yyleftmost_state;
+    }
+  else
+    yystates[0] = yys;
+
+  if (yyx->yystate->yyposn < yys->yyposn + 1)
+    YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
+               yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
+               yyx->yyrule - 1);
+  else
+    YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
+               yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
+               yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
+               (unsigned long int) yyx->yystate->yyposn);
+  for (yyi = 1; yyi <= yynrhs; yyi += 1)
+    {
+      if (yystates[yyi]->yyresolved)
+        {
+          if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
+            YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
+                       yytokenName (yystos[yystates[yyi]->yylrState]));
+          else
+            YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
+                       yytokenName (yystos[yystates[yyi]->yylrState]),
+                       (unsigned long int) (yystates[yyi-1]->yyposn + 1),
+                       (unsigned long int) yystates[yyi]->yyposn);
+        }
+      else
+        yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
+    }
+}
+#endif
+
+static YYRESULTTAG
+yyreportAmbiguity (yySemanticOption* yyx0,
+                   yySemanticOption* yyx1, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  YYUSE (yyx0);
+  YYUSE (yyx1);
+
+#if YYDEBUG
+  YYFPRINTF (stderr, "Ambiguity detected.\n");
+  YYFPRINTF (stderr, "Option 1,\n");
+  yyreportTree (yyx0, 2);
+  YYFPRINTF (stderr, "\nOption 2,\n");
+  yyreportTree (yyx1, 2);
+  YYFPRINTF (stderr, "\n");
+#endif
+
+  yyerror (yylocp, yyparser, ps, YY_("syntax is ambiguous"));
+  return yyabort;
+}
+
+/** Resolve the locations for each of the YYN1 states in *YYSTACKP,
+ *  ending at YYS1.  Has no effect on previously resolved states.
+ *  The first semantic option of a state is always chosen.  */
+static void
+yyresolveLocations (yyGLRState* yys1, int yyn1,
+                    yyGLRStack *yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  if (0 < yyn1)
+    {
+      yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp, yyparser, ps);
+      if (!yys1->yyresolved)
+        {
+          yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
+          int yynrhs;
+          yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
+          YYASSERT (yyoption != YY_NULLPTR);
+          yynrhs = yyrhsLength (yyoption->yyrule);
+          if (yynrhs > 0)
+            {
+              yyGLRState *yys;
+              int yyn;
+              yyresolveLocations (yyoption->yystate, yynrhs,
+                                  yystackp, yyparser, ps);
+              for (yys = yyoption->yystate, yyn = yynrhs;
+                   yyn > 0;
+                   yys = yys->yypred, yyn -= 1)
+                yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
+            }
+          else
+            {
+              /* Both yyresolveAction and yyresolveLocations traverse the GSS
+                 in reverse rightmost order.  It is only necessary to invoke
+                 yyresolveLocations on a subforest for which yyresolveAction
+                 would have been invoked next had an ambiguity not been
+                 detected.  Thus the location of the previous state (but not
+                 necessarily the previous state itself) is guaranteed to be
+                 resolved already.  */
+              yyGLRState *yyprevious = yyoption->yystate;
+              yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
+            }
+          {
+            int yychar_current = yychar;
+            YYSTYPE yylval_current = yylval;
+            YYLTYPE yylloc_current = yylloc;
+            yychar = yyoption->yyrawchar;
+            yylval = yyoption->yyval;
+            yylloc = yyoption->yyloc;
+            YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
+            yychar = yychar_current;
+            yylval = yylval_current;
+            yylloc = yylloc_current;
+          }
+        }
+    }
+}
+
+/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
+ *  perform the indicated actions, and set the semantic value of YYS.
+ *  If result != yyok, the chain of semantic options in YYS has been
+ *  cleared instead or it has been left unmodified except that
+ *  redundant options may have been removed.  Regardless of whether
+ *  result = yyok, YYS has been left with consistent data so that
+ *  yydestroyGLRState can be invoked if necessary.  */
+static YYRESULTTAG
+yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
+  yySemanticOption* yybest = yyoptionList;
+  yySemanticOption** yypp;
+  yybool yymerge = yyfalse;
+  YYSTYPE yysval;
+  YYRESULTTAG yyflag;
+  YYLTYPE *yylocp = &yys->yyloc;
+
+  for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; )
+    {
+      yySemanticOption* yyp = *yypp;
+
+      if (yyidenticalOptions (yybest, yyp))
+        {
+          yymergeOptionSets (yybest, yyp);
+          *yypp = yyp->yynext;
+        }
+      else
+        {
+          switch (yypreference (yybest, yyp))
+            {
+            case 0:
+              yyresolveLocations (yys, 1, yystackp, yyparser, ps);
+              return yyreportAmbiguity (yybest, yyp, yylocp, yyparser, ps);
+              break;
+            case 1:
+              yymerge = yytrue;
+              break;
+            case 2:
+              break;
+            case 3:
+              yybest = yyp;
+              yymerge = yyfalse;
+              break;
+            default:
+              /* This cannot happen so it is not worth a YYASSERT (yyfalse),
+                 but some compilers complain if the default case is
+                 omitted.  */
+              break;
+            }
+          yypp = &yyp->yynext;
+        }
+    }
+
+  if (yymerge)
+    {
+      yySemanticOption* yyp;
+      int yyprec = yydprec[yybest->yyrule];
+      yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp, yyparser, ps);
+      if (yyflag == yyok)
+        for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext)
+          {
+            if (yyprec == yydprec[yyp->yyrule])
+              {
+                YYSTYPE yysval_other;
+                YYLTYPE yydummy;
+                yyflag = yyresolveAction (yyp, yystackp, &yysval_other, &yydummy, yyparser, ps);
+                if (yyflag != yyok)
+                  {
+                    yydestruct ("Cleanup: discarding incompletely merged value for",
+                                yystos[yys->yylrState],
+                                &yysval, yylocp, yyparser, ps);
+                    break;
+                  }
+                yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
+              }
+          }
+    }
+  else
+    yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp, yyparser, ps);
+
+  if (yyflag == yyok)
+    {
+      yys->yyresolved = yytrue;
+      yys->yysemantics.yysval = yysval;
+    }
+  else
+    yys->yysemantics.yyfirstVal = YY_NULLPTR;
+  return yyflag;
+}
+
+static YYRESULTTAG
+yyresolveStack (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  if (yystackp->yysplitPoint != YY_NULLPTR)
+    {
+      yyGLRState* yys;
+      int yyn;
+
+      for (yyn = 0, yys = yystackp->yytops.yystates[0];
+           yys != yystackp->yysplitPoint;
+           yys = yys->yypred, yyn += 1)
+        continue;
+      YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
+                             , yyparser, ps));
+    }
+  return yyok;
+}
+
+static void
+yycompressStack (yyGLRStack* yystackp)
+{
+  yyGLRState* yyp, *yyq, *yyr;
+
+  if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR)
+    return;
+
+  for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
+       yyp != yystackp->yysplitPoint;
+       yyr = yyp, yyp = yyq, yyq = yyp->yypred)
+    yyp->yypred = yyr;
+
+  yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
+  yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
+  yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
+  yystackp->yysplitPoint = YY_NULLPTR;
+  yystackp->yylastDeleted = YY_NULLPTR;
+
+  while (yyr != YY_NULLPTR)
+    {
+      yystackp->yynextFree->yystate = *yyr;
+      yyr = yyr->yypred;
+      yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
+      yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
+      yystackp->yynextFree += 1;
+      yystackp->yyspaceLeft -= 1;
+    }
+}
+
+static YYRESULTTAG
+yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
+                   size_t yyposn, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
+    {
+      yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
+      YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
+                  (unsigned long int) yyk, yystate));
+
+      YYASSERT (yystate != YYFINAL);
+
+      if (yyisDefaultedState (yystate))
+        {
+          YYRESULTTAG yyflag;
+          yyRuleNum yyrule = yydefaultAction (yystate);
+          if (yyrule == 0)
+            {
+              YYDPRINTF ((stderr, "Stack %lu dies.\n",
+                          (unsigned long int) yyk));
+              yymarkStackDeleted (yystackp, yyk);
+              return yyok;
+            }
+          yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule], yyparser, ps);
+          if (yyflag == yyerr)
+            {
+              YYDPRINTF ((stderr,
+                          "Stack %lu dies "
+                          "(predicate failure or explicit user error).\n",
+                          (unsigned long int) yyk));
+              yymarkStackDeleted (yystackp, yyk);
+              return yyok;
+            }
+          if (yyflag != yyok)
+            return yyflag;
+        }
+      else
+        {
+          yySymbol yytoken;
+          int yyaction;
+          const short int* yyconflicts;
+
+          yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
+          if (yychar == YYEMPTY)
+            {
+              YYDPRINTF ((stderr, "Reading a token: "));
+              yychar = yylex (&yylval, &yylloc, lex_scanner);
+            }
+
+          if (yychar <= YYEOF)
+            {
+              yychar = yytoken = YYEOF;
+              YYDPRINTF ((stderr, "Now at end of input.\n"));
+            }
+          else
+            {
+              yytoken = YYTRANSLATE (yychar);
+              YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+            }
+
+          yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+
+          while (*yyconflicts != 0)
+            {
+              YYRESULTTAG yyflag;
+              size_t yynewStack = yysplitStack (yystackp, yyk);
+              YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
+                          (unsigned long int) yynewStack,
+                          (unsigned long int) yyk));
+              yyflag = yyglrReduce (yystackp, yynewStack,
+                                    *yyconflicts,
+                                    yyimmediate[*yyconflicts], yyparser, ps);
+              if (yyflag == yyok)
+                YYCHK (yyprocessOneStack (yystackp, yynewStack,
+                                          yyposn, yylocp, yyparser, ps));
+              else if (yyflag == yyerr)
+                {
+                  YYDPRINTF ((stderr, "Stack %lu dies.\n",
+                              (unsigned long int) yynewStack));
+                  yymarkStackDeleted (yystackp, yynewStack);
+                }
+              else
+                return yyflag;
+              yyconflicts += 1;
+            }
+
+          if (yyisShiftAction (yyaction))
+            break;
+          else if (yyisErrorAction (yyaction))
+            {
+              YYDPRINTF ((stderr, "Stack %lu dies.\n",
+                          (unsigned long int) yyk));
+              yymarkStackDeleted (yystackp, yyk);
+              break;
+            }
+          else
+            {
+              YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
+                                                yyimmediate[-yyaction], yyparser, ps);
+              if (yyflag == yyerr)
+                {
+                  YYDPRINTF ((stderr,
+                              "Stack %lu dies "
+                              "(predicate failure or explicit user error).\n",
+                              (unsigned long int) yyk));
+                  yymarkStackDeleted (yystackp, yyk);
+                  break;
+                }
+              else if (yyflag != yyok)
+                return yyflag;
+            }
+        }
+    }
+  return yyok;
+}
+
+static void
+yyreportSyntaxError (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  if (yystackp->yyerrState != 0)
+    return;
+#if ! YYERROR_VERBOSE
+  yyerror (&yylloc, yyparser, ps, YY_("syntax error"));
+#else
+  {
+  yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+  size_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
+  size_t yysize = yysize0;
+  yybool yysize_overflow = yyfalse;
+  char* yymsg = YY_NULLPTR;
+  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+  /* Internationalized format string. */
+  const char *yyformat = YY_NULLPTR;
+  /* Arguments of yyformat. */
+  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+  /* Number of reported tokens (one for the "unexpected", one per
+     "expected").  */
+  int yycount = 0;
+
+  /* There are many possibilities here to consider:
+     - If this state is a consistent state with a default action, then
+       the only way this function was invoked is if the default action
+       is an error action.  In that case, don't check for expected
+       tokens because there are none.
+     - The only way there can be no lookahead present (in yychar) is if
+       this state is a consistent state with a default action.  Thus,
+       detecting the absence of a lookahead is sufficient to determine
+       that there is no unexpected or expected token to report.  In that
+       case, just report a simple "syntax error".
+     - Don't assume there isn't a lookahead just because this state is a
+       consistent state with a default action.  There might have been a
+       previous inconsistent state, consistent state with a non-default
+       action, or user semantic action that manipulated yychar.
+     - Of course, the expected token list depends on states to have
+       correct lookahead information, and it depends on the parser not
+       to perform extra reductions after fetching a lookahead from the
+       scanner and before detecting a syntax error.  Thus, state merging
+       (from LALR or IELR) and default reductions corrupt the expected
+       token list.  However, the list is correct for canonical LR with
+       one exception: it will still contain any token that will not be
+       accepted due to an error action in a later state.
+  */
+  if (yytoken != YYEMPTY)
+    {
+      int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
+      yyarg[yycount++] = yytokenName (yytoken);
+      if (!yypact_value_is_default (yyn))
+        {
+          /* Start YYX at -YYN if negative to avoid negative indexes in
+             YYCHECK.  In other words, skip the first -YYN actions for this
+             state because they are default actions.  */
+          int yyxbegin = yyn < 0 ? -yyn : 0;
+          /* Stay within bounds of both yycheck and yytname.  */
+          int yychecklim = YYLAST - yyn + 1;
+          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+          int yyx;
+          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+                && !yytable_value_is_error (yytable[yyx + yyn]))
+              {
+                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+                  {
+                    yycount = 1;
+                    yysize = yysize0;
+                    break;
+                  }
+                yyarg[yycount++] = yytokenName (yyx);
+                {
+                  size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
+                  yysize_overflow |= yysz < yysize;
+                  yysize = yysz;
+                }
+              }
+        }
+    }
+
+  switch (yycount)
+    {
+#define YYCASE_(N, S)                   \
+      case N:                           \
+        yyformat = S;                   \
+      break
+      YYCASE_(0, YY_("syntax error"));
+      YYCASE_(1, YY_("syntax error, unexpected %s"));
+      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+#undef YYCASE_
+    }
+
+  {
+    size_t yysz = yysize + strlen (yyformat);
+    yysize_overflow |= yysz < yysize;
+    yysize = yysz;
+  }
+
+  if (!yysize_overflow)
+    yymsg = (char *) YYMALLOC (yysize);
+
+  if (yymsg)
+    {
+      char *yyp = yymsg;
+      int yyi = 0;
+      while ((*yyp = *yyformat))
+        {
+          if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+            {
+              yyp += yytnamerr (yyp, yyarg[yyi++]);
+              yyformat += 2;
+            }
+          else
+            {
+              yyp++;
+              yyformat++;
+            }
+        }
+      yyerror (&yylloc, yyparser, ps, yymsg);
+      YYFREE (yymsg);
+    }
+  else
+    {
+      yyerror (&yylloc, yyparser, ps, YY_("syntax error"));
+      yyMemoryExhausted (yystackp);
+    }
+  }
+#endif /* YYERROR_VERBOSE */
+  yynerrs += 1;
+}
+
+/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
+   yylval, and yylloc are the syntactic category, semantic value, and location
+   of the lookahead.  */
+static void
+yyrecoverSyntaxError (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
+{
+  size_t yyk;
+  int yyj;
+
+  if (yystackp->yyerrState == 3)
+    /* We just shifted the error token and (perhaps) took some
+       reductions.  Skip tokens until we can proceed.  */
+    while (yytrue)
+      {
+        yySymbol yytoken;
+        if (yychar == YYEOF)
+          yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
+        if (yychar != YYEMPTY)
+          {
+            /* We throw away the lookahead, but the error range
+               of the shifted error token must take it into account.  */
+            yyGLRState *yys = yystackp->yytops.yystates[0];
+            yyGLRStackItem yyerror_range[3];
+            yyerror_range[1].yystate.yyloc = yys->yyloc;
+            yyerror_range[2].yystate.yyloc = yylloc;
+            YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);
+            yytoken = YYTRANSLATE (yychar);
+            yydestruct ("Error: discarding",
+                        yytoken, &yylval, &yylloc, yyparser, ps);
+          }
+        YYDPRINTF ((stderr, "Reading a token: "));
+        yychar = yylex (&yylval, &yylloc, lex_scanner);
+        if (yychar <= YYEOF)
+          {
+            yychar = yytoken = YYEOF;
+            YYDPRINTF ((stderr, "Now at end of input.\n"));
+          }
+        else
+          {
+            yytoken = YYTRANSLATE (yychar);
+            YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+          }
+        yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
+        if (yypact_value_is_default (yyj))
+          return;
+        yyj += yytoken;
+        if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
+          {
+            if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
+              return;
+          }
+        else if (! yytable_value_is_error (yytable[yyj]))
+          return;
+      }
+
+  /* Reduce to one stack.  */
+  for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
+    if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
+      break;
+  if (yyk >= yystackp->yytops.yysize)
+    yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
+  for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
+    yymarkStackDeleted (yystackp, yyk);
+  yyremoveDeletes (yystackp);
+  yycompressStack (yystackp);
+
+  /* Now pop stack until we find a state that shifts the error token.  */
+  yystackp->yyerrState = 3;
+  while (yystackp->yytops.yystates[0] != YY_NULLPTR)
+    {
+      yyGLRState *yys = yystackp->yytops.yystates[0];
+      yyj = yypact[yys->yylrState];
+      if (! yypact_value_is_default (yyj))
+        {
+          yyj += YYTERROR;
+          if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
+              && yyisShiftAction (yytable[yyj]))
+            {
+              /* Shift the error token.  */
+              /* First adjust its location.*/
+              YYLTYPE yyerrloc;
+              yystackp->yyerror_range[2].yystate.yyloc = yylloc;
+              YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);
+              YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
+                               &yylval, &yyerrloc);
+              yyglrShift (yystackp, 0, yytable[yyj],
+                          yys->yyposn, &yylval, &yyerrloc);
+              yys = yystackp->yytops.yystates[0];
+              break;
+            }
+        }
+      yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;
+      if (yys->yypred != YY_NULLPTR)
+        yydestroyGLRState ("Error: popping", yys, yyparser, ps);
+      yystackp->yytops.yystates[0] = yys->yypred;
+      yystackp->yynextFree -= 1;
+      yystackp->yyspaceLeft += 1;
+    }
+  if (yystackp->yytops.yystates[0] == YY_NULLPTR)
+    yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
+}
+
+#define YYCHK1(YYE)                                                          \
+  do {                                                                       \
+    switch (YYE) {                                                           \
+    case yyok:                                                               \
+      break;                                                                 \
+    case yyabort:                                                            \
+      goto yyabortlab;                                                       \
+    case yyaccept:                                                           \
+      goto yyacceptlab;                                                      \
+    case yyerr:                                                              \
+      goto yyuser_error;                                                     \
+    default:                                                                 \
+      goto yybuglab;                                                         \
+    }                                                                        \
+  } while (0)
+
+/*----------.
+| yyparse.  |
+`----------*/
+
+int
+yyparse (yy::parser& yyparser, tidl::Parser* ps)
+{
+  int yyresult;
+  yyGLRStack yystack;
+  yyGLRStack* const yystackp = &yystack;
+  size_t yyposn;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yychar = YYEMPTY;
+  yylval = yyval_default;
+  yylloc = yyloc_default;
+
+  /* User initialization code.  */
+  yylloc.initialize ();
+#line 3238 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:2237
+
+  if (! yyinitGLRStack (yystackp, YYINITDEPTH))
+    goto yyexhaustedlab;
+  switch (YYSETJMP (yystack.yyexception_buffer))
+    {
+    case 0: break;
+    case 1: goto yyabortlab;
+    case 2: goto yyexhaustedlab;
+    default: goto yybuglab;
+    }
+  yyglrShift (&yystack, 0, 0, 0, &yylval, &yylloc);
+  yyposn = 0;
+
+  while (yytrue)
+    {
+      /* For efficiency, we have two loops, the first of which is
+         specialized to deterministic operation (single stack, no
+         potential ambiguity).  */
+      /* Standard mode */
+      while (yytrue)
+        {
+          yyRuleNum yyrule;
+          int yyaction;
+          const short int* yyconflicts;
+
+          yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
+          YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+          if (yystate == YYFINAL)
+            goto yyacceptlab;
+          if (yyisDefaultedState (yystate))
+            {
+              yyrule = yydefaultAction (yystate);
+              if (yyrule == 0)
+                {
+               yystack.yyerror_range[1].yystate.yyloc = yylloc;
+                  yyreportSyntaxError (&yystack, yyparser, ps);
+                  goto yyuser_error;
+                }
+              YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue, yyparser, ps));
+            }
+          else
+            {
+              yySymbol yytoken;
+              if (yychar == YYEMPTY)
+                {
+                  YYDPRINTF ((stderr, "Reading a token: "));
+                  yychar = yylex (&yylval, &yylloc, lex_scanner);
+                }
+
+              if (yychar <= YYEOF)
+                {
+                  yychar = yytoken = YYEOF;
+                  YYDPRINTF ((stderr, "Now at end of input.\n"));
+                }
+              else
+                {
+                  yytoken = YYTRANSLATE (yychar);
+                  YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+                }
+
+              yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+              if (*yyconflicts != 0)
+                break;
+              if (yyisShiftAction (yyaction))
+                {
+                  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+                  yychar = YYEMPTY;
+                  yyposn += 1;
+                  yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
+                  if (0 < yystack.yyerrState)
+                    yystack.yyerrState -= 1;
+                }
+              else if (yyisErrorAction (yyaction))
+                {
+               yystack.yyerror_range[1].yystate.yyloc = yylloc;
+                  yyreportSyntaxError (&yystack, yyparser, ps);
+                  goto yyuser_error;
+                }
+              else
+                YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue, yyparser, ps));
+            }
+        }
+
+      while (yytrue)
+        {
+          yySymbol yytoken_to_shift;
+          size_t yys;
+
+          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+            yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
+
+          /* yyprocessOneStack returns one of three things:
+
+              - An error flag.  If the caller is yyprocessOneStack, it
+                immediately returns as well.  When the caller is finally
+                yyparse, it jumps to an error label via YYCHK1.
+
+              - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
+                (&yystack, yys), which sets the top state of yys to NULL.  Thus,
+                yyparse's following invocation of yyremoveDeletes will remove
+                the stack.
+
+              - yyok, when ready to shift a token.
+
+             Except in the first case, yyparse will invoke yyremoveDeletes and
+             then shift the next token onto all remaining stacks.  This
+             synchronization of the shift (that is, after all preceding
+             reductions on all stacks) helps prevent double destructor calls
+             on yylval in the event of memory exhaustion.  */
+
+          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+            YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, &yylloc, yyparser, ps));
+          yyremoveDeletes (&yystack);
+          if (yystack.yytops.yysize == 0)
+            {
+              yyundeleteLastStack (&yystack);
+              if (yystack.yytops.yysize == 0)
+                yyFail (&yystack, &yylloc, yyparser, ps, YY_("syntax error"));
+              YYCHK1 (yyresolveStack (&yystack, yyparser, ps));
+              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
+           yystack.yyerror_range[1].yystate.yyloc = yylloc;
+              yyreportSyntaxError (&yystack, yyparser, ps);
+              goto yyuser_error;
+            }
+
+          /* If any yyglrShift call fails, it will fail after shifting.  Thus,
+             a copy of yylval will already be on stack 0 in the event of a
+             failure in the following loop.  Thus, yychar is set to YYEMPTY
+             before the loop to make sure the user destructor for yylval isn't
+             called twice.  */
+          yytoken_to_shift = YYTRANSLATE (yychar);
+          yychar = YYEMPTY;
+          yyposn += 1;
+          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+            {
+              int yyaction;
+              const short int* yyconflicts;
+              yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
+              yygetLRActions (yystate, yytoken_to_shift, &yyaction,
+                              &yyconflicts);
+              /* Note that yyconflicts were handled by yyprocessOneStack.  */
+              YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
+              YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
+              yyglrShift (&yystack, yys, yyaction, yyposn,
+                          &yylval, &yylloc);
+              YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
+                          (unsigned long int) yys,
+                          yystack.yytops.yystates[yys]->yylrState));
+            }
+
+          if (yystack.yytops.yysize == 1)
+            {
+              YYCHK1 (yyresolveStack (&yystack, yyparser, ps));
+              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
+              yycompressStack (&yystack);
+              break;
+            }
+        }
+      continue;
+    yyuser_error:
+      yyrecoverSyntaxError (&yystack, yyparser, ps);
+      yyposn = yystack.yytops.yystates[0]->yyposn;
+    }
+
+ yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+ yybuglab:
+  YYASSERT (yyfalse);
+  goto yyabortlab;
+
+ yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+ yyexhaustedlab:
+  yyerror (&yylloc, yyparser, ps, YY_("memory exhausted"));
+  yyresult = 2;
+  goto yyreturn;
+
+ yyreturn:
+  if (yychar != YYEMPTY)
+    yydestruct ("Cleanup: discarding lookahead",
+                YYTRANSLATE (yychar), &yylval, &yylloc, yyparser, ps);
+
+  /* If the stack is well-formed, pop the stack until it is empty,
+     destroying its entries as we go.  But free the stack regardless
+     of whether it is well-formed.  */
+  if (yystack.yyitems)
+    {
+      yyGLRState** yystates = yystack.yytops.yystates;
+      if (yystates)
+        {
+          size_t yysize = yystack.yytops.yysize;
+          size_t yyk;
+          for (yyk = 0; yyk < yysize; yyk += 1)
+            if (yystates[yyk])
+              {
+                while (yystates[yyk])
+                  {
+                    yyGLRState *yys = yystates[yyk];
+                 yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;
+                  if (yys->yypred != YY_NULLPTR)
+                      yydestroyGLRState ("Cleanup: popping", yys, yyparser, ps);
+                    yystates[yyk] = yys->yypred;
+                    yystack.yynextFree -= 1;
+                    yystack.yyspaceLeft += 1;
+                  }
+                break;
+              }
+        }
+      yyfreeGLRStack (&yystack);
+    }
+
+  return yyresult;
+}
+
+/* DEBUGGING ONLY */
+#if YYDEBUG
+static void
+yy_yypstack (yyGLRState* yys)
+{
+  if (yys->yypred)
+    {
+      yy_yypstack (yys->yypred);
+      YYFPRINTF (stderr, " -> ");
+    }
+  YYFPRINTF (stderr, "%d@%lu", yys->yylrState,
+             (unsigned long int) yys->yyposn);
+}
+
+static void
+yypstates (yyGLRState* yyst)
+{
+  if (yyst == YY_NULLPTR)
+    YYFPRINTF (stderr, "<null>");
+  else
+    yy_yypstack (yyst);
+  YYFPRINTF (stderr, "\n");
+}
+
+static void
+yypstack (yyGLRStack* yystackp, size_t yyk)
+{
+  yypstates (yystackp->yytops.yystates[yyk]);
+}
+
+#define YYINDEX(YYX)                                                         \
+    ((YYX) == YY_NULLPTR ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
+
+
+static void
+yypdumpstack (yyGLRStack* yystackp)
+{
+  yyGLRStackItem* yyp;
+  size_t yyi;
+  for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
+    {
+      YYFPRINTF (stderr, "%3lu. ",
+                 (unsigned long int) (yyp - yystackp->yyitems));
+      if (*(yybool *) yyp)
+        {
+          YYASSERT (yyp->yystate.yyisState);
+          YYASSERT (yyp->yyoption.yyisState);
+          YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
+                     yyp->yystate.yyresolved, yyp->yystate.yylrState,
+                     (unsigned long int) yyp->yystate.yyposn,
+                     (long int) YYINDEX (yyp->yystate.yypred));
+          if (! yyp->yystate.yyresolved)
+            YYFPRINTF (stderr, ", firstVal: %ld",
+                       (long int) YYINDEX (yyp->yystate
+                                             .yysemantics.yyfirstVal));
+        }
+      else
+        {
+          YYASSERT (!yyp->yystate.yyisState);
+          YYASSERT (!yyp->yyoption.yyisState);
+          YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
+                     yyp->yyoption.yyrule - 1,
+                     (long int) YYINDEX (yyp->yyoption.yystate),
+                     (long int) YYINDEX (yyp->yyoption.yynext));
+        }
+      YYFPRINTF (stderr, "\n");
+    }
+  YYFPRINTF (stderr, "Tops:");
+  for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
+    YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
+               (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
+  YYFPRINTF (stderr, "\n");
+}
+#endif
+
+#undef yylval
+#undef yychar
+#undef yynerrs
+#undef yylloc
+
+
+
+#line 466 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.c:2551
+
+
+#include <ctype.h>
+#include <stdio.h>
+
+void yy::parser::error(const yy::parser::location_type& l,
+                       const std::string& errstr) {
+  ps->ReportError(errstr, l.begin.line);
+}
+
+
+#line 3551 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:2551
+
+/*------------------.
+| Report an error.  |
+`------------------*/
+
+static void
+yyerror (const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps, const char* msg)
+{
+  YYUSE (yyparser);
+  YYUSE (ps);
+  yyparser.error (*yylocationp, msg);
+}
+
+
+
+namespace yy {
+#line 3568 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:2551
+  /// Build a parser object.
+  parser::parser (tidl::Parser* ps_yyarg)
+    :
+#if YYDEBUG
+      yycdebug_ (&std::cerr),
+#endif
+      ps (ps_yyarg)
+  {
+  }
+
+  parser::~parser ()
+  {
+  }
+
+  int
+  parser::parse ()
+  {
+    return ::yyparse (*this, ps);
+  }
+
+#if YYDEBUG
+  /*--------------------.
+  | Print this symbol.  |
+  `--------------------*/
+
+  inline void
+  parser::yy_symbol_value_print_ (int yytype,
+                           const semantic_type* yyvaluep,
+                           const location_type* yylocationp)
+  {
+    YYUSE (yylocationp);
+    YYUSE (yyvaluep);
+    std::ostream& yyoutput = debug_stream ();
+    std::ostream& yyo = yyoutput;
+    YYUSE (yyo);
+    YYUSE (yytype);
+  }
+
+
+  void
+  parser::yy_symbol_print_ (int yytype,
+                           const semantic_type* yyvaluep,
+                           const location_type* yylocationp)
+  {
+    *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
+               << ' ' << yytname[yytype] << " ("
+               << *yylocationp << ": ";
+    yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
+    *yycdebug_ << ')';
+  }
+
+  std::ostream&
+  parser::debug_stream () const
+  {
+    return *yycdebug_;
+  }
+
+  void
+  parser::set_debug_stream (std::ostream& o)
+  {
+    yycdebug_ = &o;
+  }
+
+
+  parser::debug_level_type
+  parser::debug_level () const
+  {
+    return yydebug;
+  }
+
+  void
+  parser::set_debug_level (debug_level_type l)
+  {
+    // Actually, it is yydebug which is really used.
+    yydebug = l;
+  }
+
+#endif
+
+} // yy
+#line 3649 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.cpp" // glr.c:2551
diff --git a/idlc/ast/tidlc_y.hpp b/idlc/ast/tidlc_y.hpp
new file mode 100644 (file)
index 0000000..fa8c197
--- /dev/null
@@ -0,0 +1,292 @@
+// A Bison parser, made by GNU Bison 3.0.2.
+
+// Skeleton interface for Bison GLR parsers in C++
+
+// Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton.  Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+// C++ GLR parser skeleton written by Akim Demaille.
+
+#ifndef YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_TIDLC_Y_HPP_INCLUDED
+# define YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_TIDLC_Y_HPP_INCLUDED
+
+
+#include <stdexcept>
+#include <string>
+#include <iostream>
+#include "location.hh"
+
+/* Debug traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+
+namespace yy {
+#line 52 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.hpp" // glr.cc:329
+
+
+  /// A Bison parser.
+  class parser
+  {
+  public:
+#ifndef YYSTYPE
+    /// Symbol semantic values.
+    union semantic_type
+    {
+    #line 37 "/home/gogo/work/next/tidl/idlc/ast/tidlc.yy" // glr.cc:329
+
+  tidl::Document* doc;
+  tidl::Interface* interf;
+  tidl::Declaration* decl;
+  tidl::Declarations* decls;
+  tidl::BaseType* b_type;
+  tidl::ParameterType* p_type;
+  tidl::Token* direction;
+  tidl::Parameter* param;
+  tidl::Parameters* params;
+  tidl::Token* token;
+  tidl::Structure* structure;
+  tidl::Element* elm;
+  tidl::Elements* elms;
+  tidl::Block* blk;
+  tidl::Attribute* attr;
+  tidl::Attributes* attrs;
+
+#line 82 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.hpp" // glr.cc:329
+    };
+#else
+    typedef YYSTYPE semantic_type;
+#endif
+    /// Symbol locations.
+    typedef location location_type;
+
+    /// Syntax errors thrown from user actions.
+    struct syntax_error : std::runtime_error
+    {
+      syntax_error (const location_type& l, const std::string& m);
+      location_type location;
+    };
+
+    /// Tokens.
+    struct token
+    {
+      enum yytokentype
+      {
+        T_LEFT = 258,
+        T_RIGHT = 259,
+        T_COMMA = 260,
+        T_SEMICOLON = 261,
+        T_BRACE_OPEN = 262,
+        T_BRACE_CLOSE = 263,
+        T_IN = 264,
+        T_OUT = 265,
+        T_REF = 266,
+        T_ASYNC = 267,
+        T_META_OPEN = 268,
+        T_META_CLOSE = 269,
+        T_EQUAL = 270,
+        T_DELEGATE = 271,
+        T_UNKNOWN = 272,
+        T_ID = 273,
+        T_STRUCTURE = 274,
+        T_INTERFACE = 275,
+        T_CHAR = 276,
+        T_SHORT = 277,
+        T_INT = 278,
+        T_LONG = 279,
+        T_FLOAT = 280,
+        T_DOUBLE = 281,
+        T_VOID = 282,
+        T_BUNDLE = 283,
+        T_STRING = 284,
+        T_BOOL = 285,
+        T_LIST = 286,
+        T_ARRAY = 287,
+        T_VALUE = 288,
+        T_SB_OPEN = 289,
+        T_SB_CLOSE = 290
+      };
+    };
+
+    /// (External) token type, as returned by yylex.
+    typedef token::yytokentype token_type;
+
+    /// Internal symbol number.
+    typedef int symbol_number_type;
+
+    /// Internal symbol number for tokens (subsumed by symbol_number_type).
+    typedef unsigned char token_number_type;
+
+    /// A complete symbol.
+    ///
+    /// Expects its Base type to provide access to the symbol type
+    /// via type_get().
+    ///
+    /// Provide access to semantic value and location.
+    template <typename Base>
+    struct basic_symbol : Base
+    {
+      /// Alias to Base.
+      typedef Base super_type;
+
+      /// Default constructor.
+      basic_symbol ();
+
+      /// Copy constructor.
+      basic_symbol (const basic_symbol& other);
+
+      /// Constructor for valueless symbols.
+      basic_symbol (typename Base::kind_type t,
+                    const location_type& l);
+
+      /// Constructor for symbols with semantic value.
+      basic_symbol (typename Base::kind_type t,
+                    const semantic_type& v,
+                    const location_type& l);
+
+      ~basic_symbol ();
+
+      /// Destructive move, \a s is emptied into this.
+      void move (basic_symbol& s);
+
+      /// The semantic value.
+      semantic_type value;
+
+      /// The location.
+      location_type location;
+
+    private:
+      /// Assignment operator.
+      basic_symbol& operator= (const basic_symbol& other);
+    };
+
+    /// Type access provider for token (enum) based symbols.
+    struct by_type
+    {
+      /// Default constructor.
+      by_type ();
+
+      /// Copy constructor.
+      by_type (const by_type& other);
+
+      /// The symbol type as needed by the constructor.
+      typedef token_type kind_type;
+
+      /// Constructor from (external) token numbers.
+      by_type (kind_type t);
+
+      /// Steal the symbol type from \a that.
+      void move (by_type& that);
+
+      /// The (internal) type number (corresponding to \a type).
+      /// -1 when this symbol is empty.
+      symbol_number_type type_get () const;
+
+      /// The token.
+      token_type token () const;
+
+      enum { empty = 0 };
+
+      /// The symbol type.
+      /// -1 when this symbol is empty.
+      token_number_type type;
+    };
+
+    /// "External" symbols: returned by the scanner.
+    typedef basic_symbol<by_type> symbol_type;
+
+
+
+    /// Build a parser object.
+    parser (tidl::Parser* ps_yyarg);
+    virtual ~parser ();
+
+    /// Parse.
+    /// \returns  0 iff parsing succeeded.
+    virtual int parse ();
+
+    /// The current debugging stream.
+    std::ostream& debug_stream () const;
+    /// Set the current debugging stream.
+    void set_debug_stream (std::ostream &);
+
+    /// Type for debugging levels.
+    typedef int debug_level_type;
+    /// The current debugging level.
+    debug_level_type debug_level () const;
+    /// Set the current debugging level.
+    void set_debug_level (debug_level_type l);
+
+  public:
+    /// Report a syntax error.
+    /// \param loc    where the syntax error is found.
+    /// \param msg    a description of the syntax error.
+    virtual void error (const location_type& loc, const std::string& msg);
+
+# if YYDEBUG
+  public:
+    /// \brief Report a symbol value on the debug stream.
+    /// \param yytype       The token type.
+    /// \param yyvaluep     Its semantic value.
+    /// \param yylocationp  Its location.
+    virtual void yy_symbol_value_print_ (int yytype,
+                                         const semantic_type* yyvaluep,
+                                         const location_type* yylocationp);
+    /// \brief Report a symbol on the debug stream.
+    /// \param yytype       The token type.
+    /// \param yyvaluep     Its semantic value.
+    /// \param yylocationp  Its location.
+    virtual void yy_symbol_print_ (int yytype,
+                                   const semantic_type* yyvaluep,
+                                   const location_type* yylocationp);
+  private:
+    // Debugging.
+    std::ostream* yycdebug_;
+#endif
+
+
+    // User arguments.
+    tidl::Parser* ps;
+  };
+
+
+
+#ifndef YYSTYPE
+# define YYSTYPE yy::parser::semantic_type
+#endif
+#ifndef YYLTYPE
+# define YYLTYPE yy::parser::location_type
+#endif
+
+
+} // yy
+#line 290 "/home/gogo/work/next/tidl/idlc/ast/tidlc_y.hpp" // glr.cc:329
+
+
+#endif // !YY_YY_HOME_GOGO_WORK_NEXT_TIDL_IDLC_AST_TIDLC_Y_HPP_INCLUDED
diff --git a/idlc/ast/type.cc b/idlc/ast/type.cc
new file mode 100644 (file)
index 0000000..09ad70e
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <utility>
+
+#include "idlc/ast/type.h"
+
+namespace tidl {
+
+Token::Token(std::string name, std::string comments)
+    : name_(std::move(name)), comments_(std::move(comments)) {
+}
+
+BaseType::BaseType(std::string name, std::string comments,
+                   bool user_defined)
+    : Token(std::move(name), std::move(comments)), user_defined_(user_defined) {
+}
+
+BaseType::BaseType(const BaseType& type)
+  : Token(type.ToString(), type.GetComments()),
+    user_defined_(type.IsUserDefinedType()) {
+  if (type.GetMetaType() != nullptr) {
+    SetMetaType(new BaseType(*type.GetMetaType()));
+  }
+}
+
+void BaseType::SetMetaType(BaseType* type) {
+  meta_type_.reset(type);
+}
+
+ParameterType::ParameterType(BaseType* type)
+    : type_(type),
+    dir_(Direction::IN) {
+}
+
+ParameterType::ParameterType(BaseType* type, const std::string& dir)
+    : type_(type) {
+  if (dir == "in")
+    dir_ = Direction::IN;
+  else if (dir == "out")
+    dir_ = Direction::OUT;
+  else if (dir == "ref")
+    dir_ = Direction::REF;
+  else
+    dir_ = Direction::IN;
+}
+
+}  // namespace tidl
diff --git a/idlc/ast/type.h b/idlc/ast/type.h
new file mode 100644 (file)
index 0000000..e3cf288
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_TYPE_H_
+#define IDLC_TYPE_H_
+
+#include <string>
+#include <memory>
+
+namespace tidl {
+
+class Token {
+ public:
+  Token(std::string name, std::string comments);
+  virtual ~Token() = default;
+
+  virtual std::string ToString() const { return name_; }
+  virtual std::string GetComments() const { return comments_; }
+
+ private:
+  std::string name_;
+  std::string comments_;
+};
+
+class BaseType : public Token {
+ public:
+  explicit BaseType(std::string name, std::string comments,
+                    bool user_defined = false);
+  BaseType(const BaseType& type);
+
+  void SetMetaType(BaseType* type);
+  const BaseType* GetMetaType() const {
+    return meta_type_.get();
+  }
+
+  std::string GetFullName() const {
+    std::string str = ToString();
+
+    if (meta_type_.get() != nullptr) {
+      str += "<";
+      str += meta_type_->GetFullName();
+      str += ">";
+    }
+
+    return str;
+  }
+
+  bool IsUserDefinedType() const {
+    return user_defined_;
+  }
+
+ private:
+  std::unique_ptr<BaseType> meta_type_;
+  bool user_defined_;
+};
+
+class ParameterType {
+ public:
+  enum class Direction {
+    IN,
+    OUT,
+    REF
+  };
+
+  ParameterType(BaseType* type, const std::string& dir);
+  explicit ParameterType(BaseType* type);
+  Direction GetDirection() const { return dir_; }
+  const BaseType& GetBaseType() const { return *type_; }
+
+ private:
+  std::unique_ptr<BaseType> type_;
+  Direction dir_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_TYPE_H_
diff --git a/idlc/attribute.cc b/idlc/attribute.cc
deleted file mode 100644 (file)
index 666e071..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/attribute.h"
-
-namespace tidl {
-
-Attribute::Attribute(std::string key, std::string value, unsigned line)
-    : key_(std::move(key)), value_(std::move(value)), line_(line) {
-}
-
-const std::string& Attribute::GetKey() const {
-  return key_;
-}
-
-const std::string& Attribute::GetValue() const {
-  return value_;
-}
-
-const unsigned Attribute::GetLine() const {
-  return line_;
-}
-
-void Attributes::Add(Attribute* attr) {
-  attrs_.emplace_back(attr);
-}
-
-const std::list<std::unique_ptr<Attribute>>& Attributes::GetAttrs() const {
-  return attrs_;
-}
-
-bool Attributes::Exist(Attribute* attr) const {
-  for (auto& a : attrs_) {
-    if (a->GetKey() == attr->GetKey() &&
-        a->GetValue() == attr->GetValue())
-      return true;
-  }
-
-  return false;
-}
-
-}  // namespace tidl
diff --git a/idlc/attribute.h b/idlc/attribute.h
deleted file mode 100644 (file)
index 360348e..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_ATTRIBUTE_H_
-#define IDLC_ATTRIBUTE_H_
-
-#include <string>
-#include <list>
-#include <memory>
-
-namespace tidl {
-
-class Attribute {
- public:
-  Attribute(std::string key, std::string value, unsigned line);
-
-  const std::string& GetKey() const;
-  const std::string& GetValue() const;
-  const unsigned GetLine() const;
-
- private:
-  std::string key_;
-  std::string value_;
-  unsigned line_;
-};
-
-class Attributes {
- public:
-  void Add(Attribute* attr);
-  const std::list<std::unique_ptr<Attribute>>& GetAttrs() const;
-  bool Exist(Attribute* attr) const;
-
- private:
-  std::list<std::unique_ptr<Attribute>> attrs_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_ATTRIBUTE_H_
diff --git a/idlc/block.cc b/idlc/block.cc
deleted file mode 100644 (file)
index 2a3ee86..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/type.h"
-#include "idlc/block.h"
-
-namespace tidl {
-
-Block::Block(std::string id, Block::Type type,
-             std::string comments, unsigned line)
-    : id_(std::move(id)), type_(type), comments_(std::move(comments)),
-      line_(line) {}
-
-const std::string& Block::GetID() const {
-  return id_;
-}
-
-const Block::Type& Block::GetType() const {
-  return type_;
-}
-
-const unsigned Block::GetLine() const {
-  return line_;
-}
-
-const std::string& Block::GetComments() const {
-  return comments_;
-}
-
-}  // namespace tidl
diff --git a/idlc/block.h b/idlc/block.h
deleted file mode 100644 (file)
index bbdd026..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_BLOCK_H_
-#define IDLC_BLOCK_H_
-
-#include <string>
-#include <memory>
-
-#include "idlc/declaration.h"
-
-namespace tidl {
-
-class Block {
- public:
-  enum Type {
-    TYPE_INTERFACE = 0,
-    TYPE_STRUCTURE,
-  };
-
-  Block(std::string id, Block::Type type, std::string comments,
-        unsigned line);
-  virtual ~Block() = default;
-
-  const std::string& GetID() const;
-  const Block::Type& GetType() const;
-  const unsigned GetLine() const;
-  const std::string& GetComments() const;
-
- private:
-  std::string id_;
-  Block::Type type_;
-  std::string comments_;
-  unsigned line_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_BLOCK_H_
-
diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc
deleted file mode 100644 (file)
index 8f8cde2..0000000
+++ /dev/null
@@ -1,1186 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <vector>
-
-#include "idlc/c_gen/c_body_gen_base.h"
-
-namespace {
-#include "idlc/c_gen/c_body_gen_base_cb.h"
-}
-
-namespace tidl {
-
-CBodyGeneratorBase::CBodyGeneratorBase(std::shared_ptr<Document> doc)
-    : CGeneratorBase(doc) {
-  parcel_type_map_ = {
-    {"char", "byte"},
-    {"int", "int32"},
-    {"short", "int16"},
-    {"long", "int64"},
-    {"string", "string"},
-    {"bool", "bool"},
-    {"float", "float"},
-    {"double", "double"},
-    {"bundle", "bundle"},
-  };
-}
-
-void CBodyGeneratorBase::GenStructures(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() == Block::TYPE_STRUCTURE) {
-      const Structure &st = static_cast<const Structure&>(*i);
-      GenStructure(stream, st);
-      for (auto& j : st.GetElements().GetElms()) {
-       auto& t = j->GetType();
-       AddStructureFromType(t);
-      }
-    } else {
-      const Interface &inf = static_cast<const Interface&>(*i);
-      for (auto& d : inf.GetDeclarations().GetDecls()) {
-        for (auto& p : d->GetParameters().GetParams()) {
-          if (IsDelegateType(inf, p->GetParameterType().GetBaseType()))
-            continue;
-          AddStructureFromType(p->GetParameterType().GetBaseType());
-        }
-      }
-    }
-  }
-
-  for (auto& p : GetStructures()) {
-    const Structure& st = *p.second;
-    GenStructure(stream, st);
-  }
-}
-
-void CBodyGeneratorBase::GenStructure(std::ofstream& stream,
-                                      const Structure& st) {
-  GenStructureDeclaration(stream, st);
-  GenStructureParcelSerializer(stream, st);
-  GenStructureParcelDeserializer(stream, st);
-  GenStructureConstructor(stream, st);
-  GenStructureDestructor(stream, st);
-  GenStructureCloner(stream, st);
-  GenStructureSetter(stream, st);
-  GenStructureGetter(stream, st);
-  GenStructureIterator(stream, st);
-  GenStructureRemover(stream, st);
-  GenStructureLengthGetter(stream, st);
-}
-
-void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
-                                                 const Structure& st) {
-  stream << SmartIndent(GenTemplateString(CB_STRUCT_DECL,
-        [&]()->std::string {
-          return st.GetComments();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : st.GetElements().GetElms()) {
-            str += NLine(1) + GetStringFromElementType(i->GetType()) +
-                i->GetID() + ";";
-            if (i->GetType().ToString() == "array")
-              str += NLine(1) + "int " + i->GetID() + "_size;";
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
-                                              const Structure& st) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_SERIALIZER, "##", GetStructIdWithNamespace(st)),
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : st.GetElements().GetElms()) {
-            str += NLine(1);
-            str += GetParcelWriteString(i->GetID(), i->GetType());
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
-                                                const Structure& st) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_DESERIALIZER, "##", GetStructIdWithNamespace(st)),
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : st.GetElements().GetElms()) {
-            str += NLine(1);
-            str += GetParcelReadString(i->GetID(), i->GetType());
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
-                                                 const Structure& st) {
-  stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##",
-      GetStructIdWithNamespace(st)));
-}
-
-void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
-                                                const Structure& st) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_DTOR, "##",
-            GetStructIdWithNamespace(st)),
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : st.GetElements().GetElms()) {
-            str += GetFinalizeString(i->GetID(), i->GetType(), "h->");
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
-                                            const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_SETTER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "list")
-              return "add";
-            return "set";
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().IsUserDefinedType())
-              return GetParcelParamTypeString(i->GetType());
-
-            if (i->GetType().ToString() == "list") {
-              if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                  i->GetType().GetMetaType()->ToString() == "list" ||
-                  i->GetType().GetMetaType()->ToString() == "array") {
-                return GetParcelParamTypeString(*i->GetType().GetMetaType());
-              } else {
-                return ConvertTypeToString(ParameterType::Direction::IN,
-                    *i->GetType().GetMetaType());
-              }
-            }
-
-            if (i->GetType().ToString() == "array") {
-              return GetStringFromElementType(i->GetType());
-            }
-
-            return ConvertTypeToString(ParameterType::Direction::IN,
-                i->GetType());
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "array") {
-              std::string str;
-              str += i->GetID();
-              str += ", ";
-              str += "int " + i->GetID() + "_size";
-              return str;
-            }
-            return i->GetID();
-          },
-          [&]()->std::string {
-            if ((i->GetType().IsUserDefinedType() ||
-                 i->GetType().ToString() == "string" ||
-                 i->GetType().ToString() == "bundle") ||
-                ((i->GetType().ToString() == "list" ||
-                  i->GetType().ToString() == "array") &&
-                  (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                   i->GetType().GetMetaType()->ToString() == "list" ||
-                   i->GetType().GetMetaType()->ToString() == "array" ||
-                   i->GetType().GetMetaType()->ToString() == "string" ||
-                   i->GetType().GetMetaType()->ToString() == "bundle")))
-              return "!h || !" + i->GetID();
-
-            return "!h";
-          },
-          [&]()->std::string {
-            std::string str;
-            str += NLine(1);
-            str += GetSetterString(i->GetID(), i->GetType());
-            return str;
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
-                                            const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() == "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_GETTER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "array")
-              return GetStringFromElementType(i->GetType()) + "*";
-
-            return ConvertTypeToString(ParameterType::Direction::OUT,
-                i->GetType());
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "array") {
-              std::string str;
-              str += i->GetID();
-              str += ", ";
-              str += "int *" + i->GetID() + "_size";
-              return str;
-            }
-            return i->GetID();
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "array") {
-              std::string str;
-              str += "!";
-              str += i->GetID();
-              str += " || ";
-              str += "!" + i->GetID() + "_size";
-              return str;
-            }
-            return "!" + i->GetID();
-          },
-          [&]()->std::string {
-            std::string str;
-            str += NLine(1);
-            str += GetGetterString(i->GetID(), i->GetType());
-            return str;
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
-                                              const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_ITERATOR,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                i->GetType().GetMetaType()->ToString() == "list" ||
-                i->GetType().GetMetaType()->ToString() == "array")
-              return GetParcelParamTypeString(*i->GetType().GetMetaType());
-
-            return ConvertTypeToString(ParameterType::Direction::IN,
-                *i->GetType().GetMetaType());
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            std::string str;
-            str += NLine(1);
-            str += GetIteratorString(i->GetID(), i->GetType());
-            return str;
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream,
-                                             const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_REMOVER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                i->GetType().GetMetaType()->ToString() == "list" ||
-                i->GetType().GetMetaType()->ToString() == "array" ||
-                i->GetType().GetMetaType()->ToString() == "string" ||
-                i->GetType().GetMetaType()->ToString() == "bundle")
-              return GetParcelParamTypeString(*i->GetType().GetMetaType());
-
-            return ConvertTypeToString(ParameterType::Direction::IN,
-                *i->GetType().GetMetaType(), false);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            std::string str;
-
-            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                i->GetType().GetMetaType()->ToString() == "list" ||
-                i->GetType().GetMetaType()->ToString() == "array") {
-              str = GetHandlePrefix()
-                  + GetFullNameFromType(*i->GetType().GetMetaType())
-                  + "_destroy(value);";
-            } else {
-              str = GetFinalizeString("value", *i->GetType().GetMetaType(), "");
-            }
-
-            if (str == "")
-              return "free(value);\n";
-            return str;
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
-                                                  const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_STRUCT_LENGTH_GETTER,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          }));
-  }
-}
-
-void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
-                                            const Structure& st) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_STRUCT_CLONER, "##", GetStructIdWithNamespace(st)),
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : st.GetElements().GetElms()) {
-            str += NLine(1);
-            str += GetClonerString(i->GetID(), i->GetType(), st);
-          }
-          return str;
-        }));
-}
-
-std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
-                                                    bool meta_type) {
-  if (type.IsUserDefinedType())
-    return "";
-
-  if (type.ToString() == "list" ||
-      type.ToString() == "array") {
-    if (meta_type)
-      return "";
-    return "array_count";
-  }
-
-  return parcel_type_map_[type.ToString()];
-}
-
-std::string CBodyGeneratorBase::GetParcelWriteFunctionString(
-    const BaseType& type, bool meta_type) {
-  std::string str = "rpc_port_parcel_write";
-  std::string parcel_type = GetParcelTypeString(type, meta_type);
-  if (parcel_type != "")
-    str += "_" + parcel_type;
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id,
-                                                     const BaseType& type) {
-  std::string str;
-  const char parcel[] = "$$(parcel, $$);";
-  const char ternary_operation[] = "## ? ## : \"\"";
-
-  str += GenTemplateString(parcel,
-      [&]()->std::string {
-        return GetParcelWriteFunctionString(type);
-      },
-      [&]()->std::string {
-        if (type.IsUserDefinedType())
-          return "&h->" + id + "->parcelable, h->" + id;
-        if (type.ToString() == "list")
-          return "g_list_length(h->" + id + ")";
-        if (type.ToString() == "array")
-          return "h->" + id + "_size";
-        if (type.ToString() == "string")
-          return ReplaceAll(ternary_operation, "##", "h->" + id);
-        return "h->" + id;
-      });
-
-  if (type.ToString() == "list") {
-    str += GenTemplateString(CB_WRITE_LIST_BLOCK,
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          return GenTemplateString(parcel,
-              [&]()->std::string {
-                return GetParcelWriteFunctionString(*type.GetMetaType(), true);
-              },
-              [&]()->std::string {
-                if (type.GetMetaType()->IsUserDefinedType() ||
-                    type.GetMetaType()->ToString() == "list" ||
-                    type.GetMetaType()->ToString() == "array")
-                  return "&value->parcelable, value";
-                if (type.GetMetaType()->ToString() == "bundle")
-                  return "value";
-                if (type.GetMetaType()->ToString() == "string")
-                  return ReplaceAll(ternary_operation, "##", "value");
-                return "*value";
-              });
-        });
-  } else if (type.ToString() == "array") {
-    str += GenTemplateString(CB_WRITE_ARRAY_BLOCK,
-        [&]()->std::string {
-          return "h->" + id + "_size";
-        },
-        [&]()->std::string {
-          return GenTemplateString(parcel,
-              [&]()->std::string {
-                return GetParcelWriteFunctionString(*type.GetMetaType(), true);
-              },
-              [&]()->std::string {
-                if (type.GetMetaType()->IsUserDefinedType() ||
-                    type.GetMetaType()->ToString() == "list" ||
-                    type.GetMetaType()->ToString() == "array")
-                  return "&h->" + id + "[i]->parcelable, h->" + id +"[i]";
-                if (type.GetMetaType()->ToString() == "string")
-                  return ReplaceAll(ternary_operation, "##", "h->" + id
-                      + "[i]");
-                return "h->" + id + "[i]";
-              });
-        });
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetParcelReadFunctionString(
-    const BaseType& type, bool meta_type) {
-  std::string str = "rpc_port_parcel_read";
-  std::string parcel_type = GetParcelTypeString(type, meta_type);
-  if (parcel_type != "")
-    str += "_" + parcel_type;
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id,
-                                                    const BaseType& type) {
-  std::string str;
-  const char parcel[] = "$$(parcel, $$);";
-
-  if (type.ToString() == "list") {
-    str += GenTemplateString(CB_READ_LIST_BLOCK,
-        [&]()->std::string {
-          return GenTemplateString(parcel,
-              [&]()->std::string {
-                return GetParcelReadFunctionString(type);
-              },
-              [&]()->std::string {
-                return "&len";
-              });
-        },
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          std::string s;
-
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array") {
-            s += GetConstructorString(*type.GetMetaType(), "value");
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!value";
-                },
-                [&]()->std::string {
-                  std::string ss;
-                  ss += "_E(\"Failed to create handle\");" + NLine(1);
-                  ss += "return;";
-                  return ss;
-                });
-            s += NLine(1);
-            s += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(*type.GetMetaType(), true);
-                },
-                [&]()->std::string {
-                  return "&value->parcelable, value";
-                });
-          } else if (type.GetMetaType()->ToString() == "string" ||
-                     type.GetMetaType()->ToString() == "bundle") {
-            s += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(*type.GetMetaType());
-                },
-                [&]()->std::string {
-                  return "&value";
-                });
-          } else {
-            s += "value = calloc(1, sizeof(*value));" + NLine(1);
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!value";
-                },
-                [&]()->std::string {
-                  std::string ss;
-                  ss += "_E(\"Out of memory\");" + NLine(1);
-                  ss += "return;";
-                  return ss;
-                });
-            s += NLine(1);
-            s += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(*type.GetMetaType());
-                },
-                [&]()->std::string {
-                  return "value";
-                });
-          }
-
-          return s;
-        },
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          return "h->" + id;
-        });
-  } else if (type.ToString() == "array") {
-    str += GenTemplateString(ReplaceAll(CB_READ_ARRAY_BLOCK, "##", id),
-        [&]()->std::string {
-          return GenTemplateString(parcel,
-              [&]()->std::string {
-                return GetParcelReadFunctionString(type);
-              },
-              [&]()->std::string {
-                return "&h->" + id + "_size";
-              });
-        },
-        [&]()->std::string {
-          return GetReturnTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          return GetErrorValue(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          std::string s;
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array") {
-            s += GetConstructorString(*type.GetMetaType(), "value");
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!value";
-                },
-                [&]()->std::string {
-                  std::string ss;
-                  ss += "_E(\"Failed to create handle\");" + NLine(1);
-                  ss += "return;";
-                  return ss;
-                });
-            s += NLine(1);
-            s += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(*type.GetMetaType(), true);
-                },
-                [&]()->std::string {
-                  return "&value->parcelable, value";
-                });
-          } else {
-            s += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(*type.GetMetaType());
-                },
-                [&]()->std::string {
-                  return "&value";
-                });
-          }
-          s += NLine(1);
-          s += GetSetterString("h->" + id + "[i]", "value");
-          return s;
-        });
-  } else if (type.IsUserDefinedType()) {
-    str += GenTemplateString(ReplaceAll(CB_READ_USER_DEFINED_BLOCK, "##", id),
-        [&]()->std::string {
-          return GetFullNameFromType(type);
-        });
-  } else {
-    str += GenTemplateString(parcel,
-        [&]()->std::string {
-          return GetParcelReadFunctionString(type);
-        },
-        [&]()->std::string {
-          if (type.IsUserDefinedType())
-            return "&h->" + id + "->parcelable, h->" + id;
-          return "&h->" + id;
-        });
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id,
-    const BaseType& type, const std::string& handle) {
-  std::string str;
-
-  if (!type.IsUserDefinedType() &&
-       type.ToString() != "list" &&
-       type.ToString() != "array" &&
-       type.ToString() != "string" &&
-       type.ToString() != "bundle")
-    return str;
-
-  if (type.ToString() == "list") {
-    str += GenTemplateString(CB_FINALIZE_LIST_BLOCK,
-        [&]()->std::string {
-          return handle + id;
-        },
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          return GenTemplateString(CB_IF_STATEMENT,
-              [&]()->std::string {
-                return "value";
-              },
-              [&]()->std::string {
-                return GetDestructorString(*type.GetMetaType(),
-                    "value", true) + NLine(1);
-              });
-        },
-        [&]()->std::string {
-          return handle + id;
-        });
-  } else if (type.ToString() == "array") {
-    if (!type.GetMetaType()->IsUserDefinedType() &&
-         type.GetMetaType()->ToString() != "list" &&
-         type.GetMetaType()->ToString() != "array" &&
-         type.GetMetaType()->ToString() != "string" &&
-         type.GetMetaType()->ToString() != "bundle") {
-      return GenTemplateString(CB_IF_STATEMENT,
-              [&]()->std::string {
-                return handle + id;
-              },
-              [&]()->std::string {
-                return "free(" + handle + id + ");";
-              });
-    }
-    str += GenTemplateString(CB_FINALIZE_ARRAY_BLOCK,
-        [&]()->std::string {
-          return handle + id + "_size";
-        },
-        [&]()->std::string {
-          return GenTemplateString(CB_IF_STATEMENT,
-              [&]()->std::string {
-                return handle + id + "[i]";
-              },
-              [&]()->std::string {
-                return GetDestructorString(*type.GetMetaType(),
-                    handle + id + "[i]", true) + NLine(1);
-              });
-        },
-        [&]()->std::string {
-          return handle + id;
-        });
-  } else {
-    str += GenTemplateString(CB_IF_STATEMENT,
-        [&]()->std::string {
-          return handle + id;
-        },
-        [&]()->std::string {
-          return GetDestructorString(type, handle + id) + NLine(1);
-        });
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
-                                                const BaseType& type) {
-  std::string str;
-
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "string" ||
-      type.ToString() == "bundle") {
-    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          std::string s;
-          s += GetDestructorString(type, "h->" + id) + NLine(1);
-          s += GetSetterString("h->" + id, "NULL");
-          return s;
-        });
-    str += NLine(1);
-
-    str += NLine(1);
-    str += GetSetterString(type, "h->" + id, id);
-    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-        [&]()->std::string {
-          return "!h->" + id;
-        },
-        [&]()->std::string {
-          std::string s;
-          s += "_E(\"Failed to duplicate data\");" + NLine(1);
-          s += "return -1;";
-          return s;
-        });
-    str += NLine(1);
-  } else if (type.ToString() == "list") {
-    str += GenTemplateString(CB_SETTER_LIST_BLOCK,
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          std::string s;
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "string" ||
-              type.GetMetaType()->ToString() == "bundle" ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array") {
-            s += GetSetterString(*type.GetMetaType(), "value", id);
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!value";
-                },
-                [&]()->std::string {
-                  std::string s;
-                  s += "_E(\"Out of memory\");" + NLine(1);
-                  s += "return -1;";
-                  return s;
-                });
-            s += NLine(1);
-          } else {
-            s += "value = calloc(1, sizeof(*value));" + NLine(1);
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!value";
-                },
-                [&]()->std::string {
-                  std::string s;
-                  s += "_E(\"Out of memory\");" + NLine(1);
-                  s += "return -1;";
-                  return s;
-                });
-            s += NLine(1);
-            s += GetSetterString("*value", id);
-          }
-          return s;
-        },
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          return "h->" + id;
-        });
-  } else if (type.ToString() == "array") {
-    str += GetFinalizeString(id, type, "h->") + NLine(1);
-    str += GetSetterString("h->" + id, "NULL");
-    str += NLine(1);
-    str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id),
-        [&]()->std::string {
-          return GetSetterString(*type.GetMetaType(),
-              "h->" + id + "[i]", id + "[i]");
-        });
-  } else {
-    str += GetSetterString(type, "h->" + id, id);
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetGetterString(const std::string& id,
-                                                const BaseType& type) {
-  std::string str;
-
-  if (type.ToString() == "array") {
-    str += GenTemplateString(ReplaceAll(CB_GETTER_ARRAY_BLOCK, "##", id),
-        [&]()->std::string {
-           return GetSetterString(*type.GetMetaType(),
-              "(*" + id + ")[i]", "h->" + id + "[i]");
-        });
-  } else {
-    if (type.IsUserDefinedType() ||
-        type.ToString() == "string" ||
-        type.ToString() == "bundle") {
-      str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-          [&]()->std::string {
-            return "!h->" + id;
-          },
-          [&]()->std::string {
-            std::string s;
-            s += "_E(\"Invalid parameter: h->" + id + " is NULL\");" + NLine(1);
-            s += "return -1;";
-            return s;
-          });
-      str += NLine(1);
-      str += NLine(1);
-    }
-
-    if (type.IsUserDefinedType()) {
-      str += GetHandlePrefix() + GetFullNameFromType(type) +
-        "_clone(h->"+ id + ", " + id +");" + NLine(1);
-    } else {
-      str += GetSetterString(type, "*" + id, "h->" + id);
-    }
-
-    if (type.IsUserDefinedType() ||
-        type.ToString() == "string" ||
-        type.ToString() == "bundle") {
-      str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-          [&]()->std::string {
-            return "*" + id + " == NULL";
-          },
-          [&]()->std::string {
-            std::string s;
-            s += "_E(\"Failed to duplicate " + id + "\");" + NLine(1);
-            s += "return -1;";
-            return s;
-          });
-      str += NLine(1);
-    }
-  }
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetIteratorString(const std::string& id,
-                                                  const BaseType& type) {
-  std::string str;
-
-  str += GenTemplateString(CB_ITERATOR_BLOCK,
-      [&]()->std::string {
-        return "h->" + id;
-      },
-      [&]()->std::string {
-        return GetParcelParamTypeString(*type.GetMetaType());
-      },
-      [&]()->std::string {
-        if (type.GetMetaType()->IsUserDefinedType() ||
-            type.GetMetaType()->ToString() == "list" ||
-            type.GetMetaType()->ToString() == "array" ||
-            type.GetMetaType()->ToString() == "string" ||
-            type.GetMetaType()->ToString() == "bundle")
-          return "value";
-
-        return "*value";
-      });
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
-                                                const BaseType& type,
-                                                const Structure& st) {
-  std::string str;
-
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "string" ||
-      type.ToString() == "bundle") {
-    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          std::string s;
-          s += GetSetterString(type, "handle->" + id, "h->" + id);
-          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-              [&]()->std::string {
-                return "!handle->" + id;
-              },
-              [&]()->std::string {
-                std::string ss;
-                ss += "_E(\"Failed to duplicate h->" + id + "\");" + NLine(1);
-                ss += "rpc_port_" + GetStructIdWithNamespace(st)
-                   + "_destroy(handle);" + NLine(1);
-                ss += "return -1;";
-                return ss;
-              });
-          return s;
-        });
-    str += NLine(1);
-  } else  if (type.ToString() == "list") {
-    str += GenTemplateString(CB_CLONER_LIST_BLOCK,
-        [&]()->std::string {
-          return "h->" + id;
-        },
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          return GetParcelParamTypeString(*type.GetMetaType());
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          std::string s;
-          if (type.GetMetaType()->IsUserDefinedType() ||
-              type.GetMetaType()->ToString() == "list" ||
-              type.GetMetaType()->ToString() == "array" ||
-              type.GetMetaType()->ToString() == "string" ||
-              type.GetMetaType()->ToString() == "bundle") {
-            s += GetSetterString(*type.GetMetaType(),
-                "new_value", "value");
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!new_value";
-                },
-              [&]()->std::string {
-                std::string ss;
-                ss += "_E(\"Failed to duplicate value\");" + NLine(1);
-                ss += "rpc_port_" + GetStructIdWithNamespace(st)
-                   + "_destroy(handle);" + NLine(1);
-                ss += "return -1;";
-                return ss;
-              });
-          } else {
-            s += "new_value = calloc(1, sizeof(*new_value));" + NLine(1);
-            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
-                [&]()->std::string {
-                  return "!new_value";
-                },
-                [&]()->std::string {
-                  std::string tmp;
-                  tmp += "_E(\"Out of memory\");" + NLine(1);
-                  tmp += "rpc_port_" + GetStructIdWithNamespace(st)
-                      + "_destroy(handle);" + NLine(1);
-                  tmp += "return -1;";
-                  return tmp;
-                });
-            s += NLine(1);
-            s += GetSetterString(*type.GetMetaType(),
-                "*new_value", "*value");
-          }
-          s += NLine(1);
-          return s;
-        },
-        [&]()->std::string {
-          return "handle->" + id;
-        },
-        [&]()->std::string {
-          return "handle->" + id;
-        });
-  } else if (type.ToString() == "array") {
-    str += GenTemplateString(ReplaceAll(CB_CLONER_ARRAY_BLOCK, "##", id),
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-           return GetSetterString(*type.GetMetaType(),
-              "handle->" + id + "[i]", "h->" + id + "[i]");
-        });
-  } else {
-    str += GetSetterString(type, "handle->" + id, "h->" + id);
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
-                                                    const std::string& value,
-                                                    bool container_value) {
-  std::string str;
-
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "list" ||
-      type.ToString() == "array") {
-    str += GetHandlePrefix() + GetFullNameFromType(type) +
-        "_destroy(" + value + ");";
-  } else if (type.ToString() == "bundle") {
-    str += "bundle_free(" + value + ");";
-  } else if (type.ToString() == "string" || container_value) {
-    str += "free(" + value + ");";
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
-                                                     const std::string& value) {
-  std::string str;
-  str += GetHandlePrefix() + GetFullNameFromType(type) +
-      "_create(&" + value + ");" + NLine(1);
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetSetterString(const BaseType& type,
-                                                const std::string& lvalue,
-                                                const std::string& rvalue) {
-  std::string str;
-
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "list" ||
-      type.ToString() == "array") {
-    str += GetHandlePrefix() + GetFullNameFromType(type) +
-        "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
-  } else if (type.ToString() == "string")  {
-    str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
-  } else if (type.ToString() == "bundle") {
-    str += lvalue + " = bundle_dup(" + rvalue + ");" + NLine(1);
-  } else {
-    str += GetSetterString(lvalue, rvalue);
-  }
-
-  return str;
-}
-
-std::string CBodyGeneratorBase::GetSetterString(const std::string& lvalue,
-                                                const std::string& rvalue) {
-  std::string str;
-  str += lvalue + " = " + rvalue + ";";
-  return str;
-}
-
-void CBodyGeneratorBase::GenIncludeHeader(std::ofstream& stream) {
-  std::string str;
-  str += "#include \"";
-  str += FileName.substr(0, FileName.length() - 2);
-  str += ".h\"";
-  stream << NLine(1);
-  stream << str;
-  stream << NLine(1);
-}
-
-void CBodyGeneratorBase::GenLogTag(std::ofstream& stream,
-                                   const std::string& log_tag) {
-  GenTemplate(CB_LOG_TAG, stream,
-      [&]()->std::string {
-        return log_tag;
-      });
-}
-
-void CBodyGeneratorBase::GenInterfaceEnumerations(std::ofstream& stream,
-                                                  const Interface& inf) {
-  GenInterfaceMethodEnumeration(stream, inf);
-  GenInterfaceDelegateEnumeration(stream, inf);
-}
-
-bool CBodyGeneratorBase::HasDelegate(const Interface& inf) const {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
-void CBodyGeneratorBase::GenInterfaceDelegateEnumeration(
-    std::ofstream& stream, const Interface& inf) {
-  int count = 1;
-
-  if (!HasDelegate(inf))
-    return;
-
-  stream << SmartIndent(GenTemplateString(CB_DELEGATE_ENUM,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : inf.GetDeclarations().GetDecls()) {
-            if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-              continue;
-
-            str += GenTemplateString(CB_DELEGATE_ENUM_FORMAT,
-                [&]()->std::string {
-                  return GetInterfaceIdWithNamespace(inf);
-                },
-                [&]()->std::string {
-                  return i->GetID();
-                },
-                [&]()->std::string {
-                  return std::to_string(count++);
-                });
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenInterfaceMethodEnumeration(
-    std::ofstream& stream, const Interface& inf) {
-  stream << SmartIndent(GenTemplateString(CB_METHOD_ENUM,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : inf.GetDeclarations().GetDecls()) {
-            if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-              continue;
-            str += GenTemplateString(CB_METHOD_ENUM_FORMAT,
-                [&]()->std::string {
-                  return GetInterfaceIdWithNamespace(inf);
-                },
-                [&]()->std::string {
-                  return i->GetID();
-                });
-          }
-          return str;
-        }));
-}
-
-void CBodyGeneratorBase::GenLogDefinition(std::ofstream& stream) {
-  stream << SmartIndent(CB_LOG_DEF);
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_body_gen_base.h b/idlc/c_gen/c_body_gen_base.h
deleted file mode 100644 (file)
index 32af40a..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_BODY_GEN_BASE_H_
-#define IDLC_C_GEN_C_BODY_GEN_BASE_H_
-
-#include <memory>
-#include <string>
-#include <map>
-
-#include "idlc/c_gen/c_gen_base.h"
-
-namespace tidl {
-
-class CBodyGeneratorBase : public CGeneratorBase {
- public:
-  explicit CBodyGeneratorBase(std::shared_ptr<Document> doc);
-  virtual ~CBodyGeneratorBase() = default;
-
-  void GenStructures(std::ofstream& stream);
-  void GenIncludeHeader(std::ofstream& stream);
-  void GenLogTag(std::ofstream& stream, const std::string& log_tag);
-  void GenInterfaceEnumerations(std::ofstream& stream, const Interface& inf);
-  std::string GetParcelWriteFunctionString(const BaseType& type,
-                                           bool meta_type = false);
-  std::string GetParcelReadFunctionString(const BaseType& type,
-                                          bool meta_type = false);
-  std::string GetDestructorString(const BaseType& type,
-                                  const std::string& value,
-                                  bool container_value = false);
-  std::string GetConstructorString(const BaseType& type,
-                                   const std::string& value);
-  bool HasDelegate(const Interface& inf) const;
-  void GenLogDefinition(std::ofstream& stream);
-
- private:
-  void GenInterfaceMethodEnumeration(std::ofstream& stream,
-                                     const Interface& inf);
-  void GenInterfaceDelegateEnumeration(std::ofstream& stream,
-                                       const Interface& inf);
-
- private:
-  void GenStructure(std::ofstream& stream, const Structure& st);
-  void GenStructureDeclaration(std::ofstream& stream, const Structure& st);
-  void GenStructureParcelSerializer(std::ofstream& stream, const Structure& st);
-  void GenStructureParcelDeserializer(std::ofstream& stream,
-                                      const Structure& st);
-  void GenStructureConstructor(std::ofstream& stream, const Structure& st);
-  void GenStructureDestructor(std::ofstream& stream, const Structure& st);
-  void GenStructureSetter(std::ofstream& stream, const Structure& st);
-  void GenStructureGetter(std::ofstream& stream, const Structure& st);
-  void GenStructureIterator(std::ofstream& stream, const Structure& st);
-  void GenStructureCloner(std::ofstream& stream, const Structure& st);
-  void GenStructureRemover(std::ofstream& stream, const Structure& st);
-  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
-
- private:
-  std::string GetParcelTypeString(const BaseType& type, bool meta_type);
-  std::string GetParcelWriteString(const std::string& id, const BaseType& type);
-  std::string GetParcelReadString(const std::string& id, const BaseType& type);
-  std::string GetFinalizeString(const std::string& id, const BaseType& type,
-                                const std::string& handle);
-  std::string GetSetterString(const std::string& id, const BaseType& type);
-  std::string GetGetterString(const std::string& id, const BaseType& type);
-  std::string GetIteratorString(const std::string& id, const BaseType& type);
-  std::string GetClonerString(const std::string& id, const BaseType& type,
-                              const Structure& st);
-  std::string GetSetterString(const BaseType& type, const std::string& lvalue,
-                              const std::string& rvalue);
-  std::string GetSetterString(const std::string& lvalue,
-                              const std::string& rvalue);
-
- private:
-  std::map<std::string, std::string> parcel_type_map_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_BODY_GEN_BASE_H_
diff --git a/idlc/c_gen/c_body_gen_base_cb.h b/idlc/c_gen/c_body_gen_base_cb.h
deleted file mode 100644 (file)
index a9d7ef1..0000000
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
-#define IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
-
-const char CB_STRUCT_DECL[] =
-R"__c_cb(
-$$struct $$_s {
-    rpc_port_parcelable_t parcelable;$$
-};
-)__c_cb";
-
-const char CB_STRUCT_SERIALIZER[] =
-R"__c_cb(
-static void __##_to(rpc_port_parcel_h parcel, void *data)
-{
-    rpc_port_##_h h = data;
-
-    if (!parcel || !h) {
-        _E("Invalid parameter");
-        return;
-    }
-$$
-}
-)__c_cb";
-
-const char CB_STRUCT_DESERIALIZER[] =
-R"__c_cb(
-static void __##_from(rpc_port_parcel_h parcel, void *data)
-{
-    rpc_port_##_h h = data;
-
-    if (!parcel || !h) {
-        _E("Invalid parameter");
-        return;
-    }
-$$
-}
-)__c_cb";
-
-const char CB_STRUCT_CTOR[] =
-R"__c_cb(
-int rpc_port_##_create(rpc_port_##_h *h)
-{
-    struct ##_s *handle;
-
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    handle = calloc(1, sizeof(struct ##_s));
-    if (!handle) {
-        _E("Out of memory");
-        return -1;
-    }
-
-    handle->parcelable.to = __##_to;
-    handle->parcelable.from = __##_from;
-
-    *h = handle;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_DTOR[] =
-R"__c_cb(
-int rpc_port_##_destroy(rpc_port_##_h h)
-{
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-$$
-    free(h);
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_SETTER[] =
-R"__c_cb(
-int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$)
-{
-    if ($$) {
-        _E("Invalid parameter");
-        return -1;
-    }
-$$
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$)
-{
-    if (!h || $$) {
-        _E("Invalid parameter");
-        return -1;
-    }
-$$
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_ITERATOR[] =
-R"__c_cb(
-int rpc_port_$$_foreach_$$(rpc_port_$$_h h,
-        bool (*callback)($$$$, void *user_data), void *user_data)
-{
-    if (!h || !callback) {
-        _E("Invalid parameter");
-        return -1;
-    }
-$$
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_REMOVER[] =
-R"__c_cb(
-int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth)
-{
-    GList *iter;
-
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    iter = g_list_nth(h->$$, nth);
-    if (iter == NULL)
-        return -1;
-
-    $$value = iter->data;
-    h->$$ = g_list_remove_link(h->$$, iter);
-$$
-    g_list_free(iter);
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_LENGTH_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length)
-{
-    if (!h || !length) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    *length = g_list_length(h->$$);
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_STRUCT_CLONER[] =
-R"__c_cb(
-int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)
-{
-    rpc_port_##_h handle = NULL;
-
-    if (!h || !clone) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    rpc_port_##_create(&handle);
-    if (!handle) {
-        _E("Failed to create ## handle");
-        return -1;
-    }
-$$
-    *clone = handle;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_WRITE_LIST_BLOCK[] =
-R"__c_cb(
-do {
-    GList *iter;
-
-    iter = $$;
-    while (iter) {
-        $$value = iter->data;
-
-        iter = g_list_next(iter);
-        if (!value) {
-            _W("Warning: value is NULL");
-            continue;
-        }
-        $$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_WRITE_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    for (int i = 0; i < $$; i++) {
-$$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_READ_LIST_BLOCK[] =
-R"__c_cb(do {
-    int len = 0;
-
-    $$
-    for (int i = 0; i < len; i++) {
-        $$value = NULL;
-
-        $$
-        $$ = g_list_append($$, value);
-    }
-} while (0);
-)__c_cb";
-
-const char CB_READ_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    $$
-
-    h->## = calloc(h->##_size, sizeof(*h->##));
-    if (!h->##) {
-        _E("Out of memory");
-        return;
-    }
-
-    for (int i = 0; i < h->##_size; i++) {
-        $$value = $$;
-
-        $$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_READ_USER_DEFINED_BLOCK[] =
-R"__c_cb(do {
-    rpc_port_$$_create(&h->##);
-    if (!h->##) {
-        _E("Failed to create handle");
-        return;
-    }
-
-    rpc_port_parcel_read(parcel, &h->##->parcelable, h->##);
-} while (0);
-)__c_cb";
-
-const char CB_FINALIZE_LIST_BLOCK[] =
-R"__c_cb(
-do {
-    GList *iter;
-
-    iter = $$;
-    while (iter) {
-        $$value = iter->data;
-        $$
-        iter = g_list_next(iter);
-    }
-    g_list_free($$);
-} while (0);
-)__c_cb";
-
-const char CB_FINALIZE_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    for (int i = 0; i < $$; i++) {
-        $$
-    }
-    free($$);
-} while (0);
-)__c_cb";
-
-const char CB_SETTER_LIST_BLOCK[] =
-R"__c_cb(
-do {
-    $$value = NULL;
-
-    $$
-    $$ = g_list_append($$, value);
-} while (0);
-)__c_cb";
-
-const char CB_SETTER_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    h->## = calloc(##_size, sizeof(*##));
-    if (!h->##) {
-        _E("Out of memory");
-        return -1;
-    }
-    h->##_size = ##_size;
-
-    for (int i = 0; i < h->##_size; i++) {
-        $$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_GETTER_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    if (h->##_size == 0) {
-        _W("## is empty");
-        break;
-    }
-
-    *## = calloc(h->##_size, sizeof(*h->##));
-    if (!*##) {
-        _E("Out of memory");
-        return -1;
-    }
-    *##_size = h->##_size;
-
-    for (int i = 0; i < h->##_size; i++) {
-        $$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_ITERATOR_BLOCK[] =
-R"__c_cb(
-do {
-    GList *iter;
-
-    iter = $$;
-    while (iter) {
-        $$value = iter->data;
-
-        iter = g_list_next(iter);
-        if (!value) {
-            _W("Warning: value is NULL");
-            continue;
-        }
-
-        bool ret = callback($$, user_data);
-        if (!ret)
-            break;
-    }
-} while (0);
-)__c_cb";
-
-const char CB_CLONER_LIST_BLOCK[] =
-R"__c_cb(
-do {
-    GList *iter;
-
-    iter = $$;
-    while (iter) {
-        $$new_value;
-        $$value = iter->data;
-
-        if (!value) {
-            _E("Error: value is NULL");
-            rpc_port_$$_destroy(handle);
-            return -1;
-        }
-
-        $$
-        $$ = g_list_append($$, new_value);
-        iter = g_list_next(iter);
-    }
-} while (0);
-)__c_cb";
-
-const char CB_CLONER_ARRAY_BLOCK[] =
-R"__c_cb(
-do {
-    if (h->##_size == 0) {
-        _W("## is empty");
-        break;
-    }
-
-    handle->## = calloc(h->##_size, sizeof(*h->##));
-    if (!handle->##) {
-        _E("Out of memory");
-        rpc_port_$$_destroy(handle);
-        return -1;
-    }
-    handle->##_size = h->##_size;
-
-    for (int i = 0; i < h->##_size; i++) {
-        $$
-    }
-} while (0);
-)__c_cb";
-
-const char CB_IF_STATEMENT_WITH_BRACES[] =
-R"__c_cb(if ($$) {
-    $$
-}
-)__c_cb";
-
-const char CB_IF_STATEMENT[] =
-R"__c_cb(if ($$)
-    $$
-)__c_cb";
-
-const char CB_DELEGATE_ENUM_FORMAT[] = "\n$$_DELEGATE_$$ = $$,";
-
-const char CB_DELEGATE_ENUM[] =
-R"__c_cb(
-enum $$_delegate_e {$$
-};
-)__c_cb";
-
-const char CB_METHOD_ENUM_FORMAT[] = "\n$$_METHOD_$$,";
-
-const char CB_METHOD_ENUM[] =
-R"__c_cb(
-enum $$_method_e {
-    $$_METHOD_Result,
-    $$_METHOD_Callback,$$
-};
-)__c_cb";
-
-const char CB_LOG_TAG[] =
-R"__c_cb(
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "$$"
-)__c_cb";
-
-const char CB_LOG_DEF[] =
-R"__c_cb(
-#ifdef _E
-#undef _E
-#endif
-
-#ifdef _W
-#undef _W
-#endif
-
-#ifdef _I
-#undef _I
-#endif
-
-#ifdef _D
-#undef _D
-#endif
-
-#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
diff --git a/idlc/c_gen/c_gen_base.cc b/idlc/c_gen/c_gen_base.cc
deleted file mode 100644 (file)
index 0b975f2..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <ctime>
-#include <cassert>
-#include <vector>
-#include <sstream>
-#include <algorithm>
-
-#include "idlc/c_gen/c_gen_base.h"
-
-namespace {
-#include "idlc/c_gen/c_gen_base_cb.h"
-}
-
-namespace tidl {
-
-CGeneratorBase::CGeneratorBase(std::shared_ptr<Document> doc)
-    : Generator(doc) {
-  structures_.clear();
-  type_map_ = {
-      {"char", "char "}, {"int", "int "}, {"short", "short "},
-      {"long", "long long "}, {"bool", "bool "}, {"string", "char *"},
-      {"list", "GList *"}, {"float", "float "}, {"double", "double "},
-      {"bundle", "bundle *"}, {"void", "void "}
-  };
-}
-
-std::string CGeneratorBase::Tab(int cnt) {
-  std::string str;
-
-  for (int i = 0; i < cnt; ++i) {
-    str += "\t";
-  }
-
-  return str;
-}
-
-std::string CGeneratorBase::NLine(int cnt) {
-  std::string str;
-
-  for (int i = 0; i < cnt; ++i) {
-    str += "\n";
-  }
-
-  return str;
-}
-
-std::string CGeneratorBase::ConvertTypeToString(
-    ParameterType::Direction direction, const BaseType& type, bool bconst) {
-  if (type.IsUserDefinedType()) {
-    if (direction == ParameterType::Direction::IN)
-      return GetHandlePrefix() + type.ToString() + "_h ";
-    else
-      return GetHandlePrefix() + type.ToString() + "_h *";
-  }
-
-  if (type.ToString() == "array") {
-    if (direction == ParameterType::Direction::IN) {
-      return GetReturnTypeString(*type.GetMetaType()) + "*";
-    } else {
-      return GetReturnTypeString(*type.GetMetaType()) + "**";
-    }
-  }
-
-  if (type.ToString() == "string") {
-    if (direction == ParameterType::Direction::IN) {
-      if (!bconst)
-        return "char *";
-      return "const char *";
-    } else
-      return "char **";
-  }
-
-  if (direction == ParameterType::Direction::IN && bconst)
-    return type_map_[type.ToString()];
-
-  return type_map_[type.ToString()] + "*";
-}
-
-std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) {
-  std::string str = type.ToString();
-
-  if (type.GetMetaType() != nullptr) {
-    str += "_";
-    str += GetFullNameFromType(*type.GetMetaType());
-  }
-
-  return str;
-}
-
-std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type,
-                                                     bool is_pointer) {
-  if (type.IsUserDefinedType())
-    return GetHandlePrefix() + type.ToString() + "_h ";
-
-  if (type.ToString() == "list" ||
-      type.ToString() == "array")
-    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
-
-  if (type.ToString() == "string")
-    return "char *";
-
-  if (type.ToString() == "bundle")
-    return "bundle *";
-
-  if (is_pointer)
-    return type_map_[type.ToString()] + "*";
-
-  return type_map_[type.ToString()];
-}
-
-std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
-  if (type.IsUserDefinedType())
-    return GetHandlePrefix() + type.ToString() + "_h ";
-
-  if (type.ToString() == "list" ||
-      type.ToString() == "array")
-    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
-
-  return type_map_[type.ToString()];
-}
-
-void CGeneratorBase::AddStructureFromType(const BaseType& type) {
-  if (type.GetMetaType() == nullptr)
-    return;
-
-  BaseType* t = new BaseType(type);
-  assert(t != nullptr);
-
-  std::string type_name = GetFullNameFromType(type);
-  Element* elm = new Element(type_name + "s", t, "", __LINE__);
-  assert(elm != nullptr);
-
-  Elements* elms = new Elements();
-  assert(elms != nullptr);
-  elms->Add(elm);
-
-  Structure* st = new Structure(type_name, elms, "", __LINE__);
-  assert(st != nullptr);
-
-  if (StructureExist(*st)) {
-    delete st;
-  } else {
-    structures_[type_name] = std::unique_ptr<Structure>(st);
-  }
-
-  AddStructureFromType(*type.GetMetaType());
-}
-
-std::string CGeneratorBase::SmartIndent(std::string lines) {
-  std::stringstream ss(lines);
-  std::string result;
-  std::string line;
-  std::string next_line;
-  std::string tab;
-  std::string back;
-  std::size_t found;
-  bool if_statement = false;
-  bool continuous = false;
-  int tab_size = 0;
-  int line_count = 0;
-
-  while (std::getline(ss, next_line, '\n')) {
-    line_count++;
-    if (line_count == 1) {
-      line = Trim(next_line);
-      continue;
-    }
-
-    tab.clear();
-    found = line.find('}');
-    if (found != std::string::npos) {
-      tab_size--;
-    }
-
-    if (line.length() > 0) {
-      tab += Tab(tab_size);
-    }
-
-    if (continuous && tab_size == 0 &&
-        found == std::string::npos) {
-      tab += Tab(2);
-    }
-
-    if (found == std::string::npos && if_statement) {
-      tab_size--;
-      if_statement = false;
-    }
-
-    continuous = false;
-    back = line.back();
-    if (back == ",")
-      continuous = true;
-
-    if (line.empty() ||
-        line.length() == 0 ||
-        std::all_of(line.begin(), line.end(), isspace)) {
-      std::string n_line = Trim(next_line);
-      if (n_line.empty() ||
-          n_line.length() == 0 ||
-          n_line.find('}') != std::string::npos ||
-          std::all_of(n_line.begin(), n_line.end(), isspace)) {
-        line = n_line;
-        continue;
-      } else {
-        result += tab + line;
-        result += NLine(1);
-      }
-    } else {
-      result += tab + line;
-      result += NLine(1);
-    }
-
-    found = line.find('{');
-    if (found != std::string::npos) {
-      tab_size++;
-    } else {
-      found = line.find("if (");
-      if (found != std::string::npos) {
-        tab_size++;
-        if_statement = true;
-      }
-    }
-
-    line = Trim(next_line);
-  }
-
-  result += line;
-  result += NLine(1);
-
-  return result;
-}
-
-std::string CGeneratorBase::Trim(const std::string& str) {
-  std::size_t first = str.find_first_not_of(" \t\r\n");
-  if (first == std::string::npos)
-    return str;
-
-  std::size_t last = str.find_last_not_of(" \t\r\n");
-  return str.substr(first, (last - first + 1));
-}
-
-void CGeneratorBase::GenVersion(std::ofstream& stream) {
-  GenTemplate(CB_VERSION, stream,
-      [&]()->std::string {
-        return FULLVER;
-      });
-}
-
-void CGeneratorBase::GenIncludeDefaultHeaders(std::ofstream& stream,
-                                              bool body) {
-  if (body) {
-    stream << CB_BODY_HEADER;
-  } else {
-    stream << CB_HEADER;
-  }
-}
-
-void CGeneratorBase::GenGNUSourceDefinition(std::ofstream& stream) {
-  const char format[] = "#define _GNU_SOURCE\n";
-
-  stream << NLine(1);
-  stream << std::string(format);
-}
-
-bool CGeneratorBase::StructureExist(const Structure& st) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-
-    const Structure &s = static_cast<const Structure&>(*i);
-    if (s.GetID() == st.GetID())
-      return true;
-  }
-  return false;
-}
-
-std::string CGeneratorBase::GetParamTypeString(
-    ParameterType::Direction direction, const BaseType& type) {
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "list" ||
-      type.ToString() == "array") {
-    if (direction == ParameterType::Direction::IN)
-      return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
-    else
-      return GetHandlePrefix() + GetFullNameFromType(type) + "_h *";
-  }
-
-  if (type.ToString() == "string") {
-    if (direction == ParameterType::Direction::IN)
-      return "const char *";
-    else
-      return "char **";
-  }
-
-  if (direction == ParameterType::Direction::IN)
-    return type_map_[type.ToString()];
-
-  return type_map_[type.ToString()] + "*";
-}
-
-std::string CGeneratorBase::GetErrorValue(const BaseType& type) {
-  if (type.IsUserDefinedType() ||
-      type.ToString() == "list" ||
-      type.ToString() == "array" ||
-      type.ToString() == "bundle" ||
-      type.ToString() == "string")
-    return "NULL";
-  if (type.ToString() == "bool")
-    return "false";
-  if (type.ToString() == "char")
-    return "0";
-  return "-1";
-}
-
-std::string CGeneratorBase::GetStringFromElementType(const BaseType& type) {
-  if (type.IsUserDefinedType())
-    return GetHandlePrefix() + type.ToString() + "_h ";
-  if (type.ToString() == "array")
-    return GetReturnTypeString(*type.GetMetaType()) + "*";
-
-  return type_map_[type.ToString()];
-}
-
-std::string CGeneratorBase::GetStructIdWithNamespace(const Structure& st) {
-  if (!HasNamespace())
-    return st.GetID();
-  return GetFileNamespace() + "_" + st.GetID();
-}
-
-std::string CGeneratorBase::GetInterfaceIdWithNamespace(const Interface& inf) {
-  if (!HasNamespace())
-    return inf.GetID();
-  return GetFileNamespace() + "_" + inf.GetID();
-}
-
-std::string CGeneratorBase::GetHandlePrefix() {
-  if (!HasNamespace())
-    return "rpc_port_";
-  return "rpc_port_" + GetFileNamespace() + "_";
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_gen_base.h b/idlc/c_gen/c_gen_base.h
deleted file mode 100644 (file)
index 1bc2ae3..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_GEN_BASE_H_
-#define IDLC_C_GEN_C_GEN_BASE_H_
-
-#include <memory>
-#include <string>
-#include <map>
-
-#include "idlc/type.h"
-#include "idlc/structure.h"
-#include "idlc/generator.h"
-
-namespace tidl {
-
-class CGeneratorBase : public Generator {
- public:
-  explicit CGeneratorBase(std::shared_ptr<Document> doc);
-  virtual ~CGeneratorBase() = default;
-
-  std::string Trim(const std::string& str);
-  std::string SmartIndent(std::string lines);
-  std::string Tab(int cnt);
-  std::string NLine(int cnt);
-  std::string ConvertTypeToString(ParameterType::Direction direction,
-                                  const BaseType& type, bool bconst = true);
-  std::string GetFullNameFromType(const BaseType& type);
-  std::string GetParcelParamTypeString(const BaseType& type,
-                                       bool is_pointer = true);
-  std::string GetReturnTypeString(const BaseType& type);
-  std::string GetParamTypeString(ParameterType::Direction direction,
-                                 const BaseType& type);
-  std::string GetStringFromElementType(const BaseType& type);
-  std::string GetErrorValue(const BaseType& type);
-  void AddStructureFromType(const BaseType& type);
-  const std::map<std::string, std::unique_ptr<Structure>>& GetStructures(void) {
-    return structures_;
-  }
-
-  void GenVersion(std::ofstream& stream);
-  void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true);
-  void GenGNUSourceDefinition(std::ofstream& stream);
-  std::string GetStructIdWithNamespace(const Structure& st);
-  std::string GetInterfaceIdWithNamespace(const Interface& inf);
-  std::string GetHandlePrefix();
-
- private:
-  bool StructureExist(const Structure& st);
-
- private:
-  std::map<std::string, std::unique_ptr<Structure>> structures_;
-  std::map<std::string, std::string> type_map_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_GEN_BASE_H_
diff --git a/idlc/c_gen/c_gen_base_cb.h b/idlc/c_gen/c_gen_base_cb.h
deleted file mode 100644 (file)
index 5af4d66..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_GEN_BASE_CB_H_
-#define IDLC_C_GEN_C_GEN_BASE_CB_H_
-
-const char CB_VERSION[] =
-R"__c_cb(/*
- * Generated by tidlc $$.
- */
-)__c_cb";
-
-const char CB_HEADER[] =
-R"__c_cb(
-#include <stdbool.h>
-#include <bundle.h>
-)__c_cb";
-
-const char CB_BODY_HEADER[] =
-R"__c_cb(
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <libgen.h>
-#include <glib.h>
-#include <dlog.h>
-#include <rpc-port.h>
-#include <rpc-port-parcel.h>
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_GEN_BASE_CB_H_
diff --git a/idlc/c_gen/c_header_gen_base.cc b/idlc/c_gen/c_header_gen_base.cc
deleted file mode 100644 (file)
index ee86046..0000000
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <vector>
-
-#include "idlc/c_gen/c_header_gen_base.h"
-
-namespace {
-#include "idlc/c_gen/c_header_gen_base_cb.h"
-}
-
-namespace tidl {
-
-CHeaderGeneratorBase::CHeaderGeneratorBase(std::shared_ptr<Document> doc)
-    : CGeneratorBase(doc) {}
-
-void CHeaderGeneratorBase::GenPragmaOnce(std::ofstream& stream) {
-  const char format[] = "#pragma once\n";
-
-  stream << NLine(1);
-  stream << std::string(format);
-}
-
-void CHeaderGeneratorBase::GenExplicitLinkageOpen(std::ofstream& stream) {
-  stream << CB_EXPLICIT_LINKAGE_OPEN;
-}
-
-void CHeaderGeneratorBase::GenExplicitLinkageClose(std::ofstream& stream) {
-  stream << CB_EXPLICIT_LINKAGE_CLOSE;
-}
-
-void CHeaderGeneratorBase::GenStructures(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() == Block::TYPE_STRUCTURE) {
-      const Structure &st = static_cast<const Structure&>(*i);
-      GenStructure(stream, st);
-      for (auto& j : st.GetElements().GetElms()) {
-       auto& t = j->GetType();
-       AddStructureFromType(t);
-      }
-    } else {
-      const Interface &inf = static_cast<const Interface&>(*i);
-      for (auto& d : inf.GetDeclarations().GetDecls()) {
-        for (auto& p : d->GetParameters().GetParams()) {
-          if (IsDelegateType(inf, p->GetParameterType().GetBaseType()))
-            continue;
-          AddStructureFromType(p->GetParameterType().GetBaseType());
-        }
-      }
-    }
-  }
-
-  for (auto& p : GetStructures()) {
-    const Structure& st = *p.second;
-    GenStructure(stream, st);
-  }
-}
-
-void CHeaderGeneratorBase::GenStructure(std::ofstream& stream,
-                                        const Structure& st) {
-  GenStructureDeclaration(stream, st);
-  GenStructureConstructor(stream, st);
-  GenStructureDestructor(stream, st);
-  GenStructureCloner(stream, st);
-  GenStructureSetter(stream, st);
-  GenStructureGetter(stream, st);
-  GenStructureIterator(stream, st);
-  GenStructureRemover(stream, st);
-  GenStructureLengthGetter(stream, st);
-}
-
-void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
-                                                   const Structure& st) {
-  GenTemplate(CB_STRUCT_DECL, stream,
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      },
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      });
-}
-
-void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
-                                                   const Structure& st) {
-  GenTemplate(CB_STRUCT_CTOR, stream,
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      },
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      });
-}
-
-void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
-                                                  const Structure& st) {
-  GenTemplate(CB_STRUCT_DTOR, stream,
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      },
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      });
-}
-
-void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
-                                              const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    GenTemplate(CB_STRUCT_SETTER, stream,
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "list")
-              return "add";
-            return "set";
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetStructIdWithNamespace(st);
-          },
-          [&]()->std::string {
-            if (i->GetType().IsUserDefinedType())
-              return GetParcelParamTypeString(i->GetType());
-
-            if (i->GetType().ToString() == "list") {
-              if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-                  i->GetType().GetMetaType()->ToString() == "list" ||
-                  i->GetType().GetMetaType()->ToString() == "array") {
-                return GetParcelParamTypeString(*i->GetType().GetMetaType());
-              } else {
-                return ConvertTypeToString(ParameterType::Direction::IN,
-                    *i->GetType().GetMetaType());
-              }
-            }
-
-            if (i->GetType().ToString() == "array") {
-              return GetStringFromElementType(i->GetType());
-            }
-
-            return ConvertTypeToString(ParameterType::Direction::IN,
-                i->GetType());
-          },
-          [&]()->std::string {
-            if (i->GetType().ToString() == "array") {
-              std::string str;
-              str += i->GetID();
-              str += ", ";
-              str += "int " + i->GetID() + "_size";
-              return str;
-            }
-            return i->GetID();
-          });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
-                                              const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() == "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_GETTER, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          if (i->GetType().ToString() == "array")
-              return GetStringFromElementType(i->GetType()) + "*";
-
-          return ConvertTypeToString(ParameterType::Direction::OUT,
-              i->GetType());
-        },
-        [&]()->std::string {
-          if (i->GetType().ToString() == "array") {
-            std::string str;
-            str += i->GetID();
-            str += ", ";
-            str += "int *" + i->GetID() + "_size";
-            return str;
-          }
-          return i->GetID();
-        });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
-                                                const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_ITERATOR, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          if (i->GetType().GetMetaType()->IsUserDefinedType() ||
-              i->GetType().GetMetaType()->ToString() == "list" ||
-              i->GetType().GetMetaType()->ToString() == "array")
-            return GetParcelParamTypeString(*i->GetType().GetMetaType());
-
-          return ConvertTypeToString(ParameterType::Direction::IN,
-              *i->GetType().GetMetaType());
-        },
-        [&]()->std::string {
-          return i->GetID();
-        });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureRemover(std::ofstream& stream,
-                                               const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_REMOVER, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
-                                                    const Structure& st) {
-  for (auto& i : st.GetElements().GetElms()) {
-    if (i->GetType().ToString() != "list")
-      continue;
-
-    GenTemplate(CB_STRUCT_LENGTH_GETTER, stream,
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          return GetStructIdWithNamespace(st);
-        });
-  }
-}
-
-void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
-                                              const Structure& st) {
-  GenTemplate(CB_STRUCT_CLONER, stream,
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      },
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      },
-      [&]()->std::string {
-        return GetStructIdWithNamespace(st);
-      });
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_header_gen_base.h b/idlc/c_gen/c_header_gen_base.h
deleted file mode 100644 (file)
index 494fac4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_HEADER_GEN_BASE_H_
-#define IDLC_C_GEN_C_HEADER_GEN_BASE_H_
-
-#include <memory>
-#include <string>
-#include <map>
-
-#include "idlc/c_gen/c_gen_base.h"
-
-namespace tidl {
-
-class CHeaderGeneratorBase : public CGeneratorBase {
- public:
-  explicit CHeaderGeneratorBase(std::shared_ptr<Document> doc);
-  virtual ~CHeaderGeneratorBase() = default;
-
-  void GenPragmaOnce(std::ofstream& stream);
-  void GenExplicitLinkageOpen(std::ofstream& stream);
-  void GenExplicitLinkageClose(std::ofstream& stream);
-  void GenStructures(std::ofstream& stream);
-
- private:
-  void GenStructure(std::ofstream& stream, const Structure& st);
-  void GenStructureDeclaration(std::ofstream& stream, const Structure& st);
-  void GenStructureParcelTo(std::ofstream& stream, const Structure& st);
-  void GenStructureParcelFrom(std::ofstream& stream, const Structure& st);
-  void GenStructureConstructor(std::ofstream& stream, const Structure& st);
-  void GenStructureDestructor(std::ofstream& stream, const Structure& st);
-  void GenStructureSetter(std::ofstream& stream, const Structure& st);
-  void GenStructureGetter(std::ofstream& stream, const Structure& st);
-  void GenStructureIterator(std::ofstream& stream, const Structure& st);
-  void GenStructureRemover(std::ofstream& stream, const Structure& st);
-  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
-  void GenStructureCloner(std::ofstream& stream, const Structure& st);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_HEADER_GEN_BASE_H_
diff --git a/idlc/c_gen/c_header_gen_base_cb.h b/idlc/c_gen/c_header_gen_base_cb.h
deleted file mode 100644 (file)
index e0229f5..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
-#define IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
-
-const char CB_EXPLICIT_LINKAGE_OPEN[] =
-R"__c_cb(
-#ifdef __cplusplus
-extern "C" {
-#endif
-)__c_cb";
-
-const char CB_EXPLICIT_LINKAGE_CLOSE[] =
-R"__c_cb(
-#ifdef __cplusplus
-}
-#endif
-)__c_cb";
-
-const char CB_STRUCT_DECL[] =
-R"__c_cb(
-typedef struct $$_s *rpc_port_$$_h;
-)__c_cb";
-
-const char CB_STRUCT_CTOR[] =
-R"__c_cb(
-int rpc_port_$$_create(rpc_port_$$_h *h);
-)__c_cb";
-
-const char CB_STRUCT_DTOR[] =
-R"__c_cb(
-int rpc_port_$$_destroy(rpc_port_$$_h h);
-)__c_cb";
-
-const char CB_STRUCT_SETTER[] =
-R"__c_cb(
-int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$);
-)__c_cb";
-
-const char CB_STRUCT_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$);
-)__c_cb";
-
-const char CB_STRUCT_ITERATOR[] =
-R"__c_cb(
-int rpc_port_$$_foreach_$$(rpc_port_$$_h h,
-        bool (*callback)($$$$, void *user_data), void *user_data);
-)__c_cb";
-
-const char CB_STRUCT_REMOVER[] =
-R"__c_cb(
-int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth);
-)__c_cb";
-
-const char CB_STRUCT_LENGTH_GETTER[] =
-R"__c_cb(
-int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length);
-)__c_cb";
-
-const char CB_STRUCT_CLONER[] =
-R"__c_cb(
-int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc
deleted file mode 100644 (file)
index 39683d4..0000000
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/c_gen/c_proxy_body_gen.h"
-
-namespace {
-#include "idlc/c_gen/c_proxy_body_gen_cb.h"
-}
-
-namespace tidl {
-
-CProxyBodyGen::CProxyBodyGen(std::shared_ptr<Document> doc)
-    : CBodyGeneratorBase(doc) {}
-
-void CProxyBodyGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  GenGNUSourceDefinition(stream);
-  GenIncludeDefaultHeaders(stream);
-  GenIncludeHeader(stream);
-  GenLogTag(stream, std::string("RPC_PORT_PROXY"));
-  GenLogDefinition(stream);
-  GenTypedefProxyDelegate(stream);
-  GenStructures(stream);
-  GenInterfaces(stream);
-}
-
-void CProxyBodyGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void CProxyBodyGen::GenTypedefProxyDelegate(std::ofstream& stream) {
-  const char format[] =
-      "typedef void (*proxy_delegate)(GList **list, rpc_port_parcel_h parcel," \
-      " int seq_id, int id);\n";
-  stream << NLine(1);
-  stream << std::string(format);
-}
-
-void CProxyBodyGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-
-    const Interface &inf = static_cast<const Interface&>(*i);
-    GenInterface(stream, inf);
-  }
-}
-
-void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
-  GenInterfaceEnumerations(stream, inf);
-  GenInterfaceDeclaration(stream, inf);
-  GenInterfaceDelegators(stream, inf);
-  GenInterfaceDelegatorTable(stream, inf);
-  GenInterfaceDelegatorHandler(stream, inf);
-  GenInterfaceConsumeCommand(stream, inf);
-  GenInterfaceOnConnectedEventCB(stream, inf);
-  GenInterfaceOnDisconnectedEventCB(stream, inf);
-  GenInterfaceOnRejectedEventCB(stream, inf);
-  GenInterfaceOnReceivedEventCB(stream, inf);
-  GenInterfaceMethods(stream, inf);
-  GenInterfaceHandleCtor(stream, inf);
-  GenInterfaceHandleDtor(stream, inf);
-  GenInterfaceCtor(stream, inf);
-  GenInterfaceConnect(stream, inf);
-  GenInterfaceDtor(stream, inf);
-}
-
-void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
-                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
-                                           const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
-  }
-}
-
-void CProxyBodyGen::GenInterfaceDelegator(std::ofstream& stream,
-                                          const std::string& id,
-                                          const Declaration& decl) {
-  GenInterfaceDelegatorDeclaration(stream, id, decl);
-  GenInterfaceDelegatorSerializer(stream, id, decl);
-  GenInterfaceDelegatorDeserializer(stream, id, decl);
-  GenInterfaceDelegatorConstructor(stream, id, decl);
-  GenInterfaceDelegatorDestructor(stream, id, decl);
-  GenInterfaceDelegatorDisposer(stream, id, decl);
-  GenInterfaceDelegatorInvoker(stream, id, decl);
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorDeclaration(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_DELEGATE_STRUCT, "##", id + "_" + decl.GetID()));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorSerializer(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(
-      ReplaceAll(CB_DELEGATE_SERIALIZER, "##", id + "_" + decl.GetID()));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorDeserializer(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(
-      ReplaceAll(CB_DELEGATE_DESERIALIZER, "##", id + "_" + decl.GetID()));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorConstructor(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID()),
-        [&]()->std::string {
-          return id;
-        },
-        [&]()->std::string {
-          return decl.GetID();
-        }));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorDisposer(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
-        [&]()->std::string {
-          return id;
-        }));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorInvoker(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  const char parcel[] = "$$(parcel, $$);\n";
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_DELEGATE_INVOKER, "##", id + "_" + decl.GetID()),
-        [&]()->std::string {
-          return id;
-        },
-        [&]()->std::string {
-          return decl.GetID();
-        },
-        [&]()->std::string {
-          std::string str;
-          int cnt = 0;
-          for (auto& i : decl.GetParameters().GetParams()) {
-            str += GetParcelParamTypeString(
-              i->GetParameterType().GetBaseType(), false) +
-              i->GetID() + ";" + NLine(1);
-            cnt++;
-          }
-          if (cnt > 0)
-            str += NLine(1);
-          for (auto& i : decl.GetParameters().GetParams()) {
-            if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
-                i->GetParameterType().GetBaseType().ToString() == "list" ||
-                i->GetParameterType().GetBaseType().ToString() == "array") {
-              str += GetConstructorString(i->GetParameterType().GetBaseType(),
-                  i->GetID());
-            }
-            str += GenTemplateString(parcel,
-                [&]()->std::string {
-                    return GetParcelReadFunctionString(
-                        i->GetParameterType().GetBaseType(), true);
-                },
-                [&]()->std::string {
-                  if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
-                      i->GetParameterType().GetBaseType()
-                          .ToString() == "list" ||
-                      i->GetParameterType().GetBaseType().ToString() == "array")
-                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
-                  return "&" + i->GetID();
-                });
-          }
-          return str;
-        },
-        [&]()->std::string {
-          std::string str;
-          str += "handle->callback(handle->user_data";
-          for (auto& i : decl.GetParameters().GetParams()) {
-            str += ", ";
-            str += i->GetID();
-          }
-          str += ");" + NLine(1);
-          return str;
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : decl.GetParameters().GetParams()) {
-            str += GetDestructorString(i->GetParameterType().GetBaseType(),
-                i->GetID());
-            str += NLine(1);
-          }
-          return str;
-        }));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorDestructor(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_DELEGATE_DTOR, "##", id + "_" + decl.GetID()));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorTable(std::ofstream& stream,
-                                               const Interface& inf) {
-  const char block[] =
-      "static proxy_delegate __$$_delegate_table[] = {\n" \
-      "$$" \
-      "};\n";
-  const char delegate_format[] = "[$$] = $$,\n";
-  std::string str;
-  int cnt = 0;
-
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    str += GenTemplateString(delegate_format,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf) + "_DELEGATE_" + i->GetID();
-        },
-        [&]()->std::string {
-          return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_"
-              + i->GetID();
-        });
-    cnt++;
-  }
-
-  if (cnt == 0)
-    return;
-
-  stream << NLine(1);
-  stream << SmartIndent(GenTemplateString(block,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          return str;
-        }));
-}
-
-void CProxyBodyGen::GenInterfaceDelegatorHandler(std::ofstream& stream,
-                                                 const Interface& inf) {
-  std::string str;
-  int cnt = 0;
-
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    cnt++;
-  }
-
-  stream << SmartIndent(GenTemplateString(
-      ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##",
-          GetInterfaceIdWithNamespace(inf)),
-          [&]()->std::string {
-            if (cnt == 0)
-              return str;
-            return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##",
-                GetInterfaceIdWithNamespace(inf));
-          }));
-}
-
-void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream,
-                                               const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
-                                                   const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
-                                                      const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
-                                        const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_INTERFACE_METHODS, "##",
-          GetInterfaceIdWithNamespace(inf)),
-          [&]()->std::string {
-            return GetReturnTypeString(i->GetType());
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            std::string str;
-            for (auto& p : i->GetParameters().GetParams()) {
-              str += ", ";
-              if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
-                str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
-                    p->GetParameterType().GetBaseType().ToString() +
-                    "_h " + p->GetID();
-              } else {
-                str += GetParamTypeString(p->GetParameterType().GetDirection(),
-                    p->GetParameterType().GetBaseType()) + p->GetID();
-              }
-            }
-            return str;
-          },
-          [&]()->std::string {
-            if (GetReturnTypeString(i->GetType()) != "void ")
-              return GetReturnTypeString(i->GetType()) + "ret = " +
-                  GetErrorValue(i->GetType()) + ";";
-            return "";
-          },
-          [&]()->std::string {
-            std::string str;
-            for (auto& p : i->GetParameters().GetParams()) {
-              if (p->GetParameterType().GetDirection() ==
-                  ParameterType::Direction::OUT ||
-                  p->GetParameterType().GetBaseType().IsUserDefinedType() ||
-                  p->GetParameterType().GetBaseType().ToString() == "list" ||
-                  p->GetParameterType().GetBaseType().ToString() == "array" ||
-                  p->GetParameterType().GetBaseType().ToString() == "bundle")
-                str += " || !" + p->GetID();
-            }
-            return str;
-          },
-          [&]()->std::string {
-            if (GetReturnTypeString(i->GetType()) != "void ")
-              return " ret";
-            return "";
-          },
-          [&]()->std::string {
-            if (GetReturnTypeString(i->GetType()) != "void ")
-              return " ret";
-            return "";
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetMethodWriteString(inf, *i);
-          },
-          [&]()->std::string {
-            return GetMethodReadString(inf, *i);
-          }));
-  }
-}
-
-void CProxyBodyGen::GenInterfaceHandleCtor(std::ofstream& stream,
-                                           const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_CTOR, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceHandleDtor(std::ofstream& stream,
-                                           const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_DTOR, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceCtor(std::ofstream& stream,
-                                        const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
-                                        const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyBodyGen::GenInterfaceDtor(std::ofstream& stream,
-                                           const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
-                                                const Declaration& decl) {
-  const char setter[] = "$$($$, $$);\n";
-  const char ternary_operation[] = "## ? ## : \"\"";
-  std::string str;
-  for (auto& p : decl.GetParameters().GetParams()) {
-    if (p->GetParameterType().GetDirection() == ParameterType::Direction::OUT)
-      continue;
-    if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
-      str += GenTemplateString(ReplaceAll(CB_DELEGATE_BLOCK, "##",
-          GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType()
-              .GetBaseType().ToString()),
-          [&]()->std::string {
-            return p->GetID();
-          });
-    } else {
-      str += GenTemplateString(setter,
-          [&]()->std::string {
-            return GetParcelWriteFunctionString(
-                p->GetParameterType().GetBaseType(), true);
-          },
-          [&]()->std::string {
-            return "parcel";
-          },
-          [&]()->std::string {
-            if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
-                p->GetParameterType().GetBaseType().ToString() == "list" ||
-                p->GetParameterType().GetBaseType().ToString() == "array") {
-              if (p->GetParameterType().GetDirection()
-                  == ParameterType::Direction::REF)
-                return "&(*" + p->GetID() + ")->parcelable, " + "*"
-                    + p->GetID();
-              else
-                return "&" + p->GetID() + "->parcelable, " + p->GetID();
-            } else if (p->GetParameterType().GetDirection()
-                       == ParameterType::Direction::REF) {
-              if (p->GetParameterType().GetBaseType().ToString() == "string")
-                return ReplaceAll(ternary_operation, "##", "*" + p->GetID());
-              return "*" + p->GetID();
-            } else if (p->GetParameterType().GetBaseType().ToString() ==
-                "string") {
-              return ReplaceAll(ternary_operation, "##", p->GetID());
-            }
-            return p->GetID();
-          });
-    }
-  }
-  return str;
-}
-
-std::string CProxyBodyGen::GetMethodReadString(const Interface& inf,
-                                               const Declaration& decl) {
-  const char setter[] = "$$($$, $$);\n";
-  std::string str;
-  if (decl.GetMethodType() != Declaration::MethodType::SYNC) {
-    str += "set_last_result(r);" + NLine(1);
-    return str;
-  }
-  str += GenTemplateString(CB_RECEIVE_BLOCK,
-      [&]()->std::string {
-        std::string s;
-        for (auto& p : decl.GetParameters().GetParams()) {
-          if (p->GetParameterType().GetDirection() !=
-              ParameterType::Direction::OUT)
-            continue;
-          s += GetReturnTypeString(p->GetParameterType().GetBaseType()) +
-              "out_" + p->GetID() + ";" + NLine(1);
-        }
-        return s;
-      },
-      [&]()->std::string {
-        return GetInterfaceIdWithNamespace(inf);
-      },
-      [&]()->std::string {
-        std::string s;
-        for (auto& p : decl.GetParameters().GetParams()) {
-          if (p->GetParameterType().GetDirection() !=
-              ParameterType::Direction::OUT)
-            continue;
-          if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
-              p->GetParameterType().GetBaseType().ToString() == "list" ||
-              p->GetParameterType().GetBaseType().ToString() == "array") {
-            s += GetConstructorString(p->GetParameterType().GetBaseType(),
-                "out_" + p->GetID());
-            }
-            s += GenTemplateString(setter,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(
-                      p->GetParameterType().GetBaseType(), true);
-                },
-                [&]()->std::string {
-                  return "parcel_received";
-                },
-                [&]()->std::string {
-                  auto& t = p->GetParameterType().GetBaseType();
-                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
-                      t.ToString() == "array") {
-                    return "&out_" + p->GetID() + "->parcelable, out_"
-                        + p->GetID();
-                  }
-
-                  return "&out_" + p->GetID();
-                });
-            s += "*" + p->GetID() + " = out_" + p->GetID() + ";" + NLine(1);
-          }
-          if (GetReturnTypeString(decl.GetType()) != "void ") {
-            if (decl.GetType().IsUserDefinedType() ||
-                decl.GetType().ToString() == "list" ||
-                decl.GetType().ToString() == "array") {
-              s += GetConstructorString(decl.GetType(), "ret");
-            }
-            s += GenTemplateString(setter,
-                [&]()->std::string {
-                  return GetParcelReadFunctionString(decl.GetType(), false);
-                },
-                [&]()->std::string {
-                  return "parcel_received";
-                },
-                [&]()->std::string {
-                  if (decl.GetType().IsUserDefinedType() ||
-                      decl.GetType().ToString() == "list" ||
-                      decl.GetType().ToString() == "array")
-                    return "&ret->parcelable, ret";
-                  return "&ret";
-                });
-          }
-          return s;
-        });
-  if (GetReturnTypeString(decl.GetType()) != "void ") {
-    str += "set_last_result(r);" + NLine(1);
-    str += NLine(1);
-    str += "return ret;";
-  }
-  return str;
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_proxy_body_gen.h b/idlc/c_gen/c_proxy_body_gen.h
deleted file mode 100644 (file)
index 04dd55e..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_PROXY_BODY_GEN_H_
-#define IDLC_C_GEN_C_PROXY_BODY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/c_gen/c_body_gen_base.h"
-
-namespace tidl {
-
-class CProxyBodyGen : public CBodyGeneratorBase {
- public:
-  explicit CProxyBodyGen(std::shared_ptr<Document> doc);
-  virtual ~CProxyBodyGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenTypedefProxyDelegate(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-
- private:
-  void GenInterface(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegatorTable(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegatorHandler(std::ofstream& stream,
-                                    const Interface& inf);
-  void GenInterfaceConsumeCommand(std::ofstream& stream,
-                                  const Interface& inf);
-  void GenInterfaceOnConnectedEventCB(std::ofstream& stream,
-                                      const Interface& inf);
-  void GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
-                                         const Interface& inf);
-  void GenInterfaceOnRejectedEventCB(std::ofstream& stream,
-                                     const Interface& inf);
-  void GenInterfaceOnReceivedEventCB(std::ofstream& stream,
-                                     const Interface& inf);
-  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceHandleCtor(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceHandleDtor(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
-
- private:
-  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
-                             const Declaration& decl);
-  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
-                                        const std::string& id,
-                                        const Declaration& decl);
-  void GenInterfaceDelegatorSerializer(std::ofstream& stream,
-                                       const std::string& id,
-                                       const Declaration& decl);
-  void GenInterfaceDelegatorDeserializer(std::ofstream& stream,
-                                         const std::string& id,
-                                         const Declaration& decl);
-  void GenInterfaceDelegatorConstructor(std::ofstream& stream,
-                                        const std::string& id,
-                                        const Declaration& decl);
-  void GenInterfaceDelegatorDisposer(std::ofstream& stream,
-                                     const std::string& id,
-                                     const Declaration& decl);
-  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
-                                    const std::string& id,
-                                    const Declaration& decl);
-  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
-                                       const std::string& id,
-                                       const Declaration& decl);
-
- private:
-  std::string GetMethodWriteString(const Interface& inf,
-                                   const Declaration& decl);
-  std::string GetMethodReadString(const Interface& inf,
-                                  const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_PROXY_BODY_GEN_H_
diff --git a/idlc/c_gen/c_proxy_body_gen_cb.h b/idlc/c_gen/c_proxy_body_gen_cb.h
deleted file mode 100644 (file)
index 3d9ad62..0000000
+++ /dev/null
@@ -1,496 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
-#define IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
-
-const char CB_INTERFACE_STRUCT[] =
-R"__c_cb(
-struct ##_s {
-    char *stub_appid;
-    rpc_port_proxy_h proxy;
-    rpc_port_h port;
-    rpc_port_h callback_port;
-    rpc_port_proxy_##_callback_s callback;
-    void *user_data;
-    GList *delegates;
-    GRecMutex mutex;
-};
-)__c_cb";
-
-const char CB_DELEGATE_STRUCT[] =
-R"__c_cb(
-struct ##_s {
-    rpc_port_parcelable_t parcelable;
-    int id;
-    int seq_id;
-    ## callback;
-    bool once;
-    void *user_data;
-};
-)__c_cb";
-
-const char CB_DELEGATE_SERIALIZER[] =
-R"__c_cb(
-static void __##_to(rpc_port_parcel_h parcel, void *data)
-{
-    struct ##_s *handle = data;
-
-    if (!handle) {
-        _E("Invalid parameter");
-        return;
-    }
-
-    rpc_port_parcel_write_int32(parcel, handle->id);
-    rpc_port_parcel_write_int32(parcel, handle->seq_id);
-    rpc_port_parcel_write_bool(parcel, handle->once);
-}
-)__c_cb";
-
-const char CB_DELEGATE_DESERIALIZER[] =
-R"__c_cb(
-static void __##_from(rpc_port_parcel_h parcel, void *data)
-{
-    struct ##_s *handle = data;
-
-    if (!handle) {
-        _E("Invalid parameter");
-        return;
-    }
-
-    rpc_port_parcel_read_int32(parcel, &handle->id);
-    rpc_port_parcel_read_int32(parcel, &handle->seq_id);
-    rpc_port_parcel_read_bool(parcel, &handle->once);
-}
-)__c_cb";
-
-const char CB_DELEGATE_CTOR[] =
-R"__c_cb(
-rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data)
-{
-    struct ##_s *handle;
-    static int seq_num;
-
-    handle = calloc(1, sizeof(struct ##_s));
-    if (!handle) {
-        _E("Out of memory");
-        return NULL;
-    }
-
-    handle->parcelable.to = __##_to;
-    handle->parcelable.from= __##_from;
-    handle->id = $$_DELEGATE_$$;
-    handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
-    handle->callback = callback;
-    handle->once = once;
-    handle->user_data = user_data;
-
-    return handle;
-}
-)__c_cb";
-
-const char CB_DELEGATE_DISPOSER[] =
-R"__c_cb(
-int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate)
-{
-    struct ##_s *handle;
-    GList *iter;
-
-    if (!proxy || !delegate) {
-        _E("Invalid handle %p %p", proxy, delegate);
-        return -1;
-    }
-
-    iter = proxy->delegates;
-    while (iter) {
-        handle = (struct ##_s *)iter->data;
-        if (handle == delegate) {
-            proxy->delegates = g_list_remove_link(proxy->delegates, iter);
-            free(handle);
-            g_list_free(iter);
-            return 0;
-        }
-        iter = g_list_next(iter);
-    }
-
-    return -1;
-}
-)__c_cb";
-
-const char CB_DELEGATE_DTOR[] =
-R"__c_cb(
-int rpc_port_##_destroy(rpc_port_##_h delegate)
-{
-    if (!delegate) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    free(delegate);
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_DELEGATE_INVOKER[] =
-R"__c_cb(
-static void __$$_delegate_$$(GList **list, rpc_port_parcel_h parcel, int seq_id, int id)
-{
-$$
-    do {
-        struct ##_s *handle;
-        GList *iter;
-
-        iter = *list;
-        while (iter) {
-            handle = (struct ##_s *)iter->data;
-            if (handle->seq_id == seq_id && handle->id == id) {
-                bool once = handle->once;
-
-                $$
-                if (once) {
-                    *list = g_list_remove_link(*list, iter);
-                    free(handle);
-                    g_list_free(iter);
-                }
-                break;
-            }
-            iter = g_list_next(iter);
-        }
-    } while (0);
-$$
-}
-)__c_cb";
-
-const char CB_PROCESS_RECEIVED_EVENT[] =
-R"__c_cb(
-static void __##_process_received_event(GList **list, rpc_port_parcel_h parcel)
-{
-$$
-}
-)__c_cb";
-
-const char CB_PROCESS_RECEIVED_EVENT_IMPL[] =
-R"__c_cb(int id;
-int seq_id;
-bool once;
-
-rpc_port_parcel_read_int32(parcel, &id);
-rpc_port_parcel_read_int32(parcel, &seq_id);
-rpc_port_parcel_read_bool(parcel, &once);
-
-if (id > 0 && id < (sizeof(__##_delegate_table) / sizeof(__##_delegate_table[0]))) {
-    if (__##_delegate_table[id])
-        __##_delegate_table[id](list, parcel, seq_id, id);
-} else {
-    _W("Unknown id(%d)", id);
-})__c_cb";
-
-const char CB_CONSUME_COMMAND[] =
-R"__c_cb(
-static rpc_port_parcel_h __##_consume_command(rpc_port_proxy_##_h h)
-{
-    rpc_port_parcel_h parcel = NULL;
-    int cmd = -1;
-
-    do {
-        rpc_port_parcel_create_from_port(&parcel, h->port);
-        if (!parcel)
-            break;
-
-        rpc_port_parcel_read_int32(parcel, &cmd);
-        if (cmd == ##_METHOD_Result)
-            return parcel;
-
-        rpc_port_parcel_destroy(parcel);
-        parcel = NULL;
-    } while (true);
-
-    return NULL;
-}
-)__c_cb";
-
-const char CB_ON_CONNECTED[] =
-R"__c_cb(
-static void __##_on_connected(const char *endpoint, const char *port_name, rpc_port_h port, void *data)
-{
-    rpc_port_proxy_##_h handle = data;
-
-    handle->port = port;
-    rpc_port_proxy_get_port(handle->proxy, RPC_PORT_PORT_CALLBACK, &handle->callback_port);
-    if (handle->callback.connected)
-        handle->callback.connected(handle, handle->user_data);
-    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
-}
-)__c_cb";
-
-const char CB_ON_DISCONNECTED[] =
-R"__c_cb(
-static void __##_on_disconnected(const char *endpoint, const char *port_name, void *data)
-{
-    rpc_port_proxy_##_h handle = data;
-
-    handle->port = NULL;
-    if (handle->callback.disconnected)
-        handle->callback.disconnected(handle, handle->user_data);
-    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
-}
-)__c_cb";
-
-const char CB_ON_REJECTED[] =
-R"__c_cb(
-static void __##_on_rejected(const char *endpoint, const char *port_name, void *data)
-{
-    rpc_port_proxy_##_h handle = data;
-
-    handle->port = NULL;
-    if (handle->callback.rejected)
-        handle->callback.rejected(handle, handle->user_data);
-    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
-}
-)__c_cb";
-
-const char CB_ON_RECEIVED[] =
-R"__c_cb(
-static void __##_on_received(const char *endpoint, const char *port_name, void *data)
-{
-    rpc_port_proxy_##_h handle = data;
-    rpc_port_parcel_h parcel_received = NULL;
-    int cmd = -1;
-
-    rpc_port_parcel_create_from_port(&parcel_received, handle->callback_port);
-    if (!parcel_received) {
-        _E("Failed to create parcel from port(%s)", port_name);
-        return;
-    }
-
-    rpc_port_parcel_read_int32(parcel_received, &cmd);
-    if (cmd != ##_METHOD_Callback) {
-        _E("Invalid protocol");
-        rpc_port_parcel_destroy(parcel_received);
-        return;
-    }
-
-    __##_process_received_event(&handle->delegates, parcel_received);
-    rpc_port_parcel_destroy(parcel_received);
-    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
-}
-)__c_cb";
-
-const char CB_INTERFACE_METHODS[] =
-R"__c_cb(
-$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$)
-{
-    rpc_port_parcel_h parcel;
-    int r;
-$$
-
-    if (!h$$) {
-        _E("Invalid parameter");
-        return$$;
-    }
-
-    if (!h->port) {
-        _E("Not connected");
-        return$$;
-    }
-
-    rpc_port_parcel_create(&parcel);
-    rpc_port_parcel_write_int32(parcel, ##_METHOD_$$);
-$$
-    r = rpc_port_parcel_send(parcel, h->port);
-    if (r != RPC_PORT_ERROR_NONE) {
-        _E("Failed to send parcel. result(%d)", r);
-        r = RPC_PORT_ERROR_IO_ERROR;
-    }
-
-    rpc_port_parcel_destroy(parcel);
-$$
-}
-)__c_cb";
-
-const char CB_INTERFACE_HANDLE_CTOR[] =
-R"__c_cb(
-static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data)
-{
-    struct ##_s *handle;
-
-    handle = calloc(1, sizeof(struct ##_s));
-    if (!handle) {
-        _E("Out of memory");
-        return NULL;
-    }
-
-    handle->stub_appid = strdup(stub_appid);
-    if (!handle->stub_appid) {
-        _E("Out of memory");
-        free(handle);
-        return NULL;
-    }
-
-    rpc_port_proxy_create(&handle->proxy);
-    if (!handle->proxy) {
-        _E("Failed to create proxy");
-        free(handle->stub_appid);
-        free(handle);
-        return NULL;
-    }
-
-    g_rec_mutex_init(&handle->mutex);
-
-    handle->callback = *callback;
-    handle->user_data = user_data;
-
-    return handle;
-}
-)__c_cb";
-
-const char CB_INTERFACE_HANDLE_DTOR[] =
-R"__c_cb(
-static void __destroy_##(struct ##_s *h)
-{
-    if (!h)
-        return;
-
-    g_rec_mutex_clear(&h->mutex);
-
-    if (h->delegates)
-        g_list_free_full(h->delegates, free);
-
-    if (h->proxy)
-        rpc_port_proxy_destroy(h->proxy);
-
-    if (h->stub_appid)
-        free(h->stub_appid);
-
-    free(h);
-}
-)__c_cb";
-
-const char CB_INTERFACE_CTOR[] =
-R"__c_cb(
-int rpc_port_proxy_##_create(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data, rpc_port_proxy_##_h *h)
-{
-    struct ##_s *handle;
-    int r;
-
-    if (!stub_appid || !callback || !h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    handle = __create_##(stub_appid, callback, user_data);
-    if (!handle)
-        return -1;
-
-    r = rpc_port_proxy_add_connected_event_cb(handle->proxy, __##_on_connected, handle);
-    if (r != 0) {
-        _E("Failed to add connected event cb. err = %d", r);
-        __destroy_##(handle);
-        return r;
-    }
-
-    r = rpc_port_proxy_add_disconnected_event_cb(handle->proxy, __##_on_disconnected, handle);
-    if (r != 0) {
-        _E("Failed to add disconnected event cb. err = %d", r);
-        __destroy_##(handle);
-        return r;
-    }
-
-    r = rpc_port_proxy_add_rejected_event_cb(handle->proxy, __##_on_rejected, handle);
-    if (r != 0) {
-        _E("Failed to add rejected event cb. err = %d", r);
-        __destroy_##(handle);
-        return r;
-    }
-
-    r = rpc_port_proxy_add_received_event_cb(handle->proxy, __##_on_received, handle);
-    if (r != 0) {
-        _E("Failed to add received event cb. err = %d", r);
-        __destroy_##(handle);
-        return r;
-    }
-
-    *h = handle;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONNECT[] =
-R"__c_cb(
-int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h)
-{
-    int r;
-
-    if (!h || !h->proxy) {
-        _E("Invalid parameter");
-       return -1;
-    }
-
-    r = rpc_port_proxy_connect(h->proxy, h->stub_appid, "##");
-    if (r != 0) {
-        _E("Failed to connect ##(%s)", h->stub_appid);
-       return r;
-    }
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_DTOR[] =
-R"__c_cb(
-int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h)
-{
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    __destroy_##(h);
-    return 0;
-}
-)__c_cb";
-
-const char CB_DELEGATE_BLOCK[] =
-R"__c_cb(
-do {
-    struct ##_s *handle = $$;
-
-    rpc_port_parcel_write(parcel, &handle->parcelable, handle);
-    h->delegates = g_list_append(h->delegates, handle);
-} while (0);
-)__c_cb";
-
-const char CB_RECEIVE_BLOCK[] =
-R"__c_cb(
-g_rec_mutex_lock(&h->mutex);
-do {
-    rpc_port_parcel_h parcel_received;
-$$
-    parcel_received = __$$_consume_command(h);
-    if (!parcel_received) {
-        _E("Invalid protocol");
-        break;
-    }
-
-$$
-    rpc_port_parcel_destroy(parcel_received);
-} while (0);
-g_rec_mutex_unlock(&h->mutex);
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
diff --git a/idlc/c_gen/c_proxy_header_gen.cc b/idlc/c_gen/c_proxy_header_gen.cc
deleted file mode 100644 (file)
index e9eac53..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/c_gen/c_proxy_header_gen.h"
-
-namespace {
-#include "idlc/c_gen/c_proxy_header_gen_cb.h"
-}
-
-namespace tidl {
-
-CProxyHeaderGen::CProxyHeaderGen(std::shared_ptr<Document> doc)
-    : CHeaderGeneratorBase(doc) {}
-
-void CProxyHeaderGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  GenPragmaOnce(stream);
-  GenIncludeDefaultHeaders(stream, false);
-  GenExplicitLinkageOpen(stream);
-  GenStructures(stream);
-  GenInterfaces(stream);
-}
-
-void CProxyHeaderGen::OnFiniGen(std::ofstream& stream) {
-  GenExplicitLinkageClose(stream);
-}
-
-void CProxyHeaderGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-
-    const Interface &inf = static_cast<const Interface&>(*i);
-    GenInterface(stream, inf);
-  }
-}
-
-void CProxyHeaderGen::GenInterface(std::ofstream& stream,
-                                   const Interface& inf) {
-  GenInterfaceDeclaration(stream, inf);
-  GenInterfaceDelegators(stream, inf);
-  GenInterfaceCtor(stream, inf);
-  GenInterfaceConnect(stream, inf);
-  GenInterfaceDtor(stream, inf);
-  GenInterfaceMethods(stream, inf);
-}
-
-void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
-                                             const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
-  }
-}
-
-void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
-                                            const std::string& id,
-                                            const Declaration& decl) {
-  const char handle[] = "typedef struct $$_s *rpc_port_$$_h;";
-
-  stream << NLine(1);
-  stream << GenTemplateString(handle,
-      [&]()->std::string {
-        return id + "_" + decl.GetID();
-      },
-      [&]()->std::string {
-        return id + "_" + decl.GetID();
-      });
-
-  stream << NLine(1);
-  stream << GenTemplateString(CB_INTERFACE_DELEGATOR,
-      [&]()->std::string {
-        return GetReturnTypeString(decl.GetType());
-      },
-      [&]()->std::string {
-        return id + "_" + decl.GetID();
-      },
-      [&]()->std::string {
-        std::string str;
-        str += "void *user_data";
-        for (auto& p : decl.GetParameters().GetParams()) {
-          str += ", ";
-          str += GetParamTypeString(p->GetParameterType().GetDirection(),
-              p->GetParameterType().GetBaseType()) + p->GetID();
-        }
-        return str;
-      });
-
-  stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID());
-  stream << ReplaceAll(CB_DELEGATE_DTOR, "##", id + "_" + decl.GetID());
-  stream << GenTemplateString(
-      ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
-      [&]()->std::string {
-        return id;
-      });
-}
-
-void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
-                                              const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
-                                          const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    stream << GenTemplateString(
-        ReplaceAll(CB_INTERFACE_METHODS, "##",
-            GetInterfaceIdWithNamespace(inf)),
-        [&]()->std::string {
-          return GetReturnTypeString(i->GetType());
-        },
-        [&]()->std::string {
-          return i->GetID();
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& p : i->GetParameters().GetParams()) {
-            str += ", ";
-            if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
-              str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
-                  p->GetParameterType().GetBaseType().ToString() +
-                  "_h " + p->GetID();
-            } else {
-              str += GetParamTypeString(p->GetParameterType().GetDirection(),
-                  p->GetParameterType().GetBaseType()) + p->GetID();
-            }
-          }
-          return str;
-        });
-  }
-}
-
-void CProxyHeaderGen::GenInterfaceCtor(std::ofstream& stream,
-                                          const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CTOR, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
-                                          const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONNECT, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CProxyHeaderGen::GenInterfaceDtor(std::ofstream& stream,
-                                             const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_DTOR, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_proxy_header_gen.h b/idlc/c_gen/c_proxy_header_gen.h
deleted file mode 100644 (file)
index 04f3abf..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
-#define IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/c_gen/c_header_gen_base.h"
-
-namespace tidl {
-
-class CProxyHeaderGen : public CHeaderGeneratorBase {
- public:
-  explicit CProxyHeaderGen(std::shared_ptr<Document> doc);
-  virtual ~CProxyHeaderGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenInterfaces(std::ofstream& stream);
-
- private:
-  void GenInterface(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
-
- private:
-  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
-                             const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
diff --git a/idlc/c_gen/c_proxy_header_gen_cb.h b/idlc/c_gen/c_proxy_header_gen_cb.h
deleted file mode 100644 (file)
index 4fe6daf..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
-#define IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
-
-const char CB_INTERFACE_DECL[] =
-R"__c_cb(
-typedef struct ##_s *rpc_port_proxy_##_h;
-
-typedef struct {
-    void (*connected)(rpc_port_proxy_##_h h, void *user_data);
-    void (*disconnected)(rpc_port_proxy_##_h h, void *user_data);
-    void (*rejected)(rpc_port_proxy_##_h h, void *user_data);
-} rpc_port_proxy_##_callback_s;
-)__c_cb";
-
-const char CB_INTERFACE_CTOR[] =
-R"__c_cb(
-int rpc_port_proxy_##_create(const char *stub_appid,
-        rpc_port_proxy_##_callback_s *callback, void *user_data,
-        rpc_port_proxy_##_h *h);
-)__c_cb";
-
-const char CB_INTERFACE_CONNECT[] =
-R"__c_cb(
-int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h);
-)__c_cb";
-
-const char CB_INTERFACE_DTOR[] =
-R"__c_cb(
-int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h);
-)__c_cb";
-
-const char CB_INTERFACE_METHODS[] =
-R"__c_cb(
-$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR[] =
-R"__c_cb(
-typedef $$(*$$)($$);
-)__c_cb";
-
-const char CB_DELEGATE_CTOR[] =
-R"__c_cb(
-rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data);
-)__c_cb";
-
-const char CB_DELEGATE_DISPOSER[] =
-R"__c_cb(
-int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate);
-)__c_cb";
-
-const char CB_DELEGATE_DTOR[] =
-R"__c_cb(
-int rpc_port_##_destroy(rpc_port_##_h delegate);
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
diff --git a/idlc/c_gen/c_stub_body_gen.cc b/idlc/c_gen/c_stub_body_gen.cc
deleted file mode 100644 (file)
index bfa6095..0000000
+++ /dev/null
@@ -1,572 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/c_gen/c_stub_body_gen.h"
-
-namespace {
-#include "idlc/c_gen/c_stub_body_gen_cb.h"
-}
-
-namespace tidl {
-
-CStubBodyGen::CStubBodyGen(std::shared_ptr<Document> doc)
-    : CBodyGeneratorBase(doc) {}
-
-void CStubBodyGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  GenGNUSourceDefinition(stream);
-  GenIncludeDefaultHeaders(stream);
-  GenIncludeHeader(stream);
-  GenLogTag(stream, std::string("RPC_PORT_STUB"));
-  GenLogDefinition(stream);
-  GenTypedefStubMethod(stream);
-  GenStructures(stream);
-  GenInterfaces(stream);
-}
-
-void CStubBodyGen::OnFiniGen(std::ofstream& stream) {}
-
-void CStubBodyGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-
-    const Interface &inf = static_cast<const Interface&>(*i);
-    GenInterface(stream, inf);
-  }
-}
-
-void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
-  GenInterfaceEnumerations(stream, inf);
-  GenInterfaceGlobalVariables(stream, inf);
-  GenInterfaceContext(stream, inf);
-  GenInterfaceDelegators(stream, inf);
-  GenInterfaceMethods(stream, inf);
-  GenInterfaceMethodTable(stream, inf);
-  GenInterfaceOnConnectedEventCB(stream, inf);
-  GenInterfaceOnDisconnectedEventCB(stream, inf);
-  GenInterfaceOnReceivedEventCB(stream, inf);
-  GenInterfaceAddPrivileges(stream, inf);
-  GenInterfaceRegister(stream, inf);
-  GenInterfaceUnregister(stream, inf);
-  GenInterfaceClientNumberGetter(stream, inf);
-}
-
-void CStubBodyGen::GenInterfaceMethods(std::ofstream& stream,
-                                       const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-
-    stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD,
-          [&]()->std::string {
-            return GetInterfaceIdWithNamespace(inf);
-          },
-          [&]()->std::string {
-            return i->GetID();
-          },
-          [&]()->std::string {
-            return GetInterfaceIdWithNamespace(inf);
-          },
-          [&]()->std::string {
-            return GetInterfaceIdWithNamespace(inf);
-          },
-          [&]()->std::string {
-            return GetMethodString(inf, *i);
-          }));
-  }
-}
-
-void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
-                                           const Interface& inf) {
-  std::string str;
-  int cnt = 0;
-
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    str += GenTemplateString(CB_INTERFACE_METHOD_FORMAT,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf) + "_METHOD_" + i->GetID();
-        },
-        [&]()->std::string {
-          return "__" + GetInterfaceIdWithNamespace(inf) + "_method_"
-              + i->GetID();
-        });
-    cnt++;
-  }
-
-  if (cnt == 0)
-    return;
-
-  stream << NLine(1);
-  stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD_TABLE,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          return str;
-        }));
-}
-
-void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##",
-          GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
-                                                     const Interface& inf) {
-  stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##",
-          GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
-                                                 const Interface& inf) {
-  stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##",
-          GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
-                                        const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
-                                          const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
-                                               const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-std::string CStubBodyGen::GetMethodString(const Interface& inf,
-                                          const Declaration& decl) {
-  std::string str;
-  const char port_setter[] = "rpc_port_$$_set_port($$, callback_port);\n";
-  const char setter[] = "$$($$, $$);\n";
-  const char do_while_block[] =
-      "do {\n" \
-      "    rpc_port_parcel_h result;\n" \
-      "\n" \
-      "    rpc_port_parcel_create(&result);\n" \
-      "    rpc_port_parcel_write_int32(result, $$_METHOD_Result);\n" \
-      "$$" \
-      "    r = rpc_port_parcel_send(result, port);\n" \
-      "    rpc_port_parcel_destroy(result);\n" \
-      "} while (0);\n";
-  const char ternary_operation[] = "## ? ## : \"\"";
-  int cnt = 0;
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
-      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
-          i->GetParameterType().GetBaseType().ToString() + "_h " +
-          i->GetID() + " = NULL;" + NLine(1);
-    } else if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
-               i->GetParameterType().GetBaseType().ToString() == "list" ||
-               i->GetParameterType().GetBaseType().ToString() == "array") {
-      str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
-          i->GetID() + " = NULL;" + NLine(1);
-    } else {
-      str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
-          i->GetID() + ";" + NLine(1);
-    }
-    if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
-      cnt++;
-  }
-  str += NLine(1);
-
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
-      continue;
-
-    if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
-        i->GetParameterType().GetBaseType().ToString() == "list" ||
-        i->GetParameterType().GetBaseType().ToString() == "array") {
-      if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
-        str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
-            i->GetParameterType().GetBaseType().ToString() +
-            "_create(&" + i->GetID() + ");" + NLine(1);
-        str += "\nif (!" + i->GetID() + ") {\n";
-        str += "    _E(\"Failed to create handle\");\n";
-        str += "    return -1;\n";
-        str += "}\n\n";
-        str += GenTemplateString(port_setter,
-            [&]()->std::string {
-              return GetInterfaceIdWithNamespace(inf) + "_" +
-                  i->GetParameterType().GetBaseType().ToString();
-            },
-            [&]()->std::string {
-              return i->GetID();
-            });
-      } else {
-         str += GetConstructorString(i->GetParameterType().GetBaseType(),
-          i->GetID());
-      }
-    }
-
-    str += GenTemplateString(setter,
-          [&]()->std::string {
-            return GetParcelReadFunctionString(
-                i->GetParameterType().GetBaseType(), true);
-          },
-          [&]()->std::string {
-            return "parcel";
-          },
-          [&]()->std::string {
-            if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
-                i->GetParameterType().GetBaseType().ToString() == "list" ||
-                i->GetParameterType().GetBaseType().ToString() == "array")
-              return "&" + i->GetID() + "->parcelable, " + i->GetID();
-            return "&" + i->GetID();
-          });
-  }
-
-  if (cnt > 0)
-    str += NLine(1);
-
-  if (decl.GetMethodType() == Declaration::MethodType::SYNC &&
-      decl.GetType().ToString() != "void") {
-    str += GetReturnTypeString(decl.GetType()) + "ret = ";
-  }
-
-  str += "context->callback." + decl.GetID() + "(context";
-  for (auto& i : decl.GetParameters().GetParams()) {
-    str += ", ";
-    if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
-      str += "&" + i->GetID();
-    else
-      str += i->GetID();
-  }
-  str += ", context->user_data);" + NLine(1);
-  if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
-    str += GenTemplateString(do_while_block,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          std::string s;
-          for (auto& i : decl.GetParameters().GetParams()) {
-            if (i->GetParameterType().GetDirection() ==
-                ParameterType::Direction::IN)
-              continue;
-            s += GenTemplateString(setter,
-                [&]()->std::string {
-                  return GetParcelWriteFunctionString(
-                      i->GetParameterType().GetBaseType(), true);
-                },
-                [&]()->std::string {
-                  return "result";
-                },
-                [&]()->std::string {
-                  auto& t = i->GetParameterType().GetBaseType();
-                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
-                      t.ToString() == "array")
-                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
-                  else if (t.ToString() == "string")
-                    return ReplaceAll(ternary_operation, "##", i->GetID());
-                  return i->GetID();
-                });
-          }
-          if (decl.GetType().ToString() != "void") {
-            s += GenTemplateString(setter,
-                [&]()->std::string {
-                  return GetParcelWriteFunctionString(decl.GetType(), true);
-                },
-                [&]()->std::string {
-                  return "result";
-                },
-                [&]()->std::string {
-                  if (decl.GetType().IsUserDefinedType() ||
-                      decl.GetType().ToString() == "list" ||
-                      decl.GetType().ToString() == "array")
-                    return "&ret->parcelable, ret";
-                  else if (decl.GetType().ToString() == "string")
-                    return ReplaceAll(ternary_operation, "##", "ret");
-                  return "ret";
-                });
-          }
-          return s;
-        });
-    }
-
-  for (auto& i : decl.GetParameters().GetParams()) {
-    str += NLine(1);
-    if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
-      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
-          i->GetParameterType().GetBaseType().ToString() +
-          "_destroy(" + i->GetID() + ");";
-    } else {
-      str += GetDestructorString(i->GetParameterType().GetBaseType(),
-          i->GetID());
-    }
-  }
-
-  str += GetDestructorString(decl.GetType(), "ret");
-
-  return str;
-}
-
-std::string CStubBodyGen::GetAddPrivilegeString(const std::string& id,
-                                                const Attribute& attr) {
-  std::string str;
-
-  str += GenTemplateString(CB_INTERFACE_PRIVILEGE_BLOCK,
-      [&]()->std::string {
-        return "rpc_port_stub_add_privilege(__" + id +
-            "_stub, \"" + attr.GetValue() + "\")";
-      },
-      [&]()->std::string {
-        return attr.GetValue();
-      });
-  return str;
-}
-
-std::string CStubBodyGen::GetTrustedModeString(const std::string& id,
-                                               const Attribute& attr) {
-  std::string str;
-
-  str += GenTemplateString(CB_INTERFACE_TRUSTED_MODE_BLOCK,
-      [&]()->std::string {
-        return "rpc_port_stub_set_trusted(__" + id +
-            "_stub, " + attr.GetValue() + ")";
-      },
-      [&]()->std::string {
-        return attr.GetValue();
-      });
-  return str;
-}
-
-void CStubBodyGen::GenInterfaceDelegators(std::ofstream& stream,
-                                          const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
-  }
-}
-
-void CStubBodyGen::GenInterfaceDelegator(std::ofstream& stream,
-                                         const std::string& id,
-                                         const Declaration& decl) {
-  GenInterfaceDelegatorDeclaration(stream, id, decl);
-  GenInterfaceDelegatorSerializer(stream, id, decl);
-  GenInterfaceDelegatorDeserializer(stream, id, decl);
-  GenInterfaceDelegatorConstructor(stream, id, decl);
-  GenInterfaceDelegatorDestructor(stream, id, decl);
-  GenInterfaceDelegatorCloner(stream, id, decl);
-  GenInterfaceDelegatorInvoker(stream, id, decl);
-  GenInterfaceDelegatorPortSetter(stream, id, decl);
-}
-
-void CStubBodyGen::GenInterfaceDelegatorDeclaration(std::ofstream& stream,
-                                                    const std::string& id,
-                                                    const Declaration& decl) {
-  stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_DECL,
-        [&]()->std::string {
-          return id + "_" + decl.GetID();
-        }));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
-                                                    const std::string& id,
-                                                    const Declaration& decl) {
-  stream << SmartIndent(GenTemplateString(
-        ReplaceAll(CB_INTERFACE_DELEGATOR_CTOR, "##", id + "_" + decl.GetID()),
-        [&]()->std::string {
-          return id;
-        },
-        [&]()->std::string {
-          return decl.GetID();
-        }));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorDestructor(std::ofstream& stream,
-                                                   const std::string& id,
-                                                   const Declaration& decl) {
-  stream << SmartIndent(
-      ReplaceAll(CB_INTERFACE_DELEGATOR_DTOR, "##", id + "_" + decl.GetID()));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream,
-                                                   const std::string& id,
-                                                   const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_DELEGATOR_SERIALIZER, "##", id + "_" + decl.GetID()));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream,
-                                                     const std::string& id,
-                                                     const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_DELEGATOR_DESERIALIZER, "##", id + "_" + decl.GetID()));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorCloner(std::ofstream& stream,
-                                               const std::string& id,
-                                               const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_DELEGATOR_CLONER, "##", id + "_" + decl.GetID()));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
-                                                const std::string& id,
-                                                const Declaration& decl) {
-  const char parcel[] = "$$(parcel, $$);\n";
-  const char ternary_operation[] = "## ? ## : \"\"";
-  stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_INVOKER,
-        [&]()->std::string {
-          return id + "_" + decl.GetID();
-        },
-        [&]()->std::string {
-          std::string str;
-          str += "rpc_port_" + id + "_" + decl.GetID() + "_h h";
-          for (auto& i : decl.GetParameters().GetParams()) {
-            str += ", ";
-            str += GetParamTypeString(i->GetParameterType().GetDirection(),
-                i->GetParameterType().GetBaseType()) + i->GetID();
-          }
-          return str;
-        },
-        [&]()->std::string {
-          return id;
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : decl.GetParameters().GetParams()) {
-            str += GenTemplateString(parcel,
-                [&]()->std::string {
-                  return GetParcelWriteFunctionString(
-                      i->GetParameterType().GetBaseType(), true);
-                },
-                [&]()->std::string {
-                  auto& t = i->GetParameterType().GetBaseType();
-                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
-                      t.ToString() == "array")
-                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
-                  else if (t.ToString() == "string")
-                    return ReplaceAll(ternary_operation, "##", i->GetID());
-                  return i->GetID();
-                });
-          }
-          return str;
-        }));
-}
-
-void CStubBodyGen::GenInterfaceDelegatorPortSetter(std::ofstream& stream,
-                                                   const std::string& id,
-                                                   const Declaration& decl) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_DELEGATOR_PORT_SETTER, "##", id + "_" + decl.GetID()));
-}
-
-void CStubBodyGen::GenInterfaceContext(std::ofstream& stream,
-                                       const Interface& inf) {
-  GenInterfaceContextDeclaration(stream, inf);
-  GenInterfaceContextConstructor(stream, inf);
-  GenInterfaceContextDestructor(stream, inf);
-  GenInterfaceContextFinder(stream, inf);
-  GenInterfaceContextTagSetter(stream, inf);
-  GenInterfaceContextTagGetter(stream, inf);
-  GenInterfaceContextSenderGetter(stream, inf);
-}
-
-void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextConstructor(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream,
-                                                 const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream,
-                                             const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_FINDER, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream,
-                                                const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_TAG_SETTER, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream,
-                                                const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_TAG_GETTER, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenInterfaceContextSenderGetter(std::ofstream& stream,
-                                                   const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(
-      CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf)));
-}
-
-void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) {
-  stream << CB_STUB_METHOD_TYPE;
-}
-
-void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
-                                             const Interface& inf) {
-  stream << SmartIndent(GenTemplateString(CB_INTERFACE_ADD_PRIVILEGE,
-        [&]()->std::string {
-          return GetInterfaceIdWithNamespace(inf);
-        },
-        [&]()->std::string {
-          std::string str;
-          for (auto& a : inf.GetAttributes().GetAttrs()) {
-            if (a->GetKey() == "privilege") {
-              str += GetAddPrivilegeString(
-                  GetInterfaceIdWithNamespace(inf), *a);
-              str += NLine(1);
-            } else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
-              str += GetTrustedModeString(GetInterfaceIdWithNamespace(inf), *a);
-              str += NLine(1);
-            }
-          }
-
-          if (!str.empty())
-            str = SmartIndent("int r;\n\n") + str;
-          return str;
-        }));
-}
-
-void CStubBodyGen::GenInterfaceClientNumberGetter(std::ofstream& stream,
-                                                  const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CLIENT_NUMBER_GETTER, "##",
-      GetInterfaceIdWithNamespace(inf)));
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_stub_body_gen.h b/idlc/c_gen/c_stub_body_gen.h
deleted file mode 100644 (file)
index 69c88f9..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_H_
-#define IDLC_C_GEN_C_STUB_BODY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/c_gen/c_body_gen_base.h"
-
-namespace tidl {
-
-class CStubBodyGen : public CBodyGeneratorBase {
- public:
-  explicit CStubBodyGen(std::shared_ptr<Document> doc);
-  virtual ~CStubBodyGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& inf);
-  void GenTypedefStubMethod(std::ofstream& stream);
-  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceMethodTable(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceOnConnectedEventCB(std::ofstream& stream,
-                                      const Interface& inf);
-  void GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
-                                         const Interface& inf);
-  void GenInterfaceOnReceivedEventCB(std::ofstream& stream,
-                                     const Interface& inf);
-  void GenInterfaceRegister(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceUnregister(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceGlobalVariables(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceAddPrivileges(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceClientNumberGetter(std::ofstream& stream,
-                                      const Interface& inf);
-
- private:
-  void GenInterfaceContextDeclaration(std::ofstream& stream,
-                                      const Interface& inf);
-  void GenInterfaceContextConstructor(std::ofstream& stream,
-                                      const Interface& inf);
-  void GenInterfaceContextDestructor(std::ofstream& stream,
-                                     const Interface& inf);
-  void GenInterfaceContextFinder(std::ofstream& stream,
-                                 const Interface& inf);
-  void GenInterfaceContextTagSetter(std::ofstream& stream,
-                                    const Interface& inf);
-  void GenInterfaceContextTagGetter(std::ofstream& stream,
-                                    const Interface& inf);
-  void GenInterfaceContextSenderGetter(std::ofstream& stream,
-                                       const Interface& inf);
-
- private:
-  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
-                             const Declaration& decl);
-  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
-                                        const std::string& id,
-                                       const Declaration& decl);
-  void GenInterfaceDelegatorConstructor(std::ofstream& stream,
-                                      const std::string& id,
-                                       const Declaration& decl);
-  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
-                                      const std::string& id,
-                                      const Declaration& decl);
-  void GenInterfaceDelegatorSerializer(std::ofstream& stream,
-                                      const std::string& id,
-                                      const Declaration& decl);
-  void GenInterfaceDelegatorDeserializer(std::ofstream& stream,
-                                        const std::string& id,
-                                        const Declaration& decl);
-  void GenInterfaceDelegatorCloner(std::ofstream& stream,
-                                  const std::string& id,
-                                  const Declaration& decl);
-  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
-                                   const std::string& id,
-                                   const Declaration& decl);
-  void GenInterfaceDelegatorPortSetter(std::ofstream& stream,
-                                       const std::string& id,
-                                       const Declaration& decl);
-
- private:
-  std::string GetMethodString(const Interface& id, const Declaration& decl);
-  std::string GetAddEventCBString(const std::string& id);
-  std::string GetAddPrivilegeString(const std::string& id,
-                                    const Attribute& attr);
-  std::string GetTrustedModeString(const std::string& id,
-                                   const Attribute& attr);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_STUB_BODY_GEN_H_
diff --git a/idlc/c_gen/c_stub_body_gen_cb.h b/idlc/c_gen/c_stub_body_gen_cb.h
deleted file mode 100644 (file)
index 7c77b83..0000000
+++ /dev/null
@@ -1,570 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
-#define IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
-
-const char CB_INTERFACE_METHOD[] =
-R"__c_cb(
-static int __$$_method_$$(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
-{
-    rpc_port_stub_$$_context_h context = data;
-    rpc_port_h callback_port;
-    int r;
-
-    r = rpc_port_stub_get_port(__$$_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
-    if (r != 0) {
-        _E("Failed to get callback port");
-        return -1;
-    }
-
-$$
-    return r;
-}
-)__c_cb";
-
-const char CB_INTERFACE_METHOD_TABLE[] =
-R"__c_cb(static stub_method __$$_method_table[] = {$$
-};
-)__c_cb";
-
-const char CB_INTERFACE_METHOD_FORMAT[] =
-R"__c_cb(
-[$$] = $$,)__c_cb";
-
-const char CB_INTERFACE_ON_CONNECTED[] =
-R"__c_cb(
-static void __##_on_connected(const char *sender, const char *instance, void *data)
-{
-    rpc_port_stub_##_context_h context;
-
-    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
-    context = __create_##_context(sender, instance);
-    if (!context)
-        return;
-
-    if (context->callback.create)
-        context->callback.create(context, context->user_data);
-    __##_contexts = g_list_append(__##_contexts, context);
-}
-)__c_cb";
-
-const char CB_INTERFACE_ON_DISCONNECTED[] =
-R"__c_cb(
-static void __##_on_disconnected(const char *sender, const char *instance, void *data)
-{
-    rpc_port_stub_##_context_h context;
-
-    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
-    context = __find_##_context(instance);
-    if (!context)
-        return;
-
-    if (context->callback.terminate)
-        context->callback.terminate(context, context->user_data);
-    __##_contexts = g_list_remove(__##_contexts, context);
-    __destroy_##_context(context);
-}
-)__c_cb";
-
-const char CB_INTERFACE_ON_RECEIVED[] =
-R"__c_cb(
-static int __##_on_received(const char *sender, const char *instance, rpc_port_h port, void *data)
-{
-    rpc_port_stub_##_context_h context;
-    rpc_port_parcel_h parcel;
-    int cmd = -1;
-    int r;
-
-    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
-    context = __find_##_context(instance);
-    if (!context) {
-        _E("Failed to find ## context(%s)", instance);
-        return -1;
-    }
-
-    context->port = port;
-    r = rpc_port_parcel_create_from_port(&parcel, port);
-    if (r != 0) {
-        _E("Failed to create parcel from port");
-        return r;
-    }
-
-    rpc_port_parcel_read_int32(parcel, &cmd);
-    if (cmd > 1 && cmd < (sizeof(__##_method_table) / sizeof(__##_method_table[0]))) {
-         if (__##_method_table[cmd])
-             r = __##_method_table[cmd](port, parcel, context);
-    } else {
-         _E("Unknown Command(%d)", cmd);
-         r = -1;
-    }
-
-    rpc_port_parcel_destroy(parcel);
-
-    return r;
-}
-)__c_cb";
-
-const char CB_INTERFACE_REGISTER[] =
-R"__c_cb(
-int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data)
-{
-    int r;
-
-    if (__##_stub) {
-        _W("Already exists");
-        return -1;
-    }
-
-    if (!callback) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    __##_callback = *callback;
-    __##_user_data = user_data;
-    r = rpc_port_stub_create(&__##_stub, "##");
-    if (r != 0) {
-        _E("Failed to create stub handle");
-        return r;
-    }
-
-    r = rpc_port_stub_add_received_event_cb(__##_stub, __##_on_received, NULL);
-    if (r != 0) {
-        _E("Failed to add received event callback");
-        rpc_port_stub_destroy(__##_stub);
-        __##_stub = NULL;
-        return r;
-    }
-
-    r = rpc_port_stub_add_connected_event_cb(__##_stub, __##_on_connected, NULL);
-    if (r != 0) {
-        _E("Failed to add connected event callback");
-        rpc_port_stub_destroy(__##_stub);
-        __##_stub = NULL;
-        return r;
-    }
-
-    r = rpc_port_stub_add_disconnected_event_cb(__##_stub, __##_on_disconnected, NULL);
-    if (r != 0) {
-        _E("Failed to add disconnected event callback");
-        rpc_port_stub_destroy(__##_stub);
-        __##_stub = NULL;
-        return r;
-    }
-
-    r = __##_add_privileges();
-    if (r != 0) {
-        _E("Failed to add privileges");
-        rpc_port_stub_destroy(__##_stub);
-        __##_stub = NULL;
-        return r;
-    }
-
-    r = rpc_port_stub_listen(__##_stub);
-    if (r != 0) {
-        _E("Failed to listen stub");
-        rpc_port_stub_destroy(__##_stub);
-        __##_stub = NULL;
-        return r;
-    }
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_UNREGISTER[] =
-R"__c_cb(
-int rpc_port_stub_##_unregister(void)
-{
-    int r;
-
-    if (!__##_stub)
-        return -1;
-
-    if (__##_contexts) {
-        g_list_free_full(__##_contexts, __destroy_##_context);
-        __##_contexts = NULL;
-    }
-
-    r = rpc_port_stub_destroy(__##_stub);
-    __##_stub = NULL;
-
-    return r;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CLIENT_NUMBER_GETTER[] =
-R"__c_cb(
-int rpc_port_stub_##_get_client_number(unsigned int *n)
-{
-       if (!n) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       if (!__##_stub) {
-               _E("## Stub is not ready");
-               return -1;
-       }
-
-       *n = g_list_length(__##_contexts);
-
-       return 0;
-}
-)__c_cb";
-
-const char CB_GLOBALS[] =
-R"__c_cb(
-static rpc_port_stub_h __##_stub;
-static rpc_port_stub_##_callback_s __##_callback;
-static void *__##_user_data;
-static GList *__##_contexts;
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_DECL[] =
-R"__c_cb(
-struct $$_s {
-    rpc_port_parcelable_t parcelable;
-    rpc_port_h port;
-    int id;
-    int seq_id;
-    bool once;
-    bool valid;
-};
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_CTOR[] =
-R"__c_cb(
-static int rpc_port_##_create(rpc_port_##_h *h)
-{
-    struct ##_s *handle;
-    static int seq_num;
-
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    handle = calloc(1, sizeof(struct ##_s));
-    if (!handle) {
-        _E("Out of memory");
-        return -1;
-    }
-
-    handle->parcelable.to = __##_to;
-    handle->parcelable.from = __##_from;
-    handle->id = $$_DELEGATE_$$;
-    handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
-    handle->once = false;
-    handle->valid = true;
-
-    *h = handle;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_DTOR[] =
-R"__c_cb(
-int rpc_port_##_destroy(rpc_port_##_h h)
-{
-    if (!h) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    free(h);
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_SERIALIZER[] =
-R"__c_cb(
-static void __##_to(rpc_port_parcel_h parcel, void *data)
-{
-    rpc_port_##_h handle = data;
-
-    if (!handle) {
-        _E("Invalid parameter");
-        return;
-    }
-
-    rpc_port_parcel_write_int32(parcel, handle->id);
-    rpc_port_parcel_write_int32(parcel, handle->seq_id);
-    rpc_port_parcel_write_bool(parcel, handle->once);
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_DESERIALIZER[] =
-R"__c_cb(
-static void __##_from(rpc_port_parcel_h parcel, void *data)
-{
-    rpc_port_##_h handle = data;
-
-    if (!handle) {
-        _E("Invalid parameter");
-        return;
-    }
-
-    rpc_port_parcel_read_int32(parcel, &handle->id);
-    rpc_port_parcel_read_int32(parcel, &handle->seq_id);
-    rpc_port_parcel_read_bool(parcel, &handle->once);
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_CLONER[] =
-R"__c_cb(
-int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)
-{
-    rpc_port_##_h handle;
-
-    if (!h || !clone) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    handle = calloc(1, sizeof(struct ##_s));
-    if (!handle) {
-        _E("Out of memory");
-        return -1;
-    }
-
-    handle->parcelable = h->parcelable;
-    handle->port = h->port;
-    handle->id = h->id;
-    handle->seq_id = h->seq_id;
-    handle->once = h->once;
-    handle->valid = h->valid;
-
-    *clone = handle;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_INVOKER[] =
-R"__c_cb(
-int rpc_port_$$_invoke($$)
-{
-    rpc_port_parcel_h parcel = NULL;
-    int r;
-
-    if (!h || !h->port) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    if (h->once && !h->valid) {
-        _E("Invalid callback");
-        return -1;
-    }
-
-    rpc_port_parcel_create(&parcel);
-    if (!parcel) {
-        _E("Failed to create parcel");
-        return -1;
-    }
-
-    rpc_port_parcel_write_int32(parcel, $$_METHOD_Callback);
-    rpc_port_parcel_write(parcel, &h->parcelable, h);
-$$
-    r = rpc_port_parcel_send(parcel, h->port);
-    rpc_port_parcel_destroy(parcel);
-    h->valid = false;
-
-    return r;
-}
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_PORT_SETTER[] =
-R"__c_cb(
-int rpc_port_##_set_port(rpc_port_##_h h, rpc_port_h port)
-{
-    if (!h || !port) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    h->port = port;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_DECL[] =
-R"__c_cb(
-struct ##_context_s {
-    char *sender;
-    char *instance;
-    rpc_port_h port;
-    void *tag;
-    rpc_port_stub_##_callback_s callback;
-    void *user_data;
-};
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_CTOR[] =
-R"__c_cb(
-static struct ##_context_s *__create_##_context(const char *sender, const char *instance)
-{
-    struct ##_context_s *handle;
-
-    handle = calloc(1, sizeof(struct ##_context_s));
-    if (!handle) {
-        _E("Out of memory");
-        return NULL;
-    }
-
-    handle->sender = strdup(sender);
-    if (!handle->sender) {
-        _E("Out of memory");
-        free(handle);
-        return NULL;
-    }
-
-    handle->instance = strdup(instance);
-    if (!handle->instance) {
-        _E("Out of memory");
-        free(handle->sender);
-        free(handle);
-        return NULL;
-    }
-
-    handle->callback = __##_callback;
-    handle->user_data = __##_user_data;
-
-    return handle;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_DTOR[] =
-R"__c_cb(
-static void __destroy_##_context(gpointer data)
-{
-    struct ##_context_s *handle = data;
-
-    if (!handle) {
-        _E("Critical error!");
-        return;
-    }
-
-    free(handle->instance);
-    free(handle->sender);
-    free(handle);
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_FINDER[] =
-R"__c_cb(
-static struct ##_context_s *__find_##_context(const char *instance)
-{
-    struct ##_context_s *handle;
-    GList *iter;
-
-    iter = __##_contexts;
-    while (iter) {
-        handle = (struct ##_context_s *)iter->data;
-        if (!strcmp(handle->instance, instance))
-            return handle;
-        iter = g_list_next(iter);
-    }
-
-    return NULL;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_TAG_SETTER[] =
-R"__c_cb(
-int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag)
-{
-    if (!ctx) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    ctx->tag = tag;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_TAG_GETTER[] =
-R"__c_cb(
-int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag)
-{
-    if (!ctx || !tag) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    *tag = ctx->tag;
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_GET_SENDER[] =
-R"__c_cb(
-int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender)
-{
-    if (!ctx || !sender) {
-        _E("Invalid parameter");
-        return -1;
-    }
-
-    *sender = strdup(ctx->sender);
-    if (*sender == NULL) {
-        _E("Out of memory");
-        return -1;
-    }
-
-    return 0;
-}
-)__c_cb";
-
-const char CB_STUB_METHOD_TYPE[] =
-R"__c_cb(
-typedef int (*stub_method)(rpc_port_h, rpc_port_parcel_h, void *data);
-)__c_cb";
-
-const char CB_INTERFACE_ADD_PRIVILEGE[] =
-R"__c_cb(
-static int __$$_add_privileges(void)
-{
-$$
-    return 0;
-}
-)__c_cb";
-
-const char CB_INTERFACE_PRIVILEGE_BLOCK[] =
-R"__c_cb(r = $$;
-if (r != 0) {
-    _E("Failed to add privilege($$)");
-    return r;
-}
-)__c_cb";
-
-const char CB_INTERFACE_TRUSTED_MODE_BLOCK[] =
-R"__c_cb(r = $$;
-if (r != 0) {
-    _E("Failed to set trusted mode($$)");
-    return r;
-}
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
diff --git a/idlc/c_gen/c_stub_header_gen.cc b/idlc/c_gen/c_stub_header_gen.cc
deleted file mode 100644 (file)
index 1936606..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/c_gen/c_stub_header_gen.h"
-
-namespace {
-#include "idlc/c_gen/c_stub_header_gen_cb.h"
-}
-
-namespace tidl {
-
-CStubHeaderGen::CStubHeaderGen(std::shared_ptr<Document> doc)
-    : CHeaderGeneratorBase(doc) {}
-
-void CStubHeaderGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  GenPragmaOnce(stream);
-  GenIncludeDefaultHeaders(stream, false);
-  GenExplicitLinkageOpen(stream);
-  GenStructures(stream);
-  GenInterfaces(stream);
-}
-
-void CStubHeaderGen::OnFiniGen(std::ofstream& stream) {
-  GenExplicitLinkageClose(stream);
-}
-
-void CStubHeaderGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-
-    const Interface &inf = static_cast<const Interface&>(*i);
-    GenInterface(stream, inf);
-  }
-}
-
-void CStubHeaderGen::GenInterface(std::ofstream& stream,
-                                  const Interface& inf) {
-  GenInterfaceContext(stream, inf);
-  GenInterfaceDelegators(stream, inf);
-  GenInterfaceDeclaration(stream, inf);
-  GenInterfaceRegister(stream, inf);
-  GenInterfaceUnregister(stream, inf);
-  GenInterfaceClientNumberGetter(stream, inf);
-}
-
-void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
-                                             const Interface& inf) {
-  stream << SmartIndent(GenTemplateString(ReplaceAll(
-        CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)),
-        [&]()->std::string {
-          std::string str;
-          for (auto& i : inf.GetDeclarations().GetDecls()) {
-            if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-              continue;
-            str += NLine(1);
-            str += GenTemplateString(CB_INTERFACE_CALLBACK,
-                [&]()->std::string {
-                  return GetReturnTypeString(i->GetType());
-                },
-                [&]()->std::string {
-                  return i->GetID();
-                },
-                [&]()->std::string {
-                  return GetInterfaceIdWithNamespace(inf);
-                },
-                [&]()->std::string {
-                  std::string s;
-                  for (auto& p : i->GetParameters().GetParams()) {
-                    if (IsDelegateType(inf, p->GetParameterType()
-                        .GetBaseType())) {
-                      s += "rpc_port_" + GetInterfaceIdWithNamespace(inf)
-                        + "_" + p->GetParameterType().GetBaseType().ToString()
-                        + "_h " + p->GetID();
-                    } else {
-                      s += GetParamTypeString(p->GetParameterType()
-                          .GetDirection(), p->GetParameterType().GetBaseType())
-                        + p->GetID();
-                    }
-                    s += ", ";
-                  }
-                  return s;
-                });
-          }
-          return str;
-        }));
-}
-
-void CStubHeaderGen::GenInterfaceContext(std::ofstream& stream,
-                                         const Interface& inf) {
-  GenInterfaceContextDeclaration(stream, inf);
-  GenInterfaceContextTagSetter(stream, inf);
-  GenInterfaceContextTagGetter(stream, inf);
-  GenInterfaceContextSenderGetter(stream, inf);
-}
-
-void CStubHeaderGen::GenInterfaceContextDeclaration(
-    std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceContextTagSetter(
-    std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceContextTagGetter(
-    std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceContextSenderGetter(
-    std::ofstream& stream, const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
-                                            const Interface& inf) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
-  }
-}
-
-void CStubHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
-                                           const std::string& id,
-                                           const Declaration& decl) {
-  GenInterfaceDelegatorDeclaration(stream, id, decl);
-  GenInterfaceDelegatorDestructor(stream, id, decl);
-  GenInterfaceDelegatorCloner(stream, id, decl);
-  GenInterfaceDelegatorInvoker(stream, id, decl);
-}
-
-void CStubHeaderGen::GenInterfaceDelegatorDeclaration(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << ReplaceAll(
-      CB_INTERFACE_DELEGATOR_DECL, "##", id + "_" + decl.GetID());
-}
-
-void CStubHeaderGen::GenInterfaceDelegatorDestructor(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << ReplaceAll(
-      CB_INTERFACE_DELEGATOR_DTOR, "##", id + "_" + decl.GetID());
-}
-
-void CStubHeaderGen::GenInterfaceDelegatorCloner(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << ReplaceAll(
-      CB_INTERFACE_DELEGATOR_CLONER, "##", id + "_" + decl.GetID());
-}
-
-void CStubHeaderGen::GenInterfaceDelegatorInvoker(
-    std::ofstream& stream, const std::string& id, const Declaration& decl) {
-  stream << GenTemplateString(ReplaceAll(
-      CB_INTERFACE_DELEGATOR_INVOKER, "##", id + "_" + decl.GetID()),
-      [&]()->std::string {
-        std::string str;
-        for (auto& i : decl.GetParameters().GetParams()) {
-          str += ", ";
-          str += GetParamTypeString(i->GetParameterType().GetDirection(),
-              i->GetParameterType().GetBaseType()) + i->GetID();
-        }
-        return str;
-      });
-}
-
-void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream,
-                                          const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_REGISTER, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceUnregister(std::ofstream& stream,
-                                            const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-void CStubHeaderGen::GenInterfaceClientNumberGetter(std::ofstream& stream,
-                                                    const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_CLIENT_NUMBER_GETTER, "##",
-      GetInterfaceIdWithNamespace(inf));
-}
-
-}  // namespace tidl
diff --git a/idlc/c_gen/c_stub_header_gen.h b/idlc/c_gen/c_stub_header_gen.h
deleted file mode 100644 (file)
index 3564967..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_STUB_HEADER_GEN_H_
-#define IDLC_C_GEN_C_STUB_HEADER_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/c_gen/c_header_gen_base.h"
-
-namespace tidl {
-
-class CStubHeaderGen : public CHeaderGeneratorBase {
- public:
-  explicit CStubHeaderGen(std::shared_ptr<Document> doc);
-  virtual ~CStubHeaderGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceRegister(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceUnregister(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceClientNumberGetter(std::ofstream& stream,
-                                       const Interface& inf);
-
- private:
-  void GenInterfaceContextDeclaration(std::ofstream& stream,
-                                      const Interface& inf);
-  void GenInterfaceContextTagSetter(std::ofstream& stream,
-                                    const Interface& inf);
-  void GenInterfaceContextTagGetter(std::ofstream& stream,
-                                    const Interface& inf);
-  void GenInterfaceContextSenderGetter(std::ofstream& stream,
-                                       const Interface& inf);
-
- private:
-  void GenInterfaceDelegator(std::ofstream& stream,
-                             const std::string& id,
-                             const Declaration& decl);
-  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
-                                        const std::string& id,
-                                        const Declaration& decl);
-  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
-                                      const std::string& id,
-                                      const Declaration& decl);
-  void GenInterfaceDelegatorCloner(std::ofstream& stream,
-                                  const std::string& id,
-                                  const Declaration& decl);
-  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
-                                   const std::string& id,
-                                   const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_C_GEN_C_STUB_HEADER_GEN_H_
diff --git a/idlc/c_gen/c_stub_header_gen_cb.h b/idlc/c_gen/c_stub_header_gen_cb.h
deleted file mode 100644 (file)
index 49e37f0..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
-#define IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
-
-const char CB_INTERFACE_DECL[] =
-R"__c_cb(
-typedef struct {
-    void (*create)(rpc_port_stub_##_context_h context, void *user_data);
-    void (*terminate)(rpc_port_stub_##_context_h context, void *user_data);
-$$
-} rpc_port_stub_##_callback_s;
-)__c_cb";
-
-const char CB_INTERFACE_CALLBACK[] =
-R"__c_cb($$(*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_DECL[] =
-R"__c_cb(
-typedef struct ##_context_s* rpc_port_stub_##_context_h;
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_SET_TAG[] =
-R"__c_cb(
-int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag);
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_GET_TAG[] =
-R"__c_cb(
-int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag);
-)__c_cb";
-
-const char CB_INTERFACE_CONTEXT_GET_SENDER[] =
-R"__c_cb(
-int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender);
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_DECL[] =
-R"__c_cb(
-typedef struct ##_s *rpc_port_##_h;
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_DTOR[] =
-R"__c_cb(
-int rpc_port_##_destroy(rpc_port_##_h h);
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_CLONER[] =
-R"__c_cb(
-int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone);
-)__c_cb";
-
-const char CB_INTERFACE_DELEGATOR_INVOKER[] =
-R"__c_cb(
-int rpc_port_##_invoke(rpc_port_##_h h$$);
-)__c_cb";
-
-const char CB_INTERFACE_REGISTER[] =
-R"__c_cb(
-int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data);
-)__c_cb";
-
-const char CB_INTERFACE_UNREGISTER[] =
-R"__c_cb(
-int rpc_port_stub_##_unregister(void);
-)__c_cb";
-
-const char CB_INTERFACE_CLIENT_NUMBER_GETTER[] =
-R"__c_cb(
-int rpc_port_stub_##_get_client_number(unsigned int *n);
-)__c_cb";
-
-#endif  // IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
diff --git a/idlc/cpp_gen/cpp_gen_base.cc b/idlc/cpp_gen/cpp_gen_base.cc
deleted file mode 100644 (file)
index d18fbd1..0000000
+++ /dev/null
@@ -1,703 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <ctime>
-#include <vector>
-#include <utility>
-
-#include "idlc/cpp_gen/cpp_gen_base.h"
-
-namespace {
-#include "idlc/cpp_gen/cpp_gen_base_cb.h"
-}
-
-namespace tidl {
-
-CppGeneratorBase::CppGeneratorBase(std::shared_ptr<Document> doc)
-    : Generator(doc) {
-  type_map_ = {
-      {"char", "char"}, {"int", "int"}, {"short", "short"},
-      {"long", "long long"}, {"string", "std::string"}, {"bool", "bool"},
-      {"list", "std::list"}, {"float", "float"}, {"double", "double"},
-      {"bundle", "Bundle"}, {"void", "void"}, {"array", "std::vector"}
-  };
-
-  parcel_type_map_ = {
-    {"char", "byte"},
-    {"int", "int32"},
-    {"short", "int16"},
-    {"long", "int64"},
-    {"string", "string"},
-    {"bool", "bool"},
-    {"float", "float"},
-    {"double", "double"},
-    {"bundle", "bundle"},
-  };
-
-  type_init_map_ = {
-    {"char", "0"},
-    {"int", "0"},
-    {"short", "0"},
-    {"long", "0"},
-    {"bool", "false"},
-    {"float", "0.0f"},
-    {"double", "0.0"},
-  };
-}
-
-void CppGeneratorBase::GenStructuresForHeader(std::ofstream& stream) {
-  stream << CB_BUNDLE;
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenStructureForHeader(stream, st);
-    stream << std::endl;
-  }
-}
-
-void CppGeneratorBase::GenStructureForHeader(std::ofstream& stream,
-                                             const Structure& st) {
-  const char ctor[] = "  $$();\n" \
-                      "  $$($$);\n";
-  const char variable[] = "$$\n";
-
-  stream << "class " << st.GetID() << " final ";
-
-  GenBrace(stream, 0, [&]() {
-    stream << " public:" << NLine(1);
-    GenTemplate(ctor, stream,
-      [&]()->std::string {
-        return st.GetID();
-      },
-      [&]()->std::string {
-        return st.GetID();
-      },
-      [&]()->std::string {
-        std::string str;
-        int n = 1;
-        for (auto& i : st.GetElements().GetElms()) {
-          if (n != 1)
-            str += ", ";
-          str += ConvertTypeToString(i->GetType()) + " " + i->GetID();
-          n++;
-        }
-        return str;
-      });
-
-    stream << NLine(1);
-    for (auto& i : st.GetElements().GetElms()) {
-      GenSetter(stream, *i);
-      GenGetter(stream, *i);
-      stream << NLine(1);
-    }
-
-    stream << " private:";
-    GenTemplate(variable, stream,
-      [&]()->std::string {
-        std::string str;
-        for (auto& i : st.GetElements().GetElms()) {
-          str += NLine(1) + Tab(1)
-              + ConvertTypeToString(i->GetType()) + " "
-              + i->GetID() + "_";
-          if (type_init_map_.find(i->GetType().ToString())
-              == type_init_map_.end()) {
-            str += ";";
-          } else {
-            str += " = " + type_init_map_[i->GetType().ToString()] + ";";
-          }
-        }
-        str += NLine(1);
-        return str;
-      });
-  }, false, false);
-  stream << ";" << NLine(1);
-}
-
-void CppGeneratorBase::GenSetter(std::ofstream& stream, const Element& ele) {
-  const char setter[] =
-      "void Set$$($$ $$) {\n" \
-      "  $$_ = $$;\n" \
-      "}\n";
-
-  GenTemplate(AddIndent(TAB_SIZE, setter, true), stream,
-    [&]()->std::string {
-      return ele.GetID();
-    },
-    [&]()->std::string {
-      return ConvertTypeToString(ele.GetType());
-    },
-    [&]()->std::string {
-      return ele.GetID();
-    },
-    [&]()->std::string {
-      return ele.GetID();
-    },
-    [&]()->std::string {
-      if (ele.GetType().IsUserDefinedType() ||
-        ele.GetType().GetMetaType() != nullptr ||
-        ele.GetType().ToString() == "string" ||
-        ele.GetType().ToString() == "bundle") {
-        return "std::move(" + ele.GetID() + ")";
-      }
-
-      return ele.GetID();
-    });
-  stream << NLine(1);
-}
-
-void CppGeneratorBase::GenGetter(std::ofstream& stream, const Element& ele) {
-  const char getter[] =
-      "$$ Get$$() const {\n" \
-      "  return $$_;\n" \
-      "}\n";
-
-  GenTemplate(AddIndent(TAB_SIZE, getter, true), stream,
-    [&]()->std::string {
-      if (ele.GetType().IsUserDefinedType() ||
-        ele.GetType().GetMetaType() != nullptr ||
-        ele.GetType().ToString() == "string" ||
-        ele.GetType().ToString() == "bundle") {
-        return "const " + ConvertTypeToString(ele.GetType()) + "&";
-      }
-
-      return ConvertTypeToString(ele.GetType());
-    },
-    [&]()->std::string {
-      return ele.GetID();
-    },
-    [&]()->std::string {
-      return ele.GetID();
-    });
-}
-
-void CppGeneratorBase::GenStructuresForBody(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenStructureForBody(stream, st);
-    stream << std::endl;
-  }
-}
-
-void CppGeneratorBase::GenStructureForBody(std::ofstream& stream,
-    const Structure& st) {
-  std::vector<std::pair<std::string, std::string>> v;
-  const char ctor[] = "##::##() {}\n\n" \
-                      "##::##($$)\n" \
-                      "    : $$ {}";
-
-  for (auto& i : st.GetElements().GetElms()) {
-    std::pair<std::string, std::string> p;
-
-    p.first = ConvertTypeToString(i->GetType());
-    p.second = i->GetID();
-    v.push_back(p);
-  }
-
-  GenTemplate(ReplaceAll(ctor, "##", st.GetID()), stream,
-    [&]()->std::string {
-      std::string str;
-      for (auto& i : v) {
-        str += i.first + " " + i.second;
-
-        if (i != v.back())
-          str += ", ";
-      }
-      return str;
-    },
-    [&]()->std::string {
-      std::string str;
-      for (auto& i : v) {
-        str += i.second + "_(std::move(" + i.second + "))";
-
-        if (i != v.back())
-          str += ", ";
-      }
-      return str;
-    });
-  stream <<  NLine(2);
-}
-
-void CppGeneratorBase::GenSerializer(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenSerializer(stream, st);
-    stream << NLine(1);
-  }
-}
-
-void CppGeneratorBase::GenPrototype(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenSerializer(stream, st, true);
-    GenDeSerializer(stream, st, true);
-  }
-  GenListSerializer(stream, true);
-  stream << NLine(1);
-}
-
-void CppGeneratorBase::GenSerializer(std::ofstream& stream, const Structure& st,
-                                     bool proto) {
-  const char parcel_str[] = "rpc_port_parcel_h";
-
-  stream << parcel_str << " operator << ("
-         << parcel_str << " h, const " << st.GetID() << "& param)";
-  if (proto) {
-    stream << ";" << NLine(1);
-    return;
-  }
-
-  stream << " ";
-  GenBrace(stream, 0, [&]() {
-    for (auto& i : st.GetElements().GetElms()) {
-      stream << AddIndent(TAB_SIZE,
-          ConvertTypeToSerializer(i->GetType(),
-              "param.Get" + i->GetID() + "()", "h"));
-    }
-    stream << Tab(1) << "return h;" << NLine(1);
-  }, false);
-}
-
-void CppGeneratorBase::GenDeSerializer(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenDeSerializer(stream, st);
-    stream << std::endl;
-  }
-}
-
-void CppGeneratorBase::GenDeSerializer(std::ofstream& stream,
-                                       const Structure& st, bool proto) {
-  const char parcel_str[] = "rpc_port_parcel_h";
-
-  stream << parcel_str << " operator >> ("
-         << parcel_str << " h, " << st.GetID() << "& param)";
-  if (proto) {
-    stream << ";" << NLine(1);
-    return;
-  }
-
-  stream << " ";
-  GenBrace(stream, 0, [&]() {
-    for (auto& i : st.GetElements().GetElms()) {
-      stream << AddIndent(TAB_SIZE,
-          ConvertTypeToDeserializer(i->GetType(), i->GetID(), "h"));
-      stream << Tab(1) << "param.Set" << i->GetID() << "(std::move("
-             << i->GetID() << "));" << NLine(2);
-    }
-    stream << Tab(1) << "return h;" << NLine(1);
-  }, false);
-}
-
-std::string CppGeneratorBase::ConvertTypeToString(const BaseType& type) {
-  if (type.IsUserDefinedType()) {
-    if (IsDelegateType(type)) {
-      return "std::unique_ptr<" + type.ToString() + ">";
-    }
-    return type.ToString();
-  }
-
-  if (type.GetMetaType() != nullptr)
-    return type_map_[type.ToString()] + "<" +
-        ConvertTypeToString(*(type.GetMetaType())) + ">";
-
-  return type_map_[type.ToString()];
-}
-
-std::string CppGeneratorBase::Tab(int cnt) {
-  std::string t(cnt * 2, ' ');
-
-  return t;
-}
-
-std::string CppGeneratorBase::NLine(int cnt) {
-  std::string t(cnt, '\n');
-
-  return t;
-}
-
-void CppGeneratorBase::AddSerializerList(const BaseType& type) {
-  if (type.GetMetaType() != nullptr) {
-    serializer_list_[ConvertTypeToString(type)] = &type;
-    AddSerializerList(*type.GetMetaType());
-  }
-}
-
-void CppGeneratorBase::GenListSerializer(std::ofstream& stream,
-                                         const BaseType& type, bool proto) {
-  stream << "rpc_port_parcel_h operator << (rpc_port_parcel_h h, const "
-         << ConvertTypeToString(type) << "& c)";
-
-  if (proto) {
-    stream << ";" << NLine(1);
-    stream << "rpc_port_parcel_h operator >> (rpc_port_parcel_h h, "
-           << ConvertTypeToString(type) << "& c);" << NLine(1);
-    return;
-  }
-
-  stream << " ";
-  GenBrace(stream, 0, [&]() {
-    stream << Tab(1)
-           << "rpc_port_parcel_write_array_count(h, c.size());"
-           << NLine(1);
-    stream << Tab(1) << "for (const auto& i : c) ";
-    GenBrace(stream, TAB_SIZE, [&]() {
-      auto& mt = *type.GetMetaType();
-      stream << AddIndent(TAB_SIZE * 2, ConvertTypeToSerializer(mt, "i", "h"));
-    }, false);
-    stream << Tab(1) << "return h;" << NLine(1);
-  }, false);
-  stream << NLine(1);
-
-  stream << "rpc_port_parcel_h operator >> (rpc_port_parcel_h h, "
-         << ConvertTypeToString(type) << "& c) ";
-  GenBrace(stream, 0, [&]() {
-    stream << Tab(1) << "int l = 0;" << NLine(1);
-    stream << Tab(1)
-           << "rpc_port_parcel_read_array_count(h, &l);" << NLine(1);
-    stream << Tab(1) << "for (int i = 0; i < l; i++) ";
-    GenBrace(stream, TAB_SIZE, [&]() {
-      auto& mt = *type.GetMetaType();
-      stream << AddIndent(TAB_SIZE * 2,
-          ConvertTypeToDeserializer(mt, "v", "h", true));
-      stream << Tab(2) << "c.push_back(std::move(v));" << NLine(1);
-    }, false);
-    stream << Tab(1) << "return h;" << NLine(1);
-  }, false);
-}
-
-void CppGeneratorBase::GenListSerializer(std::ofstream& stream, bool proto) {
-  serializer_list_.clear();
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() == Block::TYPE_STRUCTURE) {
-      const Structure& st = static_cast<const Structure&>(*i);
-      for (auto& j : st.GetElements().GetElms()) {
-        auto& t = j->GetType();
-        AddSerializerList(t);
-      }
-    } else if (i->GetType() == Block::TYPE_INTERFACE) {
-      const Interface& iface = static_cast<const Interface&>(*i);
-      for (auto& j : iface.GetDeclarations().GetDecls()) {
-        auto& t = j->GetType();
-        AddSerializerList(t);
-        for (auto& k : j->GetParameters().GetParams()) {
-          auto& t1 = k->GetParameterType().GetBaseType();
-          AddSerializerList(t1);
-        }
-      }
-    }
-  }
-
-  for (auto& p : serializer_list_) {
-    const BaseType* t = p.second;
-    GenListSerializer(stream, *t, proto);
-  }
-}
-
-void CppGeneratorBase::GenMethodId(std::ofstream& stream,
-                                   const Interface& iface) {
-  stream << Tab(1) << "enum class MethodId : int ";
-  GenBrace(stream, TAB_SIZE, [&]() {
-    int cnt = 2;
-    stream << Tab(2) << "__Result = 0," << NLine(1);
-    stream << Tab(2) << "__Callback = 1," << NLine(1);
-    for (auto& i : iface.GetDeclarations().GetDecls()) {
-      if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-        continue;
-      stream << Tab(2)
-             << i->GetID() << " = " << cnt++ << "," << NLine(1);
-    }
-  }, false, false);
-  stream << ";" << NLine(2);
-}
-
-void CppGeneratorBase::GenDelegateId(std::ofstream& stream,
-                                     const Interface& iface) {
-  stream << Tab(1) << "enum class DelegateId : int ";
-  GenBrace(stream, TAB_SIZE, [&]() {
-    int cnt = 1;
-    for (auto& i : iface.GetDeclarations().GetDecls()) {
-        if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          continue;
-        stream << Tab(2)
-               << i->GetID() << " = " << cnt++ << "," << NLine(1);
-    }
-  }, false, false);
-  stream << ";" << NLine(2);
-}
-
-void CppGeneratorBase::GenParameters(std::ofstream& stream,
-                                     const Parameters& ps) {
-  stream << GetParameters(ps);
-}
-
-std::string CppGeneratorBase::GetParameters(const Parameters& ps) {
-  bool first = true;
-  std::string ret;
-  for (auto& i : ps.GetParams()) {
-    if (!first) {
-      ret += ", ";
-    }
-
-    std::string ref;
-    auto dir = i->GetParameterType().GetDirection();
-    if (dir == ParameterType::Direction::OUT ||
-        dir == ParameterType::Direction::REF) {
-      ref = "&";
-    }
-
-    ret += ConvertTypeToString(i->GetParameterType().GetBaseType())
-        + ref + " " + i->GetID();
-    first = false;
-  }
-
-  return ret;
-}
-
-void CppGeneratorBase::GenDeclaration(std::ofstream& stream,
-                                     const Interface& iface,
-                                     const Declaration& decl) {
-  stream << ConvertTypeToString(decl.GetType()) << " " << iface.GetID() << "::"
-         << decl.GetID() << "(";
-  GenParameters(stream, decl.GetParameters());
-  stream << ") ";
-}
-
-std::string CppGeneratorBase::ConvertTypeToSerializer(
-    const BaseType& type, std::string id, std::string parcel) {
-  std::string ret;
-
-  if (type.ToString() == "string") {
-    ret += "rpc_port_parcel_write_"
-        + parcel_type_map_[type.ToString()]
-        + "(" + parcel + ", " + id + ".c_str());\n";
-  } else if (type.ToString() == "bundle") {
-    ret += "rpc_port_parcel_write_bundle(" + parcel + ", "
-        + id + ".GetHandle());\n";
-  } else if (type.GetMetaType() || type.IsUserDefinedType()) {
-    if (type.IsUserDefinedType() && IsDelegateType(type))
-      ret += parcel + " << *" + id + ";\n";
-    else
-      ret += parcel + " << " + id + ";\n";
-  } else {
-    ret += "rpc_port_parcel_write_"
-        + parcel_type_map_[type.ToString()]
-        + "(" + parcel + ", " + id + ");\n";
-  }
-
-  return ret;
-}
-
-std::string CppGeneratorBase::ConvertTypeToDeserializer(
-    const BaseType& type, std::string id, std::string parcel,
-    bool make_new_type) {
-  std::string ret;
-
-  if (type.ToString() == "string") {
-    ret += "char* " + id + "_raw  = nullptr;\n";
-    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
-        + "(" + parcel + ", &" + id + "_raw);\n";
-    if (make_new_type) {
-      ret += "std::string " + id + "(" + id + "_raw);\n";
-    } else {
-      ret += id + " = " + id + "_raw;\n";
-    }
-    ret += "free(" + id + "_raw);\n";
-  } else if (type.ToString() == "bundle") {
-    ret += "bundle* " + id + "_raw = nullptr;\n";
-    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
-        + "(" + parcel + ", &" + id + "_raw);\n";
-    if (make_new_type) {
-      ret += "Bundle " + id + "(" + id + "_raw);\n";
-    } else {
-      ret +=  id + " = " + id + "_raw;\n"
-          + "bundle_free(" + id + "_raw);\n";
-    }
-  } else if (type.GetMetaType() != nullptr || type.IsUserDefinedType()) {
-    std::string n;
-
-    if (type.GetMetaType() != nullptr || IsDelegateType(type))
-      n = ConvertTypeToString(type);
-    else
-      n = type.ToString();
-
-    if (make_new_type) {
-      ret += n + " ";
-      if (IsDelegateType(type)) {
-        ret += id + "(new " + type.ToString()
-            + "(callback_port, std::weak_ptr<ServiceBase>(b)));\n";
-      } else {
-        ret += id + ";\n";
-      }
-    }
-    if (IsDelegateType(type))
-      ret += parcel + " >> *" + id + ";\n";
-    else
-      ret += parcel + " >> " + id + ";\n";
-  } else {
-    if (make_new_type)
-      ret += ConvertTypeToString(type) + " " + id + ";\n";
-    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
-        + "(" + parcel + ", &" + id + ");\n";
-  }
-
-  return ret;
-}
-
-void CppGeneratorBase::GenBodyCallbacks(std::ofstream& stream,
-                                   const Interface& iface, bool is_proxy) {
-  stream << ReplaceAll(CB_CALLBACK_BASE, "##", iface.GetID());
-
-  for (auto& i : iface.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          continue;
-    GenBodyCallback(stream, iface, *i, is_proxy);
-  }
-}
-
-void CppGeneratorBase::GenBodyCallback(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl, bool is_proxy) {
-  if (!is_proxy) {
-    GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream,
-      [&]()->std::string {
-        return iface.GetID();
-      },
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        return GetParameters(decl.GetParameters());
-      },
-      [&]()->std::string {
-        std::string m;
-        for (auto& i : decl.GetParameters().GetParams()) {
-          auto& pt = i->GetParameterType();
-          m += AddIndent(TAB_SIZE,
-              ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p"));
-        }
-        return m;
-      });
-  } else {
-    GenTemplate(CB_CALLBACK_ON_RECEIVED_EVENT_METHOD, stream,
-      [&]()->std::string {
-        return iface.GetID();
-      },
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        int cnt = 1;
-        std::string ret;
-        for (auto& i : decl.GetParameters().GetParams()) {
-          std::string v = "param" + std::to_string(cnt);
-          std::string c = ConvertTypeToDeserializer(
-              i->GetParameterType().GetBaseType(), v, "parcel");
-          ret += AddIndent(TAB_SIZE, c) + NLine(1);
-          cnt++;
-        }
-
-        cnt = 1;
-        ret += Tab(1) + "OnReceived(";
-        for (int i = 0; i < decl.GetParameters().GetParams().size(); i++) {
-          if (cnt != 1) {
-            ret += ", ";
-          }
-          ret += "std::move(param" + std::to_string(cnt) + ")";
-          cnt++;
-        }
-        ret += ");";
-
-        return ret;
-      });
-  }
-}
-
-void CppGeneratorBase::GenHeaderCallbacks(std::ofstream& stream,
-                                          const Interface& iface,
-                                          bool is_proxy) {
-  stream << CB_CALLBACK_BASE_HEADER_FRONT;
-  if (is_proxy) {
-    stream << Tab(1)
-           << "  virtual void OnReceivedEvent(rpc_port_parcel_h port) = 0;"
-           << NLine(1);
-  }
-  stream << CB_CALLBACK_BASE_HEADER_BACK;
-
-  for (auto& i : iface.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          continue;
-    GenHeaderCallback(stream, *i, is_proxy);
-  }
-}
-
-void CppGeneratorBase::GenHeaderCallback(std::ofstream& stream,
-                                         const Declaration& decl,
-                                         bool is_proxy) {
-  stream << GenTemplateString(CB_CALLBACK_CLASS,
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        return ReplaceAll(
-            is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB,
-            "##", decl.GetID());
-      },
-      [&]()->std::string {
-        std::string ret;
-        if (is_proxy) {
-          ret = Tab(2) + "virtual void OnReceived("
-              + GetParameters(decl.GetParameters())
-              + ") {}" + NLine(1);
-        } else {
-          ret = Tab(2) + "void Invoke("
-              + GetParameters(decl.GetParameters())
-              + ");" + NLine(1);
-        }
-
-        return ret;
-      },
-      [&]()->std::string {
-        return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB;
-      });
-}
-
-void CppGeneratorBase::GenVersion(std::ofstream& stream) {
-  GenTemplate(CB_VERSION, stream,
-    [&]()->std::string {
-      return FULLVER;
-    });
-}
-
-void CppGeneratorBase::GenLogTag(std::ofstream& stream, std::string id) {
-  GenTemplate(CB_LOG_TAG, stream,
-      [&]()->std::string {
-        return id;
-      });
-}
-
-void CppGeneratorBase::GenLogDefinition(std::ofstream& stream) {
-  stream << CB_LOG_DEF;
-}
-
-}  // namespace tidl
diff --git a/idlc/cpp_gen/cpp_gen_base.h b/idlc/cpp_gen/cpp_gen_base.h
deleted file mode 100644 (file)
index c59e6bc..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_GEN_BASE_H_
-#define IDLC_CPP_GEN_CPP_GEN_BASE_H_
-
-#include <memory>
-#include <string>
-#include <map>
-
-#include "idlc/type.h"
-#include "idlc/structure.h"
-#include "idlc/generator.h"
-
-namespace tidl {
-
-class CppGeneratorBase : public Generator {
- public:
-  explicit CppGeneratorBase(std::shared_ptr<Document> doc);
-  virtual ~CppGeneratorBase() = default;
-
-  void GenVersion(std::ofstream& stream);
-  void GenStructuresForHeader(std::ofstream& stream);
-  void GenStructuresForBody(std::ofstream& stream);
-  void GenSerializer(std::ofstream& stream);
-  void GenDeSerializer(std::ofstream& stream);
-  void GenListSerializer(std::ofstream& stream, bool proto = false);
-  void GenPrototype(std::ofstream& stream);
-  void GenMethodId(std::ofstream& stream, const Interface& iface);
-  void GenDelegateId(std::ofstream& stream, const Interface& iface);
-  void GenParameters(std::ofstream& stream, const Parameters& ps);
-  void GenDeclaration(std::ofstream& stream, const Interface& iface,
-                      const Declaration& decl);
-  void GenBodyCallbacks(std::ofstream& stream, const Interface& iface,
-                        bool is_proxy);
-  void GenHeaderCallbacks(std::ofstream& stream, const Interface& iface,
-                          bool is_proxy);
-  std::string ConvertTypeToString(const BaseType& type);
-  std::string Tab(int cnt);
-  std::string NLine(int cnt);
-  std::string ConvertTypeToDeserializer(const BaseType& type,
-                                        std::string id, std::string parcel,
-                                        bool make_new_type = true);
-  std::string ConvertTypeToSerializer(const BaseType& type,
-                                      std::string id, std::string parcel);
-  std::string GetParameters(const Parameters& ps);
-  void GenLogTag(std::ofstream& stream, std::string id);
-  void GenLogDefinition(std::ofstream& stream);
-
- private:
-  void GenSetter(std::ofstream& stream, const Element& ele);
-  void GenGetter(std::ofstream& stream, const Element& ele);
-  void AddSerializerList(const BaseType& type);
-  void GenListSerializer(std::ofstream& stream, const BaseType& type,
-                         bool proto = false);
-  void GenDeSerializer(std::ofstream& stream, const Structure& st,
-                       bool proto = false);
-  void GenSerializer(std::ofstream& stream, const Structure& st,
-                     bool proto = false);
-  void GenStructureForHeader(std::ofstream& stream, const Structure& st);
-  void GenStructureForBody(std::ofstream& stream, const Structure& st);
-  void GenBodyCallback(std::ofstream& stream, const Interface& iface,
-                       const Declaration& decl, bool is_proxy);
-  void GenHeaderCallback(std::ofstream& stream, const Declaration& decl,
-                         bool is_proxy);
-
- protected:
-  const int TAB_SIZE = 2;
-
- private:
-  std::map<std::string, std::string> type_map_;
-  std::map<std::string, std::string> parcel_type_map_;
-  std::map<std::string, std::string> type_init_map_;
-  std::map<std::string, const BaseType*> serializer_list_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CPP_GEN_CPP_GEN_BASE_H_
diff --git a/idlc/cpp_gen/cpp_gen_base_cb.h b/idlc/cpp_gen/cpp_gen_base_cb.h
deleted file mode 100644 (file)
index 56216c4..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
-#define IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
-
-const char CB_BUNDLE[] = R"__cls_bundle(class Bundle final {
- public:
-  Bundle() {
-    raw_ = bundle_create();
-  }
-
-  Bundle(bundle* b) {
-    raw_ = b;
-  }
-
-  ~Bundle() {
-    if (raw_)
-      bundle_free(raw_);
-  }
-
-  Bundle(Bundle&& b) : raw_(b.raw_) {
-    b.raw_ = nullptr;
-  }
-
-  Bundle& operator = (Bundle&& b) {
-    raw_ = b.raw_;
-    b.raw_ = nullptr;
-    return *this;
-  }
-
-  Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
-
-  Bundle& operator = (const Bundle& b) {
-    raw_ = bundle_dup(b.GetHandle());
-    return *this;
-  }
-
-  bundle* GetHandle() const {
-    return raw_;
-  }
-
- private:
-  bundle* raw_;
-};
-
-)__cls_bundle";
-
-const char CB_CALLBACK_BASE[] =
-R"__cpp_cb(
-std::atomic<int> ##::CallbackBase::seq_num_ { 0 };
-
-##::CallbackBase::CallbackBase(int delegate_id, bool once)
-    : id_(delegate_id), once_(once) {
-  seq_id_ = seq_num_++;
-}
-
-int ##::CallbackBase::GetId() const {
-  return id_;
-}
-
-int ##::CallbackBase::GetSeqId() const {
-  return seq_id_;
-}
-
-bool ##::CallbackBase::IsOnce() const {
-  return once_;
-}
-
-std::string ##::CallbackBase::GetTag() const {
-  return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const ##::CallbackBase& cb) {
-  rpc_port_parcel_write_int32(h, cb.id_);
-  rpc_port_parcel_write_int32(h, cb.seq_id_);
-  rpc_port_parcel_write_bool(h, cb.once_);
-
-  return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, ##::CallbackBase& cb) {
-  rpc_port_parcel_read_int32(h, &cb.id_);
-  rpc_port_parcel_read_int32(h, &cb.seq_id_);
-  rpc_port_parcel_read_bool(h, &cb.once_);
-
-  return h;
-}
-)__cpp_cb";
-
-const char CB_VERSION[] =
-R"__cpp_cb(/*
- * Generated by tidlc $$.
- */
-)__cpp_cb";
-
-const char CB_CALLBACK_BASE_HEADER_FRONT[] =
-R"__cpp_cb(
-  class CallbackBase {
-   public:
-    CallbackBase(int delegate_id, bool once);
-    virtual ~CallbackBase() = default;
-)__cpp_cb";
-
-const char CB_CALLBACK_BASE_HEADER_BACK[] =
-R"__cpp_cb(
-    int GetId() const;
-    int GetSeqId() const;
-    bool IsOnce() const;
-    std::string GetTag() const;
-
-   private:
-    friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb);
-    friend rpc_port_parcel_h operator >> (rpc_port_parcel_h h, CallbackBase& cb);
-
-    static std::atomic<int> seq_num_;
-    int id_;
-    int seq_id_;
-    bool once_;
-  };
-)__cpp_cb";
-
-const char CB_CALLBACK_CLASS[] =
-R"__cpp_cb(
-  class $$ : public CallbackBase {
-   public:$$
-$$
-   private:$$
-  };
-)__cpp_cb";
-
-const char CB_CALLBACK_CTOR_STUB[] =
-R"__cpp_cb(
-    ##(rpc_port_h port, std::weak_ptr<ServiceBase> service)
-        : CallbackBase(static_cast<int>(DelegateId::##), false) {
-      port_ = port;
-      service_ = std::move(service);
-    }
-)__cpp_cb";
-
-const char CB_CALLBACK_CTOR_PROXY[] =
-R"__cpp_cb(
-    ##(bool once = false)
-        : CallbackBase(static_cast<int>(DelegateId::##), once) {}
-)__cpp_cb";
-
-const char CB_CALLBACK_PRIVATE_PROXY[] =
-R"__cpp_cb(
-    void OnReceivedEvent(rpc_port_parcel_h port) override;
-)__cpp_cb";
-
-const char CB_CALLBACK_PRIVATE_STUB[] =
-R"__cpp_cb(
-    rpc_port_h port_;
-    std::weak_ptr<ServiceBase> service_;
-    bool valid_ = true;
-)__cpp_cb";
-
-const char CB_CALLBACK_INVOKE_METHOD[] =
-R"__cpp_cb(
-void $$::$$::Invoke($$) {
-  if (port_ == nullptr)
-      throw NotConnectedSocketException();
-  if (service_.lock().get() == nullptr)
-      throw NotConnectedSocketException();
-
-  if (IsOnce() && !valid_)
-      throw InvalidCallbackException();
-
-  rpc_port_parcel_h p;
-  rpc_port_parcel_create(&p);
-  rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::__Callback));
-  p << *this;
-$$
-  // Send
-  set_last_result(rpc_port_parcel_send(p, port_));
-  rpc_port_parcel_destroy(p);
-  valid_ = false;
-}
-)__cpp_cb";
-
-const char CB_CALLBACK_ON_RECEIVED_EVENT_METHOD[] =
-R"__cpp_cb(
-void $$::$$::OnReceivedEvent(rpc_port_parcel_h parcel) {
-$$
-}
-)__cpp_cb";
-
-const char CB_LOG_TAG[] =
-R"__cpp_cb(
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "$$"
-)__cpp_cb";
-
-const char CB_LOG_DEF[] =
-R"__cpp_cb(
-#ifdef _E
-#undef _E
-#endif
-
-#ifdef _W
-#undef _W
-#endif
-
-#ifdef _I
-#undef _I
-#endif
-
-#ifdef _D
-#undef _D
-#endif
-
-#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-)__cpp_cb";
-
-#endif  // IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
diff --git a/idlc/cpp_gen/cpp_proxy_body_gen.cc b/idlc/cpp_gen/cpp_proxy_body_gen.cc
deleted file mode 100644 (file)
index 0fe8607..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cpp_gen/cpp_proxy_body_gen.h"
-
-namespace {
-#include "idlc/cpp_gen/cpp_proxy_body_gen_cb.h"
-}
-
-namespace tidl {
-
-CppProxyBodyGen::CppProxyBodyGen(std::shared_ptr<Document> doc)
-    : CppGeneratorBase(doc) {}
-
-void CppProxyBodyGen::OnInitGen(std::ofstream& stream) {
-  std::string key(".cc");
-  std::string header_file = FileName;
-
-  std::size_t found = header_file.rfind(key);
-  if (found != std::string::npos)
-    header_file.replace(found, key.length(), ".h");
-
-  GenVersion(stream);
-  stream << NLine(1);
-  stream << "#include <stdlib.h>" << NLine(1)
-         << "#include <assert.h>" << NLine(1)
-         << "#include <dlog.h>" << NLine(1)
-         <<  NLine(1)
-         << "#include \"" << header_file << "\"" << NLine(2);
-  GenLogTag(stream, "RPC_PORT_PROXY");
-  GenLogDefinition(stream);
-  stream << NLine(1);
-  GenNamespace(stream);
-}
-
-void CppProxyBodyGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void CppProxyBodyGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace rpc_port ";
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << " ";
-    GenBrace(stream, 0, [&]() {
-      stream <<  NLine(1);
-      GenStructuresForBody(stream);
-      stream << "namespace proxy ";
-      GenBrace(stream, 0, [&]() {
-        GenPrototype(stream);
-        GenSerializer(stream);
-        GenDeSerializer(stream);
-        GenListSerializer(stream);
-        GenInterfaces(stream);
-      }, false, false);
-      stream << "  // namespace proxy" + NLine(1);
-    }, false, false);
-    stream << "  // namespace " + GetFileNamespace() + NLine(1);
-  }, false, false);
-  stream << "  // namespace rpc_port" + NLine(1);
-}
-
-void CppProxyBodyGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-  }
-}
-
-void CppProxyBodyGen::GenInterface(std::ofstream& stream,
-                                   const Interface& iface) {
-  GenBodyCallbacks(stream, iface, true);
-  GenConstructor(stream, iface);
-  GenDestructor(stream, iface);
-  GenHelperMethods(stream, iface);
-  GenMethods(stream, iface);
-}
-
-void CppProxyBodyGen::GenConstructor(std::ofstream& stream,
-                                     const Interface& iface) {
-  GenTemplate(CB_PROXY_INTERFACE_CTOR, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
-}
-
-void CppProxyBodyGen::GenDestructor(std::ofstream& stream,
-                                    const Interface& iface) {
-  GenTemplate(CB_DTOR, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
-}
-
-void CppProxyBodyGen::GenHelperMethods(std::ofstream& stream,
-                                       const Interface& iface) {
-  stream << ReplaceAll(CB_PROXY_HELPER_METHODS, "##", iface.GetID())
-         << NLine(1);
-}
-
-void CppProxyBodyGen::GenMethods(std::ofstream& stream,
-                                 const Interface& iface) {
-  auto& decls = iface.GetDeclarations();
-
-  for (auto& i : decls.GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-
-    GenDeclaration(stream, iface, *i);
-    GenBrace(stream, 0, [&]() {
-      GenInvocation(stream, *i);
-    }, false);
-    stream << NLine(1);
-  }
-}
-
-void CppProxyBodyGen::GenInvocation(std::ofstream& stream,
-    const Declaration& decl) {
-  stream << CB_INVOCATION_PRE;
-
-  // Serialize
-  stream << Tab(1)
-         << "rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::"
-         << decl.GetID() << "));" << NLine(1);
-  std::string m;
-  std::string l;
-  for (auto& i : decl.GetParameters().GetParams()) {
-    auto& pt = i->GetParameterType();
-    if (pt.GetDirection() == ParameterType::Direction::OUT)
-      continue;
-    m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
-    if (IsDelegateType(pt.GetBaseType())) {
-      l += "delegate_list_.emplace_back(" + i->GetID() + ".release());\n";
-    }
-  }
-  stream << AddIndent(TAB_SIZE, m) << NLine(1);
-
-  if (decl.GetMethodType() == Declaration::MethodType::SYNC)
-    stream << Tab(1) << "rpc_port_parcel_h parcel_received;" << NLine(1);
-  stream << Tab(1) << "do ";
-  GenBrace(stream, TAB_SIZE, [&]() {
-    stream << Tab(2) << "std::lock_guard<std::recursive_mutex> lock(mutex_);"
-           << NLine(2);
-    if (!l.empty())
-      stream << AddIndent(TAB_SIZE * 2, l);
-    stream << CB_INVOCATION_MID << NLine(1);
-    if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
-      stream << Tab(2) << "// Receive" << NLine(1);
-      stream << Tab(2)
-             << "ConsumeCommand(&parcel_received, port_);" << NLine(1);
-    }
-  }, false, false);
-  stream << " while (false);" << NLine(1);
-
-  // Deserialize
-  if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
-    stream << Tab(1) << "rpc_port_parcel_destroy(p);"
-         << NLine(1);
-    return;
-  }
-
-  stream << CB_INVOCATION_RECEIVE << NLine(1);
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN) {
-      continue;
-    }
-
-    std::string c = ConvertTypeToDeserializer(
-        i->GetParameterType().GetBaseType(),
-        i->GetID(), "parcel_received", false);
-    if (c != "")
-      stream << AddIndent(TAB_SIZE, c);
-  }
-
-  if (decl.GetType().ToString() != "void") {
-    stream << AddIndent(TAB_SIZE,
-                        ConvertTypeToDeserializer(decl.GetType(),
-                                                "ret", "parcel_received"));
-  }
-
-  stream << CB_INVOCATION_END;
-}
-
-}  // namespace tidl
diff --git a/idlc/cpp_gen/cpp_proxy_body_gen.h b/idlc/cpp_gen/cpp_proxy_body_gen.h
deleted file mode 100644 (file)
index 0b6c6d4..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
-#define IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cpp_gen/cpp_gen_base.h"
-
-namespace tidl {
-
-class CppProxyBodyGen : public CppGeneratorBase {
- public:
-  explicit CppProxyBodyGen(std::shared_ptr<Document> doc);
-  virtual ~CppProxyBodyGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenNamespace(std::ofstream& stream);
-  void GenStructures(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenConstructor(std::ofstream& stream, const Interface& iface);
-  void GenDestructor(std::ofstream& stream, const Interface& iface);
-  void GenHelperMethods(std::ofstream& stream, const Interface& iface);
-  void GenMethods(std::ofstream& stream, const Interface& iface);
-  void GenInvocation(std::ofstream& stream, const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
diff --git a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h
deleted file mode 100644 (file)
index b5dbefd..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
-#define IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
-
-const char CB_DTOR[] =
-R"__cpp_cb(
-$$::~$$() {
-  if (proxy_)
-    rpc_port_proxy_destroy(proxy_);
-}
-)__cpp_cb";
-
-const char CB_INVOCATION_PRE[] =
-R"__cpp_cb(  if (port_ == nullptr) {
-    _E("Not connected");
-    throw NotConnectedSocketException();
-  }
-
-  rpc_port_parcel_h p;
-  rpc_port_parcel_create(&p);
-)__cpp_cb";
-
-const char CB_INVOCATION_MID[] =
-R"__cpp_cb(
-    // Send
-    int r = rpc_port_parcel_send(p, port_);
-    if (r != RPC_PORT_ERROR_NONE) {
-      _E("Failed to send parcel. result(%d)", r);
-      rpc_port_parcel_destroy(p);
-      throw InvalidIOException();
-    }
-)__cpp_cb";
-
-const char CB_INVOCATION_RECEIVE[] =
-R"__cpp_cb(
-  if (parcel_received == nullptr) {
-    _E("Invalid protocol");
-    throw InvalidProtocolException();
-  }
-)__cpp_cb";
-
-const char CB_INVOCATION_END[] =
-R"__cpp_cb(
-  rpc_port_parcel_destroy(p);
-  rpc_port_parcel_destroy(parcel_received);
-
-  return ret;
-)__cpp_cb";
-
-const char CB_PROXY_HELPER_METHODS[] =
-R"__cpp_cb(
-void ##::Connect() {
-  int ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "##");
-  if (ret != RPC_PORT_ERROR_NONE) {
-    _E("Failed to connect ##");
-    switch (ret) {
-      case RPC_PORT_ERROR_INVALID_PARAMETER:
-        throw InvalidIDException();
-
-      case RPC_PORT_ERROR_IO_ERROR:
-        throw InvalidIOException();
-
-      case RPC_PORT_ERROR_PERMISSION_DENIED:
-        throw PermissionDeniedException();
-    }
-  }
-}
-
-void ##::DisposeCallback(const std::string& tag) {
-  for (auto& i : delegate_list_) {
-    if (i->GetTag() == tag) {
-      delegate_list_.remove(i);
-      return;
-    }
-  }
-}
-
-void ##::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
-  int id = 0;
-  int seq_id = 0;
-  bool once = false;
-
-  rpc_port_parcel_read_int32(parcel, &id);
-  rpc_port_parcel_read_int32(parcel, &seq_id);
-  rpc_port_parcel_read_bool(parcel, &once);
-
-  for (auto& i : delegate_list_) {
-    if (i->GetId() == id && i->GetSeqId() == seq_id) {
-      i->OnReceivedEvent(parcel);
-      if (i->IsOnce())
-        delegate_list_.remove(i);
-      break;
-    }
-  }
-}
-
-void ##::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
-  do {
-    rpc_port_parcel_h p;
-    int ret = rpc_port_parcel_create_from_port(&p, port);
-    int cmd;
-
-    if (ret != 0)
-      break;
-    rpc_port_parcel_read_int32(p, &cmd);
-    if (cmd == static_cast<int>(MethodId::__Result)) {
-      *parcel = p;
-      return;
-    }
-
-    rpc_port_parcel_destroy(p);
-    *parcel = nullptr;
-  } while (true);
-  *parcel = nullptr;
-}
-
-void ##::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
-  ##* l = static_cast<##*>(data);
-  rpc_port_h cb_port;
-
-  l->port_ = port;
-  rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
-  l->callback_port_ = cb_port;
-  l->listener_->OnConnected();
-}
-
-void ##::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
-  ##* l = static_cast<##*>(data);
-  l->delegate_list_.clear();
-  l->listener_->OnDisconnected();
-}
-
-void ##::OnRejectedCB(const char *ep, const char *port_name, void *data) {
-  ##* l = static_cast<##*>(data);
-  l->listener_->OnRejected();
-}
-
-void ##::OnReceivedCB(const char *ep, const char *port_name, void *data) {
-  ##* l = static_cast<##*>(data);
-  int cmd;
-  rpc_port_parcel_h parcel_received;
-
-  if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
-    _E("Failed to create parcel from port");
-    return;
-  }
-
-  rpc_port_parcel_read_int32(parcel_received, &cmd);
-  if (cmd != static_cast<int>(MethodId::__Callback)) {
-    rpc_port_parcel_destroy(parcel_received);
-    return;
-  }
-
-  l->ProcessReceivedEvent(parcel_received);
-  rpc_port_parcel_destroy(parcel_received);
-}
-)__cpp_cb";
-
-const char CB_PROXY_INTERFACE_CTOR[] =
-R"__cpp_cb(
-$$::$$(IEventListener* listener, const std::string& target_appid)
-    : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
-      listener_(listener), target_appid_(target_appid) {
-  int r = rpc_port_proxy_create(&proxy_);
-
-  if (r != RPC_PORT_ERROR_NONE) {
-    _E("Failed to create proxy");
-    throw InvalidIOException();
-  }
-
-  rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
-  rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
-  rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
-  rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-)__cpp_cb";
-
-#endif  // IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
diff --git a/idlc/cpp_gen/cpp_proxy_header_gen.cc b/idlc/cpp_gen/cpp_proxy_header_gen.cc
deleted file mode 100644 (file)
index 153cbeb..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cpp_gen/cpp_proxy_header_gen.h"
-
-namespace {
-#include "idlc/cpp_gen/cpp_proxy_header_gen_cb.h"
-}
-
-namespace tidl {
-
-CppProxyHeaderGen::CppProxyHeaderGen(std::shared_ptr<Document> doc)
-    : CppGeneratorBase(doc) {}
-
-void CppProxyHeaderGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  stream << CB_HEADER;
-  GenNamespace(stream);
-}
-
-void CppProxyHeaderGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void CppProxyHeaderGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace rpc_port ";
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << " ";
-    GenBrace(stream, 0, [&]() {
-      stream <<  NLine(1);
-      GenStructuresForHeader(stream);
-      stream << "namespace proxy ";
-      GenBrace(stream, 0, [&]() {
-        GenExceptions(stream);
-        GenInterfaces(stream);
-      }, false, false);
-      stream << "  // namespace proxy" + NLine(1);
-    }, false, false);
-    stream << "  // namespace " + GetFileNamespace() + NLine(1);
-  }, false, false);
-  stream << "  // namespace rpc_port" + NLine(1);
-}
-
-void CppProxyHeaderGen::GenExceptions(std::ofstream& stream) {
-  stream << CB_EXCEPTIONS;
-}
-
-void CppProxyHeaderGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-  }
-}
-
-void CppProxyHeaderGen::GenInterface(std::ofstream& stream,
-                                     const Interface& iface) {
-  stream << NLine(1) << "class " << iface.GetID() << " ";
-  GenBrace(stream, 0, [&]() {
-    stream << " public:" << NLine(1);
-    GenHeaderCallbacks(stream, iface, true);
-    GenTemplate(CB_PUBLIC_MEMBERS, stream,
-      [&]()->std::string {
-        return iface.GetID();
-      },
-      [&]()->std::string {
-        return iface.GetID();
-      });
-    GenMethods(stream, iface);
-    stream << NLine(1) << " private:" << NLine(1);
-    GenMethodId(stream, iface);
-    GenDelegateId(stream, iface);
-    stream << CB_PRIVATE_MEMBERS;
-  }, false, false);
-  stream << ";" << NLine(1);
-}
-
-void CppProxyHeaderGen::GenMethods(std::ofstream& stream,
-                                   const Interface& iface) {
-  auto& decls = iface.GetDeclarations();
-
-  for (auto& i : decls.GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-
-    GenDeclaration(stream, *i);
-  }
-}
-
-void CppProxyHeaderGen::GenDeclaration(std::ofstream& stream,
-                                       const Declaration& decl) {
-  if (!decl.GetComments().empty())
-    stream << NLine(1) << AddIndent(TAB_SIZE, decl.GetComments());
-
-  stream << Tab(1) << ConvertTypeToString(decl.GetType()) << " "
-         << decl.GetID() << "(";
-  GenParameters(stream, decl.GetParameters());
-  stream << ");" << NLine(1);
-}
-}  // namespace tidl
diff --git a/idlc/cpp_gen/cpp_proxy_header_gen.h b/idlc/cpp_gen/cpp_proxy_header_gen.h
deleted file mode 100644 (file)
index 96cb19c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
-#define IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cpp_gen/cpp_gen_base.h"
-
-namespace tidl {
-
-class CppProxyHeaderGen : public CppGeneratorBase {
- public:
-  explicit CppProxyHeaderGen(std::shared_ptr<Document> doc);
-  virtual ~CppProxyHeaderGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenNamespace(std::ofstream& stream);
-  void GenExceptions(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenMethods(std::ofstream& stream, const Interface& iface);
-  void GenDeclaration(std::ofstream& stream, const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
diff --git a/idlc/cpp_gen/cpp_proxy_header_gen_cb.h b/idlc/cpp_gen/cpp_proxy_header_gen_cb.h
deleted file mode 100644 (file)
index 0bf19ee..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
-#define IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
-
-const char CB_EXCEPTIONS[] =
-R"__cpp_cb(
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-class InvalidIOException : public Exception {};
-class PermissionDeniedException : public Exception {};
-class InvalidIDException : public Exception {};
-)__cpp_cb";
-
-const char CB_PUBLIC_MEMBERS[] =
-R"__cpp_cb(
-  class IEventListener {
-   public:
-    /// <summary>
-    /// This method will be invoked when the client app is connected to the servicece app.
-    /// </summary>
-    virtual void OnConnected() = 0;
-
-    /// <summary>
-    /// This method will be invoked after the client app was disconnected from the servicece app.
-    /// </summary>
-    virtual void OnDisconnected() = 0;
-
-    /// <summary>
-    /// This method will be invoked when the service app rejects the client app.
-    /// </summary>
-    virtual void OnRejected() = 0;
-  };
-
-  /// <summary>
-  /// Constructor for this class
-  /// </summary>
-  /// <param name="listener">The listener for events</param>
-  /// <param name="target_appid">The service app ID to connect</param>
-  $$(IEventListener* listener, const std::string& target_appid);
-
-  /// <summary>
-  /// Destructor for this class
-  /// </summary>
-  virtual ~$$();
-
-  /// <summary>
-  /// Connects to the service app.
-  /// </summary>
-  /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
-  /// <privilege>http://tizen.org/privilege/datasharing</privilege>
-  /// <exception cref="InvalidIDException">
-  /// Thrown when the appid to connect is invalid.
-  /// </exception>
-  /// <exception cref="InvalidIOException">
-  /// Thrown when internal I/O error happen.
-  /// </exception>
-  /// <exception cref="PermissionDeniedException">
-  /// Thrown when the permission is denied.
-  /// </exception>
-  /// <remark> If you want to use this method, you must add privileges.</remark>
-  void Connect();
-
-  /// <summary>
-  /// Disposes delegate objects in this interface
-  /// </summary>
-  /// <param name="tag">The tag string from delegate object</param>
-  void DisposeCallback(const std::string& tag);
-
-)__cpp_cb";
-
-const char CB_PRIVATE_MEMBERS[] =
-R"__cpp_cb(  void ProcessReceivedEvent(rpc_port_parcel_h parcel);
-  void ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port);
-
-  static void OnConnectedCB(const char *ep, const char *port_name,
-                            rpc_port_h port, void *data);
-  static void OnDisconnectedCB(const char *ep, const char *port_name,
-                               void *data);
-  static void OnRejectedCB(const char *ep, const char *port_name, void *data);
-  static void OnReceivedCB(const char *ep, const char *port_name, void *data);
-
-  rpc_port_h port_;
-  rpc_port_h callback_port_;
-  rpc_port_proxy_h proxy_;
-  IEventListener* listener_;
-  std::recursive_mutex mutex_;
-  std::list<std::unique_ptr<CallbackBase>> delegate_list_;
-  std::string target_appid_;
-)__cpp_cb";
-
-const char CB_HEADER[] =
-R"__cpp_cb(
-#pragma once
-
-#include <bundle.h>
-#include <rpc-port-parcel.h>
-#include <rpc-port.h>
-
-#include <string>
-#include <vector>
-#include <memory>
-#include <mutex>
-#include <list>
-#include <atomic>
-
-)__cpp_cb";
-
-#endif  // IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
diff --git a/idlc/cpp_gen/cpp_stub_body_gen.cc b/idlc/cpp_gen/cpp_stub_body_gen.cc
deleted file mode 100644 (file)
index f564f9e..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cpp_gen/cpp_stub_body_gen.h"
-
-namespace {
-#include "idlc/cpp_gen/cpp_stub_body_gen_cb.h"
-}
-
-namespace tidl {
-
-CppStubBodyGen::CppStubBodyGen(std::shared_ptr<Document> doc)
-    : CppGeneratorBase(doc) {}
-
-void CppStubBodyGen::OnInitGen(std::ofstream& stream) {
-  std::string key(".cc");
-  std::string header_file = FileName;
-
-  std::size_t found = header_file.rfind(key);
-  if (found != std::string::npos)
-    header_file.replace(found, key.length(), ".h");
-
-  GenVersion(stream);
-  stream << NLine(1);
-  stream << "#include <stdlib.h>" << NLine(1)
-         << "#include <assert.h>" << NLine(1)
-         << "#include <libgen.h>" << NLine(1)
-         << "#include <dlog.h>" << NLine(1)
-         <<  NLine(1)
-         << "#include \"" << header_file << "\"" << NLine(2);
-  GenLogTag(stream, "RPC_PORT_STUB");
-  GenLogDefinition(stream);
-  stream << NLine(1);
-  GenNamespace(stream);
-}
-
-void CppStubBodyGen::OnFiniGen(std::ofstream& stream) {}
-
-void CppStubBodyGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace rpc_port ";
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << " ";
-    GenBrace(stream, 0, [&]() {
-      stream <<  NLine(1);
-      GenStructuresForBody(stream);
-      stream << "namespace stub ";
-      GenBrace(stream, 0, [&]() {
-        GenPrototype(stream);
-        GenSerializer(stream);
-        GenDeSerializer(stream);
-        GenListSerializer(stream);
-        GenInterfaces(stream);
-      }, false, false);
-      stream << "  // namespace stub" + NLine(1);
-    }, false, false);
-    stream << "  // namespace " + GetFileNamespace() + NLine(1);
-  }, false, false);
-  stream << "  // namespace rpc_port" + NLine(1);
-}
-
-void CppStubBodyGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-  }
-}
-
-void CppStubBodyGen::GenInterface(std::ofstream& stream,
-                                    const Interface& iface) {
-  GenServiceBase(stream, iface);
-  GenBodyCallbacks(stream, iface, false);
-  GenDefaultMethods(stream, iface);
-  GenReceivedEvent(stream, iface);
-}
-
-void CppStubBodyGen::GenServiceBase(std::ofstream& stream,
-                                    const Interface& iface) {
-  GenTemplate(CB_CTOR_SERVICE_BASE, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    });
-  stream << NLine(1);
-}
-
-void CppStubBodyGen::GenConstructor(std::ofstream& stream,
-                                    const Interface& iface) {
-  stream << ReplaceAll(CB_CTOR_FRONT, "##", iface.GetID());
-
-  for (auto& i : iface.GetAttributes().GetAttrs()) {
-    if (i->GetKey() == "privilege") {
-      stream << Tab(1) << "rpc_port_stub_add_privilege(stub_, \""
-             << i->GetValue() << "\");" << NLine(1);
-    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
-      stream << Tab(1) << "rpc_port_stub_set_trusted(stub_, "
-             << i->GetValue() << ");" << NLine(1);
-    }
-  }
-
-  stream << "}" << NLine(1);
-}
-
-void CppStubBodyGen::GenDefaultMethods(std::ofstream& stream,
-                                       const Interface& iface) {
-  GenConstructor(stream, iface);
-  stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID());
-}
-
-void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
-                                      const Interface& iface) {
-  GenTemplate(CB_ON_RECEIVED_CB_FRONT, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
-  for (auto& i : iface.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    stream << Tab(2) << "case static_cast<int>(MethodId::"
-           << i->GetID() << "): ";
-    GenBrace(stream, TAB_SIZE * 2, [&]() {
-      GenInvocation(stream, *i);
-      stream << Tab(3) << "break;" << NLine(1);
-    }, false);
-    stream << NLine(1);
-  }
-  stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
-}
-
-void CppStubBodyGen::GenInvocation(std::ofstream& stream,
-    const Declaration& decl) {
-  int cnt = 1;
-
-  // Deserialize
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
-      cnt++;
-      continue;
-    }
-
-    std::string v = "param" + std::to_string(cnt);
-    std::string c = ConvertTypeToDeserializer(
-        i->GetParameterType().GetBaseType(), v, "p");
-    stream << AddIndent(TAB_SIZE * 3, c);
-    cnt++;
-  }
-
-  // Invoke
-  cnt = 1;
-  std::string m;
-  std::string d;
-  bool hasRet = false;
-
-  if (decl.GetType().ToString() != "void") {
-    m += "auto retVal = ";
-    hasRet = true;
-  }
-
-  m += "b->" + decl.GetID() + "(";
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (cnt != 1) {
-      m += ", ";
-    }
-
-    std::string v = "param" + std::to_string(cnt);
-    auto& pt = i->GetParameterType();
-    if (pt.GetDirection() == ParameterType::Direction::OUT) {
-      d += ConvertTypeToString(pt.GetBaseType()) + " " + v + ";\n";
-    }
-    if (IsDelegateType(pt.GetBaseType())) {
-      m += "std::move(";
-      m += v;
-      m += ")";
-    } else {
-      m += v;
-    }
-    cnt++;
-  }
-
-  m += ");\n";
-  stream << AddIndent(TAB_SIZE * 3, d);
-  stream << AddIndent(TAB_SIZE * 3, m);
-
-  // Serialize
-  if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
-    return;
-
-  cnt = 0;
-  m = "rpc_port_parcel_write_int32(" \
-      "result, static_cast<int>(MethodId::__Result));\n";
-  for (auto& i : decl.GetParameters().GetParams()) {
-    auto& pt = i->GetParameterType();
-    cnt++;
-    if (pt.GetDirection() == ParameterType::Direction::IN)
-      continue;
-    m += ConvertTypeToSerializer(pt.GetBaseType(),
-                                "param" + std::to_string(cnt), "result");
-  }
-
-  if (hasRet) {
-    m += ConvertTypeToSerializer(decl.GetType(), "retVal", "result");
-  }
-
-  m += "ret = rpc_port_parcel_send(result, port);\n";
-  stream << AddIndent(TAB_SIZE * 3, m);
-}
-
-}  // namespace tidl
diff --git a/idlc/cpp_gen/cpp_stub_body_gen.h b/idlc/cpp_gen/cpp_stub_body_gen.h
deleted file mode 100644 (file)
index fa8b7cc..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
-#define IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cpp_gen/cpp_gen_base.h"
-
-namespace tidl {
-
-class CppStubBodyGen : public CppGeneratorBase {
- public:
-  explicit CppStubBodyGen(std::shared_ptr<Document> doc);
-  virtual ~CppStubBodyGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenNamespace(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenServiceBase(std::ofstream& stream, const Interface& iface);
-  void GenDefaultMethods(std::ofstream& stream, const Interface& iface);
-  void GenReceivedEvent(std::ofstream& stream, const Interface& iface);
-  void GenInvocation(std::ofstream& stream, const Declaration& decl);
-  void GenConstructor(std::ofstream& stream, const Interface& iface);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
diff --git a/idlc/cpp_gen/cpp_stub_body_gen_cb.h b/idlc/cpp_gen/cpp_stub_body_gen_cb.h
deleted file mode 100644 (file)
index d3fad11..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
-#define IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
-
-const char CB_CTOR_FRONT[] =
-R"__cpp_cb(
-##::##() {
-  int r = rpc_port_stub_create(&stub_, "##");
-  if (r != RPC_PORT_ERROR_NONE) {
-    _E("Failed to create stub handle");
-    throw InvalidIOException();
-  }
-  rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this);
-  rpc_port_stub_add_disconnected_event_cb(stub_, OnDisconnectedCB, this);
-  rpc_port_stub_add_received_event_cb(stub_, OnReceivedCB, this);
-)__cpp_cb";
-
-const char CB_DEFAULT_METHODS[] =
-R"__cpp_cb(
-##::~##() {
-  for (auto& i : services_) {
-    i->OnTerminate();
-  }
-
-  if (stub_) {
-    rpc_port_stub_destroy(stub_);
-  }
-}
-
-void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) {
-  service_factory_ = std::move(service_factory);
-  int r = rpc_port_stub_listen(stub_);
-  if (r != RPC_PORT_ERROR_NONE) {
-    _E("Failed to listen stub");
-    switch (r) {
-      case RPC_PORT_ERROR_INVALID_PARAMETER:
-      case RPC_PORT_ERROR_IO_ERROR:
-        throw InvalidIOException();
-    }
-  }
-}
-
-void ##::OnConnectedCB(const char* sender, const char* instance, void *data) {
-  ##* stub = static_cast<##*>(data);
-  auto s = stub->service_factory_->CreateService(sender, instance);
-  s->OnCreate();
-  stub->services_.emplace_back(std::move(s));
-}
-
-void ##::OnDisconnectedCB(const char* sender, const char* instance, void *data) {
-  ##* stub = static_cast<##*>(data);
-
-  for (auto& i : stub->services_) {
-    if (i->GetInstance() == instance) {
-      i->OnTerminate();
-      stub->services_.remove(i);
-      return;
-    }
-  }
-}
-)__cpp_cb";
-
-const char CB_ON_RECEIVED_CB_FRONT[] =
-R"__cpp_cb(
-int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
-{
-  auto* cxt = static_cast<$$*>(data);
-  rpc_port_parcel_h p;
-  rpc_port_parcel_h result;
-  int cmd;
-  int ret;
-  std::shared_ptr<ServiceBase> b;
-  rpc_port_h callback_port;
-
-  for (auto& i : cxt->services_) {
-    if (i->GetInstance() == instance) {
-      b = i;
-      break;
-    }
-  }
-
-  if (b.get() == nullptr) {
-    _E("Failed to find $$ context(%s)", instance);
-    return -1;
-  }
-
-  ret = rpc_port_stub_get_port(cxt->stub_, RPC_PORT_PORT_CALLBACK, instance,
-      &callback_port);
-  if (ret != 0) {
-    _E("Failed to get callback port");
-  }
-
-  ret = rpc_port_parcel_create_from_port(&p, port);
-  if (ret != 0) {
-    _E("Failed to create parcel from port");
-    return ret;
-  }
-
-  rpc_port_parcel_create(&result);
-  rpc_port_parcel_read_int32(p, &cmd);
-
-  switch (cmd) {
-)__cpp_cb";
-
-const char CB_ON_RECEIVED_CB_BACK[] =
-R"__cpp_cb(    default:
-      _E("Unknown command(%d)", cmd);
-      rpc_port_parcel_destroy(p);
-      rpc_port_parcel_destroy(result);
-      return -1;
-  }
-
-  rpc_port_parcel_destroy(p);
-  rpc_port_parcel_destroy(result);
-
-  return ret;
-}
-)__cpp_cb";
-
-const char CB_CTOR_SERVICE_BASE[] =
-R"__cpp_cb($$::ServiceBase::ServiceBase(std::string sender, std::string instance)
-    : sender_(std::move(sender)), instance_(std::move(instance)) {})__cpp_cb";
-
-#endif  // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
diff --git a/idlc/cpp_gen/cpp_stub_header_gen.cc b/idlc/cpp_gen/cpp_stub_header_gen.cc
deleted file mode 100644 (file)
index a4e591b..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cpp_gen/cpp_stub_header_gen.h"
-
-namespace {
-#include "idlc/cpp_gen/cpp_stub_header_gen_cb.h"
-}
-
-namespace tidl {
-
-CppStubHeaderGen::CppStubHeaderGen(std::shared_ptr<Document> doc)
-    : CppGeneratorBase(doc) {}
-
-void CppStubHeaderGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  stream << CB_HEADER;
-  GenNamespace(stream);
-}
-
-void CppStubHeaderGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void CppStubHeaderGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace rpc_port ";
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << " ";
-    GenBrace(stream, 0, [&]() {
-      stream <<  NLine(1);
-      GenStructuresForHeader(stream);
-      stream << "namespace stub ";
-      GenBrace(stream, 0, [&]() {
-        GenExceptions(stream);
-        GenInterfaces(stream);
-      }, false, false);
-      stream << "  // namespace stub" + NLine(1);
-    }, false, false);
-    stream << "  // namespace " + GetFileNamespace() + NLine(1);
-  }, false, false);
-  stream << "  // namespace rpc_port" + NLine(1);
-}
-
-void CppStubHeaderGen::GenExceptions(std::ofstream& stream) {
-  stream << CB_EXCEPTIONS;
-}
-
-void CppStubHeaderGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-  }
-}
-
-void CppStubHeaderGen::GenInterface(std::ofstream& stream,
-                                    const Interface& iface) {
-  stream << NLine(1) << "class " << iface.GetID() << " final ";
-  GenBrace(stream, 0, [&]() {
-    GenPublic(stream, iface);
-    GenPrivate(stream, iface);
-  }, false, false);
-  stream << ";" << NLine(1);
-}
-
-void CppStubHeaderGen::GenPublic(std::ofstream& stream,
-                                 const Interface& iface) {
-  stream << " public:" << NLine(1);
-  stream << "  class ServiceBase;" << NLine(1);
-  GenHeaderCallbacks(stream, iface, false);
-  GenServiceBase(stream, iface);
-  GenPublicMethods(stream, iface);
-}
-
-void CppStubHeaderGen::GenPrivate(std::ofstream& stream,
-                                 const Interface& iface) {
-  stream << " private:" << NLine(1);
-  GenMethodId(stream, iface);
-  GenDelegateId(stream, iface);
-  stream << CB_PRIVATE_MEMBERS;
-}
-
-void CppStubHeaderGen::GenServiceBase(std::ofstream& stream,
-                                      const Interface& iface) {
-  stream << CB_SERVICE_BASE_FRONT;
-  auto& decls = iface.GetDeclarations();
-
-  for (auto& i : decls.GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    if (!i->GetComments().empty())
-      stream << NLine(1) << AddIndent(TAB_SIZE * 2, i->GetComments());
-    stream << Tab(2) << "virtual " << ConvertTypeToString(i->GetType())
-           << " " << i->GetID() << "(";
-    GenParameters(stream, i->GetParameters());
-    stream << ") = 0;" << NLine(1);
-  }
-
-  stream << CB_SERVICE_BASE_BACK << NLine(2);
-}
-
-void CppStubHeaderGen::GenPublicMethods(std::ofstream& stream,
-                                        const Interface& iface) {
-  stream << ReplaceAll(CB_PUBLIC_METHODS, "##", iface.GetID());
-}
-
-}  // namespace tidl
diff --git a/idlc/cpp_gen/cpp_stub_header_gen.h b/idlc/cpp_gen/cpp_stub_header_gen.h
deleted file mode 100644 (file)
index 52bebfe..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
-#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cpp_gen/cpp_gen_base.h"
-
-namespace tidl {
-
-class CppStubHeaderGen : public CppGeneratorBase {
- public:
-  explicit CppStubHeaderGen(std::shared_ptr<Document> doc);
-  virtual ~CppStubHeaderGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenExceptions(std::ofstream& stream);
-  void GenNamespace(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenPublic(std::ofstream& stream, const Interface& iface);
-  void GenPrivate(std::ofstream& stream, const Interface& iface);
-  void GenServiceBase(std::ofstream& stream, const Interface& iface);
-  void GenPublicMethods(std::ofstream& stream, const Interface& iface);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
diff --git a/idlc/cpp_gen/cpp_stub_header_gen_cb.h b/idlc/cpp_gen/cpp_stub_header_gen_cb.h
deleted file mode 100644 (file)
index 8cb4c1f..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
-#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
-
-const char CB_EXCEPTIONS[] =
-R"__cpp_cb(
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-class InvalidIOException : public Exception {};
-class InvalidCallbackException : public Exception {};
-)__cpp_cb";
-
-const char CB_PRIVATE_MEMBERS[] =
-R"__cpp_cb(  static void OnConnectedCB(const char* sender, const char* instance, void* data);
-  static void OnDisconnectedCB(const char* sender, const char* instance, void* data);
-  static int OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void* data);
-
-  rpc_port_stub_h stub_;
-  std::shared_ptr<ServiceBase::Factory> service_factory_;
-  std::list<std::shared_ptr<ServiceBase>> services_;
-)__cpp_cb";
-
-const char CB_SERVICE_BASE_FRONT[] =
-R"__cpp_cb(
-  class ServiceBase {
-   public:
-    class Factory {
-     public:
-      /// <summary>
-      /// The method for making service instances
-      /// </summary>
-      /// <param name="sender">The client app ID</param>
-      /// <param name="instance">The client instance ID</param>
-      virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
-    };
-
-    virtual ~ServiceBase() = default;
-
-    /// <summary>
-    /// Gets client app ID
-    /// </summary>
-    const std::string& GetSender() const {
-      return sender_;
-    }
-
-    /// <summary>
-    /// Gets client instance ID
-    /// </summary>
-    const std::string& GetInstance() const {
-      return instance_;
-    }
-
-    /// <summary>
-    /// This method will be called when the client is connected
-    /// </summary>
-    virtual void OnCreate() = 0;
-
-    /// <summary>
-    /// This method will be called when the client is disconnected
-    /// </summary>
-    virtual void OnTerminate() = 0;
-
-)__cpp_cb";
-
-const char CB_SERVICE_BASE_BACK[] =
-R"__cpp_cb(
-   protected:
-    ServiceBase(std::string sender, std::string instance);
-
-   private:
-    std::string sender_;
-    std::string instance_;
-  };)__cpp_cb";
-
-const char CB_PUBLIC_METHODS[] =
-R"__cpp_cb(  ##();
-  ~##();
-
-  /// <summary>
-  /// Listens to client apps
-  /// </summary>
-  /// <param name="service_factory">The factory object for making service instances</param>
-  /// <exception cref="InvalidIOException">
-  /// Thrown when internal I/O error happen.
-  /// </exception>
-  void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);
-
-  /// <summary>
-  /// Gets service objects which are connected
-  /// </summary>
-  /// <returns>The list of service objects which are connected</returns>
-  const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
-    return services_;
-  }
-
-)__cpp_cb";
-
-const char CB_HEADER[] =
-R"__cpp_cb(
-#pragma once
-
-#include <bundle.h>
-#include <rpc-port-parcel.h>
-#include <rpc-port.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-#include <list>
-#include <atomic>
-
-)__cpp_cb";
-
-#endif  // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
diff --git a/idlc/cs_gen/cs_cb_interop.h b/idlc/cs_gen/cs_cb_interop.h
deleted file mode 100644 (file)
index 4e6cf90..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_CB_INTEROP_H_
-#define IDLC_CS_GEN_CS_CB_INTEROP_H_
-
-const char cs_cb_interop[] =
-R"__cs_cb(
-internal static partial class Interop
-{
-    internal static partial class LibRPCPort
-    {
-        internal static partial class Libraries
-        {
-            public const string RpcPort = "librpc-port.so.1";
-        }
-
-        internal enum ErrorCode
-        {
-            None = Tizen.Internals.Errors.ErrorCode.None,
-            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
-            OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
-            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
-            IoError = Tizen.Internals.Errors.ErrorCode.IoError,
-        }
-
-        internal enum PortType
-        {
-            Main,
-            Callback
-        }
-
-        internal static partial class Parcel
-        {
-            //int rpc_port_parcel_create(rpc_port_parcel_h *h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create")]
-            internal static extern ErrorCode Create(out IntPtr handle);
-
-            //int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_port")]
-            internal static extern ErrorCode CreateFromPort(out IntPtr parcelHandle, IntPtr portHandle);
-
-            //int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_send")]
-            internal static extern ErrorCode Send(IntPtr parcelHandle, IntPtr portHandle);
-
-            //int rpc_port_parcel_destroy(rpc_port_parcel_h h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_destroy")]
-            internal static extern ErrorCode Destroy(IntPtr handle);
-
-            //int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_byte")]
-            internal static extern ErrorCode WriteByte(IntPtr parcelHandle, byte b);
-
-            //int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int16")]
-            internal static extern ErrorCode WriteInt16(IntPtr parcelHandle, short i);
-
-            //int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int32")]
-            internal static extern ErrorCode WriteInt32(IntPtr parcelHandle, int i);
-
-            //int rpc_port_parcel_write_int64(rpc_port_parcel_h h, int i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int64")]
-            internal static extern ErrorCode WriteInt64(IntPtr parcelHandle, long i);
-
-            //int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_float")]
-            internal static extern ErrorCode WriteFloat(IntPtr parcelHandle, float f);
-
-            //int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_double")]
-            internal static extern ErrorCode WriteDouble(IntPtr parcelHandle, double d);
-
-            //int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_string")]
-            internal static extern ErrorCode WriteString(IntPtr parcelHandle, string str);
-
-            //int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bool")]
-            internal static extern ErrorCode WriteBool(IntPtr parcelHandle, bool b);
-
-            //int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bundle")]
-            internal static extern ErrorCode WriteBundle(IntPtr parcelHandle, IntPtr b);
-
-            //int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_array_count")]
-            internal static extern ErrorCode WriteArrayCount(IntPtr parcelHandle, int count);
-
-            //int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_byte")]
-            internal static extern ErrorCode ReadByte(IntPtr parcelHandle, out byte b);
-
-            //int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int16")]
-            internal static extern ErrorCode ReadInt16(IntPtr parcelHandle, out short i);
-
-            //int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int32")]
-            internal static extern ErrorCode ReadInt32(IntPtr parcelHandle, out int i);
-
-            //int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int64")]
-            internal static extern ErrorCode ReadInt64(IntPtr parcelHandle, out long i);
-
-            //int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_float")]
-            internal static extern ErrorCode ReadFloat(IntPtr parcelHandle, out float f);
-
-            //int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_double")]
-            internal static extern ErrorCode ReadDouble(IntPtr parcelHandle, out double f);
-
-            //int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_string")]
-            internal static extern ErrorCode ReadString(IntPtr parcelHandle, out string str);
-
-            //int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bool")]
-            internal static extern ErrorCode ReadBool(IntPtr parcelHandle, out bool b);
-
-            //int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bundle")]
-            internal static extern ErrorCode ReadBundle(IntPtr parcelHandle, out IntPtr b);
-
-            //int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_array_count")]
-            internal static extern ErrorCode ReadArrayCount(IntPtr parcelHandle, out int count);
-
-            //int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, unsigned int size);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_read")]
-            internal static extern ErrorCode Read(IntPtr parcelHandle, [In, Out] byte[] buf, int size);
-
-            //int rpc_port_parcel_burst_write(rpc_port_parcel_h h, const unsigned char *buf, unsigned int size);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_write")]
-            internal static extern ErrorCode Write(IntPtr parcelHandle, byte[] buf, int size);
-        }
-
-        internal static partial class Proxy
-        {
-            //typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep, const char* port_name, rpc_port_h port, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void ConnectedEventCallback(string endPoint, string port_name, IntPtr port, IntPtr data);
-
-            //typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *ep, const char* port_name, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void DisconnectedEventCallback(string endPoint, string port_name, IntPtr data);
-
-            //typedef void (*rpc_port_proxy_rejected_event_cb) (const char* ep, const char* port_name, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void RejectedEventCallback(string endPoint, string port_name, IntPtr data);
-
-            //typedef void (*rpc_port_proxy_received_event_cb) (const char* ep, const char* port_name, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void ReceivedEventCallback(string endPoint, string port_name, IntPtr data);
-
-            //int rpc_port_proxy_create(rpc_port_proxy_h *h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_create")]
-            internal static extern ErrorCode Create(out IntPtr handle);
-
-            //int rpc_port_proxy_destroy(rpc_port_proxy_h h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_destroy")]
-            internal static extern ErrorCode Destroy(IntPtr handle);
-
-            //int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, const char* port);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect")]
-            internal static extern ErrorCode Connect(IntPtr handle, string appId, string port);
-
-            //int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_connected_event_cb")]
-            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
-
-            //int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_disconnected_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_disconnected_event_cb")]
-            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
-
-            //int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_rejected_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_rejected_event_cb")]
-            internal static extern ErrorCode AddRejectedEventCb(IntPtr handle, RejectedEventCallback cb, IntPtr data);
-
-            //int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, rpc_port_proxy_received_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_received_event_cb")]
-            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
-
-            //int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, rpc_port_h* port);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_get_port")]
-            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, out IntPtr port);
-        }
-
-        internal static partial class Stub
-        {
-            //typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, const char *instance, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void ConnectedEventCallback(string sender, string instance, IntPtr data);
-
-            //typedef void (* rpc_port_stub_disconnected_event_cb) (const char* sender, const char *instance, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate void DisconnectedEventCallback(string sender, string instance, IntPtr data);
-
-            //typedef void (* rpc_port_stub_received_event_cb) (const char* sender, const char *instance, rpc_port_h port, void* data);
-            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-            internal delegate int ReceivedEventCallback(string sender, string instance, IntPtr port, IntPtr data);
-
-            //int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_create")]
-            internal static extern ErrorCode Create(out IntPtr handle, string portName);
-
-            //int rpc_port_stub_destroy(rpc_port_stub_h h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_destroy")]
-            internal static extern ErrorCode Destroy(IntPtr handle);
-
-            //int rpc_port_stub_listen(rpc_port_stub_h h);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_listen")]
-            internal static extern ErrorCode Listen(IntPtr handle);
-
-            //int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_connected_event_cb")]
-            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
-
-            //int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, rpc_port_stub_disconnected_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_disconnected_event_cb")]
-            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
-
-            //int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void* data);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_received_event_cb")]
-            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
-
-            //int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_privilege")]
-            internal static extern ErrorCode AddPrivilege(IntPtr handle, string privilege);
-
-            //int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_set_trusted")]
-            internal static extern ErrorCode SetTrusted(IntPtr handle, bool trusted);
-
-            //int rpc_port_stub_get_port(rpc_port_stub_h h, rpc_port_port_type_e type, const char* instance, rpc_port_h *port);
-            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_get_port")]
-            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, string instance, out IntPtr port);
-        }
-    }
-}
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_CB_INTEROP_H_
diff --git a/idlc/cs_gen/cs_cb_rpc_port.h b/idlc/cs_gen/cs_cb_rpc_port.h
deleted file mode 100644 (file)
index 573aebb..0000000
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_CB_RPC_PORT_H_
-#define IDLC_CS_GEN_CS_CB_RPC_PORT_H_
-
-const char cs_cb_rpc_port[] =
-R"__cs_cb(
-namespace Tizen.Applications.RPCPort
-{
-    public class InvalidIOException : InvalidOperationException { }
-    public class InvalidIDException : InvalidOperationException { }
-    public class PermissionDeniedException : InvalidOperationException { }
-    public class InvalidProtocolException : InvalidOperationException { }
-    public class NotConnectedSocketException : InvalidOperationException { }
-    public class InvalidCallbackException : InvalidOperationException { }
-
-    public class Port
-    {
-        public enum Type
-        {
-            Main,
-            Callback
-        }
-
-        internal IntPtr Handle { get; set; }
-        internal Port() { }
-    }
-
-    public class Parcel : IDisposable
-    {
-        private IntPtr _handle;
-
-        public Parcel()
-        {
-            var r = Interop.LibRPCPort.Parcel.Create(out _handle);
-            if (r != Interop.LibRPCPort.ErrorCode.None)
-                throw new InvalidIOException();
-        }
-
-        public Parcel(Port port)
-        {
-            var r = Interop.LibRPCPort.Parcel.CreateFromPort(out _handle, port.Handle);
-            if (r != Interop.LibRPCPort.ErrorCode.None)
-                throw new InvalidIOException();
-        }
-
-        public void Send(Port p)
-        {
-            var r = Interop.LibRPCPort.Parcel.Send(_handle, p.Handle);
-            if (r != Interop.LibRPCPort.ErrorCode.None)
-                throw new InvalidIOException();
-        }
-
-        public void WriteByte(byte b)
-        {
-            Interop.LibRPCPort.Parcel.WriteByte(_handle, b);
-        }
-
-        public void WriteShort(short b)
-        {
-            Interop.LibRPCPort.Parcel.WriteInt16(_handle, b);
-        }
-
-        public void WriteInt(int b)
-        {
-            Interop.LibRPCPort.Parcel.WriteInt32(_handle, b);
-        }
-
-        public void WriteLong(long b)
-        {
-            Interop.LibRPCPort.Parcel.WriteInt64(_handle, b);
-        }
-
-        public void WriteFloat(float b)
-        {
-            Interop.LibRPCPort.Parcel.WriteFloat(_handle, b);
-        }
-
-        public void WriteDouble(double b)
-        {
-            Interop.LibRPCPort.Parcel.WriteDouble(_handle, b);
-        }
-
-        public void WriteString(string b)
-        {
-            Interop.LibRPCPort.Parcel.WriteString(_handle, b);
-        }
-
-        public void WriteBool(bool b)
-        {
-            Interop.LibRPCPort.Parcel.WriteBool(_handle, b);
-        }
-
-        public void WriteBundle(Bundle b)
-        {
-            Interop.LibRPCPort.Parcel.WriteBundle(_handle, b.SafeBundleHandle.DangerousGetHandle());
-        }
-
-        public void WriteArrayCount(int cnt)
-        {
-            Interop.LibRPCPort.Parcel.WriteArrayCount(_handle, cnt);
-        }
-
-        public byte ReadByte()
-        {
-            Interop.LibRPCPort.Parcel.ReadByte(_handle, out byte b);
-            return b;
-        }
-
-        public short ReadShort()
-        {
-            Interop.LibRPCPort.Parcel.ReadInt16(_handle, out short b);
-            return b;
-        }
-
-        public int ReadInt()
-        {
-            Interop.LibRPCPort.Parcel.ReadInt32(_handle, out int b);
-            return b;
-        }
-
-        public long ReadLong()
-        {
-            Interop.LibRPCPort.Parcel.ReadInt64(_handle, out long b);
-            return b;
-        }
-
-        public float ReadFloat()
-        {
-            Interop.LibRPCPort.Parcel.ReadFloat(_handle, out float b);
-            return b;
-        }
-
-        public double ReadDouble()
-        {
-            Interop.LibRPCPort.Parcel.ReadDouble(_handle, out double b);
-            return b;
-        }
-
-        public string ReadString()
-        {
-            Interop.LibRPCPort.Parcel.ReadString(_handle, out string b);
-            return b;
-        }
-
-        public bool ReadBool()
-        {
-            Interop.LibRPCPort.Parcel.ReadBool(_handle, out bool b);
-            return b;
-        }
-
-        public Bundle ReadBundle()
-        {
-            Interop.LibRPCPort.Parcel.ReadBundle(_handle, out IntPtr b);
-
-            return new Bundle(new SafeBundleHandle(b, true));
-        }
-
-        public int ReadArrayCount()
-        {
-            Interop.LibRPCPort.Parcel.ReadArrayCount(_handle, out int b);
-            return b;
-        }
-
-        public void Write(byte[] bytes)
-        {
-            Interop.LibRPCPort.Parcel.Write(_handle, bytes, bytes.Length);
-        }
-
-        public byte[] Read(int size)
-        {
-            var ret = new byte[size];
-            Interop.LibRPCPort.Parcel.Read(_handle, ret, size);
-            return ret;
-        }
-
-        #region IDisposable Support
-        private bool disposedValue = false;
-
-        protected virtual void Dispose(bool disposing)
-        {
-            if (!disposedValue)
-            {
-                if (disposing)
-                {
-                }
-
-                if (_handle != IntPtr.Zero)
-                {
-                    Interop.LibRPCPort.Parcel.Destroy(_handle);
-                    _handle = IntPtr.Zero;
-                }
-
-                disposedValue = true;
-            }
-        }
-
-        ~Parcel()
-        {
-            Dispose(false);
-        }
-
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-        #endregion
-    }
-
-    public abstract class ProxyBase : IDisposable
-    {
-        private Interop.LibRPCPort.Proxy.ConnectedEventCallback _connectedEventCallback;
-        private Interop.LibRPCPort.Proxy.DisconnectedEventCallback _disconnectedEventCallback;
-        private Interop.LibRPCPort.Proxy.RejectedEventCallback _rejectedEventCallback;
-        private Interop.LibRPCPort.Proxy.ReceivedEventCallback _receivedEventCallback;
-        private IntPtr _proxy;
-
-        protected Port Port { get; private set; }
-        protected Port CallbackPort { get; private set; }
-
-        public ProxyBase()
-        {
-            if (Interop.LibRPCPort.Proxy.Create(out _proxy) != Interop.LibRPCPort.ErrorCode.None)
-                throw new InvalidIOException();
-            _connectedEventCallback = new Interop.LibRPCPort.Proxy.ConnectedEventCallback(OnConnectedEvent);
-            _disconnectedEventCallback = new Interop.LibRPCPort.Proxy.DisconnectedEventCallback(OnDisconnectedEvent);
-            _rejectedEventCallback = new Interop.LibRPCPort.Proxy.RejectedEventCallback(OnRejectedEvent);
-            _receivedEventCallback = new Interop.LibRPCPort.Proxy.ReceivedEventCallback(OnReceivedEvent);
-            Interop.LibRPCPort.Proxy.AddConnectedEventCb(_proxy, _connectedEventCallback, IntPtr.Zero);
-            Interop.LibRPCPort.Proxy.AddDisconnectedEventCb(_proxy, _disconnectedEventCallback, IntPtr.Zero);
-            Interop.LibRPCPort.Proxy.AddRejectedEventCb(_proxy, _rejectedEventCallback, IntPtr.Zero);
-            Interop.LibRPCPort.Proxy.AddReceivedEventCb(_proxy, _receivedEventCallback, IntPtr.Zero);
-        }
-
-        protected void Connect(string appid, string port)
-        {
-            var err = Interop.LibRPCPort.Proxy.Connect(_proxy, appid, port);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                    throw new InvalidIDException();
-                case Interop.LibRPCPort.ErrorCode.PermissionDenied:
-                    throw new PermissionDeniedException();
-                case Interop.LibRPCPort.ErrorCode.IoError:
-                    throw new InvalidIOException();
-            }
-        }
-
-        protected Port GetPort(Port.Type t)
-        {
-            var err = Interop.LibRPCPort.Proxy.GetPort(_proxy,
-                (Interop.LibRPCPort.PortType)t, out IntPtr port);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                case Interop.LibRPCPort.ErrorCode.IoError:
-                    throw new InvalidIOException();
-            }
-
-            return new Port() { Handle = port };
-        }
-
-        protected abstract void OnConnectedEvent(string endPoint, string portName, Port port);
-        protected abstract void OnDisconnectedEvent(string endPoint, string portName);
-        protected abstract void OnReceivedEvent(string endPoint, string portName);
-        protected abstract void OnRejectedEvent(string endPoint, string portName);
-
-        private void OnConnectedEvent(string endPoint, string portName, IntPtr port, IntPtr data)
-        {
-            Port = new Port() { Handle = port };
-            CallbackPort = GetPort(Port.Type.Callback);
-            OnConnectedEvent(endPoint, portName, Port);
-        }
-
-        private void OnDisconnectedEvent(string endPoint, string portName, IntPtr data)
-        {
-            Port = null;
-            CallbackPort = null;
-            OnDisconnectedEvent(endPoint, portName);
-        }
-
-        private void OnReceivedEvent(string endPoint, string portName, IntPtr data)
-        {
-            OnReceivedEvent(endPoint, portName);
-        }
-
-        private void OnRejectedEvent(string endPoint, string portName, IntPtr data)
-        {
-            OnRejectedEvent(endPoint, portName);
-        }
-
-        #region IDisposable Support
-        private bool disposedValue = false;
-
-        protected virtual void Dispose(bool disposing)
-        {
-            if (!disposedValue)
-            {
-                if (disposing)
-                {
-                }
-                if (_proxy != IntPtr.Zero)
-                    Interop.LibRPCPort.Proxy.Destroy(_proxy);
-                _proxy = IntPtr.Zero;
-
-                disposedValue = true;
-            }
-        }
-
-        ~ProxyBase()
-        {
-            Dispose(false);
-        }
-
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-        #endregion
-    }
-
-    public abstract class StubBase : IDisposable
-    {
-        private Interop.LibRPCPort.Stub.ConnectedEventCallback _connectedEventCallback;
-        private Interop.LibRPCPort.Stub.DisconnectedEventCallback _disconnectedEventCallback;
-        private Interop.LibRPCPort.Stub.ReceivedEventCallback _receivedEventCallback;
-        private IntPtr _stub;
-
-        public string PortName { get; private set; }
-
-        public StubBase(string portName)
-        {
-            if (Interop.LibRPCPort.Stub.Create(out _stub, portName) != Interop.LibRPCPort.ErrorCode.None)
-                throw new InvalidIOException();
-            PortName = portName;
-            _connectedEventCallback = new Interop.LibRPCPort.Stub.ConnectedEventCallback(OnConnectedEvent);
-            _disconnectedEventCallback = new Interop.LibRPCPort.Stub.DisconnectedEventCallback(OnDisconnectedEvent);
-            _receivedEventCallback = new Interop.LibRPCPort.Stub.ReceivedEventCallback(OnReceivedEvent);
-            Interop.LibRPCPort.Stub.AddReceivedEventCb(_stub, _receivedEventCallback, IntPtr.Zero);
-            Interop.LibRPCPort.Stub.AddConnectedEventCb(_stub, _connectedEventCallback, IntPtr.Zero);
-            Interop.LibRPCPort.Stub.AddDisconnectedEventCb(_stub, _disconnectedEventCallback, IntPtr.Zero);
-        }
-
-        protected void Listen()
-        {
-            var err = Interop.LibRPCPort.Stub.Listen(_stub);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                case Interop.LibRPCPort.ErrorCode.IoError:
-                    throw new InvalidIOException();
-            }
-        }
-
-        protected void AddPrivilege(string privilege)
-        {
-            var err = Interop.LibRPCPort.Stub.AddPrivilege(_stub, privilege);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                    throw new InvalidIOException();
-            }
-        }
-
-        protected void SetTrusted(bool trusted)
-        {
-            var err = Interop.LibRPCPort.Stub.SetTrusted(_stub, trusted);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                    throw new InvalidIOException();
-            }
-        }
-
-        protected Port GetPort(Port.Type t, string instance)
-        {
-            var err = Interop.LibRPCPort.Stub.GetPort(_stub,
-                (Interop.LibRPCPort.PortType)t, instance, out IntPtr port);
-            switch (err)
-            {
-                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
-                    throw new InvalidIDException();
-                case Interop.LibRPCPort.ErrorCode.IoError:
-                    throw new InvalidIOException();
-            }
-
-            return new Port() { Handle = port };
-        }
-
-        protected abstract void OnConnectedEvent(string sender, string instance);
-
-        protected abstract void OnDisconnectedEvent(string sender, string instance);
-
-        protected abstract bool OnReceivedEvent(string sender, string instance, Port port);
-
-        protected abstract void OnTerminatedEvent();
-
-        private void OnConnectedEvent(string sender, string instance, IntPtr data)
-        {
-            OnConnectedEvent(sender, instance);
-        }
-
-        private void OnDisconnectedEvent(string sender, string instance, IntPtr data)
-        {
-            OnDisconnectedEvent(sender, instance);
-        }
-
-        private int OnReceivedEvent(string sender, string instance, IntPtr port, IntPtr data)
-        {
-            bool b = OnReceivedEvent(sender, instance, new Port() { Handle = port });
-            if (b)
-                return 0;
-            return -1;
-        }
-
-        #region IDisposable Support
-        private bool disposedValue = false;
-
-        protected virtual void Dispose(bool disposing)
-        {
-            if (!disposedValue)
-            {
-                if (disposing)
-                {
-                }
-
-                OnTerminatedEvent();
-
-                if (_stub != IntPtr.Zero)
-                    Interop.LibRPCPort.Stub.Destroy(_stub);
-                _stub = IntPtr.Zero;
-
-                disposedValue = true;
-            }
-        }
-
-        ~StubBase()
-        {
-            Dispose(false);
-        }
-
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-        #endregion
-    }
-}
-
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_CB_RPC_PORT_H_
diff --git a/idlc/cs_gen/cs_cb_version.h b/idlc/cs_gen/cs_cb_version.h
deleted file mode 100644 (file)
index c0102a4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_CB_VERSION_H_
-#define IDLC_CS_GEN_CS_CB_VERSION_H_
-
-const char cs_cb_version[] =
-R"__cs_cb(/*
- * Generated by tidlc $$.
- */
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_CB_VERSION_H_
diff --git a/idlc/cs_gen/cs_gen_base.cc b/idlc/cs_gen/cs_gen_base.cc
deleted file mode 100644 (file)
index d1f7b65..0000000
+++ /dev/null
@@ -1,507 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <ctime>
-#include <vector>
-
-#include "idlc/cs_gen/cs_gen_base.h"
-
-namespace {
-#include "idlc/cs_gen/cs_cb_version.h"
-#include "idlc/cs_gen/cs_gen_base_cb.h"
-#include "idlc/cs_gen/cs_cb_rpc_port.h"
-}
-
-namespace tidl {
-
-CsGeneratorBase::CsGeneratorBase(std::shared_ptr<Document> doc)
-    : Generator(doc) {
-  type_map_ = {
-      {"char", "byte"}, {"int", "int"}, {"short", "short"},
-      {"long", "long"}, {"string", "string"}, {"bool", "bool"},
-      {"list", "LinkedList"}, {"array", "List"}, {"float", "float"},
-      {"double", "double"}, {"bundle", "Bundle"}, {"void", "void"}
-  };
-
-  parcel_type_map_ = {
-    {"char", "Byte"},
-    {"int", "Int"},
-    {"short", "Short"},
-    {"long", "Long"},
-    {"string", "String"},
-    {"bool", "Bool"},
-    {"float", "Float"},
-    {"double", "Double"},
-    {"bundle", "Bundle"},
-  };
-}
-
-void CsGeneratorBase::GenStructures(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_STRUCTURE)
-      continue;
-    Structure& st = static_cast<Structure&>(*i);
-    GenStructure(stream, st);
-    stream << std::endl;
-  }
-}
-
-void CsGeneratorBase::GenStructure(std::ofstream& stream, const Structure& st) {
-  std::vector<std::string> v;
-
-  stream << Tab(1) <<"public sealed class " << st.GetID() << NLine(1);
-  GenBrace(stream, TAB_SIZE, [&]() {
-    for (auto& i : st.GetElements().GetElms()) {
-      GenTemplate(CB_PROPERTY, stream,
-        [&]()->std::string {
-          return ConvertTypeToString(i->GetType());
-        },
-        [&]()->std::string {
-          return i->GetID();
-        });
-      if (i->GetType().ToString() == "bundle") {
-        v.push_back(i->GetID() + " = " + "new Bundle()");
-      }
-    }
-
-    GenTemplate(CB_CTOR, stream,
-      [&]()->std::string {
-        return st.GetID();
-      },
-      [&]()->std::string {
-        std::string str;
-        for (auto& i : v) {
-          str += "            " + i + ";\n";
-        }
-        return str;
-      });
-  });
-}
-
-void CsGeneratorBase::GenSerializer(std::ofstream& stream,
-    const Structure& st) {
-  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
-                   << st.GetID() << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    for (auto& i : st.GetElements().GetElms()) {
-      auto& t = i->GetType();
-      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
-        stream << Tab(4) << "h.Write"
-                         << ConvertTypeToParcelType(t.ToString())
-                         << "(param."
-                         << i->GetID()
-                         << ");" << NLine(1);
-      } else {
-        stream << Tab(4) << "Serialize(h, param." << i->GetID()
-                         << ");" << NLine(1);
-      }
-    }
-  });
-  stream << NLine(1);
-
-  stream << Tab(3) << "private static void Deserialize(Parcel h, "
-                   << st.GetID() << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    for (auto& i : st.GetElements().GetElms()) {
-      auto& t = i->GetType();
-      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
-        stream << Tab(4) << "var " << i->GetID() << " = "
-                         << "h.Read"
-                         << ConvertTypeToParcelType(t.ToString())
-                         << "();" << NLine(1);
-        stream << Tab(4) << "param." << i->GetID() << " = " << i->GetID()
-               << ";" << NLine(1);
-      } else {
-        stream << Tab(4) << "param." << i->GetID() << " = new "
-                         << ConvertTypeToString(t)
-                         << "();" << NLine(1);
-        stream << Tab(4) << "Deserialize(h, param." << i->GetID()
-                         << ");" << NLine(1);
-      }
-    }
-  });
-}
-
-void CsGeneratorBase::GenSerializer(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() == Block::TYPE_STRUCTURE) {
-      const Structure& st = static_cast<const Structure&>(*i);
-      GenSerializer(stream, st);
-    }
-  }
-}
-
-void CsGeneratorBase::AddSerializerList(const BaseType& type) {
-  if (type.GetMetaType() != nullptr) {
-    serializer_list_[ConvertTypeToString(type)] = &type;
-    AddSerializerList(*type.GetMetaType());
-  }
-}
-
-void CsGeneratorBase::GenListSerializer(std::ofstream& stream,
-    const BaseType& type) {
-  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
-                   << ConvertTypeToString(type) << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    stream << Tab(4)
-           << "h.WriteArrayCount(param.Count);"
-           << NLine(1);
-    stream << Tab(4) << "foreach (var i in param)" << NLine(1);
-    GenBrace(stream, TAB_SIZE * 4, [&]() {
-      auto& mt = *type.GetMetaType();
-      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
-        stream << Tab(5) << "h.Write"
-                         << ConvertTypeToParcelType(mt.ToString())
-                         << "(i);" << NLine(1);
-      } else {
-        stream << Tab(5) << "Serialize(h, i);" << NLine(1);
-      }
-    });
-  });
-  stream << NLine(1);
-
-  stream << Tab(3) << "private static void Deserialize(Parcel h, "
-                   << ConvertTypeToString(type) << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    stream << Tab(4)
-           << "int l = h.ReadArrayCount();"
-           << NLine(1);
-    stream << Tab(4) << "for (int i = 0; i < l; i++)" << NLine(1);
-    GenBrace(stream, TAB_SIZE * 4, [&]() {
-      auto& mt = *type.GetMetaType();
-      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
-        stream << Tab(5) << "var v = h.Read"
-                         << ConvertTypeToParcelType(mt.ToString())
-                         << "();" << NLine(1);
-      } else {
-        stream << Tab(5) << "var v = new " << ConvertTypeToString(mt)
-               << "();" << NLine(1);
-        stream << Tab(5) << "Deserialize(h, v);" << NLine(1);
-      }
-      if (type.ToString() == "list")
-        stream << Tab(5) << "param.AddLast(v);" << NLine(1);
-      else
-        stream << Tab(5) << "param.Add(v);" << NLine(1);
-    });
-  });
-}
-
-void CsGeneratorBase::GenListSerializer(std::ofstream& stream) {
-  serializer_list_.clear();
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() == Block::TYPE_STRUCTURE) {
-      const Structure& st = static_cast<const Structure&>(*i);
-      for (auto& j : st.GetElements().GetElms()) {
-        auto& t = j->GetType();
-        AddSerializerList(t);
-      }
-    } else if (i->GetType() == Block::TYPE_INTERFACE) {
-      const Interface& iface = static_cast<const Interface&>(*i);
-      for (auto& j : iface.GetDeclarations().GetDecls()) {
-        auto& t = j->GetType();
-        AddSerializerList(t);
-        for (auto& k : j->GetParameters().GetParams()) {
-          auto& t1 = k->GetParameterType().GetBaseType();
-          AddSerializerList(t1);
-        }
-      }
-    }
-  }
-
-  for (auto& p : serializer_list_) {
-    const BaseType* t = p.second;
-    GenListSerializer(stream, *t);
-  }
-}
-
-std::string CsGeneratorBase::ConvertTypeToString(const BaseType& type) {
-  if (type.IsUserDefinedType())
-    return type.ToString();
-
-  if (type.GetMetaType() != nullptr)
-    return type_map_[type.ToString()] + "<" +
-        ConvertTypeToString(*(type.GetMetaType())) + ">";
-
-  return type_map_[type.ToString()];
-}
-
-std::string CsGeneratorBase::ConvertTypeToParcelType(const std::string& key) {
-  return parcel_type_map_[key];
-}
-
-std::string CsGeneratorBase::ConvertTypeToDeserializer(
-    const BaseType& type, std::string id, std::string parcel,
-    bool make_new_type, std::string iface_id) {
-  if (type.IsUserDefinedType() ||
-      type.GetMetaType() != nullptr) {
-    std::string n;
-
-    if (type.GetMetaType() != nullptr)
-      n = ConvertTypeToString(type);
-    else
-      n = type.ToString();
-
-    std::string ret;
-
-    if (make_new_type)
-      ret = n + " ";
-
-    if (IsDelegateType(type)) {
-      ret += id + " = new " + n
-          + "(GetPort(Port.Type.Callback, instance), new WeakReference(b));\n";
-      ret += "CallbackBase.";
-    } else {
-      ret += id + " = new " + n +"();\n";
-    }
-    if (iface_id != "")
-      ret += iface_id + ".";
-    ret += "Deserialize(" + parcel + ", " + id +");\n";
-    return ret;
-  }
-
-  std::string ret;
-  if (make_new_type) {
-    ret = ConvertTypeToString(type) + " "
-        + id + " = " + parcel + ".Read"
-        + parcel_type_map_[type.ToString()]
-        + "();\n";
-  } else {
-    ret = id + " = " + parcel + ".Read"
-        + parcel_type_map_[type.ToString()]
-        + "();\n";
-  }
-
-  return ret;
-}
-
-std::string CsGeneratorBase::ConvertTypeToSerializer(
-    const BaseType& type, std::string id, std::string parcel,
-    std::string iface_id) {
-  std::string ret;
-
-  if (type.IsUserDefinedType() ||
-      type.GetMetaType() != nullptr) {
-    if (IsDelegateType(type))
-      return "CallbackBase.Serialize(" + parcel + ", " + id + ");\n";
-    if (iface_id != "")
-      ret += iface_id + ".";
-    ret += "Serialize(" + parcel + ", " + id + ");\n";
-    return ret;
-  }
-
-  ret += parcel + ".Write"
-      + parcel_type_map_[type.ToString()] + "(" + id + ");\n";
-
-  return ret;
-}
-
-std::string CsGeneratorBase::Tab(int cnt) {
-  std::string t;
-
-  for (int i = 0; i < cnt; i++) {
-    t += "    ";
-  }
-
-  return t;
-}
-
-std::string CsGeneratorBase::NLine(int cnt) {
-  std::string t;
-
-  for (int i = 0; i < cnt; i++) {
-    t += "\n";
-  }
-
-  return t;
-}
-
-void CsGeneratorBase::GenWriteBundle(std::ofstream& stream,
-    const std::string& id) {
-  GenTemplate(CB_WRITE_BUNDLE, stream,
-    [&]()->std::string {
-      return id;
-    },
-    [&]()->std::string {
-      return id;
-    });
-}
-
-void CsGeneratorBase::GenMethodId(std::ofstream& stream,
-    const Interface& iface) {
-  stream << Tab(3) << "private enum MethodId : int" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    int cnt = 2;
-    stream << Tab(4) << "__Result = 0," << NLine(1);
-    stream << Tab(4) << "__Callback = 1," << NLine(1);
-    for (auto& i : iface.GetDeclarations().GetDecls()) {
-      if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-        continue;
-      stream << Tab(4)
-             << i->GetID() << " = " << cnt++ << "," << NLine(1);
-    }
-  });
-}
-
-void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
-    const Interface& iface) {
-  stream << Tab(3) << "private enum DelegateId : int" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    int cnt = 1;
-    for (auto& i : iface.GetDeclarations().GetDecls()) {
-        if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          continue;
-        stream << Tab(4)
-               << i->GetID() << " = " << cnt++ << "," << NLine(1);
-    }
-  });
-  stream << NLine(1);
-}
-
-void CsGeneratorBase::GenDeclaration(std::ofstream& stream,
-                                     const Declaration& decl, bool semicol) {
-  stream << ConvertTypeToString(decl.GetType()) << " "
-         << decl.GetID() << "(";
-  GenParameters(stream, decl.GetParameters());
-  if (semicol)
-    stream << ");";
-  else
-    stream << ")";
-}
-
-void CsGeneratorBase::GenParameters(std::ofstream& stream,
-    const Parameters& ps) {
-  stream << GetParameters(ps);
-}
-
-std::string CsGeneratorBase::GetParameters(const Parameters& ps) {
-  bool first = true;
-  std::string ret;
-  for (auto& i : ps.GetParams()) {
-    if (!first) {
-      ret += ", ";
-    }
-
-    auto dir = i->GetParameterType().GetDirection();
-    if (dir == ParameterType::Direction::OUT) {
-      ret += "out ";
-    } else if (dir == ParameterType::Direction::REF) {
-      ret += "ref ";
-    }
-
-    ret += ConvertTypeToString(i->GetParameterType().GetBaseType())
-        + " " + i->GetID();
-    first = false;
-  }
-
-  return ret;
-}
-
-void CsGeneratorBase::GenCallbacks(std::ofstream& stream,
-                                   const Interface& iface, bool is_proxy) {
-  stream << CB_CALLBACK_BASE;
-
-  for (auto& i : iface.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-          continue;
-    GenCallback(stream, *i, iface.GetID(), is_proxy);
-  }
-}
-
-void CsGeneratorBase::GenCallback(std::ofstream& stream,
-                                  const Declaration& decl,
-                                  const std::string& id, bool is_proxy) {
-  stream << Tab(3) << "public sealed class " << decl.GetID()
-         << " : CallbackBase" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    GenTemplate(
-      is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB, stream,
-      [&]()->std::string {
-        return decl.GetID();
-      },
-      [&]()->std::string {
-        return decl.GetID();
-      });
-    stream << NLine(1);
-
-    if (is_proxy) {
-      stream << Tab(4) << "public delegate void Callback(";
-      GenParameters(stream, decl.GetParameters());
-      stream << ");" << NLine(1);
-      stream << Tab(4) << "public event Callback Received;" << NLine(2);
-      GenReceivedEvent(stream, decl, id);
-    } else {
-      stream << CB_CALLBACK_STUB_MEMBERS;
-      GenInvokeMethod(stream, decl, id);
-    }
-  });
-  stream << NLine(1);
-}
-
-void CsGeneratorBase::GenReceivedEvent(std::ofstream& stream,
-                                       const Declaration& decl,
-                                       const std::string& id) {
-  stream << Tab(4) << "internal override void OnReceivedEvent(Parcel parcel)"
-         << NLine(1);
-  GenBrace(stream, TAB_SIZE * 4, [&]() {
-    int cnt = 1;
-    for (auto& i : decl.GetParameters().GetParams()) {
-      std::string v = "param" + std::to_string(cnt);
-      std::string c = ConvertTypeToDeserializer(
-          i->GetParameterType().GetBaseType(), v, "parcel", true, id);
-      stream << AddIndent(TAB_SIZE * 5, c);
-      cnt++;
-    }
-
-    cnt = 1;
-    stream << Tab(5) << "Received?.Invoke(";
-    for (int i = 0; i < decl.GetParameters().GetParams().size(); i++) {
-      if (cnt != 1) {
-        stream << ", ";
-      }
-      std::string v = "param" + std::to_string(cnt);
-        stream << v;
-      cnt++;
-    }
-    stream << ");" << NLine(1);
-  });
-  stream << NLine(1);
-}
-
-void CsGeneratorBase::GenInvokeMethod(std::ofstream& stream,
-                                      const Declaration& decl,
-                                      const std::string& id) {
-  GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream,
-      [&]()->std::string {
-        return GetParameters(decl.GetParameters());
-      },
-      [&]()->std::string {
-        std::string m;
-        for (auto& i : decl.GetParameters().GetParams()) {
-          auto& pt = i->GetParameterType();
-          m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p", id);
-        }
-        return AddIndent(TAB_SIZE * 6, m);
-      });
-}
-
-void CsGeneratorBase::GenVersion(std::ofstream& stream) {
-  GenTemplate(::cs_cb_version, stream,
-    [&]()->std::string {
-      return FULLVER;
-    });
-  stream << NLine(1);
-}
-}  // namespace tidl
diff --git a/idlc/cs_gen/cs_gen_base.h b/idlc/cs_gen/cs_gen_base.h
deleted file mode 100644 (file)
index cbc35c9..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_GEN_BASE_H_
-#define IDLC_CS_GEN_CS_GEN_BASE_H_
-
-#include <memory>
-#include <string>
-#include <map>
-
-#include "idlc/type.h"
-#include "idlc/structure.h"
-#include "idlc/generator.h"
-
-namespace tidl {
-
-class CsGeneratorBase : public Generator {
- public:
-  explicit CsGeneratorBase(std::shared_ptr<Document> doc);
-  virtual ~CsGeneratorBase() = default;
-
-  void GenVersion(std::ofstream& stream);
-  void GenStructures(std::ofstream& stream);
-  void GenStructure(std::ofstream& stream, const Structure& st);
-  void GenSerializer(std::ofstream& stream);
-  void GenSerializer(std::ofstream& stream, const Structure& st);
-  void GenListSerializer(std::ofstream& stream);
-  void GenListSerializer(std::ofstream& stream, const BaseType& type);
-  void GenMethodId(std::ofstream& stream, const Interface& iface);
-  void GenDelegateId(std::ofstream& stream, const Interface& iface);
-  void GenDeclaration(std::ofstream& stream,
-                      const Declaration& decl, bool semicol = true);
-  void GenParameters(std::ofstream& stream, const Parameters& ps);
-  void GenCallbacks(std::ofstream& stream, const Interface& iface,
-                    bool is_proxy);
-
-  std::string ConvertTypeToString(const BaseType& type);
-  std::string ConvertTypeToDeserializer(const BaseType& type,
-                                        std::string id, std::string parcel,
-                                        bool make_new_type = true,
-                                        const std::string iface_id = "");
-  std::string ConvertTypeToSerializer(const BaseType& type,
-                                      std::string id, std::string parcel,
-                                      const std::string iface_id = "");
-  std::string ConvertTypeToParcelType(const std::string& key);
-  std::string GetParameters(const Parameters& ps);
-  std::string Tab(int cnt);
-  std::string NLine(int cnt);
-
- protected:
-  const int TAB_SIZE = 4;
-
- private:
-  void GenWriteBundle(std::ofstream& stream, const std::string& id);
-  void AddSerializerList(const BaseType& type);
-  void GenCallback(std::ofstream& stream, const Declaration& decl,
-                   const std::string& id, bool is_proxy);
-  void GenReceivedEvent(std::ofstream& stream, const Declaration& decl,
-                        const std::string& id);
-  void GenInvokeMethod(std::ofstream& stream, const Declaration& decl,
-                       const std::string& id);
-
- private:
-  std::map<std::string, std::string> type_map_;
-  std::map<std::string, std::string> parcel_type_map_;
-  std::map<std::string, const BaseType*> serializer_list_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CS_GEN_CS_GEN_BASE_H_
diff --git a/idlc/cs_gen/cs_gen_base_cb.h b/idlc/cs_gen/cs_gen_base_cb.h
deleted file mode 100644 (file)
index aabc490..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_GEN_BASE_CB_H_
-#define IDLC_CS_GEN_CS_GEN_BASE_CB_H_
-
-const char CB_CALLBACK_BASE[] =
-R"__cs_cb(
-            public abstract class CallbackBase
-            {
-                internal int Id;
-                internal int SeqId;
-                internal bool Once;
-                private static volatile int _seqNum = 0;
-
-                public string Tag
-                {
-                    get
-                    {
-                        return Id.ToString() + "::" + SeqId.ToString();
-                    }
-                }
-
-                public CallbackBase(int delegateId, bool once)
-                {
-                    Id = delegateId;
-                    SeqId = _seqNum++;
-                    Once = once;
-                }
-
-                internal virtual void OnReceivedEvent(Parcel p) {}
-
-                internal static void Serialize(Parcel h, CallbackBase param)
-                {
-                    h.WriteInt(param.Id);
-                    h.WriteInt(param.SeqId);
-                    h.WriteBool(param.Once);
-                }
-
-                internal static void Deserialize(Parcel h, CallbackBase param)
-                {
-                    param.Id = h.ReadInt();
-                    param.SeqId = h.ReadInt();
-                    param.Once = h.ReadBool();
-                }
-            }
-
-)__cs_cb";
-
-const char CB_CALLBACK_CTOR_PROXY[] =
-R"__cs_cb(                public $$(bool once = false) : base((int)DelegateId.$$, once)
-                {
-                }
-)__cs_cb";
-
-const char CB_CALLBACK_CTOR_STUB[] =
-R"__cs_cb(                internal $$(Port port, WeakReference service) : base((int)DelegateId.$$, false)
-                {
-                    _port = port;
-                    _service = service;
-                }
-)__cs_cb";
-
-const char CB_CALLBACK_STUB_MEMBERS[] =
-R"__cs_cb(                private Port _port;
-                private WeakReference _service;
-                private bool _valid = true;
-
-)__cs_cb";
-
-const char CB_CALLBACK_INVOKE_METHOD[] =
-R"__cs_cb(
-                public void Invoke($$)
-                {
-                    if (_port == null)
-                        throw new NotConnectedSocketException();
-                    if (!_service.IsAlive)
-                        throw new InvalidProtocolException();
-                    if (Once && !_valid)
-                        throw new InvalidCallbackException();
-
-                    using (var p = new Parcel())
-                    {
-                        p.WriteInt((int)MethodId.__Callback);
-                        Serialize(p, this);
-$$
-                        // Send
-                        p.Send(_port);
-                        _valid = false;
-                    }
-                }
-)__cs_cb";
-
-const char CB_PROPERTY[] = R"__cs_cb(        public $$ $$ { get; set; }
-)__cs_cb";
-
-const char CB_CTOR[] = R"__cs_cb(
-        public $$()
-        {
-$$
-        }
-)__cs_cb";
-
-const char CB_WRITE_BUNDLE[] =
-R"__cs_cb(
-                if (param.$$ != null)
-                {
-                    h.WriteBundle(param.$$);
-                }
-                else
-                {
-                    h.WriteBundle(new Bundle());
-                }
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_GEN_BASE_CB_H_
diff --git a/idlc/cs_gen/cs_lib_gen.cc b/idlc/cs_gen/cs_lib_gen.cc
deleted file mode 100644 (file)
index 8f2eba0..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cs_gen/cs_lib_gen.h"
-
-namespace {
-#include "idlc/cs_gen/cs_cb_rpc_port.h"
-#include "idlc/cs_gen/cs_cb_interop.h"
-}
-
-namespace tidl {
-
-CsLibGen::CsLibGen(std::shared_ptr<Document> doc)
-    : CsGeneratorBase(doc) {}
-
-void CsLibGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  stream << "using System;" << NLine(1)
-         << "using System.Collections.Generic;" << NLine(1)
-         << "using System.Runtime.InteropServices;" << NLine(1)
-         << "using Tizen.Applications;" << NLine(1);
-  GenInterop(stream);
-  GenRpcPort(stream);
-}
-
-void CsLibGen::OnFiniGen(std::ofstream& stream) {}
-
-void CsLibGen::GenInterop(std::ofstream& stream) {
-  stream << cs_cb_interop;
-}
-
-void CsLibGen::GenRpcPort(std::ofstream& stream) {
-  stream << cs_cb_rpc_port;
-}
-
-}  // namespace tidl
diff --git a/idlc/cs_gen/cs_lib_gen.h b/idlc/cs_gen/cs_lib_gen.h
deleted file mode 100644 (file)
index 83cc151..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_LIB_GEN_H_
-#define IDLC_CS_GEN_CS_LIB_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cs_gen/cs_gen_base.h"
-
-namespace tidl {
-
-class CsLibGen : public CsGeneratorBase {
- public:
-  explicit CsLibGen(std::shared_ptr<Document> doc);
-  virtual ~CsLibGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenInterop(std::ofstream& stream);
-  void GenRpcPort(std::ofstream& stream);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CS_GEN_CS_LIB_GEN_H_
diff --git a/idlc/cs_gen/cs_proxy_gen.cc b/idlc/cs_gen/cs_proxy_gen.cc
deleted file mode 100644 (file)
index 23e24f3..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cs_gen/cs_proxy_gen.h"
-
-namespace {
-#include "idlc/cs_gen/cs_proxy_gen_cb.h"
-}
-
-namespace tidl {
-
-CsProxyGen::CsProxyGen(std::shared_ptr<Document> doc)
-    : CsGeneratorBase(doc) {}
-
-void CsProxyGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  stream << "using System;" << NLine(1)
-         << "using System.Collections.Generic;" << NLine(1)
-         << "using System.Threading;" << NLine(1)
-         << "using Tizen.Applications;" << NLine(1)
-        << "using Tizen.Applications.RPCPort;" << NLine(1);
-  GenNamespace(stream);
-}
-
-void CsProxyGen::OnFiniGen(std::ofstream& stream) {
-}
-
-void CsProxyGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace RPCPort" << NLine(1);
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << NLine(1);
-    GenBrace(stream, 0, [&]() {
-      GenStructures(stream);
-      stream << Tab(1) << "namespace Proxy" << NLine(1);
-      GenBrace(stream, TAB_SIZE, [&]() {
-        GenInterfaces(stream);
-      });
-    });
-  });
-}
-
-void CsProxyGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-    stream << NLine(1);
-  }
-}
-
-void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
-  stream << Tab(2) << "public class " << iface.GetID()
-         << " : ProxyBase" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 2, [&]() {
-    stream << CB_DATA_MEMBERS;
-    GenCallbacks(stream, iface, true);
-    GenDelegateId(stream, iface);
-    GenMethodId(stream, iface);
-    stream << CB_EVENT_METHODS;
-    GenSerializer(stream);
-    GenListSerializer(stream);
-    GenCtor(stream, iface);
-    GenConnectMethod(stream, iface);
-    GenMethods(stream, iface);
-  });
-}
-
-void CsProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) {
-  const char* m = "public $$(string appId) => _appId = appId;\n";
-
-  stream << NLine(1);
-  GenTemplate(AddIndent(TAB_SIZE * 3, m), stream,
-    [&]()->std::string {
-      return iface.GetID();
-    });
-}
-
-void CsProxyGen::GenConnectMethod(std::ofstream& stream,
-    const Interface& iface) {
-  GenTemplate(CB_CONNECT_METHOD, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    });
-  stream << NLine(1);
-}
-
-void CsProxyGen::GenMethods(std::ofstream& stream, const Interface& iface) {
-  auto& decls = iface.GetDeclarations();
-
-  for (auto& i : decls.GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-
-    if (!i->GetComments().empty())
-      stream << AddIndent(TAB_SIZE * 3, i->GetComments());
-
-    stream << Tab(3) << "public ";
-    GenDeclaration(stream, *i, false);
-    stream << NLine(1);
-    GenBrace(stream, TAB_SIZE * 3, [&]() {
-      GenInvocation(stream, *i);
-    });
-    stream << NLine(1);
-  }
-}
-
-void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
-  GenTemplate(CB_INVOCATION_PRE, stream,
-    [&]()->std::string {
-      std::string st;
-      st += Tab(5)
-         + "p.WriteInt((int)MethodId." + decl.GetID() + ");" + NLine(1);
-      std::string m;
-      std::string l;
-      for (auto& i : decl.GetParameters().GetParams()) {
-        auto& pt = i->GetParameterType();
-        if (pt.GetDirection() == ParameterType::Direction::OUT)
-          continue;
-        m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
-        if (IsDelegateType(pt.GetBaseType())) {
-          l += "_delegateList.Add(" + i->GetID() + ");\n";
-        }
-      }
-
-      st += AddIndent(TAB_SIZE * 5, m) + NLine(1);
-
-      if (decl.GetMethodType() == Declaration::MethodType::SYNC)
-        st += Tab(5) + "Parcel parcelReceived;" + NLine(1);
-      st += Tab(5) + "lock (_lock)" + NLine(1);
-      st += Tab(5) + "{" + NLine(1);
-        if (!l.empty())
-          st += AddIndent(TAB_SIZE * 6, l) + NLine(1);
-        st += CB_INVOCATION_MID + NLine(1);
-        if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
-          st += Tab(6) + "// Receive" + NLine(1);
-          st += Tab(6)
-             + "ConsumeCommand(out parcelReceived, Port);" + NLine(1);
-        }
-      st += Tab(5) + "}";
-
-      // Deserialize
-      if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
-        return st;
-      }
-
-      const char* receive_block =
-          "if (parcelReceived == null)\n" \
-          "{\n" \
-          "    throw new InvalidProtocolException();\n" \
-          "}\n";
-      st += NLine(1) + AddIndent(TAB_SIZE * 5, receive_block) + NLine(1);
-
-      for (auto& i : decl.GetParameters().GetParams()) {
-        if (i->GetParameterType().GetDirection() ==
-            ParameterType::Direction::IN) {
-          continue;
-        }
-
-        std::string c = ConvertTypeToDeserializer(
-            i->GetParameterType().GetBaseType(),
-            i->GetID(), "parcelReceived", false);
-        if (c != "")
-          st += AddIndent(TAB_SIZE * 5, c);
-      }
-
-      if (decl.GetType().ToString() != "void") {
-        st += AddIndent(TAB_SIZE * 5,
-                        ConvertTypeToDeserializer(decl.GetType(),
-                                                  "ret", "parcelReceived"));
-      }
-
-      st += Tab(5) + "parcelReceived.Dispose();" + NLine(1);
-      st += Tab(5) + "return ret;";
-
-      return st;
-    });
-}
-
-}  // namespace tidl
diff --git a/idlc/cs_gen/cs_proxy_gen.h b/idlc/cs_gen/cs_proxy_gen.h
deleted file mode 100644 (file)
index a5a99e0..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_PROXY_GEN_H_
-#define IDLC_CS_GEN_CS_PROXY_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cs_gen/cs_gen_base.h"
-
-namespace tidl {
-
-class CsProxyGen : public CsGeneratorBase {
- public:
-  explicit CsProxyGen(std::shared_ptr<Document> doc);
-  virtual ~CsProxyGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenNamespace(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenCtor(std::ofstream& stream, const Interface& iface);
-  void GenConnectMethod(std::ofstream& stream, const Interface& iface);
-  void GenMethods(std::ofstream& stream, const Interface& iface);
-  void GenInvocation(std::ofstream& stream, const Declaration& decl);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CS_GEN_CS_PROXY_GEN_H_
diff --git a/idlc/cs_gen/cs_proxy_gen_cb.h b/idlc/cs_gen/cs_proxy_gen_cb.h
deleted file mode 100644 (file)
index a9f51ff..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
-#define IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
-
-const char CB_DATA_MEMBERS[] =
-R"__cs_cb(            public event EventHandler Connected;
-            public event EventHandler Disconnected;
-            public event EventHandler Rejected;
-
-            private bool _online = false;
-            private string _appId;
-            private Object _lock = new Object();
-            private List<CallbackBase> _delegateList = new List<CallbackBase>();
-)__cs_cb";
-
-const char CB_EVENT_METHODS[] =
-R"__cs_cb(
-            protected override void OnConnectedEvent(string endPoint, string portName, Port port)
-            {
-                _online = true;
-                Connected?.Invoke(this, null);
-            }
-
-            protected override void OnDisconnectedEvent(string endPoint, string portName)
-            {
-                _online = false;
-                Disconnected?.Invoke(this, null);
-            }
-
-            protected override void OnRejectedEvent(string endPoint, string portName)
-            {
-                Rejected?.Invoke(this, null);
-            }
-
-            private void ProcessReceivedEvent(Parcel parcel)
-            {
-                int id = parcel.ReadInt();
-                int seqId = parcel.ReadInt();
-                bool once = parcel.ReadBool();
-
-                foreach (var i in _delegateList)
-                {
-                    if ((int)i.Id == id && i.SeqId == seqId)
-                    {
-                        i.OnReceivedEvent(parcel);
-                        if (i.Once)
-                            _delegateList.Remove(i);
-                        break;
-                    }
-                }
-            }
-
-            protected override void OnReceivedEvent(string endPoint, string portName)
-            {
-                Parcel parcelReceived;
-
-                parcelReceived = new Parcel(CallbackPort);
-
-                using (parcelReceived)
-                {
-                    int cmd = parcelReceived.ReadInt();
-                    if (cmd != (int)MethodId.__Callback)
-                    {
-                        return;
-                    }
-
-                    ProcessReceivedEvent(parcelReceived);
-                }
-            }
-
-            private void ConsumeCommand(out Parcel parcel, Port port)
-            {
-                do
-                {
-                    var p = new Parcel(port);
-
-                    int cmd = p.ReadInt();
-                    if (cmd == (int)MethodId.__Result)
-                    {
-                        parcel = p;
-                        return;
-                    }
-
-                    p.Dispose();
-                    parcel = null;
-                } while (true);
-            }
-)__cs_cb";
-
-const char CB_CONNECT_METHOD[] =
-R"__cs_cb(
-            /// <summary>
-            /// Connects to the service app.
-            /// </summary>
-            /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
-            /// <privilege>http://tizen.org/privilege/datasharing</privilege>
-            /// <exception cref="InvalidIDException">
-            /// Thrown when the appid to connect is invalid.
-            /// </exception>
-            /// <exception cref="InvalidIOException">
-            /// Thrown when internal I/O error happen.
-            /// </exception>
-            /// <exception cref="PermissionDeniedException">
-            /// Thrown when the permission is denied.
-            /// </exception>
-            /// <remark> If you want to use this method, you must add privileges.</remark>
-            public void Connect()
-            {
-                Connect(_appId, "$$");
-            }
-
-            /// <summary>
-            /// Disposes delegate objects in this interface
-            /// </summary>
-            /// <param name="tag">The tag string from delegate object</param>
-            void DisposeCallback(string tag)
-            {
-                foreach (var i in _delegateList)
-                {
-                    if (i.Tag.Equals(tag))
-                    {
-                        _delegateList.Remove(i);
-                        return;
-                    }
-                }
-            }
-)__cs_cb";
-
-const char CB_INVOCATION_PRE[] =
-R"__cs_cb(                if (!_online)
-                    throw new NotConnectedSocketException();
-
-                using (Parcel p = new Parcel())
-                {
-$$
-               }
-)__cs_cb";
-
-const char CB_INVOCATION_MID[] =
-R"__cs_cb(                        // Send
-                        p.Send(Port);
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
diff --git a/idlc/cs_gen/cs_stub_gen.cc b/idlc/cs_gen/cs_stub_gen.cc
deleted file mode 100644 (file)
index e11800d..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/cs_gen/cs_stub_gen.h"
-
-namespace {
-#include "idlc/cs_gen/cs_stub_gen_cb.h"
-}
-
-namespace tidl {
-
-CsStubGen::CsStubGen(std::shared_ptr<Document> doc)
-    : CsGeneratorBase(doc) {}
-
-void CsStubGen::OnInitGen(std::ofstream& stream) {
-  GenVersion(stream);
-  stream << "using System;" << NLine(1)
-         << "using System.Collections.Generic;" << NLine(1)
-         << "using Tizen.Applications;" << NLine(1)
-         << "using Tizen.Applications.RPCPort;" << NLine(1);
-
-  GenNamespace(stream);
-}
-
-void CsStubGen::OnFiniGen(std::ofstream& stream) {}
-
-void CsStubGen::GenNamespace(std::ofstream& stream) {
-  stream << "namespace RPCPort" << NLine(1);
-  GenBrace(stream, 0, [&]() {
-    stream << "namespace " << GetFileNamespace() << NLine(1);
-    GenBrace(stream, 0, [&]() {
-      GenStructures(stream);
-      stream << Tab(1) << "namespace Stub" << NLine(1);
-      GenBrace(stream, TAB_SIZE, [&]() {
-        GenInterfaces(stream);
-      });
-    });
-  });
-}
-
-void CsStubGen::GenInterfaces(std::ofstream& stream) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-    GenInterface(stream, iface);
-    stream << std::endl;
-  }
-}
-
-void CsStubGen::GenInterface(std::ofstream& stream, const Interface& iface) {
-  stream << Tab(2) << "public sealed class " << iface.GetID()
-         << " : StubBase" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 2, [&]() {
-    stream << CB_DATA_MEMBERS;
-    GenServiceBase(stream, iface);
-    GenCallbacks(stream, iface, false);
-    GenDelegateId(stream, iface);
-    GenMethodId(stream, iface);
-    GenSerializer(stream);
-    GenListSerializer(stream);
-    GenReceivedEvent(stream, iface);
-    GenConnectedEvent(stream);
-    GenDisconnectedEvent(stream);
-    GenCtor(stream, iface);
-    GenCommonMethods(stream);
-    GenDisposable(stream, iface);
-  });
-}
-
-void CsStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) {
-  stream << CB_SERVICE_BASE_FRONT;
-  GenDeclarations(stream, iface.GetDeclarations());
-  stream << NLine(1);
-  stream << AddIndent(TAB_SIZE * 3, "}\n");
-}
-
-void CsStubGen::GenDeclarations(std::ofstream& stream,
-                                const Declarations& decls) {
-  for (auto& i : decls.GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    if (!i->GetComments().empty())
-      stream << NLine(1) << AddIndent(TAB_SIZE * 4, i->GetComments());
-    stream << Tab(4) << "public abstract ";
-    GenDeclaration(stream, *i);
-    stream << NLine(1);
-  }
-}
-
-void CsStubGen::GenReceivedEvent(std::ofstream& stream,
-    const Interface& iface) {
-  stream << CB_ON_RECEIVED_EVENT_FRONT;
-  for (auto& i : iface.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-      continue;
-    stream << Tab(7) << "case MethodId." << i->GetID() << ":" << NLine(1);
-    GenBrace(stream, TAB_SIZE * 8, [&]() {
-      GenInvocation(stream, *i);
-      stream << Tab(9) << "break;" << NLine(1);
-    });
-  }
-  stream << CB_ON_RECEIVED_EVENT_BACK;
-}
-
-void CsStubGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
-  int cnt = 1;
-
-  // Deserialize
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
-      cnt++;
-      continue;
-    }
-
-    std::string v = "param" + std::to_string(cnt);
-    std::string c = ConvertTypeToDeserializer(
-        i->GetParameterType().GetBaseType(), v, "p");
-    stream << AddIndent(TAB_SIZE * 9, c);
-    cnt++;
-  }
-
-  // Invoke
-  cnt = 1;
-  std::string m;
-  bool hasRet = false;
-
-  if (decl.GetType().ToString() != "void") {
-    m += "var retVal = ";
-    hasRet = true;
-  }
-
-  m += "b." + decl.GetID() + "(";
-  for (auto& i : decl.GetParameters().GetParams()) {
-    if (cnt != 1) {
-      m += ", ";
-    }
-
-    std::string v = "param" + std::to_string(cnt);
-    auto& pt = i->GetParameterType();
-    if (pt.GetDirection() == ParameterType::Direction::OUT) {
-      m += "out " + ConvertTypeToString(pt.GetBaseType()) + " ";
-    } else if (pt.GetDirection() == ParameterType::Direction::REF) {
-      m += "ref ";
-    }
-    m += v;
-    cnt++;
-  }
-
-  m += ");\n";
-  stream << AddIndent(TAB_SIZE * 9, m);
-
-  // Serialize
-  if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
-    return;
-
-  cnt = 0;
-  m = "result.WriteInt((int)MethodId.__Result);\n";
-  for (auto& i : decl.GetParameters().GetParams()) {
-    auto& pt = i->GetParameterType();
-    cnt++;
-    if (pt.GetDirection() == ParameterType::Direction::IN)
-      continue;
-    m += ConvertTypeToSerializer(pt.GetBaseType(),
-                                "param" + std::to_string(cnt), "result");
-  }
-
-  if (hasRet) {
-    m += ConvertTypeToSerializer(decl.GetType(), "retVal", "result");
-  }
-
-  m += "result.Send(port);\n";
-  stream << AddIndent(TAB_SIZE * 9, m);
-}
-
-void CsStubGen::GenConnectedEvent(std::ofstream& stream) {
-  stream << CB_ON_CONNECTED_EVENT;
-}
-
-void CsStubGen::GenDisconnectedEvent(std::ofstream& stream) {
-  stream << CB_ON_DISCONNECTED_EVENT;
-}
-
-void CsStubGen::GenCtor(std::ofstream& stream, const Interface& iface) {
-  GenTemplate(CB_CTOR_FRONT, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
-
-  for (auto& i : iface.GetAttributes().GetAttrs()) {
-    if (i->GetKey() == "privilege") {
-      stream << Tab(4) << "AddPrivilege(\""
-             << i->GetValue() << "\");" << NLine(1);
-    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
-      stream << Tab(4) << "SetTrusted("
-             << i->GetValue() << ");" << NLine(1);
-    }
-  }
-  stream << Tab(3) << "}" << NLine(1);
-}
-
-void CsStubGen::GenCommonMethods(std::ofstream& stream) {
-  stream << CB_COMMON_METHODS;
-}
-
-void CsStubGen::GenDisposable(std::ofstream& stream, const Interface& iface) {
-  stream << CB_DISPOSABLE;
-}
-
-}  // namespace tidl
diff --git a/idlc/cs_gen/cs_stub_gen.h b/idlc/cs_gen/cs_stub_gen.h
deleted file mode 100644 (file)
index ba47c43..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_STUB_GEN_H_
-#define IDLC_CS_GEN_CS_STUB_GEN_H_
-
-#include <memory>
-#include <string>
-
-#include "idlc/cs_gen/cs_gen_base.h"
-
-namespace tidl {
-
-class CsStubGen : public CsGeneratorBase {
- public:
-  explicit CsStubGen(std::shared_ptr<Document> doc);
-  virtual ~CsStubGen() = default;
-
-  void OnInitGen(std::ofstream& stream) override;
-  void OnFiniGen(std::ofstream& stream) override;
-
- private:
-  void GenNamespace(std::ofstream& stream);
-  void GenInterfaces(std::ofstream& stream);
-  void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenServiceBase(std::ofstream& stream, const Interface& iface);
-  void GenReceivedEvent(std::ofstream& stream, const Interface& iface);
-  void GenConnectedEvent(std::ofstream& stream);
-  void GenDisconnectedEvent(std::ofstream& stream);
-  void GenCtor(std::ofstream& stream, const Interface& iface);
-  void GenCommonMethods(std::ofstream& stream);
-  void GenDeclarations(std::ofstream& stream, const Declarations& decls);
-  void GenInvocation(std::ofstream& stream, const Declaration& decl);
-  void GenDisposable(std::ofstream& stream, const Interface& iface);
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_CS_GEN_CS_STUB_GEN_H_
diff --git a/idlc/cs_gen/cs_stub_gen_cb.h b/idlc/cs_gen/cs_stub_gen_cb.h
deleted file mode 100644 (file)
index 3be382a..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_CS_GEN_CS_STUB_GEN_CB_H_
-#define IDLC_CS_GEN_CS_STUB_GEN_CB_H_
-
-const char CB_DATA_MEMBERS[] =
-R"__cs_cb(            private List<ServiceBase> _services = new List<ServiceBase>();
-            private Type _serviceType;
-)__cs_cb";
-
-const char CB_SERVICE_BASE_FRONT[] =
-R"__cs_cb(
-            public abstract class ServiceBase
-            {
-                /// <summary>
-                /// The client app ID
-                /// </summary>
-                public string Sender
-                {
-                    get; internal set;
-                }
-
-                /// <summary>
-                /// The client instance ID
-                /// </summary>
-                public string Instance
-                {
-                    get; internal set;
-                }
-
-                protected ServiceBase()
-                {
-                }
-
-                /// <summary>
-                /// This method will be called when the client is connected
-                /// </summary>
-                public abstract void OnCreate();
-
-                /// <summary>
-                /// This method will be called when the client is disconnected
-                /// </summary>
-                public abstract void OnTerminate();
-)__cs_cb";
-
-const char CB_ON_RECEIVED_EVENT_FRONT[] =
-R"__cs_cb(
-            protected override bool OnReceivedEvent(string sender, string instance, Port port)
-            {
-                var p = new Parcel(port);
-
-                try
-                {
-                    ServiceBase b = null;
-
-                    foreach (var i in  _services)
-                    {
-                        if (i.Instance.Equals(instance))
-                        {
-                            b = i;
-                            break;
-                        }
-                    }
-
-                    if (b == null)
-                    {
-                        return false;
-                    }
-
-                    using (var result = new Parcel())
-                    {
-                        int cmd = p.ReadInt();
-
-                        switch ((MethodId)cmd)
-                        {
-)__cs_cb";
-
-const char CB_ON_RECEIVED_EVENT_BACK[] =
-R"__cs_cb(
-                            default:
-                                return false;
-                        }
-                    }
-
-                    return true;
-                }
-                catch (InvalidIOException)
-                {
-                    return false;
-                }
-                finally
-                {
-                    p.Dispose();
-                }
-            }
-)__cs_cb";
-
-const char CB_ON_CONNECTED_EVENT[] =
-R"__cs_cb(
-            protected override void OnConnectedEvent(string sender, string instance)
-            {
-                ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
-                s.Sender = sender;
-                s.Instance = instance;
-                s.OnCreate();
-                _services.Add(s);
-            }
-)__cs_cb";
-
-const char CB_ON_DISCONNECTED_EVENT[] =
-R"__cs_cb(
-            protected override void OnDisconnectedEvent(string sender, string instance)
-            {
-                foreach (var i in _services)
-                {
-                    if (i.Instance.Equals(instance))
-                    {
-                        i.OnTerminate();
-                        _services.Remove(i);
-                        break;
-                    }
-                }
-            }
-)__cs_cb";
-
-const char CB_CTOR_FRONT[] =
-R"__cs_cb(
-            public $$() : base("$$")
-            {
-)__cs_cb";
-
-const char CB_COMMON_METHODS[] =
-R"__cs_cb(
-            /// <summary>
-            /// Listens to client apps
-            /// </summary>
-            /// <param name="serviceType">The type object for making service instances</param>
-            /// <exception cref="InvalidIOException">
-            /// Thrown when internal I/O error happen.
-            /// </exception>
-            /// <exception cref="ArgumentException">
-            /// Thrown when serviceType is invalid.
-            /// </exception>
-            public void Listen(Type serviceType)
-            {
-                if (!typeof(ServiceBase).IsAssignableFrom(serviceType))
-                    throw new ArgumentException("Invalid type");
-                _serviceType = serviceType;
-                Listen();
-            }
-
-            /// <summary>
-            /// Gets service objects which are connected
-            /// </summary>
-            /// <returns>The enumerable service objects which are connected</returns>
-            public IEnumerable<ServiceBase> GetServices()
-            {
-                return _services;
-            }
-)__cs_cb";
-
-const char CB_DISPOSABLE[] =
-R"__cs_cb(
-            protected override void OnTerminatedEvent()
-            {
-                foreach (var i in _services)
-                {
-                    i.OnTerminate();
-                }
-            }
-)__cs_cb";
-
-#endif  // IDLC_CS_GEN_CS_STUB_GEN_CB_H_
diff --git a/idlc/declaration.cc b/idlc/declaration.cc
deleted file mode 100644 (file)
index 3c3c650..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-
-namespace tidl {
-
-Declaration::Declaration(std::string id, BaseType* ret_type,
-                         Parameters* params, std::string comments,
-                         unsigned line, MethodType mtype)
-    : id_(std::move(id)),
-      ret_type_(ret_type),
-      params_(params),
-      comments_(std::move(comments)),
-      line_(line),
-      mtype_(mtype) {}
-
-const std::string& Declaration::GetID() const {
-  return id_;
-}
-
-const BaseType& Declaration::GetType() const {
-  return *ret_type_;
-}
-
-const Parameters& Declaration::GetParameters() const {
-  return *params_;
-}
-
-const unsigned Declaration::GetLine() const {
-  return line_;
-}
-
-const std::string& Declaration::GetComments() const {
-  return comments_;
-}
-
-void Declarations::Add(Declaration* decl) {
-  decls_.emplace_back(decl);
-}
-
-const std::list<std::unique_ptr<Declaration>>& Declarations::GetDecls() const {
-  return decls_;
-}
-
-bool Declarations::Exist(Declaration* decl) const {
-  for (auto& d : decls_) {
-    if (d->GetID() == decl->GetID())
-      return true;
-  }
-
-  return false;
-}
-
-}  // namespace tidl
diff --git a/idlc/declaration.h b/idlc/declaration.h
deleted file mode 100644 (file)
index 9f9e17e..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_DECLARATION_H_
-#define IDLC_DECLARATION_H_
-
-#include <string>
-#include <list>
-#include <memory>
-
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-
-namespace tidl {
-
-class Declaration {
- public:
-  enum class MethodType {
-    SYNC,
-    ASYNC,
-    DELEGATE
-  };
-
-  Declaration(std::string id, BaseType* ret_type, Parameters* params,
-              std::string comments, unsigned line,
-              MethodType mtype = MethodType::SYNC);
-
-  const std::string& GetID() const;
-  const BaseType& GetType() const;
-  const Parameters& GetParameters() const;
-  MethodType GetMethodType() const { return mtype_; }
-  const unsigned GetLine() const;
-  const std::string& GetComments() const;
-
- private:
-  std::string id_;
-  std::unique_ptr<BaseType> ret_type_;
-  std::unique_ptr<Parameters> params_;
-  std::string comments_;
-  unsigned line_;
-  MethodType mtype_;
-};
-
-class Declarations {
- public:
-  void Add(Declaration* decl);
-  const std::list<std::unique_ptr<Declaration>>& GetDecls() const;
-  bool Exist(Declaration* decl) const;
-
- private:
-  std::list<std::unique_ptr<Declaration>> decls_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_DECLARATION_H_
diff --git a/idlc/document.cc b/idlc/document.cc
deleted file mode 100644 (file)
index 07b2bfa..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "idlc/document.h"
-#include "idlc/block.h"
-
-namespace tidl {
-
-Document::Document() {}
-
-void Document::AddBlock(Block* block) {
-  blocks_.emplace_back(block);
-}
-
-const std::list<std::unique_ptr<Block>>& Document::GetBlocks() const {
-  return blocks_;
-}
-
-bool Document::ExistBlock(Block* block) const {
-  for (auto& b : blocks_) {
-    if (b->GetType() == block->GetType() &&
-        b->GetID() == block->GetID())
-      return true;
-  }
-
-  return false;
-}
-
-}  // namespace tidl
diff --git a/idlc/document.h b/idlc/document.h
deleted file mode 100644 (file)
index fda59bf..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_DOCUMENT_H_
-#define IDLC_DOCUMENT_H_
-
-#include <list>
-#include <memory>
-
-#include "idlc/interface.h"
-
-namespace tidl {
-
-class Document {
- public:
-  Document();
-
-  void AddBlock(Block* block);
-  const std::list<std::unique_ptr<Block>>& GetBlocks() const;
-  bool ExistBlock(Block* block) const;
-
- private:
-  std::list<std::unique_ptr<Block>> blocks_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_DOCUMENT_H_
diff --git a/idlc/element.cc b/idlc/element.cc
deleted file mode 100644 (file)
index 092398c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/element.h"
-#include "idlc/type.h"
-
-namespace tidl {
-
-Element::Element(std::string id, BaseType* type,
-                 std::string comments, unsigned line)
-    : id_(std::move(id)), type_(type), comments_(std::move(comments)),
-      line_(line) {}
-
-const std::string& Element::GetID() const {
-  return id_;
-}
-
-const BaseType& Element::GetType() const {
-  return *type_;
-}
-
-const unsigned Element::GetLine() const {
-  return line_;
-}
-
-const std::string& Element::GetComments() const {
-  return comments_;
-}
-
-void Elements::Add(Element* elm) {
-  elms_.emplace_back(elm);
-}
-
-const std::list<std::unique_ptr<Element>>& Elements::GetElms() const {
-  return elms_;
-}
-
-bool Elements::Exist(Element* elm) const {
-  for (auto& e : elms_) {
-    if (e->GetID() == elm->GetID())
-      return true;
-  }
-
-  return false;
-}
-
-}  // namespace tidl
diff --git a/idlc/element.h b/idlc/element.h
deleted file mode 100644 (file)
index 76641a2..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_ELEMENT_H_
-#define IDLC_ELEMENT_H_
-
-#include <string>
-#include <list>
-#include <memory>
-
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-
-namespace tidl {
-
-class Element {
- public:
-  Element(std::string id, BaseType* type,
-          std::string comments, unsigned line);
-
-  const std::string& GetID() const;
-  const BaseType& GetType() const;
-  const unsigned GetLine() const;
-  const std::string& GetComments() const;
-
- private:
-  std::string id_;
-  std::unique_ptr<BaseType> type_;
-  std::string comments_;
-  unsigned line_;
-};
-
-class Elements {
- public:
-  void Add(Element* elm);
-  const std::list<std::unique_ptr<Element>>& GetElms() const;
-  bool Exist(Element* elm) const;
-
- private:
-  std::list<std::unique_ptr<Element>> elms_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_ELEMENT_H_
diff --git a/idlc/gen/c_body_gen_base.cc b/idlc/gen/c_body_gen_base.cc
new file mode 100644 (file)
index 0000000..63354b0
--- /dev/null
@@ -0,0 +1,1186 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vector>
+
+#include "idlc/gen/c_body_gen_base.h"
+
+namespace {
+#include "idlc/gen/c_body_gen_base_cb.h"
+}
+
+namespace tidl {
+
+CBodyGeneratorBase::CBodyGeneratorBase(std::shared_ptr<Document> doc)
+    : CGeneratorBase(doc) {
+  parcel_type_map_ = {
+    {"char", "byte"},
+    {"int", "int32"},
+    {"short", "int16"},
+    {"long", "int64"},
+    {"string", "string"},
+    {"bool", "bool"},
+    {"float", "float"},
+    {"double", "double"},
+    {"bundle", "bundle"},
+  };
+}
+
+void CBodyGeneratorBase::GenStructures(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() == Block::TYPE_STRUCTURE) {
+      const Structure &st = static_cast<const Structure&>(*i);
+      GenStructure(stream, st);
+      for (auto& j : st.GetElements().GetElms()) {
+       auto& t = j->GetType();
+       AddStructureFromType(t);
+      }
+    } else {
+      const Interface &inf = static_cast<const Interface&>(*i);
+      for (auto& d : inf.GetDeclarations().GetDecls()) {
+        for (auto& p : d->GetParameters().GetParams()) {
+          if (IsDelegateType(inf, p->GetParameterType().GetBaseType()))
+            continue;
+          AddStructureFromType(p->GetParameterType().GetBaseType());
+        }
+      }
+    }
+  }
+
+  for (auto& p : GetStructures()) {
+    const Structure& st = *p.second;
+    GenStructure(stream, st);
+  }
+}
+
+void CBodyGeneratorBase::GenStructure(std::ofstream& stream,
+                                      const Structure& st) {
+  GenStructureDeclaration(stream, st);
+  GenStructureParcelSerializer(stream, st);
+  GenStructureParcelDeserializer(stream, st);
+  GenStructureConstructor(stream, st);
+  GenStructureDestructor(stream, st);
+  GenStructureCloner(stream, st);
+  GenStructureSetter(stream, st);
+  GenStructureGetter(stream, st);
+  GenStructureIterator(stream, st);
+  GenStructureRemover(stream, st);
+  GenStructureLengthGetter(stream, st);
+}
+
+void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
+                                                 const Structure& st) {
+  stream << SmartIndent(GenTemplateString(CB_STRUCT_DECL,
+        [&]()->std::string {
+          return st.GetComments();
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : st.GetElements().GetElms()) {
+            str += NLine(1) + GetStringFromElementType(i->GetType()) +
+                i->GetID() + ";";
+            if (i->GetType().ToString() == "array")
+              str += NLine(1) + "int " + i->GetID() + "_size;";
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
+                                              const Structure& st) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_STRUCT_SERIALIZER, "##", GetStructIdWithNamespace(st)),
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : st.GetElements().GetElms()) {
+            str += NLine(1);
+            str += GetParcelWriteString(i->GetID(), i->GetType());
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
+                                                const Structure& st) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_STRUCT_DESERIALIZER, "##", GetStructIdWithNamespace(st)),
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : st.GetElements().GetElms()) {
+            str += NLine(1);
+            str += GetParcelReadString(i->GetID(), i->GetType());
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
+                                                 const Structure& st) {
+  stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##",
+      GetStructIdWithNamespace(st)));
+}
+
+void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
+                                                const Structure& st) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_STRUCT_DTOR, "##",
+            GetStructIdWithNamespace(st)),
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : st.GetElements().GetElms()) {
+            str += GetFinalizeString(i->GetID(), i->GetType(), "h->");
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
+                                            const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    stream << SmartIndent(GenTemplateString(CB_STRUCT_SETTER,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "list")
+              return "add";
+            return "set";
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().IsUserDefinedType())
+              return GetParcelParamTypeString(i->GetType());
+
+            if (i->GetType().ToString() == "list") {
+              if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                  i->GetType().GetMetaType()->ToString() == "list" ||
+                  i->GetType().GetMetaType()->ToString() == "array") {
+                return GetParcelParamTypeString(*i->GetType().GetMetaType());
+              } else {
+                return ConvertTypeToString(ParameterType::Direction::IN,
+                    *i->GetType().GetMetaType());
+              }
+            }
+
+            if (i->GetType().ToString() == "array") {
+              return GetStringFromElementType(i->GetType());
+            }
+
+            return ConvertTypeToString(ParameterType::Direction::IN,
+                i->GetType());
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "array") {
+              std::string str;
+              str += i->GetID();
+              str += ", ";
+              str += "int " + i->GetID() + "_size";
+              return str;
+            }
+            return i->GetID();
+          },
+          [&]()->std::string {
+            if ((i->GetType().IsUserDefinedType() ||
+                 i->GetType().ToString() == "string" ||
+                 i->GetType().ToString() == "bundle") ||
+                ((i->GetType().ToString() == "list" ||
+                  i->GetType().ToString() == "array") &&
+                  (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                   i->GetType().GetMetaType()->ToString() == "list" ||
+                   i->GetType().GetMetaType()->ToString() == "array" ||
+                   i->GetType().GetMetaType()->ToString() == "string" ||
+                   i->GetType().GetMetaType()->ToString() == "bundle")))
+              return "!h || !" + i->GetID();
+
+            return "!h";
+          },
+          [&]()->std::string {
+            std::string str;
+            str += NLine(1);
+            str += GetSetterString(i->GetID(), i->GetType());
+            return str;
+          }));
+  }
+}
+
+void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
+                                            const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() == "list")
+      continue;
+
+    stream << SmartIndent(GenTemplateString(CB_STRUCT_GETTER,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "array")
+              return GetStringFromElementType(i->GetType()) + "*";
+
+            return ConvertTypeToString(ParameterType::Direction::OUT,
+                i->GetType());
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "array") {
+              std::string str;
+              str += i->GetID();
+              str += ", ";
+              str += "int *" + i->GetID() + "_size";
+              return str;
+            }
+            return i->GetID();
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "array") {
+              std::string str;
+              str += "!";
+              str += i->GetID();
+              str += " || ";
+              str += "!" + i->GetID() + "_size";
+              return str;
+            }
+            return "!" + i->GetID();
+          },
+          [&]()->std::string {
+            std::string str;
+            str += NLine(1);
+            str += GetGetterString(i->GetID(), i->GetType());
+            return str;
+          }));
+  }
+}
+
+void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
+                                              const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    stream << SmartIndent(GenTemplateString(CB_STRUCT_ITERATOR,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                i->GetType().GetMetaType()->ToString() == "list" ||
+                i->GetType().GetMetaType()->ToString() == "array")
+              return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+            return ConvertTypeToString(ParameterType::Direction::IN,
+                *i->GetType().GetMetaType());
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            std::string str;
+            str += NLine(1);
+            str += GetIteratorString(i->GetID(), i->GetType());
+            return str;
+          }));
+  }
+}
+
+void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream,
+                                             const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    stream << SmartIndent(GenTemplateString(CB_STRUCT_REMOVER,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                i->GetType().GetMetaType()->ToString() == "list" ||
+                i->GetType().GetMetaType()->ToString() == "array" ||
+                i->GetType().GetMetaType()->ToString() == "string" ||
+                i->GetType().GetMetaType()->ToString() == "bundle")
+              return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+            return ConvertTypeToString(ParameterType::Direction::IN,
+                *i->GetType().GetMetaType(), false);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            std::string str;
+
+            if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                i->GetType().GetMetaType()->ToString() == "list" ||
+                i->GetType().GetMetaType()->ToString() == "array") {
+              str = GetHandlePrefix()
+                  + GetFullNameFromType(*i->GetType().GetMetaType())
+                  + "_destroy(value);";
+            } else {
+              str = GetFinalizeString("value", *i->GetType().GetMetaType(), "");
+            }
+
+            if (str == "")
+              return "free(value);\n";
+            return str;
+          }));
+  }
+}
+
+void CBodyGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+                                                  const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    stream << SmartIndent(GenTemplateString(CB_STRUCT_LENGTH_GETTER,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          }));
+  }
+}
+
+void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
+                                            const Structure& st) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_STRUCT_CLONER, "##", GetStructIdWithNamespace(st)),
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : st.GetElements().GetElms()) {
+            str += NLine(1);
+            str += GetClonerString(i->GetID(), i->GetType(), st);
+          }
+          return str;
+        }));
+}
+
+std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
+                                                    bool meta_type) {
+  if (type.IsUserDefinedType())
+    return "";
+
+  if (type.ToString() == "list" ||
+      type.ToString() == "array") {
+    if (meta_type)
+      return "";
+    return "array_count";
+  }
+
+  return parcel_type_map_[type.ToString()];
+}
+
+std::string CBodyGeneratorBase::GetParcelWriteFunctionString(
+    const BaseType& type, bool meta_type) {
+  std::string str = "rpc_port_parcel_write";
+  std::string parcel_type = GetParcelTypeString(type, meta_type);
+  if (parcel_type != "")
+    str += "_" + parcel_type;
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id,
+                                                     const BaseType& type) {
+  std::string str;
+  const char parcel[] = "$$(parcel, $$);";
+  const char ternary_operation[] = "## ? ## : \"\"";
+
+  str += GenTemplateString(parcel,
+      [&]()->std::string {
+        return GetParcelWriteFunctionString(type);
+      },
+      [&]()->std::string {
+        if (type.IsUserDefinedType())
+          return "&h->" + id + "->parcelable, h->" + id;
+        if (type.ToString() == "list")
+          return "g_list_length(h->" + id + ")";
+        if (type.ToString() == "array")
+          return "h->" + id + "_size";
+        if (type.ToString() == "string")
+          return ReplaceAll(ternary_operation, "##", "h->" + id);
+        return "h->" + id;
+      });
+
+  if (type.ToString() == "list") {
+    str += GenTemplateString(CB_WRITE_LIST_BLOCK,
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GenTemplateString(parcel,
+              [&]()->std::string {
+                return GetParcelWriteFunctionString(*type.GetMetaType(), true);
+              },
+              [&]()->std::string {
+                if (type.GetMetaType()->IsUserDefinedType() ||
+                    type.GetMetaType()->ToString() == "list" ||
+                    type.GetMetaType()->ToString() == "array")
+                  return "&value->parcelable, value";
+                if (type.GetMetaType()->ToString() == "bundle")
+                  return "value";
+                if (type.GetMetaType()->ToString() == "string")
+                  return ReplaceAll(ternary_operation, "##", "value");
+                return "*value";
+              });
+        });
+  } else if (type.ToString() == "array") {
+    str += GenTemplateString(CB_WRITE_ARRAY_BLOCK,
+        [&]()->std::string {
+          return "h->" + id + "_size";
+        },
+        [&]()->std::string {
+          return GenTemplateString(parcel,
+              [&]()->std::string {
+                return GetParcelWriteFunctionString(*type.GetMetaType(), true);
+              },
+              [&]()->std::string {
+                if (type.GetMetaType()->IsUserDefinedType() ||
+                    type.GetMetaType()->ToString() == "list" ||
+                    type.GetMetaType()->ToString() == "array")
+                  return "&h->" + id + "[i]->parcelable, h->" + id +"[i]";
+                if (type.GetMetaType()->ToString() == "string")
+                  return ReplaceAll(ternary_operation, "##", "h->" + id
+                      + "[i]");
+                return "h->" + id + "[i]";
+              });
+        });
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetParcelReadFunctionString(
+    const BaseType& type, bool meta_type) {
+  std::string str = "rpc_port_parcel_read";
+  std::string parcel_type = GetParcelTypeString(type, meta_type);
+  if (parcel_type != "")
+    str += "_" + parcel_type;
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id,
+                                                    const BaseType& type) {
+  std::string str;
+  const char parcel[] = "$$(parcel, $$);";
+
+  if (type.ToString() == "list") {
+    str += GenTemplateString(CB_READ_LIST_BLOCK,
+        [&]()->std::string {
+          return GenTemplateString(parcel,
+              [&]()->std::string {
+                return GetParcelReadFunctionString(type);
+              },
+              [&]()->std::string {
+                return "&len";
+              });
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          std::string s;
+
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GetConstructorString(*type.GetMetaType(), "value");
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string ss;
+                  ss += "_E(\"Failed to create handle\");" + NLine(1);
+                  ss += "return;";
+                  return ss;
+                });
+            s += NLine(1);
+            s += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(*type.GetMetaType(), true);
+                },
+                [&]()->std::string {
+                  return "&value->parcelable, value";
+                });
+          } else if (type.GetMetaType()->ToString() == "string" ||
+                     type.GetMetaType()->ToString() == "bundle") {
+            s += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(*type.GetMetaType());
+                },
+                [&]()->std::string {
+                  return "&value";
+                });
+          } else {
+            s += "value = calloc(1, sizeof(*value));" + NLine(1);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string ss;
+                  ss += "_E(\"Out of memory\");" + NLine(1);
+                  ss += "return;";
+                  return ss;
+                });
+            s += NLine(1);
+            s += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(*type.GetMetaType());
+                },
+                [&]()->std::string {
+                  return "value";
+                });
+          }
+
+          return s;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        });
+  } else if (type.ToString() == "array") {
+    str += GenTemplateString(ReplaceAll(CB_READ_ARRAY_BLOCK, "##", id),
+        [&]()->std::string {
+          return GenTemplateString(parcel,
+              [&]()->std::string {
+                return GetParcelReadFunctionString(type);
+              },
+              [&]()->std::string {
+                return "&h->" + id + "_size";
+              });
+        },
+        [&]()->std::string {
+          return GetReturnTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GetErrorValue(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          std::string s;
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GetConstructorString(*type.GetMetaType(), "value");
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string ss;
+                  ss += "_E(\"Failed to create handle\");" + NLine(1);
+                  ss += "return;";
+                  return ss;
+                });
+            s += NLine(1);
+            s += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(*type.GetMetaType(), true);
+                },
+                [&]()->std::string {
+                  return "&value->parcelable, value";
+                });
+          } else {
+            s += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(*type.GetMetaType());
+                },
+                [&]()->std::string {
+                  return "&value";
+                });
+          }
+          s += NLine(1);
+          s += GetSetterString("h->" + id + "[i]", "value");
+          return s;
+        });
+  } else if (type.IsUserDefinedType()) {
+    str += GenTemplateString(ReplaceAll(CB_READ_USER_DEFINED_BLOCK, "##", id),
+        [&]()->std::string {
+          return GetFullNameFromType(type);
+        });
+  } else {
+    str += GenTemplateString(parcel,
+        [&]()->std::string {
+          return GetParcelReadFunctionString(type);
+        },
+        [&]()->std::string {
+          if (type.IsUserDefinedType())
+            return "&h->" + id + "->parcelable, h->" + id;
+          return "&h->" + id;
+        });
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id,
+    const BaseType& type, const std::string& handle) {
+  std::string str;
+
+  if (!type.IsUserDefinedType() &&
+       type.ToString() != "list" &&
+       type.ToString() != "array" &&
+       type.ToString() != "string" &&
+       type.ToString() != "bundle")
+    return str;
+
+  if (type.ToString() == "list") {
+    str += GenTemplateString(CB_FINALIZE_LIST_BLOCK,
+        [&]()->std::string {
+          return handle + id;
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GenTemplateString(CB_IF_STATEMENT,
+              [&]()->std::string {
+                return "value";
+              },
+              [&]()->std::string {
+                return GetDestructorString(*type.GetMetaType(),
+                    "value", true) + NLine(1);
+              });
+        },
+        [&]()->std::string {
+          return handle + id;
+        });
+  } else if (type.ToString() == "array") {
+    if (!type.GetMetaType()->IsUserDefinedType() &&
+         type.GetMetaType()->ToString() != "list" &&
+         type.GetMetaType()->ToString() != "array" &&
+         type.GetMetaType()->ToString() != "string" &&
+         type.GetMetaType()->ToString() != "bundle") {
+      return GenTemplateString(CB_IF_STATEMENT,
+              [&]()->std::string {
+                return handle + id;
+              },
+              [&]()->std::string {
+                return "free(" + handle + id + ");";
+              });
+    }
+    str += GenTemplateString(CB_FINALIZE_ARRAY_BLOCK,
+        [&]()->std::string {
+          return handle + id + "_size";
+        },
+        [&]()->std::string {
+          return GenTemplateString(CB_IF_STATEMENT,
+              [&]()->std::string {
+                return handle + id + "[i]";
+              },
+              [&]()->std::string {
+                return GetDestructorString(*type.GetMetaType(),
+                    handle + id + "[i]", true) + NLine(1);
+              });
+        },
+        [&]()->std::string {
+          return handle + id;
+        });
+  } else {
+    str += GenTemplateString(CB_IF_STATEMENT,
+        [&]()->std::string {
+          return handle + id;
+        },
+        [&]()->std::string {
+          return GetDestructorString(type, handle + id) + NLine(1);
+        });
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
+                                                const BaseType& type) {
+  std::string str;
+
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "string" ||
+      type.ToString() == "bundle") {
+    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          std::string s;
+          s += GetDestructorString(type, "h->" + id) + NLine(1);
+          s += GetSetterString("h->" + id, "NULL");
+          return s;
+        });
+    str += NLine(1);
+
+    str += NLine(1);
+    str += GetSetterString(type, "h->" + id, id);
+    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+        [&]()->std::string {
+          return "!h->" + id;
+        },
+        [&]()->std::string {
+          std::string s;
+          s += "_E(\"Failed to duplicate data\");" + NLine(1);
+          s += "return -1;";
+          return s;
+        });
+    str += NLine(1);
+  } else if (type.ToString() == "list") {
+    str += GenTemplateString(CB_SETTER_LIST_BLOCK,
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          std::string s;
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "string" ||
+              type.GetMetaType()->ToString() == "bundle" ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array") {
+            s += GetSetterString(*type.GetMetaType(), "value", id);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string s;
+                  s += "_E(\"Out of memory\");" + NLine(1);
+                  s += "return -1;";
+                  return s;
+                });
+            s += NLine(1);
+          } else {
+            s += "value = calloc(1, sizeof(*value));" + NLine(1);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!value";
+                },
+                [&]()->std::string {
+                  std::string s;
+                  s += "_E(\"Out of memory\");" + NLine(1);
+                  s += "return -1;";
+                  return s;
+                });
+            s += NLine(1);
+            s += GetSetterString("*value", id);
+          }
+          return s;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return "h->" + id;
+        });
+  } else if (type.ToString() == "array") {
+    str += GetFinalizeString(id, type, "h->") + NLine(1);
+    str += GetSetterString("h->" + id, "NULL");
+    str += NLine(1);
+    str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id),
+        [&]()->std::string {
+          return GetSetterString(*type.GetMetaType(),
+              "h->" + id + "[i]", id + "[i]");
+        });
+  } else {
+    str += GetSetterString(type, "h->" + id, id);
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetGetterString(const std::string& id,
+                                                const BaseType& type) {
+  std::string str;
+
+  if (type.ToString() == "array") {
+    str += GenTemplateString(ReplaceAll(CB_GETTER_ARRAY_BLOCK, "##", id),
+        [&]()->std::string {
+           return GetSetterString(*type.GetMetaType(),
+              "(*" + id + ")[i]", "h->" + id + "[i]");
+        });
+  } else {
+    if (type.IsUserDefinedType() ||
+        type.ToString() == "string" ||
+        type.ToString() == "bundle") {
+      str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+          [&]()->std::string {
+            return "!h->" + id;
+          },
+          [&]()->std::string {
+            std::string s;
+            s += "_E(\"Invalid parameter: h->" + id + " is NULL\");" + NLine(1);
+            s += "return -1;";
+            return s;
+          });
+      str += NLine(1);
+      str += NLine(1);
+    }
+
+    if (type.IsUserDefinedType()) {
+      str += GetHandlePrefix() + GetFullNameFromType(type) +
+        "_clone(h->"+ id + ", " + id +");" + NLine(1);
+    } else {
+      str += GetSetterString(type, "*" + id, "h->" + id);
+    }
+
+    if (type.IsUserDefinedType() ||
+        type.ToString() == "string" ||
+        type.ToString() == "bundle") {
+      str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+          [&]()->std::string {
+            return "*" + id + " == NULL";
+          },
+          [&]()->std::string {
+            std::string s;
+            s += "_E(\"Failed to duplicate " + id + "\");" + NLine(1);
+            s += "return -1;";
+            return s;
+          });
+      str += NLine(1);
+    }
+  }
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetIteratorString(const std::string& id,
+                                                  const BaseType& type) {
+  std::string str;
+
+  str += GenTemplateString(CB_ITERATOR_BLOCK,
+      [&]()->std::string {
+        return "h->" + id;
+      },
+      [&]()->std::string {
+        return GetParcelParamTypeString(*type.GetMetaType());
+      },
+      [&]()->std::string {
+        if (type.GetMetaType()->IsUserDefinedType() ||
+            type.GetMetaType()->ToString() == "list" ||
+            type.GetMetaType()->ToString() == "array" ||
+            type.GetMetaType()->ToString() == "string" ||
+            type.GetMetaType()->ToString() == "bundle")
+          return "value";
+
+        return "*value";
+      });
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
+                                                const BaseType& type,
+                                                const Structure& st) {
+  std::string str;
+
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "string" ||
+      type.ToString() == "bundle") {
+    str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          std::string s;
+          s += GetSetterString(type, "handle->" + id, "h->" + id);
+          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+              [&]()->std::string {
+                return "!handle->" + id;
+              },
+              [&]()->std::string {
+                std::string ss;
+                ss += "_E(\"Failed to duplicate h->" + id + "\");" + NLine(1);
+                ss += "rpc_port_" + GetStructIdWithNamespace(st)
+                   + "_destroy(handle);" + NLine(1);
+                ss += "return -1;";
+                return ss;
+              });
+          return s;
+        });
+    str += NLine(1);
+  } else  if (type.ToString() == "list") {
+    str += GenTemplateString(CB_CLONER_LIST_BLOCK,
+        [&]()->std::string {
+          return "h->" + id;
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GetParcelParamTypeString(*type.GetMetaType());
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          std::string s;
+          if (type.GetMetaType()->IsUserDefinedType() ||
+              type.GetMetaType()->ToString() == "list" ||
+              type.GetMetaType()->ToString() == "array" ||
+              type.GetMetaType()->ToString() == "string" ||
+              type.GetMetaType()->ToString() == "bundle") {
+            s += GetSetterString(*type.GetMetaType(),
+                "new_value", "value");
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!new_value";
+                },
+              [&]()->std::string {
+                std::string ss;
+                ss += "_E(\"Failed to duplicate value\");" + NLine(1);
+                ss += "rpc_port_" + GetStructIdWithNamespace(st)
+                   + "_destroy(handle);" + NLine(1);
+                ss += "return -1;";
+                return ss;
+              });
+          } else {
+            s += "new_value = calloc(1, sizeof(*new_value));" + NLine(1);
+            s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+                [&]()->std::string {
+                  return "!new_value";
+                },
+                [&]()->std::string {
+                  std::string tmp;
+                  tmp += "_E(\"Out of memory\");" + NLine(1);
+                  tmp += "rpc_port_" + GetStructIdWithNamespace(st)
+                      + "_destroy(handle);" + NLine(1);
+                  tmp += "return -1;";
+                  return tmp;
+                });
+            s += NLine(1);
+            s += GetSetterString(*type.GetMetaType(),
+                "*new_value", "*value");
+          }
+          s += NLine(1);
+          return s;
+        },
+        [&]()->std::string {
+          return "handle->" + id;
+        },
+        [&]()->std::string {
+          return "handle->" + id;
+        });
+  } else if (type.ToString() == "array") {
+    str += GenTemplateString(ReplaceAll(CB_CLONER_ARRAY_BLOCK, "##", id),
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+           return GetSetterString(*type.GetMetaType(),
+              "handle->" + id + "[i]", "h->" + id + "[i]");
+        });
+  } else {
+    str += GetSetterString(type, "handle->" + id, "h->" + id);
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type,
+                                                    const std::string& value,
+                                                    bool container_value) {
+  std::string str;
+
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "list" ||
+      type.ToString() == "array") {
+    str += GetHandlePrefix() + GetFullNameFromType(type) +
+        "_destroy(" + value + ");";
+  } else if (type.ToString() == "bundle") {
+    str += "bundle_free(" + value + ");";
+  } else if (type.ToString() == "string" || container_value) {
+    str += "free(" + value + ");";
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
+                                                     const std::string& value) {
+  std::string str;
+  str += GetHandlePrefix() + GetFullNameFromType(type) +
+      "_create(&" + value + ");" + NLine(1);
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetSetterString(const BaseType& type,
+                                                const std::string& lvalue,
+                                                const std::string& rvalue) {
+  std::string str;
+
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "list" ||
+      type.ToString() == "array") {
+    str += GetHandlePrefix() + GetFullNameFromType(type) +
+        "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
+  } else if (type.ToString() == "string")  {
+    str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
+  } else if (type.ToString() == "bundle") {
+    str += lvalue + " = bundle_dup(" + rvalue + ");" + NLine(1);
+  } else {
+    str += GetSetterString(lvalue, rvalue);
+  }
+
+  return str;
+}
+
+std::string CBodyGeneratorBase::GetSetterString(const std::string& lvalue,
+                                                const std::string& rvalue) {
+  std::string str;
+  str += lvalue + " = " + rvalue + ";";
+  return str;
+}
+
+void CBodyGeneratorBase::GenIncludeHeader(std::ofstream& stream) {
+  std::string str;
+  str += "#include \"";
+  str += FileName.substr(0, FileName.length() - 2);
+  str += ".h\"";
+  stream << NLine(1);
+  stream << str;
+  stream << NLine(1);
+}
+
+void CBodyGeneratorBase::GenLogTag(std::ofstream& stream,
+                                   const std::string& log_tag) {
+  GenTemplate(CB_LOG_TAG, stream,
+      [&]()->std::string {
+        return log_tag;
+      });
+}
+
+void CBodyGeneratorBase::GenInterfaceEnumerations(std::ofstream& stream,
+                                                  const Interface& inf) {
+  GenInterfaceMethodEnumeration(stream, inf);
+  GenInterfaceDelegateEnumeration(stream, inf);
+}
+
+bool CBodyGeneratorBase::HasDelegate(const Interface& inf) const {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+void CBodyGeneratorBase::GenInterfaceDelegateEnumeration(
+    std::ofstream& stream, const Interface& inf) {
+  int count = 1;
+
+  if (!HasDelegate(inf))
+    return;
+
+  stream << SmartIndent(GenTemplateString(CB_DELEGATE_ENUM,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : inf.GetDeclarations().GetDecls()) {
+            if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+              continue;
+
+            str += GenTemplateString(CB_DELEGATE_ENUM_FORMAT,
+                [&]()->std::string {
+                  return GetInterfaceIdWithNamespace(inf);
+                },
+                [&]()->std::string {
+                  return i->GetID();
+                },
+                [&]()->std::string {
+                  return std::to_string(count++);
+                });
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenInterfaceMethodEnumeration(
+    std::ofstream& stream, const Interface& inf) {
+  stream << SmartIndent(GenTemplateString(CB_METHOD_ENUM,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : inf.GetDeclarations().GetDecls()) {
+            if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+              continue;
+            str += GenTemplateString(CB_METHOD_ENUM_FORMAT,
+                [&]()->std::string {
+                  return GetInterfaceIdWithNamespace(inf);
+                },
+                [&]()->std::string {
+                  return i->GetID();
+                });
+          }
+          return str;
+        }));
+}
+
+void CBodyGeneratorBase::GenLogDefinition(std::ofstream& stream) {
+  stream << SmartIndent(CB_LOG_DEF);
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_body_gen_base.h b/idlc/gen/c_body_gen_base.h
new file mode 100644 (file)
index 0000000..7de8246
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_BODY_GEN_BASE_H_
+#define IDLC_C_GEN_C_BODY_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/gen/c_gen_base.h"
+
+namespace tidl {
+
+class CBodyGeneratorBase : public CGeneratorBase {
+ public:
+  explicit CBodyGeneratorBase(std::shared_ptr<Document> doc);
+  virtual ~CBodyGeneratorBase() = default;
+
+  void GenStructures(std::ofstream& stream);
+  void GenIncludeHeader(std::ofstream& stream);
+  void GenLogTag(std::ofstream& stream, const std::string& log_tag);
+  void GenInterfaceEnumerations(std::ofstream& stream, const Interface& inf);
+  std::string GetParcelWriteFunctionString(const BaseType& type,
+                                           bool meta_type = false);
+  std::string GetParcelReadFunctionString(const BaseType& type,
+                                          bool meta_type = false);
+  std::string GetDestructorString(const BaseType& type,
+                                  const std::string& value,
+                                  bool container_value = false);
+  std::string GetConstructorString(const BaseType& type,
+                                   const std::string& value);
+  bool HasDelegate(const Interface& inf) const;
+  void GenLogDefinition(std::ofstream& stream);
+
+ private:
+  void GenInterfaceMethodEnumeration(std::ofstream& stream,
+                                     const Interface& inf);
+  void GenInterfaceDelegateEnumeration(std::ofstream& stream,
+                                       const Interface& inf);
+
+ private:
+  void GenStructure(std::ofstream& stream, const Structure& st);
+  void GenStructureDeclaration(std::ofstream& stream, const Structure& st);
+  void GenStructureParcelSerializer(std::ofstream& stream, const Structure& st);
+  void GenStructureParcelDeserializer(std::ofstream& stream,
+                                      const Structure& st);
+  void GenStructureConstructor(std::ofstream& stream, const Structure& st);
+  void GenStructureDestructor(std::ofstream& stream, const Structure& st);
+  void GenStructureSetter(std::ofstream& stream, const Structure& st);
+  void GenStructureGetter(std::ofstream& stream, const Structure& st);
+  void GenStructureIterator(std::ofstream& stream, const Structure& st);
+  void GenStructureCloner(std::ofstream& stream, const Structure& st);
+  void GenStructureRemover(std::ofstream& stream, const Structure& st);
+  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
+
+ private:
+  std::string GetParcelTypeString(const BaseType& type, bool meta_type);
+  std::string GetParcelWriteString(const std::string& id, const BaseType& type);
+  std::string GetParcelReadString(const std::string& id, const BaseType& type);
+  std::string GetFinalizeString(const std::string& id, const BaseType& type,
+                                const std::string& handle);
+  std::string GetSetterString(const std::string& id, const BaseType& type);
+  std::string GetGetterString(const std::string& id, const BaseType& type);
+  std::string GetIteratorString(const std::string& id, const BaseType& type);
+  std::string GetClonerString(const std::string& id, const BaseType& type,
+                              const Structure& st);
+  std::string GetSetterString(const BaseType& type, const std::string& lvalue,
+                              const std::string& rvalue);
+  std::string GetSetterString(const std::string& lvalue,
+                              const std::string& rvalue);
+
+ private:
+  std::map<std::string, std::string> parcel_type_map_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_BODY_GEN_BASE_H_
diff --git a/idlc/gen/c_body_gen_base_cb.h b/idlc/gen/c_body_gen_base_cb.h
new file mode 100644 (file)
index 0000000..a9d7ef1
--- /dev/null
@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
+
+const char CB_STRUCT_DECL[] =
+R"__c_cb(
+$$struct $$_s {
+    rpc_port_parcelable_t parcelable;$$
+};
+)__c_cb";
+
+const char CB_STRUCT_SERIALIZER[] =
+R"__c_cb(
+static void __##_to(rpc_port_parcel_h parcel, void *data)
+{
+    rpc_port_##_h h = data;
+
+    if (!parcel || !h) {
+        _E("Invalid parameter");
+        return;
+    }
+$$
+}
+)__c_cb";
+
+const char CB_STRUCT_DESERIALIZER[] =
+R"__c_cb(
+static void __##_from(rpc_port_parcel_h parcel, void *data)
+{
+    rpc_port_##_h h = data;
+
+    if (!parcel || !h) {
+        _E("Invalid parameter");
+        return;
+    }
+$$
+}
+)__c_cb";
+
+const char CB_STRUCT_CTOR[] =
+R"__c_cb(
+int rpc_port_##_create(rpc_port_##_h *h)
+{
+    struct ##_s *handle;
+
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    handle = calloc(1, sizeof(struct ##_s));
+    if (!handle) {
+        _E("Out of memory");
+        return -1;
+    }
+
+    handle->parcelable.to = __##_to;
+    handle->parcelable.from = __##_from;
+
+    *h = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_DTOR[] =
+R"__c_cb(
+int rpc_port_##_destroy(rpc_port_##_h h)
+{
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+$$
+    free(h);
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_SETTER[] =
+R"__c_cb(
+int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$)
+{
+    if ($$) {
+        _E("Invalid parameter");
+        return -1;
+    }
+$$
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$)
+{
+    if (!h || $$) {
+        _E("Invalid parameter");
+        return -1;
+    }
+$$
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_ITERATOR[] =
+R"__c_cb(
+int rpc_port_$$_foreach_$$(rpc_port_$$_h h,
+        bool (*callback)($$$$, void *user_data), void *user_data)
+{
+    if (!h || !callback) {
+        _E("Invalid parameter");
+        return -1;
+    }
+$$
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_REMOVER[] =
+R"__c_cb(
+int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth)
+{
+    GList *iter;
+
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    iter = g_list_nth(h->$$, nth);
+    if (iter == NULL)
+        return -1;
+
+    $$value = iter->data;
+    h->$$ = g_list_remove_link(h->$$, iter);
+$$
+    g_list_free(iter);
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_LENGTH_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length)
+{
+    if (!h || !length) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    *length = g_list_length(h->$$);
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_CLONER[] =
+R"__c_cb(
+int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)
+{
+    rpc_port_##_h handle = NULL;
+
+    if (!h || !clone) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    rpc_port_##_create(&handle);
+    if (!handle) {
+        _E("Failed to create ## handle");
+        return -1;
+    }
+$$
+    *clone = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_WRITE_LIST_BLOCK[] =
+R"__c_cb(
+do {
+    GList *iter;
+
+    iter = $$;
+    while (iter) {
+        $$value = iter->data;
+
+        iter = g_list_next(iter);
+        if (!value) {
+            _W("Warning: value is NULL");
+            continue;
+        }
+        $$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_WRITE_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    for (int i = 0; i < $$; i++) {
+$$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_READ_LIST_BLOCK[] =
+R"__c_cb(do {
+    int len = 0;
+
+    $$
+    for (int i = 0; i < len; i++) {
+        $$value = NULL;
+
+        $$
+        $$ = g_list_append($$, value);
+    }
+} while (0);
+)__c_cb";
+
+const char CB_READ_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    $$
+
+    h->## = calloc(h->##_size, sizeof(*h->##));
+    if (!h->##) {
+        _E("Out of memory");
+        return;
+    }
+
+    for (int i = 0; i < h->##_size; i++) {
+        $$value = $$;
+
+        $$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_READ_USER_DEFINED_BLOCK[] =
+R"__c_cb(do {
+    rpc_port_$$_create(&h->##);
+    if (!h->##) {
+        _E("Failed to create handle");
+        return;
+    }
+
+    rpc_port_parcel_read(parcel, &h->##->parcelable, h->##);
+} while (0);
+)__c_cb";
+
+const char CB_FINALIZE_LIST_BLOCK[] =
+R"__c_cb(
+do {
+    GList *iter;
+
+    iter = $$;
+    while (iter) {
+        $$value = iter->data;
+        $$
+        iter = g_list_next(iter);
+    }
+    g_list_free($$);
+} while (0);
+)__c_cb";
+
+const char CB_FINALIZE_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    for (int i = 0; i < $$; i++) {
+        $$
+    }
+    free($$);
+} while (0);
+)__c_cb";
+
+const char CB_SETTER_LIST_BLOCK[] =
+R"__c_cb(
+do {
+    $$value = NULL;
+
+    $$
+    $$ = g_list_append($$, value);
+} while (0);
+)__c_cb";
+
+const char CB_SETTER_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    h->## = calloc(##_size, sizeof(*##));
+    if (!h->##) {
+        _E("Out of memory");
+        return -1;
+    }
+    h->##_size = ##_size;
+
+    for (int i = 0; i < h->##_size; i++) {
+        $$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_GETTER_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    if (h->##_size == 0) {
+        _W("## is empty");
+        break;
+    }
+
+    *## = calloc(h->##_size, sizeof(*h->##));
+    if (!*##) {
+        _E("Out of memory");
+        return -1;
+    }
+    *##_size = h->##_size;
+
+    for (int i = 0; i < h->##_size; i++) {
+        $$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_ITERATOR_BLOCK[] =
+R"__c_cb(
+do {
+    GList *iter;
+
+    iter = $$;
+    while (iter) {
+        $$value = iter->data;
+
+        iter = g_list_next(iter);
+        if (!value) {
+            _W("Warning: value is NULL");
+            continue;
+        }
+
+        bool ret = callback($$, user_data);
+        if (!ret)
+            break;
+    }
+} while (0);
+)__c_cb";
+
+const char CB_CLONER_LIST_BLOCK[] =
+R"__c_cb(
+do {
+    GList *iter;
+
+    iter = $$;
+    while (iter) {
+        $$new_value;
+        $$value = iter->data;
+
+        if (!value) {
+            _E("Error: value is NULL");
+            rpc_port_$$_destroy(handle);
+            return -1;
+        }
+
+        $$
+        $$ = g_list_append($$, new_value);
+        iter = g_list_next(iter);
+    }
+} while (0);
+)__c_cb";
+
+const char CB_CLONER_ARRAY_BLOCK[] =
+R"__c_cb(
+do {
+    if (h->##_size == 0) {
+        _W("## is empty");
+        break;
+    }
+
+    handle->## = calloc(h->##_size, sizeof(*h->##));
+    if (!handle->##) {
+        _E("Out of memory");
+        rpc_port_$$_destroy(handle);
+        return -1;
+    }
+    handle->##_size = h->##_size;
+
+    for (int i = 0; i < h->##_size; i++) {
+        $$
+    }
+} while (0);
+)__c_cb";
+
+const char CB_IF_STATEMENT_WITH_BRACES[] =
+R"__c_cb(if ($$) {
+    $$
+}
+)__c_cb";
+
+const char CB_IF_STATEMENT[] =
+R"__c_cb(if ($$)
+    $$
+)__c_cb";
+
+const char CB_DELEGATE_ENUM_FORMAT[] = "\n$$_DELEGATE_$$ = $$,";
+
+const char CB_DELEGATE_ENUM[] =
+R"__c_cb(
+enum $$_delegate_e {$$
+};
+)__c_cb";
+
+const char CB_METHOD_ENUM_FORMAT[] = "\n$$_METHOD_$$,";
+
+const char CB_METHOD_ENUM[] =
+R"__c_cb(
+enum $$_method_e {
+    $$_METHOD_Result,
+    $$_METHOD_Callback,$$
+};
+)__c_cb";
+
+const char CB_LOG_TAG[] =
+R"__c_cb(
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "$$"
+)__c_cb";
+
+const char CB_LOG_DEF[] =
+R"__c_cb(
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
diff --git a/idlc/gen/c_gen_base.cc b/idlc/gen/c_gen_base.cc
new file mode 100644 (file)
index 0000000..4741359
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ctime>
+#include <cassert>
+#include <vector>
+#include <sstream>
+#include <algorithm>
+
+#include "idlc/gen/c_gen_base.h"
+
+namespace {
+#include "idlc/gen/c_gen_base_cb.h"
+}
+
+namespace tidl {
+
+CGeneratorBase::CGeneratorBase(std::shared_ptr<Document> doc)
+    : Generator(doc) {
+  structures_.clear();
+  type_map_ = {
+      {"char", "char "}, {"int", "int "}, {"short", "short "},
+      {"long", "long long "}, {"bool", "bool "}, {"string", "char *"},
+      {"list", "GList *"}, {"float", "float "}, {"double", "double "},
+      {"bundle", "bundle *"}, {"void", "void "}
+  };
+}
+
+std::string CGeneratorBase::Tab(int cnt) {
+  std::string str;
+
+  for (int i = 0; i < cnt; ++i) {
+    str += "\t";
+  }
+
+  return str;
+}
+
+std::string CGeneratorBase::NLine(int cnt) {
+  std::string str;
+
+  for (int i = 0; i < cnt; ++i) {
+    str += "\n";
+  }
+
+  return str;
+}
+
+std::string CGeneratorBase::ConvertTypeToString(
+    ParameterType::Direction direction, const BaseType& type, bool bconst) {
+  if (type.IsUserDefinedType()) {
+    if (direction == ParameterType::Direction::IN)
+      return GetHandlePrefix() + type.ToString() + "_h ";
+    else
+      return GetHandlePrefix() + type.ToString() + "_h *";
+  }
+
+  if (type.ToString() == "array") {
+    if (direction == ParameterType::Direction::IN) {
+      return GetReturnTypeString(*type.GetMetaType()) + "*";
+    } else {
+      return GetReturnTypeString(*type.GetMetaType()) + "**";
+    }
+  }
+
+  if (type.ToString() == "string") {
+    if (direction == ParameterType::Direction::IN) {
+      if (!bconst)
+        return "char *";
+      return "const char *";
+    } else
+      return "char **";
+  }
+
+  if (direction == ParameterType::Direction::IN && bconst)
+    return type_map_[type.ToString()];
+
+  return type_map_[type.ToString()] + "*";
+}
+
+std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) {
+  std::string str = type.ToString();
+
+  if (type.GetMetaType() != nullptr) {
+    str += "_";
+    str += GetFullNameFromType(*type.GetMetaType());
+  }
+
+  return str;
+}
+
+std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type,
+                                                     bool is_pointer) {
+  if (type.IsUserDefinedType())
+    return GetHandlePrefix() + type.ToString() + "_h ";
+
+  if (type.ToString() == "list" ||
+      type.ToString() == "array")
+    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
+
+  if (type.ToString() == "string")
+    return "char *";
+
+  if (type.ToString() == "bundle")
+    return "bundle *";
+
+  if (is_pointer)
+    return type_map_[type.ToString()] + "*";
+
+  return type_map_[type.ToString()];
+}
+
+std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
+  if (type.IsUserDefinedType())
+    return GetHandlePrefix() + type.ToString() + "_h ";
+
+  if (type.ToString() == "list" ||
+      type.ToString() == "array")
+    return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
+
+  return type_map_[type.ToString()];
+}
+
+void CGeneratorBase::AddStructureFromType(const BaseType& type) {
+  if (type.GetMetaType() == nullptr)
+    return;
+
+  BaseType* t = new BaseType(type);
+  assert(t != nullptr);
+
+  std::string type_name = GetFullNameFromType(type);
+  Element* elm = new Element(type_name + "s", t, "", __LINE__);
+  assert(elm != nullptr);
+
+  Elements* elms = new Elements();
+  assert(elms != nullptr);
+  elms->Add(elm);
+
+  Structure* st = new Structure(type_name, elms, "", __LINE__);
+  assert(st != nullptr);
+
+  if (StructureExist(*st)) {
+    delete st;
+  } else {
+    structures_[type_name] = std::unique_ptr<Structure>(st);
+  }
+
+  AddStructureFromType(*type.GetMetaType());
+}
+
+std::string CGeneratorBase::SmartIndent(std::string lines) {
+  std::stringstream ss(lines);
+  std::string result;
+  std::string line;
+  std::string next_line;
+  std::string tab;
+  std::string back;
+  std::size_t found;
+  bool if_statement = false;
+  bool continuous = false;
+  int tab_size = 0;
+  int line_count = 0;
+
+  while (std::getline(ss, next_line, '\n')) {
+    line_count++;
+    if (line_count == 1) {
+      line = Trim(next_line);
+      continue;
+    }
+
+    tab.clear();
+    found = line.find('}');
+    if (found != std::string::npos) {
+      tab_size--;
+    }
+
+    if (line.length() > 0) {
+      tab += Tab(tab_size);
+    }
+
+    if (continuous && tab_size == 0 &&
+        found == std::string::npos) {
+      tab += Tab(2);
+    }
+
+    if (found == std::string::npos && if_statement) {
+      tab_size--;
+      if_statement = false;
+    }
+
+    continuous = false;
+    back = line.back();
+    if (back == ",")
+      continuous = true;
+
+    if (line.empty() ||
+        line.length() == 0 ||
+        std::all_of(line.begin(), line.end(), isspace)) {
+      std::string n_line = Trim(next_line);
+      if (n_line.empty() ||
+          n_line.length() == 0 ||
+          n_line.find('}') != std::string::npos ||
+          std::all_of(n_line.begin(), n_line.end(), isspace)) {
+        line = n_line;
+        continue;
+      } else {
+        result += tab + line;
+        result += NLine(1);
+      }
+    } else {
+      result += tab + line;
+      result += NLine(1);
+    }
+
+    found = line.find('{');
+    if (found != std::string::npos) {
+      tab_size++;
+    } else {
+      found = line.find("if (");
+      if (found != std::string::npos) {
+        tab_size++;
+        if_statement = true;
+      }
+    }
+
+    line = Trim(next_line);
+  }
+
+  result += line;
+  result += NLine(1);
+
+  return result;
+}
+
+std::string CGeneratorBase::Trim(const std::string& str) {
+  std::size_t first = str.find_first_not_of(" \t\r\n");
+  if (first == std::string::npos)
+    return str;
+
+  std::size_t last = str.find_last_not_of(" \t\r\n");
+  return str.substr(first, (last - first + 1));
+}
+
+void CGeneratorBase::GenVersion(std::ofstream& stream) {
+  GenTemplate(CB_VERSION, stream,
+      [&]()->std::string {
+        return FULLVER;
+      });
+}
+
+void CGeneratorBase::GenIncludeDefaultHeaders(std::ofstream& stream,
+                                              bool body) {
+  if (body) {
+    stream << CB_BODY_HEADER;
+  } else {
+    stream << CB_HEADER;
+  }
+}
+
+void CGeneratorBase::GenGNUSourceDefinition(std::ofstream& stream) {
+  const char format[] = "#define _GNU_SOURCE\n";
+
+  stream << NLine(1);
+  stream << std::string(format);
+}
+
+bool CGeneratorBase::StructureExist(const Structure& st) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+
+    const Structure &s = static_cast<const Structure&>(*i);
+    if (s.GetID() == st.GetID())
+      return true;
+  }
+  return false;
+}
+
+std::string CGeneratorBase::GetParamTypeString(
+    ParameterType::Direction direction, const BaseType& type) {
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "list" ||
+      type.ToString() == "array") {
+    if (direction == ParameterType::Direction::IN)
+      return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
+    else
+      return GetHandlePrefix() + GetFullNameFromType(type) + "_h *";
+  }
+
+  if (type.ToString() == "string") {
+    if (direction == ParameterType::Direction::IN)
+      return "const char *";
+    else
+      return "char **";
+  }
+
+  if (direction == ParameterType::Direction::IN)
+    return type_map_[type.ToString()];
+
+  return type_map_[type.ToString()] + "*";
+}
+
+std::string CGeneratorBase::GetErrorValue(const BaseType& type) {
+  if (type.IsUserDefinedType() ||
+      type.ToString() == "list" ||
+      type.ToString() == "array" ||
+      type.ToString() == "bundle" ||
+      type.ToString() == "string")
+    return "NULL";
+  if (type.ToString() == "bool")
+    return "false";
+  if (type.ToString() == "char")
+    return "0";
+  return "-1";
+}
+
+std::string CGeneratorBase::GetStringFromElementType(const BaseType& type) {
+  if (type.IsUserDefinedType())
+    return GetHandlePrefix() + type.ToString() + "_h ";
+  if (type.ToString() == "array")
+    return GetReturnTypeString(*type.GetMetaType()) + "*";
+
+  return type_map_[type.ToString()];
+}
+
+std::string CGeneratorBase::GetStructIdWithNamespace(const Structure& st) {
+  if (!HasNamespace())
+    return st.GetID();
+  return GetFileNamespace() + "_" + st.GetID();
+}
+
+std::string CGeneratorBase::GetInterfaceIdWithNamespace(const Interface& inf) {
+  if (!HasNamespace())
+    return inf.GetID();
+  return GetFileNamespace() + "_" + inf.GetID();
+}
+
+std::string CGeneratorBase::GetHandlePrefix() {
+  if (!HasNamespace())
+    return "rpc_port_";
+  return "rpc_port_" + GetFileNamespace() + "_";
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_gen_base.h b/idlc/gen/c_gen_base.h
new file mode 100644 (file)
index 0000000..caec145
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_GEN_BASE_H_
+#define IDLC_C_GEN_C_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/structure.h"
+#include "idlc/gen/generator.h"
+
+namespace tidl {
+
+class CGeneratorBase : public Generator {
+ public:
+  explicit CGeneratorBase(std::shared_ptr<Document> doc);
+  virtual ~CGeneratorBase() = default;
+
+  std::string Trim(const std::string& str);
+  std::string SmartIndent(std::string lines);
+  std::string Tab(int cnt);
+  std::string NLine(int cnt);
+  std::string ConvertTypeToString(ParameterType::Direction direction,
+                                  const BaseType& type, bool bconst = true);
+  std::string GetFullNameFromType(const BaseType& type);
+  std::string GetParcelParamTypeString(const BaseType& type,
+                                       bool is_pointer = true);
+  std::string GetReturnTypeString(const BaseType& type);
+  std::string GetParamTypeString(ParameterType::Direction direction,
+                                 const BaseType& type);
+  std::string GetStringFromElementType(const BaseType& type);
+  std::string GetErrorValue(const BaseType& type);
+  void AddStructureFromType(const BaseType& type);
+  const std::map<std::string, std::unique_ptr<Structure>>& GetStructures(void) {
+    return structures_;
+  }
+
+  void GenVersion(std::ofstream& stream);
+  void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true);
+  void GenGNUSourceDefinition(std::ofstream& stream);
+  std::string GetStructIdWithNamespace(const Structure& st);
+  std::string GetInterfaceIdWithNamespace(const Interface& inf);
+  std::string GetHandlePrefix();
+
+ private:
+  bool StructureExist(const Structure& st);
+
+ private:
+  std::map<std::string, std::unique_ptr<Structure>> structures_;
+  std::map<std::string, std::string> type_map_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_GEN_BASE_H_
diff --git a/idlc/gen/c_gen_base_cb.h b/idlc/gen/c_gen_base_cb.h
new file mode 100644 (file)
index 0000000..5af4d66
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_GEN_BASE_CB_H_
+
+const char CB_VERSION[] =
+R"__c_cb(/*
+ * Generated by tidlc $$.
+ */
+)__c_cb";
+
+const char CB_HEADER[] =
+R"__c_cb(
+#include <stdbool.h>
+#include <bundle.h>
+)__c_cb";
+
+const char CB_BODY_HEADER[] =
+R"__c_cb(
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <glib.h>
+#include <dlog.h>
+#include <rpc-port.h>
+#include <rpc-port-parcel.h>
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_GEN_BASE_CB_H_
diff --git a/idlc/gen/c_header_gen_base.cc b/idlc/gen/c_header_gen_base.cc
new file mode 100644 (file)
index 0000000..f402fe0
--- /dev/null
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vector>
+
+#include "idlc/gen/c_header_gen_base.h"
+
+namespace {
+#include "idlc/gen/c_header_gen_base_cb.h"
+}
+
+namespace tidl {
+
+CHeaderGeneratorBase::CHeaderGeneratorBase(std::shared_ptr<Document> doc)
+    : CGeneratorBase(doc) {}
+
+void CHeaderGeneratorBase::GenPragmaOnce(std::ofstream& stream) {
+  const char format[] = "#pragma once\n";
+
+  stream << NLine(1);
+  stream << std::string(format);
+}
+
+void CHeaderGeneratorBase::GenExplicitLinkageOpen(std::ofstream& stream) {
+  stream << CB_EXPLICIT_LINKAGE_OPEN;
+}
+
+void CHeaderGeneratorBase::GenExplicitLinkageClose(std::ofstream& stream) {
+  stream << CB_EXPLICIT_LINKAGE_CLOSE;
+}
+
+void CHeaderGeneratorBase::GenStructures(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() == Block::TYPE_STRUCTURE) {
+      const Structure &st = static_cast<const Structure&>(*i);
+      GenStructure(stream, st);
+      for (auto& j : st.GetElements().GetElms()) {
+       auto& t = j->GetType();
+       AddStructureFromType(t);
+      }
+    } else {
+      const Interface &inf = static_cast<const Interface&>(*i);
+      for (auto& d : inf.GetDeclarations().GetDecls()) {
+        for (auto& p : d->GetParameters().GetParams()) {
+          if (IsDelegateType(inf, p->GetParameterType().GetBaseType()))
+            continue;
+          AddStructureFromType(p->GetParameterType().GetBaseType());
+        }
+      }
+    }
+  }
+
+  for (auto& p : GetStructures()) {
+    const Structure& st = *p.second;
+    GenStructure(stream, st);
+  }
+}
+
+void CHeaderGeneratorBase::GenStructure(std::ofstream& stream,
+                                        const Structure& st) {
+  GenStructureDeclaration(stream, st);
+  GenStructureConstructor(stream, st);
+  GenStructureDestructor(stream, st);
+  GenStructureCloner(stream, st);
+  GenStructureSetter(stream, st);
+  GenStructureGetter(stream, st);
+  GenStructureIterator(stream, st);
+  GenStructureRemover(stream, st);
+  GenStructureLengthGetter(stream, st);
+}
+
+void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
+                                                   const Structure& st) {
+  GenTemplate(CB_STRUCT_DECL, stream,
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      },
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      });
+}
+
+void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
+                                                   const Structure& st) {
+  GenTemplate(CB_STRUCT_CTOR, stream,
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      },
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      });
+}
+
+void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
+                                                  const Structure& st) {
+  GenTemplate(CB_STRUCT_DTOR, stream,
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      },
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      });
+}
+
+void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
+                                              const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    GenTemplate(CB_STRUCT_SETTER, stream,
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "list")
+              return "add";
+            return "set";
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetStructIdWithNamespace(st);
+          },
+          [&]()->std::string {
+            if (i->GetType().IsUserDefinedType())
+              return GetParcelParamTypeString(i->GetType());
+
+            if (i->GetType().ToString() == "list") {
+              if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+                  i->GetType().GetMetaType()->ToString() == "list" ||
+                  i->GetType().GetMetaType()->ToString() == "array") {
+                return GetParcelParamTypeString(*i->GetType().GetMetaType());
+              } else {
+                return ConvertTypeToString(ParameterType::Direction::IN,
+                    *i->GetType().GetMetaType());
+              }
+            }
+
+            if (i->GetType().ToString() == "array") {
+              return GetStringFromElementType(i->GetType());
+            }
+
+            return ConvertTypeToString(ParameterType::Direction::IN,
+                i->GetType());
+          },
+          [&]()->std::string {
+            if (i->GetType().ToString() == "array") {
+              std::string str;
+              str += i->GetID();
+              str += ", ";
+              str += "int " + i->GetID() + "_size";
+              return str;
+            }
+            return i->GetID();
+          });
+  }
+}
+
+void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
+                                              const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() == "list")
+      continue;
+
+    GenTemplate(CB_STRUCT_GETTER, stream,
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          return i->GetID();
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          if (i->GetType().ToString() == "array")
+              return GetStringFromElementType(i->GetType()) + "*";
+
+          return ConvertTypeToString(ParameterType::Direction::OUT,
+              i->GetType());
+        },
+        [&]()->std::string {
+          if (i->GetType().ToString() == "array") {
+            std::string str;
+            str += i->GetID();
+            str += ", ";
+            str += "int *" + i->GetID() + "_size";
+            return str;
+          }
+          return i->GetID();
+        });
+  }
+}
+
+void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
+                                                const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    GenTemplate(CB_STRUCT_ITERATOR, stream,
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          return i->GetID();
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+              i->GetType().GetMetaType()->ToString() == "list" ||
+              i->GetType().GetMetaType()->ToString() == "array")
+            return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+          return ConvertTypeToString(ParameterType::Direction::IN,
+              *i->GetType().GetMetaType());
+        },
+        [&]()->std::string {
+          return i->GetID();
+        });
+  }
+}
+
+void CHeaderGeneratorBase::GenStructureRemover(std::ofstream& stream,
+                                               const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    GenTemplate(CB_STRUCT_REMOVER, stream,
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          return i->GetID();
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        });
+  }
+}
+
+void CHeaderGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+                                                    const Structure& st) {
+  for (auto& i : st.GetElements().GetElms()) {
+    if (i->GetType().ToString() != "list")
+      continue;
+
+    GenTemplate(CB_STRUCT_LENGTH_GETTER, stream,
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        },
+        [&]()->std::string {
+          return i->GetID();
+        },
+        [&]()->std::string {
+          return GetStructIdWithNamespace(st);
+        });
+  }
+}
+
+void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
+                                              const Structure& st) {
+  GenTemplate(CB_STRUCT_CLONER, stream,
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      },
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      },
+      [&]()->std::string {
+        return GetStructIdWithNamespace(st);
+      });
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_header_gen_base.h b/idlc/gen/c_header_gen_base.h
new file mode 100644 (file)
index 0000000..4e2ad35
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_HEADER_GEN_BASE_H_
+#define IDLC_C_GEN_C_HEADER_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/gen/c_gen_base.h"
+
+namespace tidl {
+
+class CHeaderGeneratorBase : public CGeneratorBase {
+ public:
+  explicit CHeaderGeneratorBase(std::shared_ptr<Document> doc);
+  virtual ~CHeaderGeneratorBase() = default;
+
+  void GenPragmaOnce(std::ofstream& stream);
+  void GenExplicitLinkageOpen(std::ofstream& stream);
+  void GenExplicitLinkageClose(std::ofstream& stream);
+  void GenStructures(std::ofstream& stream);
+
+ private:
+  void GenStructure(std::ofstream& stream, const Structure& st);
+  void GenStructureDeclaration(std::ofstream& stream, const Structure& st);
+  void GenStructureParcelTo(std::ofstream& stream, const Structure& st);
+  void GenStructureParcelFrom(std::ofstream& stream, const Structure& st);
+  void GenStructureConstructor(std::ofstream& stream, const Structure& st);
+  void GenStructureDestructor(std::ofstream& stream, const Structure& st);
+  void GenStructureSetter(std::ofstream& stream, const Structure& st);
+  void GenStructureGetter(std::ofstream& stream, const Structure& st);
+  void GenStructureIterator(std::ofstream& stream, const Structure& st);
+  void GenStructureRemover(std::ofstream& stream, const Structure& st);
+  void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
+  void GenStructureCloner(std::ofstream& stream, const Structure& st);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_HEADER_GEN_BASE_H_
diff --git a/idlc/gen/c_header_gen_base_cb.h b/idlc/gen/c_header_gen_base_cb.h
new file mode 100644 (file)
index 0000000..e0229f5
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
+
+const char CB_EXPLICIT_LINKAGE_OPEN[] =
+R"__c_cb(
+#ifdef __cplusplus
+extern "C" {
+#endif
+)__c_cb";
+
+const char CB_EXPLICIT_LINKAGE_CLOSE[] =
+R"__c_cb(
+#ifdef __cplusplus
+}
+#endif
+)__c_cb";
+
+const char CB_STRUCT_DECL[] =
+R"__c_cb(
+typedef struct $$_s *rpc_port_$$_h;
+)__c_cb";
+
+const char CB_STRUCT_CTOR[] =
+R"__c_cb(
+int rpc_port_$$_create(rpc_port_$$_h *h);
+)__c_cb";
+
+const char CB_STRUCT_DTOR[] =
+R"__c_cb(
+int rpc_port_$$_destroy(rpc_port_$$_h h);
+)__c_cb";
+
+const char CB_STRUCT_SETTER[] =
+R"__c_cb(
+int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$);
+)__c_cb";
+
+const char CB_STRUCT_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$);
+)__c_cb";
+
+const char CB_STRUCT_ITERATOR[] =
+R"__c_cb(
+int rpc_port_$$_foreach_$$(rpc_port_$$_h h,
+        bool (*callback)($$$$, void *user_data), void *user_data);
+)__c_cb";
+
+const char CB_STRUCT_REMOVER[] =
+R"__c_cb(
+int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth);
+)__c_cb";
+
+const char CB_STRUCT_LENGTH_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length);
+)__c_cb";
+
+const char CB_STRUCT_CLONER[] =
+R"__c_cb(
+int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
diff --git a/idlc/gen/c_proxy_body_gen.cc b/idlc/gen/c_proxy_body_gen.cc
new file mode 100644 (file)
index 0000000..662b57e
--- /dev/null
@@ -0,0 +1,543 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/c_proxy_body_gen.h"
+
+namespace {
+#include "idlc/gen/c_proxy_body_gen_cb.h"
+}
+
+namespace tidl {
+
+CProxyBodyGen::CProxyBodyGen(std::shared_ptr<Document> doc)
+    : CBodyGeneratorBase(doc) {}
+
+void CProxyBodyGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  GenGNUSourceDefinition(stream);
+  GenIncludeDefaultHeaders(stream);
+  GenIncludeHeader(stream);
+  GenLogTag(stream, std::string("RPC_PORT_PROXY"));
+  GenLogDefinition(stream);
+  GenTypedefProxyDelegate(stream);
+  GenStructures(stream);
+  GenInterfaces(stream);
+}
+
+void CProxyBodyGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CProxyBodyGen::GenTypedefProxyDelegate(std::ofstream& stream) {
+  const char format[] =
+      "typedef void (*proxy_delegate)(GList **list, rpc_port_parcel_h parcel," \
+      " int seq_id, int id);\n";
+  stream << NLine(1);
+  stream << std::string(format);
+}
+
+void CProxyBodyGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+
+    const Interface &inf = static_cast<const Interface&>(*i);
+    GenInterface(stream, inf);
+  }
+}
+
+void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
+  GenInterfaceEnumerations(stream, inf);
+  GenInterfaceDeclaration(stream, inf);
+  GenInterfaceDelegators(stream, inf);
+  GenInterfaceDelegatorTable(stream, inf);
+  GenInterfaceDelegatorHandler(stream, inf);
+  GenInterfaceConsumeCommand(stream, inf);
+  GenInterfaceOnConnectedEventCB(stream, inf);
+  GenInterfaceOnDisconnectedEventCB(stream, inf);
+  GenInterfaceOnRejectedEventCB(stream, inf);
+  GenInterfaceOnReceivedEventCB(stream, inf);
+  GenInterfaceMethods(stream, inf);
+  GenInterfaceHandleCtor(stream, inf);
+  GenInterfaceHandleDtor(stream, inf);
+  GenInterfaceCtor(stream, inf);
+  GenInterfaceConnect(stream, inf);
+  GenInterfaceDtor(stream, inf);
+}
+
+void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
+                                            const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
+                                           const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
+  }
+}
+
+void CProxyBodyGen::GenInterfaceDelegator(std::ofstream& stream,
+                                          const std::string& id,
+                                          const Declaration& decl) {
+  GenInterfaceDelegatorDeclaration(stream, id, decl);
+  GenInterfaceDelegatorSerializer(stream, id, decl);
+  GenInterfaceDelegatorDeserializer(stream, id, decl);
+  GenInterfaceDelegatorConstructor(stream, id, decl);
+  GenInterfaceDelegatorDestructor(stream, id, decl);
+  GenInterfaceDelegatorDisposer(stream, id, decl);
+  GenInterfaceDelegatorInvoker(stream, id, decl);
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorDeclaration(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_DELEGATE_STRUCT, "##", id + "_" + decl.GetID()));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorSerializer(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(
+      ReplaceAll(CB_DELEGATE_SERIALIZER, "##", id + "_" + decl.GetID()));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorDeserializer(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(
+      ReplaceAll(CB_DELEGATE_DESERIALIZER, "##", id + "_" + decl.GetID()));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorConstructor(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID()),
+        [&]()->std::string {
+          return id;
+        },
+        [&]()->std::string {
+          return decl.GetID();
+        }));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorDisposer(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
+        [&]()->std::string {
+          return id;
+        }));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorInvoker(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  const char parcel[] = "$$(parcel, $$);\n";
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_DELEGATE_INVOKER, "##", id + "_" + decl.GetID()),
+        [&]()->std::string {
+          return id;
+        },
+        [&]()->std::string {
+          return decl.GetID();
+        },
+        [&]()->std::string {
+          std::string str;
+          int cnt = 0;
+          for (auto& i : decl.GetParameters().GetParams()) {
+            str += GetParcelParamTypeString(
+              i->GetParameterType().GetBaseType(), false) +
+              i->GetID() + ";" + NLine(1);
+            cnt++;
+          }
+          if (cnt > 0)
+            str += NLine(1);
+          for (auto& i : decl.GetParameters().GetParams()) {
+            if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
+                i->GetParameterType().GetBaseType().ToString() == "list" ||
+                i->GetParameterType().GetBaseType().ToString() == "array") {
+              str += GetConstructorString(i->GetParameterType().GetBaseType(),
+                  i->GetID());
+            }
+            str += GenTemplateString(parcel,
+                [&]()->std::string {
+                    return GetParcelReadFunctionString(
+                        i->GetParameterType().GetBaseType(), true);
+                },
+                [&]()->std::string {
+                  if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
+                      i->GetParameterType().GetBaseType()
+                          .ToString() == "list" ||
+                      i->GetParameterType().GetBaseType().ToString() == "array")
+                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
+                  return "&" + i->GetID();
+                });
+          }
+          return str;
+        },
+        [&]()->std::string {
+          std::string str;
+          str += "handle->callback(handle->user_data";
+          for (auto& i : decl.GetParameters().GetParams()) {
+            str += ", ";
+            str += i->GetID();
+          }
+          str += ");" + NLine(1);
+          return str;
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : decl.GetParameters().GetParams()) {
+            str += GetDestructorString(i->GetParameterType().GetBaseType(),
+                i->GetID());
+            str += NLine(1);
+          }
+          return str;
+        }));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorDestructor(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_DELEGATE_DTOR, "##", id + "_" + decl.GetID()));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorTable(std::ofstream& stream,
+                                               const Interface& inf) {
+  const char block[] =
+      "static proxy_delegate __$$_delegate_table[] = {\n" \
+      "$$" \
+      "};\n";
+  const char delegate_format[] = "[$$] = $$,\n";
+  std::string str;
+  int cnt = 0;
+
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    str += GenTemplateString(delegate_format,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf) + "_DELEGATE_" + i->GetID();
+        },
+        [&]()->std::string {
+          return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_"
+              + i->GetID();
+        });
+    cnt++;
+  }
+
+  if (cnt == 0)
+    return;
+
+  stream << NLine(1);
+  stream << SmartIndent(GenTemplateString(block,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          return str;
+        }));
+}
+
+void CProxyBodyGen::GenInterfaceDelegatorHandler(std::ofstream& stream,
+                                                 const Interface& inf) {
+  std::string str;
+  int cnt = 0;
+
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    cnt++;
+  }
+
+  stream << SmartIndent(GenTemplateString(
+      ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##",
+          GetInterfaceIdWithNamespace(inf)),
+          [&]()->std::string {
+            if (cnt == 0)
+              return str;
+            return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##",
+                GetInterfaceIdWithNamespace(inf));
+          }));
+}
+
+void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream,
+                                               const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
+                                                   const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
+                                                      const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
+                                        const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_INTERFACE_METHODS, "##",
+          GetInterfaceIdWithNamespace(inf)),
+          [&]()->std::string {
+            return GetReturnTypeString(i->GetType());
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            std::string str;
+            for (auto& p : i->GetParameters().GetParams()) {
+              str += ", ";
+              if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
+                str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
+                    p->GetParameterType().GetBaseType().ToString() +
+                    "_h " + p->GetID();
+              } else {
+                str += GetParamTypeString(p->GetParameterType().GetDirection(),
+                    p->GetParameterType().GetBaseType()) + p->GetID();
+              }
+            }
+            return str;
+          },
+          [&]()->std::string {
+            if (GetReturnTypeString(i->GetType()) != "void ")
+              return GetReturnTypeString(i->GetType()) + "ret = " +
+                  GetErrorValue(i->GetType()) + ";";
+            return "";
+          },
+          [&]()->std::string {
+            std::string str;
+            for (auto& p : i->GetParameters().GetParams()) {
+              if (p->GetParameterType().GetDirection() ==
+                  ParameterType::Direction::OUT ||
+                  p->GetParameterType().GetBaseType().IsUserDefinedType() ||
+                  p->GetParameterType().GetBaseType().ToString() == "list" ||
+                  p->GetParameterType().GetBaseType().ToString() == "array" ||
+                  p->GetParameterType().GetBaseType().ToString() == "bundle")
+                str += " || !" + p->GetID();
+            }
+            return str;
+          },
+          [&]()->std::string {
+            if (GetReturnTypeString(i->GetType()) != "void ")
+              return " ret";
+            return "";
+          },
+          [&]()->std::string {
+            if (GetReturnTypeString(i->GetType()) != "void ")
+              return " ret";
+            return "";
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetMethodWriteString(inf, *i);
+          },
+          [&]()->std::string {
+            return GetMethodReadString(inf, *i);
+          }));
+  }
+}
+
+void CProxyBodyGen::GenInterfaceHandleCtor(std::ofstream& stream,
+                                           const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_CTOR, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceHandleDtor(std::ofstream& stream,
+                                           const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_DTOR, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceCtor(std::ofstream& stream,
+                                        const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
+                                        const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceDtor(std::ofstream& stream,
+                                           const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
+                                                const Declaration& decl) {
+  const char setter[] = "$$($$, $$);\n";
+  const char ternary_operation[] = "## ? ## : \"\"";
+  std::string str;
+  for (auto& p : decl.GetParameters().GetParams()) {
+    if (p->GetParameterType().GetDirection() == ParameterType::Direction::OUT)
+      continue;
+    if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
+      str += GenTemplateString(ReplaceAll(CB_DELEGATE_BLOCK, "##",
+          GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType()
+              .GetBaseType().ToString()),
+          [&]()->std::string {
+            return p->GetID();
+          });
+    } else {
+      str += GenTemplateString(setter,
+          [&]()->std::string {
+            return GetParcelWriteFunctionString(
+                p->GetParameterType().GetBaseType(), true);
+          },
+          [&]()->std::string {
+            return "parcel";
+          },
+          [&]()->std::string {
+            if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
+                p->GetParameterType().GetBaseType().ToString() == "list" ||
+                p->GetParameterType().GetBaseType().ToString() == "array") {
+              if (p->GetParameterType().GetDirection()
+                  == ParameterType::Direction::REF)
+                return "&(*" + p->GetID() + ")->parcelable, " + "*"
+                    + p->GetID();
+              else
+                return "&" + p->GetID() + "->parcelable, " + p->GetID();
+            } else if (p->GetParameterType().GetDirection()
+                       == ParameterType::Direction::REF) {
+              if (p->GetParameterType().GetBaseType().ToString() == "string")
+                return ReplaceAll(ternary_operation, "##", "*" + p->GetID());
+              return "*" + p->GetID();
+            } else if (p->GetParameterType().GetBaseType().ToString() ==
+                "string") {
+              return ReplaceAll(ternary_operation, "##", p->GetID());
+            }
+            return p->GetID();
+          });
+    }
+  }
+  return str;
+}
+
+std::string CProxyBodyGen::GetMethodReadString(const Interface& inf,
+                                               const Declaration& decl) {
+  const char setter[] = "$$($$, $$);\n";
+  std::string str;
+  if (decl.GetMethodType() != Declaration::MethodType::SYNC) {
+    str += "set_last_result(r);" + NLine(1);
+    return str;
+  }
+  str += GenTemplateString(CB_RECEIVE_BLOCK,
+      [&]()->std::string {
+        std::string s;
+        for (auto& p : decl.GetParameters().GetParams()) {
+          if (p->GetParameterType().GetDirection() !=
+              ParameterType::Direction::OUT)
+            continue;
+          s += GetReturnTypeString(p->GetParameterType().GetBaseType()) +
+              "out_" + p->GetID() + ";" + NLine(1);
+        }
+        return s;
+      },
+      [&]()->std::string {
+        return GetInterfaceIdWithNamespace(inf);
+      },
+      [&]()->std::string {
+        std::string s;
+        for (auto& p : decl.GetParameters().GetParams()) {
+          if (p->GetParameterType().GetDirection() !=
+              ParameterType::Direction::OUT)
+            continue;
+          if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
+              p->GetParameterType().GetBaseType().ToString() == "list" ||
+              p->GetParameterType().GetBaseType().ToString() == "array") {
+            s += GetConstructorString(p->GetParameterType().GetBaseType(),
+                "out_" + p->GetID());
+            }
+            s += GenTemplateString(setter,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(
+                      p->GetParameterType().GetBaseType(), true);
+                },
+                [&]()->std::string {
+                  return "parcel_received";
+                },
+                [&]()->std::string {
+                  auto& t = p->GetParameterType().GetBaseType();
+                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
+                      t.ToString() == "array") {
+                    return "&out_" + p->GetID() + "->parcelable, out_"
+                        + p->GetID();
+                  }
+
+                  return "&out_" + p->GetID();
+                });
+            s += "*" + p->GetID() + " = out_" + p->GetID() + ";" + NLine(1);
+          }
+          if (GetReturnTypeString(decl.GetType()) != "void ") {
+            if (decl.GetType().IsUserDefinedType() ||
+                decl.GetType().ToString() == "list" ||
+                decl.GetType().ToString() == "array") {
+              s += GetConstructorString(decl.GetType(), "ret");
+            }
+            s += GenTemplateString(setter,
+                [&]()->std::string {
+                  return GetParcelReadFunctionString(decl.GetType(), false);
+                },
+                [&]()->std::string {
+                  return "parcel_received";
+                },
+                [&]()->std::string {
+                  if (decl.GetType().IsUserDefinedType() ||
+                      decl.GetType().ToString() == "list" ||
+                      decl.GetType().ToString() == "array")
+                    return "&ret->parcelable, ret";
+                  return "&ret";
+                });
+          }
+          return s;
+        });
+  if (GetReturnTypeString(decl.GetType()) != "void ") {
+    str += "set_last_result(r);" + NLine(1);
+    str += NLine(1);
+    str += "return ret;";
+  }
+  return str;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_proxy_body_gen.h b/idlc/gen/c_proxy_body_gen.h
new file mode 100644 (file)
index 0000000..5e07115
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_PROXY_BODY_GEN_H_
+#define IDLC_C_GEN_C_PROXY_BODY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/c_body_gen_base.h"
+
+namespace tidl {
+
+class CProxyBodyGen : public CBodyGeneratorBase {
+ public:
+  explicit CProxyBodyGen(std::shared_ptr<Document> doc);
+  virtual ~CProxyBodyGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenTypedefProxyDelegate(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+
+ private:
+  void GenInterface(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegatorTable(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegatorHandler(std::ofstream& stream,
+                                    const Interface& inf);
+  void GenInterfaceConsumeCommand(std::ofstream& stream,
+                                  const Interface& inf);
+  void GenInterfaceOnConnectedEventCB(std::ofstream& stream,
+                                      const Interface& inf);
+  void GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
+                                         const Interface& inf);
+  void GenInterfaceOnRejectedEventCB(std::ofstream& stream,
+                                     const Interface& inf);
+  void GenInterfaceOnReceivedEventCB(std::ofstream& stream,
+                                     const Interface& inf);
+  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceHandleCtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceHandleDtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
+
+ private:
+  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
+                             const Declaration& decl);
+  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
+                                        const std::string& id,
+                                        const Declaration& decl);
+  void GenInterfaceDelegatorSerializer(std::ofstream& stream,
+                                       const std::string& id,
+                                       const Declaration& decl);
+  void GenInterfaceDelegatorDeserializer(std::ofstream& stream,
+                                         const std::string& id,
+                                         const Declaration& decl);
+  void GenInterfaceDelegatorConstructor(std::ofstream& stream,
+                                        const std::string& id,
+                                        const Declaration& decl);
+  void GenInterfaceDelegatorDisposer(std::ofstream& stream,
+                                     const std::string& id,
+                                     const Declaration& decl);
+  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
+                                    const std::string& id,
+                                    const Declaration& decl);
+  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
+                                       const std::string& id,
+                                       const Declaration& decl);
+
+ private:
+  std::string GetMethodWriteString(const Interface& inf,
+                                   const Declaration& decl);
+  std::string GetMethodReadString(const Interface& inf,
+                                  const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_PROXY_BODY_GEN_H_
diff --git a/idlc/gen/c_proxy_body_gen_cb.h b/idlc/gen/c_proxy_body_gen_cb.h
new file mode 100644 (file)
index 0000000..3d9ad62
--- /dev/null
@@ -0,0 +1,496 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
+#define IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
+
+const char CB_INTERFACE_STRUCT[] =
+R"__c_cb(
+struct ##_s {
+    char *stub_appid;
+    rpc_port_proxy_h proxy;
+    rpc_port_h port;
+    rpc_port_h callback_port;
+    rpc_port_proxy_##_callback_s callback;
+    void *user_data;
+    GList *delegates;
+    GRecMutex mutex;
+};
+)__c_cb";
+
+const char CB_DELEGATE_STRUCT[] =
+R"__c_cb(
+struct ##_s {
+    rpc_port_parcelable_t parcelable;
+    int id;
+    int seq_id;
+    ## callback;
+    bool once;
+    void *user_data;
+};
+)__c_cb";
+
+const char CB_DELEGATE_SERIALIZER[] =
+R"__c_cb(
+static void __##_to(rpc_port_parcel_h parcel, void *data)
+{
+    struct ##_s *handle = data;
+
+    if (!handle) {
+        _E("Invalid parameter");
+        return;
+    }
+
+    rpc_port_parcel_write_int32(parcel, handle->id);
+    rpc_port_parcel_write_int32(parcel, handle->seq_id);
+    rpc_port_parcel_write_bool(parcel, handle->once);
+}
+)__c_cb";
+
+const char CB_DELEGATE_DESERIALIZER[] =
+R"__c_cb(
+static void __##_from(rpc_port_parcel_h parcel, void *data)
+{
+    struct ##_s *handle = data;
+
+    if (!handle) {
+        _E("Invalid parameter");
+        return;
+    }
+
+    rpc_port_parcel_read_int32(parcel, &handle->id);
+    rpc_port_parcel_read_int32(parcel, &handle->seq_id);
+    rpc_port_parcel_read_bool(parcel, &handle->once);
+}
+)__c_cb";
+
+const char CB_DELEGATE_CTOR[] =
+R"__c_cb(
+rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data)
+{
+    struct ##_s *handle;
+    static int seq_num;
+
+    handle = calloc(1, sizeof(struct ##_s));
+    if (!handle) {
+        _E("Out of memory");
+        return NULL;
+    }
+
+    handle->parcelable.to = __##_to;
+    handle->parcelable.from= __##_from;
+    handle->id = $$_DELEGATE_$$;
+    handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
+    handle->callback = callback;
+    handle->once = once;
+    handle->user_data = user_data;
+
+    return handle;
+}
+)__c_cb";
+
+const char CB_DELEGATE_DISPOSER[] =
+R"__c_cb(
+int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate)
+{
+    struct ##_s *handle;
+    GList *iter;
+
+    if (!proxy || !delegate) {
+        _E("Invalid handle %p %p", proxy, delegate);
+        return -1;
+    }
+
+    iter = proxy->delegates;
+    while (iter) {
+        handle = (struct ##_s *)iter->data;
+        if (handle == delegate) {
+            proxy->delegates = g_list_remove_link(proxy->delegates, iter);
+            free(handle);
+            g_list_free(iter);
+            return 0;
+        }
+        iter = g_list_next(iter);
+    }
+
+    return -1;
+}
+)__c_cb";
+
+const char CB_DELEGATE_DTOR[] =
+R"__c_cb(
+int rpc_port_##_destroy(rpc_port_##_h delegate)
+{
+    if (!delegate) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    free(delegate);
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_DELEGATE_INVOKER[] =
+R"__c_cb(
+static void __$$_delegate_$$(GList **list, rpc_port_parcel_h parcel, int seq_id, int id)
+{
+$$
+    do {
+        struct ##_s *handle;
+        GList *iter;
+
+        iter = *list;
+        while (iter) {
+            handle = (struct ##_s *)iter->data;
+            if (handle->seq_id == seq_id && handle->id == id) {
+                bool once = handle->once;
+
+                $$
+                if (once) {
+                    *list = g_list_remove_link(*list, iter);
+                    free(handle);
+                    g_list_free(iter);
+                }
+                break;
+            }
+            iter = g_list_next(iter);
+        }
+    } while (0);
+$$
+}
+)__c_cb";
+
+const char CB_PROCESS_RECEIVED_EVENT[] =
+R"__c_cb(
+static void __##_process_received_event(GList **list, rpc_port_parcel_h parcel)
+{
+$$
+}
+)__c_cb";
+
+const char CB_PROCESS_RECEIVED_EVENT_IMPL[] =
+R"__c_cb(int id;
+int seq_id;
+bool once;
+
+rpc_port_parcel_read_int32(parcel, &id);
+rpc_port_parcel_read_int32(parcel, &seq_id);
+rpc_port_parcel_read_bool(parcel, &once);
+
+if (id > 0 && id < (sizeof(__##_delegate_table) / sizeof(__##_delegate_table[0]))) {
+    if (__##_delegate_table[id])
+        __##_delegate_table[id](list, parcel, seq_id, id);
+} else {
+    _W("Unknown id(%d)", id);
+})__c_cb";
+
+const char CB_CONSUME_COMMAND[] =
+R"__c_cb(
+static rpc_port_parcel_h __##_consume_command(rpc_port_proxy_##_h h)
+{
+    rpc_port_parcel_h parcel = NULL;
+    int cmd = -1;
+
+    do {
+        rpc_port_parcel_create_from_port(&parcel, h->port);
+        if (!parcel)
+            break;
+
+        rpc_port_parcel_read_int32(parcel, &cmd);
+        if (cmd == ##_METHOD_Result)
+            return parcel;
+
+        rpc_port_parcel_destroy(parcel);
+        parcel = NULL;
+    } while (true);
+
+    return NULL;
+}
+)__c_cb";
+
+const char CB_ON_CONNECTED[] =
+R"__c_cb(
+static void __##_on_connected(const char *endpoint, const char *port_name, rpc_port_h port, void *data)
+{
+    rpc_port_proxy_##_h handle = data;
+
+    handle->port = port;
+    rpc_port_proxy_get_port(handle->proxy, RPC_PORT_PORT_CALLBACK, &handle->callback_port);
+    if (handle->callback.connected)
+        handle->callback.connected(handle, handle->user_data);
+    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+)__c_cb";
+
+const char CB_ON_DISCONNECTED[] =
+R"__c_cb(
+static void __##_on_disconnected(const char *endpoint, const char *port_name, void *data)
+{
+    rpc_port_proxy_##_h handle = data;
+
+    handle->port = NULL;
+    if (handle->callback.disconnected)
+        handle->callback.disconnected(handle, handle->user_data);
+    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+)__c_cb";
+
+const char CB_ON_REJECTED[] =
+R"__c_cb(
+static void __##_on_rejected(const char *endpoint, const char *port_name, void *data)
+{
+    rpc_port_proxy_##_h handle = data;
+
+    handle->port = NULL;
+    if (handle->callback.rejected)
+        handle->callback.rejected(handle, handle->user_data);
+    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+)__c_cb";
+
+const char CB_ON_RECEIVED[] =
+R"__c_cb(
+static void __##_on_received(const char *endpoint, const char *port_name, void *data)
+{
+    rpc_port_proxy_##_h handle = data;
+    rpc_port_parcel_h parcel_received = NULL;
+    int cmd = -1;
+
+    rpc_port_parcel_create_from_port(&parcel_received, handle->callback_port);
+    if (!parcel_received) {
+        _E("Failed to create parcel from port(%s)", port_name);
+        return;
+    }
+
+    rpc_port_parcel_read_int32(parcel_received, &cmd);
+    if (cmd != ##_METHOD_Callback) {
+        _E("Invalid protocol");
+        rpc_port_parcel_destroy(parcel_received);
+        return;
+    }
+
+    __##_process_received_event(&handle->delegates, parcel_received);
+    rpc_port_parcel_destroy(parcel_received);
+    _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name);
+}
+)__c_cb";
+
+const char CB_INTERFACE_METHODS[] =
+R"__c_cb(
+$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$)
+{
+    rpc_port_parcel_h parcel;
+    int r;
+$$
+
+    if (!h$$) {
+        _E("Invalid parameter");
+        return$$;
+    }
+
+    if (!h->port) {
+        _E("Not connected");
+        return$$;
+    }
+
+    rpc_port_parcel_create(&parcel);
+    rpc_port_parcel_write_int32(parcel, ##_METHOD_$$);
+$$
+    r = rpc_port_parcel_send(parcel, h->port);
+    if (r != RPC_PORT_ERROR_NONE) {
+        _E("Failed to send parcel. result(%d)", r);
+        r = RPC_PORT_ERROR_IO_ERROR;
+    }
+
+    rpc_port_parcel_destroy(parcel);
+$$
+}
+)__c_cb";
+
+const char CB_INTERFACE_HANDLE_CTOR[] =
+R"__c_cb(
+static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data)
+{
+    struct ##_s *handle;
+
+    handle = calloc(1, sizeof(struct ##_s));
+    if (!handle) {
+        _E("Out of memory");
+        return NULL;
+    }
+
+    handle->stub_appid = strdup(stub_appid);
+    if (!handle->stub_appid) {
+        _E("Out of memory");
+        free(handle);
+        return NULL;
+    }
+
+    rpc_port_proxy_create(&handle->proxy);
+    if (!handle->proxy) {
+        _E("Failed to create proxy");
+        free(handle->stub_appid);
+        free(handle);
+        return NULL;
+    }
+
+    g_rec_mutex_init(&handle->mutex);
+
+    handle->callback = *callback;
+    handle->user_data = user_data;
+
+    return handle;
+}
+)__c_cb";
+
+const char CB_INTERFACE_HANDLE_DTOR[] =
+R"__c_cb(
+static void __destroy_##(struct ##_s *h)
+{
+    if (!h)
+        return;
+
+    g_rec_mutex_clear(&h->mutex);
+
+    if (h->delegates)
+        g_list_free_full(h->delegates, free);
+
+    if (h->proxy)
+        rpc_port_proxy_destroy(h->proxy);
+
+    if (h->stub_appid)
+        free(h->stub_appid);
+
+    free(h);
+}
+)__c_cb";
+
+const char CB_INTERFACE_CTOR[] =
+R"__c_cb(
+int rpc_port_proxy_##_create(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data, rpc_port_proxy_##_h *h)
+{
+    struct ##_s *handle;
+    int r;
+
+    if (!stub_appid || !callback || !h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    handle = __create_##(stub_appid, callback, user_data);
+    if (!handle)
+        return -1;
+
+    r = rpc_port_proxy_add_connected_event_cb(handle->proxy, __##_on_connected, handle);
+    if (r != 0) {
+        _E("Failed to add connected event cb. err = %d", r);
+        __destroy_##(handle);
+        return r;
+    }
+
+    r = rpc_port_proxy_add_disconnected_event_cb(handle->proxy, __##_on_disconnected, handle);
+    if (r != 0) {
+        _E("Failed to add disconnected event cb. err = %d", r);
+        __destroy_##(handle);
+        return r;
+    }
+
+    r = rpc_port_proxy_add_rejected_event_cb(handle->proxy, __##_on_rejected, handle);
+    if (r != 0) {
+        _E("Failed to add rejected event cb. err = %d", r);
+        __destroy_##(handle);
+        return r;
+    }
+
+    r = rpc_port_proxy_add_received_event_cb(handle->proxy, __##_on_received, handle);
+    if (r != 0) {
+        _E("Failed to add received event cb. err = %d", r);
+        __destroy_##(handle);
+        return r;
+    }
+
+    *h = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONNECT[] =
+R"__c_cb(
+int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h)
+{
+    int r;
+
+    if (!h || !h->proxy) {
+        _E("Invalid parameter");
+       return -1;
+    }
+
+    r = rpc_port_proxy_connect(h->proxy, h->stub_appid, "##");
+    if (r != 0) {
+        _E("Failed to connect ##(%s)", h->stub_appid);
+       return r;
+    }
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_DTOR[] =
+R"__c_cb(
+int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h)
+{
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    __destroy_##(h);
+    return 0;
+}
+)__c_cb";
+
+const char CB_DELEGATE_BLOCK[] =
+R"__c_cb(
+do {
+    struct ##_s *handle = $$;
+
+    rpc_port_parcel_write(parcel, &handle->parcelable, handle);
+    h->delegates = g_list_append(h->delegates, handle);
+} while (0);
+)__c_cb";
+
+const char CB_RECEIVE_BLOCK[] =
+R"__c_cb(
+g_rec_mutex_lock(&h->mutex);
+do {
+    rpc_port_parcel_h parcel_received;
+$$
+    parcel_received = __$$_consume_command(h);
+    if (!parcel_received) {
+        _E("Invalid protocol");
+        break;
+    }
+
+$$
+    rpc_port_parcel_destroy(parcel_received);
+} while (0);
+g_rec_mutex_unlock(&h->mutex);
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
diff --git a/idlc/gen/c_proxy_header_gen.cc b/idlc/gen/c_proxy_header_gen.cc
new file mode 100644 (file)
index 0000000..64bfab4
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/c_proxy_header_gen.h"
+
+namespace {
+#include "idlc/gen/c_proxy_header_gen_cb.h"
+}
+
+namespace tidl {
+
+CProxyHeaderGen::CProxyHeaderGen(std::shared_ptr<Document> doc)
+    : CHeaderGeneratorBase(doc) {}
+
+void CProxyHeaderGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  GenPragmaOnce(stream);
+  GenIncludeDefaultHeaders(stream, false);
+  GenExplicitLinkageOpen(stream);
+  GenStructures(stream);
+  GenInterfaces(stream);
+}
+
+void CProxyHeaderGen::OnFiniGen(std::ofstream& stream) {
+  GenExplicitLinkageClose(stream);
+}
+
+void CProxyHeaderGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+
+    const Interface &inf = static_cast<const Interface&>(*i);
+    GenInterface(stream, inf);
+  }
+}
+
+void CProxyHeaderGen::GenInterface(std::ofstream& stream,
+                                   const Interface& inf) {
+  GenInterfaceDeclaration(stream, inf);
+  GenInterfaceDelegators(stream, inf);
+  GenInterfaceCtor(stream, inf);
+  GenInterfaceConnect(stream, inf);
+  GenInterfaceDtor(stream, inf);
+  GenInterfaceMethods(stream, inf);
+}
+
+void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
+                                             const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
+  }
+}
+
+void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
+                                            const std::string& id,
+                                            const Declaration& decl) {
+  const char handle[] = "typedef struct $$_s *rpc_port_$$_h;";
+
+  stream << NLine(1);
+  stream << GenTemplateString(handle,
+      [&]()->std::string {
+        return id + "_" + decl.GetID();
+      },
+      [&]()->std::string {
+        return id + "_" + decl.GetID();
+      });
+
+  stream << NLine(1);
+  stream << GenTemplateString(CB_INTERFACE_DELEGATOR,
+      [&]()->std::string {
+        return GetReturnTypeString(decl.GetType());
+      },
+      [&]()->std::string {
+        return id + "_" + decl.GetID();
+      },
+      [&]()->std::string {
+        std::string str;
+        str += "void *user_data";
+        for (auto& p : decl.GetParameters().GetParams()) {
+          str += ", ";
+          str += GetParamTypeString(p->GetParameterType().GetDirection(),
+              p->GetParameterType().GetBaseType()) + p->GetID();
+        }
+        return str;
+      });
+
+  stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID());
+  stream << ReplaceAll(CB_DELEGATE_DTOR, "##", id + "_" + decl.GetID());
+  stream << GenTemplateString(
+      ReplaceAll(CB_DELEGATE_DISPOSER, "##", id + "_" + decl.GetID()),
+      [&]()->std::string {
+        return id;
+      });
+}
+
+void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
+                                              const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
+                                          const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    stream << GenTemplateString(
+        ReplaceAll(CB_INTERFACE_METHODS, "##",
+            GetInterfaceIdWithNamespace(inf)),
+        [&]()->std::string {
+          return GetReturnTypeString(i->GetType());
+        },
+        [&]()->std::string {
+          return i->GetID();
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& p : i->GetParameters().GetParams()) {
+            str += ", ";
+            if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
+              str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
+                  p->GetParameterType().GetBaseType().ToString() +
+                  "_h " + p->GetID();
+            } else {
+              str += GetParamTypeString(p->GetParameterType().GetDirection(),
+                  p->GetParameterType().GetBaseType()) + p->GetID();
+            }
+          }
+          return str;
+        });
+  }
+}
+
+void CProxyHeaderGen::GenInterfaceCtor(std::ofstream& stream,
+                                          const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CTOR, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
+                                          const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CONNECT, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CProxyHeaderGen::GenInterfaceDtor(std::ofstream& stream,
+                                             const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_DTOR, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_proxy_header_gen.h b/idlc/gen/c_proxy_header_gen.h
new file mode 100644 (file)
index 0000000..800d67e
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
+#define IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/c_header_gen_base.h"
+
+namespace tidl {
+
+class CProxyHeaderGen : public CHeaderGeneratorBase {
+ public:
+  explicit CProxyHeaderGen(std::shared_ptr<Document> doc);
+  virtual ~CProxyHeaderGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenInterfaces(std::ofstream& stream);
+
+ private:
+  void GenInterface(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
+
+ private:
+  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
+                             const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_PROXY_HEADER_GEN_H_
diff --git a/idlc/gen/c_proxy_header_gen_cb.h b/idlc/gen/c_proxy_header_gen_cb.h
new file mode 100644 (file)
index 0000000..4fe6daf
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
+#define IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
+
+const char CB_INTERFACE_DECL[] =
+R"__c_cb(
+typedef struct ##_s *rpc_port_proxy_##_h;
+
+typedef struct {
+    void (*connected)(rpc_port_proxy_##_h h, void *user_data);
+    void (*disconnected)(rpc_port_proxy_##_h h, void *user_data);
+    void (*rejected)(rpc_port_proxy_##_h h, void *user_data);
+} rpc_port_proxy_##_callback_s;
+)__c_cb";
+
+const char CB_INTERFACE_CTOR[] =
+R"__c_cb(
+int rpc_port_proxy_##_create(const char *stub_appid,
+        rpc_port_proxy_##_callback_s *callback, void *user_data,
+        rpc_port_proxy_##_h *h);
+)__c_cb";
+
+const char CB_INTERFACE_CONNECT[] =
+R"__c_cb(
+int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h);
+)__c_cb";
+
+const char CB_INTERFACE_DTOR[] =
+R"__c_cb(
+int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h);
+)__c_cb";
+
+const char CB_INTERFACE_METHODS[] =
+R"__c_cb(
+$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR[] =
+R"__c_cb(
+typedef $$(*$$)($$);
+)__c_cb";
+
+const char CB_DELEGATE_CTOR[] =
+R"__c_cb(
+rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data);
+)__c_cb";
+
+const char CB_DELEGATE_DISPOSER[] =
+R"__c_cb(
+int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate);
+)__c_cb";
+
+const char CB_DELEGATE_DTOR[] =
+R"__c_cb(
+int rpc_port_##_destroy(rpc_port_##_h delegate);
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
diff --git a/idlc/gen/c_stub_body_gen.cc b/idlc/gen/c_stub_body_gen.cc
new file mode 100644 (file)
index 0000000..f9ebec9
--- /dev/null
@@ -0,0 +1,572 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/c_stub_body_gen.h"
+
+namespace {
+#include "idlc/gen/c_stub_body_gen_cb.h"
+}
+
+namespace tidl {
+
+CStubBodyGen::CStubBodyGen(std::shared_ptr<Document> doc)
+    : CBodyGeneratorBase(doc) {}
+
+void CStubBodyGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  GenGNUSourceDefinition(stream);
+  GenIncludeDefaultHeaders(stream);
+  GenIncludeHeader(stream);
+  GenLogTag(stream, std::string("RPC_PORT_STUB"));
+  GenLogDefinition(stream);
+  GenTypedefStubMethod(stream);
+  GenStructures(stream);
+  GenInterfaces(stream);
+}
+
+void CStubBodyGen::OnFiniGen(std::ofstream& stream) {}
+
+void CStubBodyGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+
+    const Interface &inf = static_cast<const Interface&>(*i);
+    GenInterface(stream, inf);
+  }
+}
+
+void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
+  GenInterfaceEnumerations(stream, inf);
+  GenInterfaceGlobalVariables(stream, inf);
+  GenInterfaceContext(stream, inf);
+  GenInterfaceDelegators(stream, inf);
+  GenInterfaceMethods(stream, inf);
+  GenInterfaceMethodTable(stream, inf);
+  GenInterfaceOnConnectedEventCB(stream, inf);
+  GenInterfaceOnDisconnectedEventCB(stream, inf);
+  GenInterfaceOnReceivedEventCB(stream, inf);
+  GenInterfaceAddPrivileges(stream, inf);
+  GenInterfaceRegister(stream, inf);
+  GenInterfaceUnregister(stream, inf);
+  GenInterfaceClientNumberGetter(stream, inf);
+}
+
+void CStubBodyGen::GenInterfaceMethods(std::ofstream& stream,
+                                       const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+
+    stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD,
+          [&]()->std::string {
+            return GetInterfaceIdWithNamespace(inf);
+          },
+          [&]()->std::string {
+            return i->GetID();
+          },
+          [&]()->std::string {
+            return GetInterfaceIdWithNamespace(inf);
+          },
+          [&]()->std::string {
+            return GetInterfaceIdWithNamespace(inf);
+          },
+          [&]()->std::string {
+            return GetMethodString(inf, *i);
+          }));
+  }
+}
+
+void CStubBodyGen::GenInterfaceMethodTable(std::ofstream& stream,
+                                           const Interface& inf) {
+  std::string str;
+  int cnt = 0;
+
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    str += GenTemplateString(CB_INTERFACE_METHOD_FORMAT,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf) + "_METHOD_" + i->GetID();
+        },
+        [&]()->std::string {
+          return "__" + GetInterfaceIdWithNamespace(inf) + "_method_"
+              + i->GetID();
+        });
+    cnt++;
+  }
+
+  if (cnt == 0)
+    return;
+
+  stream << NLine(1);
+  stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD_TABLE,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          return str;
+        }));
+}
+
+void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(
+      ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##",
+          GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
+                                                     const Interface& inf) {
+  stream << SmartIndent(
+      ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##",
+          GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
+                                                 const Interface& inf) {
+  stream << SmartIndent(
+      ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##",
+          GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
+                                        const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
+                                          const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
+                                               const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+std::string CStubBodyGen::GetMethodString(const Interface& inf,
+                                          const Declaration& decl) {
+  std::string str;
+  const char port_setter[] = "rpc_port_$$_set_port($$, callback_port);\n";
+  const char setter[] = "$$($$, $$);\n";
+  const char do_while_block[] =
+      "do {\n" \
+      "    rpc_port_parcel_h result;\n" \
+      "\n" \
+      "    rpc_port_parcel_create(&result);\n" \
+      "    rpc_port_parcel_write_int32(result, $$_METHOD_Result);\n" \
+      "$$" \
+      "    r = rpc_port_parcel_send(result, port);\n" \
+      "    rpc_port_parcel_destroy(result);\n" \
+      "} while (0);\n";
+  const char ternary_operation[] = "## ? ## : \"\"";
+  int cnt = 0;
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
+      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
+          i->GetParameterType().GetBaseType().ToString() + "_h " +
+          i->GetID() + " = NULL;" + NLine(1);
+    } else if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
+               i->GetParameterType().GetBaseType().ToString() == "list" ||
+               i->GetParameterType().GetBaseType().ToString() == "array") {
+      str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
+          i->GetID() + " = NULL;" + NLine(1);
+    } else {
+      str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
+          i->GetID() + ";" + NLine(1);
+    }
+    if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
+      cnt++;
+  }
+  str += NLine(1);
+
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
+      continue;
+
+    if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
+        i->GetParameterType().GetBaseType().ToString() == "list" ||
+        i->GetParameterType().GetBaseType().ToString() == "array") {
+      if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
+        str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
+            i->GetParameterType().GetBaseType().ToString() +
+            "_create(&" + i->GetID() + ");" + NLine(1);
+        str += "\nif (!" + i->GetID() + ") {\n";
+        str += "    _E(\"Failed to create handle\");\n";
+        str += "    return -1;\n";
+        str += "}\n\n";
+        str += GenTemplateString(port_setter,
+            [&]()->std::string {
+              return GetInterfaceIdWithNamespace(inf) + "_" +
+                  i->GetParameterType().GetBaseType().ToString();
+            },
+            [&]()->std::string {
+              return i->GetID();
+            });
+      } else {
+         str += GetConstructorString(i->GetParameterType().GetBaseType(),
+          i->GetID());
+      }
+    }
+
+    str += GenTemplateString(setter,
+          [&]()->std::string {
+            return GetParcelReadFunctionString(
+                i->GetParameterType().GetBaseType(), true);
+          },
+          [&]()->std::string {
+            return "parcel";
+          },
+          [&]()->std::string {
+            if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
+                i->GetParameterType().GetBaseType().ToString() == "list" ||
+                i->GetParameterType().GetBaseType().ToString() == "array")
+              return "&" + i->GetID() + "->parcelable, " + i->GetID();
+            return "&" + i->GetID();
+          });
+  }
+
+  if (cnt > 0)
+    str += NLine(1);
+
+  if (decl.GetMethodType() == Declaration::MethodType::SYNC &&
+      decl.GetType().ToString() != "void") {
+    str += GetReturnTypeString(decl.GetType()) + "ret = ";
+  }
+
+  str += "context->callback." + decl.GetID() + "(context";
+  for (auto& i : decl.GetParameters().GetParams()) {
+    str += ", ";
+    if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
+      str += "&" + i->GetID();
+    else
+      str += i->GetID();
+  }
+  str += ", context->user_data);" + NLine(1);
+  if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
+    str += GenTemplateString(do_while_block,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          std::string s;
+          for (auto& i : decl.GetParameters().GetParams()) {
+            if (i->GetParameterType().GetDirection() ==
+                ParameterType::Direction::IN)
+              continue;
+            s += GenTemplateString(setter,
+                [&]()->std::string {
+                  return GetParcelWriteFunctionString(
+                      i->GetParameterType().GetBaseType(), true);
+                },
+                [&]()->std::string {
+                  return "result";
+                },
+                [&]()->std::string {
+                  auto& t = i->GetParameterType().GetBaseType();
+                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
+                      t.ToString() == "array")
+                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
+                  else if (t.ToString() == "string")
+                    return ReplaceAll(ternary_operation, "##", i->GetID());
+                  return i->GetID();
+                });
+          }
+          if (decl.GetType().ToString() != "void") {
+            s += GenTemplateString(setter,
+                [&]()->std::string {
+                  return GetParcelWriteFunctionString(decl.GetType(), true);
+                },
+                [&]()->std::string {
+                  return "result";
+                },
+                [&]()->std::string {
+                  if (decl.GetType().IsUserDefinedType() ||
+                      decl.GetType().ToString() == "list" ||
+                      decl.GetType().ToString() == "array")
+                    return "&ret->parcelable, ret";
+                  else if (decl.GetType().ToString() == "string")
+                    return ReplaceAll(ternary_operation, "##", "ret");
+                  return "ret";
+                });
+          }
+          return s;
+        });
+    }
+
+  for (auto& i : decl.GetParameters().GetParams()) {
+    str += NLine(1);
+    if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
+      str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
+          i->GetParameterType().GetBaseType().ToString() +
+          "_destroy(" + i->GetID() + ");";
+    } else {
+      str += GetDestructorString(i->GetParameterType().GetBaseType(),
+          i->GetID());
+    }
+  }
+
+  str += GetDestructorString(decl.GetType(), "ret");
+
+  return str;
+}
+
+std::string CStubBodyGen::GetAddPrivilegeString(const std::string& id,
+                                                const Attribute& attr) {
+  std::string str;
+
+  str += GenTemplateString(CB_INTERFACE_PRIVILEGE_BLOCK,
+      [&]()->std::string {
+        return "rpc_port_stub_add_privilege(__" + id +
+            "_stub, \"" + attr.GetValue() + "\")";
+      },
+      [&]()->std::string {
+        return attr.GetValue();
+      });
+  return str;
+}
+
+std::string CStubBodyGen::GetTrustedModeString(const std::string& id,
+                                               const Attribute& attr) {
+  std::string str;
+
+  str += GenTemplateString(CB_INTERFACE_TRUSTED_MODE_BLOCK,
+      [&]()->std::string {
+        return "rpc_port_stub_set_trusted(__" + id +
+            "_stub, " + attr.GetValue() + ")";
+      },
+      [&]()->std::string {
+        return attr.GetValue();
+      });
+  return str;
+}
+
+void CStubBodyGen::GenInterfaceDelegators(std::ofstream& stream,
+                                          const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
+  }
+}
+
+void CStubBodyGen::GenInterfaceDelegator(std::ofstream& stream,
+                                         const std::string& id,
+                                         const Declaration& decl) {
+  GenInterfaceDelegatorDeclaration(stream, id, decl);
+  GenInterfaceDelegatorSerializer(stream, id, decl);
+  GenInterfaceDelegatorDeserializer(stream, id, decl);
+  GenInterfaceDelegatorConstructor(stream, id, decl);
+  GenInterfaceDelegatorDestructor(stream, id, decl);
+  GenInterfaceDelegatorCloner(stream, id, decl);
+  GenInterfaceDelegatorInvoker(stream, id, decl);
+  GenInterfaceDelegatorPortSetter(stream, id, decl);
+}
+
+void CStubBodyGen::GenInterfaceDelegatorDeclaration(std::ofstream& stream,
+                                                    const std::string& id,
+                                                    const Declaration& decl) {
+  stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_DECL,
+        [&]()->std::string {
+          return id + "_" + decl.GetID();
+        }));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
+                                                    const std::string& id,
+                                                    const Declaration& decl) {
+  stream << SmartIndent(GenTemplateString(
+        ReplaceAll(CB_INTERFACE_DELEGATOR_CTOR, "##", id + "_" + decl.GetID()),
+        [&]()->std::string {
+          return id;
+        },
+        [&]()->std::string {
+          return decl.GetID();
+        }));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorDestructor(std::ofstream& stream,
+                                                   const std::string& id,
+                                                   const Declaration& decl) {
+  stream << SmartIndent(
+      ReplaceAll(CB_INTERFACE_DELEGATOR_DTOR, "##", id + "_" + decl.GetID()));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream,
+                                                   const std::string& id,
+                                                   const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_DELEGATOR_SERIALIZER, "##", id + "_" + decl.GetID()));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream,
+                                                     const std::string& id,
+                                                     const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_DELEGATOR_DESERIALIZER, "##", id + "_" + decl.GetID()));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorCloner(std::ofstream& stream,
+                                               const std::string& id,
+                                               const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_DELEGATOR_CLONER, "##", id + "_" + decl.GetID()));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
+                                                const std::string& id,
+                                                const Declaration& decl) {
+  const char parcel[] = "$$(parcel, $$);\n";
+  const char ternary_operation[] = "## ? ## : \"\"";
+  stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_INVOKER,
+        [&]()->std::string {
+          return id + "_" + decl.GetID();
+        },
+        [&]()->std::string {
+          std::string str;
+          str += "rpc_port_" + id + "_" + decl.GetID() + "_h h";
+          for (auto& i : decl.GetParameters().GetParams()) {
+            str += ", ";
+            str += GetParamTypeString(i->GetParameterType().GetDirection(),
+                i->GetParameterType().GetBaseType()) + i->GetID();
+          }
+          return str;
+        },
+        [&]()->std::string {
+          return id;
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : decl.GetParameters().GetParams()) {
+            str += GenTemplateString(parcel,
+                [&]()->std::string {
+                  return GetParcelWriteFunctionString(
+                      i->GetParameterType().GetBaseType(), true);
+                },
+                [&]()->std::string {
+                  auto& t = i->GetParameterType().GetBaseType();
+                  if (t.IsUserDefinedType() || t.ToString() == "list" ||
+                      t.ToString() == "array")
+                    return "&" + i->GetID() + "->parcelable, " + i->GetID();
+                  else if (t.ToString() == "string")
+                    return ReplaceAll(ternary_operation, "##", i->GetID());
+                  return i->GetID();
+                });
+          }
+          return str;
+        }));
+}
+
+void CStubBodyGen::GenInterfaceDelegatorPortSetter(std::ofstream& stream,
+                                                   const std::string& id,
+                                                   const Declaration& decl) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_DELEGATOR_PORT_SETTER, "##", id + "_" + decl.GetID()));
+}
+
+void CStubBodyGen::GenInterfaceContext(std::ofstream& stream,
+                                       const Interface& inf) {
+  GenInterfaceContextDeclaration(stream, inf);
+  GenInterfaceContextConstructor(stream, inf);
+  GenInterfaceContextDestructor(stream, inf);
+  GenInterfaceContextFinder(stream, inf);
+  GenInterfaceContextTagSetter(stream, inf);
+  GenInterfaceContextTagGetter(stream, inf);
+  GenInterfaceContextSenderGetter(stream, inf);
+}
+
+void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextConstructor(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream,
+                                                 const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream,
+                                             const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_FINDER, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream,
+                                                const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_TAG_SETTER, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream,
+                                                const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_TAG_GETTER, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenInterfaceContextSenderGetter(std::ofstream& stream,
+                                                   const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(
+      CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf)));
+}
+
+void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) {
+  stream << CB_STUB_METHOD_TYPE;
+}
+
+void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
+                                             const Interface& inf) {
+  stream << SmartIndent(GenTemplateString(CB_INTERFACE_ADD_PRIVILEGE,
+        [&]()->std::string {
+          return GetInterfaceIdWithNamespace(inf);
+        },
+        [&]()->std::string {
+          std::string str;
+          for (auto& a : inf.GetAttributes().GetAttrs()) {
+            if (a->GetKey() == "privilege") {
+              str += GetAddPrivilegeString(
+                  GetInterfaceIdWithNamespace(inf), *a);
+              str += NLine(1);
+            } else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
+              str += GetTrustedModeString(GetInterfaceIdWithNamespace(inf), *a);
+              str += NLine(1);
+            }
+          }
+
+          if (!str.empty())
+            str = SmartIndent("int r;\n\n") + str;
+          return str;
+        }));
+}
+
+void CStubBodyGen::GenInterfaceClientNumberGetter(std::ofstream& stream,
+                                                  const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CLIENT_NUMBER_GETTER, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_stub_body_gen.h b/idlc/gen/c_stub_body_gen.h
new file mode 100644 (file)
index 0000000..16bf22e
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_H_
+#define IDLC_C_GEN_C_STUB_BODY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/c_body_gen_base.h"
+
+namespace tidl {
+
+class CStubBodyGen : public CBodyGeneratorBase {
+ public:
+  explicit CStubBodyGen(std::shared_ptr<Document> doc);
+  virtual ~CStubBodyGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& inf);
+  void GenTypedefStubMethod(std::ofstream& stream);
+  void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceMethodTable(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceOnConnectedEventCB(std::ofstream& stream,
+                                      const Interface& inf);
+  void GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
+                                         const Interface& inf);
+  void GenInterfaceOnReceivedEventCB(std::ofstream& stream,
+                                     const Interface& inf);
+  void GenInterfaceRegister(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceUnregister(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceGlobalVariables(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceAddPrivileges(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceClientNumberGetter(std::ofstream& stream,
+                                      const Interface& inf);
+
+ private:
+  void GenInterfaceContextDeclaration(std::ofstream& stream,
+                                      const Interface& inf);
+  void GenInterfaceContextConstructor(std::ofstream& stream,
+                                      const Interface& inf);
+  void GenInterfaceContextDestructor(std::ofstream& stream,
+                                     const Interface& inf);
+  void GenInterfaceContextFinder(std::ofstream& stream,
+                                 const Interface& inf);
+  void GenInterfaceContextTagSetter(std::ofstream& stream,
+                                    const Interface& inf);
+  void GenInterfaceContextTagGetter(std::ofstream& stream,
+                                    const Interface& inf);
+  void GenInterfaceContextSenderGetter(std::ofstream& stream,
+                                       const Interface& inf);
+
+ private:
+  void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
+                             const Declaration& decl);
+  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
+                                        const std::string& id,
+                                       const Declaration& decl);
+  void GenInterfaceDelegatorConstructor(std::ofstream& stream,
+                                      const std::string& id,
+                                       const Declaration& decl);
+  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
+                                      const std::string& id,
+                                      const Declaration& decl);
+  void GenInterfaceDelegatorSerializer(std::ofstream& stream,
+                                      const std::string& id,
+                                      const Declaration& decl);
+  void GenInterfaceDelegatorDeserializer(std::ofstream& stream,
+                                        const std::string& id,
+                                        const Declaration& decl);
+  void GenInterfaceDelegatorCloner(std::ofstream& stream,
+                                  const std::string& id,
+                                  const Declaration& decl);
+  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
+                                   const std::string& id,
+                                   const Declaration& decl);
+  void GenInterfaceDelegatorPortSetter(std::ofstream& stream,
+                                       const std::string& id,
+                                       const Declaration& decl);
+
+ private:
+  std::string GetMethodString(const Interface& id, const Declaration& decl);
+  std::string GetAddEventCBString(const std::string& id);
+  std::string GetAddPrivilegeString(const std::string& id,
+                                    const Attribute& attr);
+  std::string GetTrustedModeString(const std::string& id,
+                                   const Attribute& attr);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_STUB_BODY_GEN_H_
diff --git a/idlc/gen/c_stub_body_gen_cb.h b/idlc/gen/c_stub_body_gen_cb.h
new file mode 100644 (file)
index 0000000..7c77b83
--- /dev/null
@@ -0,0 +1,570 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
+#define IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
+
+const char CB_INTERFACE_METHOD[] =
+R"__c_cb(
+static int __$$_method_$$(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
+{
+    rpc_port_stub_$$_context_h context = data;
+    rpc_port_h callback_port;
+    int r;
+
+    r = rpc_port_stub_get_port(__$$_stub, RPC_PORT_PORT_CALLBACK, context->instance, &callback_port);
+    if (r != 0) {
+        _E("Failed to get callback port");
+        return -1;
+    }
+
+$$
+    return r;
+}
+)__c_cb";
+
+const char CB_INTERFACE_METHOD_TABLE[] =
+R"__c_cb(static stub_method __$$_method_table[] = {$$
+};
+)__c_cb";
+
+const char CB_INTERFACE_METHOD_FORMAT[] =
+R"__c_cb(
+[$$] = $$,)__c_cb";
+
+const char CB_INTERFACE_ON_CONNECTED[] =
+R"__c_cb(
+static void __##_on_connected(const char *sender, const char *instance, void *data)
+{
+    rpc_port_stub_##_context_h context;
+
+    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+    context = __create_##_context(sender, instance);
+    if (!context)
+        return;
+
+    if (context->callback.create)
+        context->callback.create(context, context->user_data);
+    __##_contexts = g_list_append(__##_contexts, context);
+}
+)__c_cb";
+
+const char CB_INTERFACE_ON_DISCONNECTED[] =
+R"__c_cb(
+static void __##_on_disconnected(const char *sender, const char *instance, void *data)
+{
+    rpc_port_stub_##_context_h context;
+
+    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+    context = __find_##_context(instance);
+    if (!context)
+        return;
+
+    if (context->callback.terminate)
+        context->callback.terminate(context, context->user_data);
+    __##_contexts = g_list_remove(__##_contexts, context);
+    __destroy_##_context(context);
+}
+)__c_cb";
+
+const char CB_INTERFACE_ON_RECEIVED[] =
+R"__c_cb(
+static int __##_on_received(const char *sender, const char *instance, rpc_port_h port, void *data)
+{
+    rpc_port_stub_##_context_h context;
+    rpc_port_parcel_h parcel;
+    int cmd = -1;
+    int r;
+
+    _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance);
+    context = __find_##_context(instance);
+    if (!context) {
+        _E("Failed to find ## context(%s)", instance);
+        return -1;
+    }
+
+    context->port = port;
+    r = rpc_port_parcel_create_from_port(&parcel, port);
+    if (r != 0) {
+        _E("Failed to create parcel from port");
+        return r;
+    }
+
+    rpc_port_parcel_read_int32(parcel, &cmd);
+    if (cmd > 1 && cmd < (sizeof(__##_method_table) / sizeof(__##_method_table[0]))) {
+         if (__##_method_table[cmd])
+             r = __##_method_table[cmd](port, parcel, context);
+    } else {
+         _E("Unknown Command(%d)", cmd);
+         r = -1;
+    }
+
+    rpc_port_parcel_destroy(parcel);
+
+    return r;
+}
+)__c_cb";
+
+const char CB_INTERFACE_REGISTER[] =
+R"__c_cb(
+int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data)
+{
+    int r;
+
+    if (__##_stub) {
+        _W("Already exists");
+        return -1;
+    }
+
+    if (!callback) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    __##_callback = *callback;
+    __##_user_data = user_data;
+    r = rpc_port_stub_create(&__##_stub, "##");
+    if (r != 0) {
+        _E("Failed to create stub handle");
+        return r;
+    }
+
+    r = rpc_port_stub_add_received_event_cb(__##_stub, __##_on_received, NULL);
+    if (r != 0) {
+        _E("Failed to add received event callback");
+        rpc_port_stub_destroy(__##_stub);
+        __##_stub = NULL;
+        return r;
+    }
+
+    r = rpc_port_stub_add_connected_event_cb(__##_stub, __##_on_connected, NULL);
+    if (r != 0) {
+        _E("Failed to add connected event callback");
+        rpc_port_stub_destroy(__##_stub);
+        __##_stub = NULL;
+        return r;
+    }
+
+    r = rpc_port_stub_add_disconnected_event_cb(__##_stub, __##_on_disconnected, NULL);
+    if (r != 0) {
+        _E("Failed to add disconnected event callback");
+        rpc_port_stub_destroy(__##_stub);
+        __##_stub = NULL;
+        return r;
+    }
+
+    r = __##_add_privileges();
+    if (r != 0) {
+        _E("Failed to add privileges");
+        rpc_port_stub_destroy(__##_stub);
+        __##_stub = NULL;
+        return r;
+    }
+
+    r = rpc_port_stub_listen(__##_stub);
+    if (r != 0) {
+        _E("Failed to listen stub");
+        rpc_port_stub_destroy(__##_stub);
+        __##_stub = NULL;
+        return r;
+    }
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_UNREGISTER[] =
+R"__c_cb(
+int rpc_port_stub_##_unregister(void)
+{
+    int r;
+
+    if (!__##_stub)
+        return -1;
+
+    if (__##_contexts) {
+        g_list_free_full(__##_contexts, __destroy_##_context);
+        __##_contexts = NULL;
+    }
+
+    r = rpc_port_stub_destroy(__##_stub);
+    __##_stub = NULL;
+
+    return r;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CLIENT_NUMBER_GETTER[] =
+R"__c_cb(
+int rpc_port_stub_##_get_client_number(unsigned int *n)
+{
+       if (!n) {
+               _E("Invalid parameter");
+               return -1;
+       }
+
+       if (!__##_stub) {
+               _E("## Stub is not ready");
+               return -1;
+       }
+
+       *n = g_list_length(__##_contexts);
+
+       return 0;
+}
+)__c_cb";
+
+const char CB_GLOBALS[] =
+R"__c_cb(
+static rpc_port_stub_h __##_stub;
+static rpc_port_stub_##_callback_s __##_callback;
+static void *__##_user_data;
+static GList *__##_contexts;
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_DECL[] =
+R"__c_cb(
+struct $$_s {
+    rpc_port_parcelable_t parcelable;
+    rpc_port_h port;
+    int id;
+    int seq_id;
+    bool once;
+    bool valid;
+};
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_CTOR[] =
+R"__c_cb(
+static int rpc_port_##_create(rpc_port_##_h *h)
+{
+    struct ##_s *handle;
+    static int seq_num;
+
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    handle = calloc(1, sizeof(struct ##_s));
+    if (!handle) {
+        _E("Out of memory");
+        return -1;
+    }
+
+    handle->parcelable.to = __##_to;
+    handle->parcelable.from = __##_from;
+    handle->id = $$_DELEGATE_$$;
+    handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1;
+    handle->once = false;
+    handle->valid = true;
+
+    *h = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_DTOR[] =
+R"__c_cb(
+int rpc_port_##_destroy(rpc_port_##_h h)
+{
+    if (!h) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    free(h);
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_SERIALIZER[] =
+R"__c_cb(
+static void __##_to(rpc_port_parcel_h parcel, void *data)
+{
+    rpc_port_##_h handle = data;
+
+    if (!handle) {
+        _E("Invalid parameter");
+        return;
+    }
+
+    rpc_port_parcel_write_int32(parcel, handle->id);
+    rpc_port_parcel_write_int32(parcel, handle->seq_id);
+    rpc_port_parcel_write_bool(parcel, handle->once);
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_DESERIALIZER[] =
+R"__c_cb(
+static void __##_from(rpc_port_parcel_h parcel, void *data)
+{
+    rpc_port_##_h handle = data;
+
+    if (!handle) {
+        _E("Invalid parameter");
+        return;
+    }
+
+    rpc_port_parcel_read_int32(parcel, &handle->id);
+    rpc_port_parcel_read_int32(parcel, &handle->seq_id);
+    rpc_port_parcel_read_bool(parcel, &handle->once);
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_CLONER[] =
+R"__c_cb(
+int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)
+{
+    rpc_port_##_h handle;
+
+    if (!h || !clone) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    handle = calloc(1, sizeof(struct ##_s));
+    if (!handle) {
+        _E("Out of memory");
+        return -1;
+    }
+
+    handle->parcelable = h->parcelable;
+    handle->port = h->port;
+    handle->id = h->id;
+    handle->seq_id = h->seq_id;
+    handle->once = h->once;
+    handle->valid = h->valid;
+
+    *clone = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_INVOKER[] =
+R"__c_cb(
+int rpc_port_$$_invoke($$)
+{
+    rpc_port_parcel_h parcel = NULL;
+    int r;
+
+    if (!h || !h->port) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    if (h->once && !h->valid) {
+        _E("Invalid callback");
+        return -1;
+    }
+
+    rpc_port_parcel_create(&parcel);
+    if (!parcel) {
+        _E("Failed to create parcel");
+        return -1;
+    }
+
+    rpc_port_parcel_write_int32(parcel, $$_METHOD_Callback);
+    rpc_port_parcel_write(parcel, &h->parcelable, h);
+$$
+    r = rpc_port_parcel_send(parcel, h->port);
+    rpc_port_parcel_destroy(parcel);
+    h->valid = false;
+
+    return r;
+}
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_PORT_SETTER[] =
+R"__c_cb(
+int rpc_port_##_set_port(rpc_port_##_h h, rpc_port_h port)
+{
+    if (!h || !port) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    h->port = port;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_DECL[] =
+R"__c_cb(
+struct ##_context_s {
+    char *sender;
+    char *instance;
+    rpc_port_h port;
+    void *tag;
+    rpc_port_stub_##_callback_s callback;
+    void *user_data;
+};
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_CTOR[] =
+R"__c_cb(
+static struct ##_context_s *__create_##_context(const char *sender, const char *instance)
+{
+    struct ##_context_s *handle;
+
+    handle = calloc(1, sizeof(struct ##_context_s));
+    if (!handle) {
+        _E("Out of memory");
+        return NULL;
+    }
+
+    handle->sender = strdup(sender);
+    if (!handle->sender) {
+        _E("Out of memory");
+        free(handle);
+        return NULL;
+    }
+
+    handle->instance = strdup(instance);
+    if (!handle->instance) {
+        _E("Out of memory");
+        free(handle->sender);
+        free(handle);
+        return NULL;
+    }
+
+    handle->callback = __##_callback;
+    handle->user_data = __##_user_data;
+
+    return handle;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_DTOR[] =
+R"__c_cb(
+static void __destroy_##_context(gpointer data)
+{
+    struct ##_context_s *handle = data;
+
+    if (!handle) {
+        _E("Critical error!");
+        return;
+    }
+
+    free(handle->instance);
+    free(handle->sender);
+    free(handle);
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_FINDER[] =
+R"__c_cb(
+static struct ##_context_s *__find_##_context(const char *instance)
+{
+    struct ##_context_s *handle;
+    GList *iter;
+
+    iter = __##_contexts;
+    while (iter) {
+        handle = (struct ##_context_s *)iter->data;
+        if (!strcmp(handle->instance, instance))
+            return handle;
+        iter = g_list_next(iter);
+    }
+
+    return NULL;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_TAG_SETTER[] =
+R"__c_cb(
+int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag)
+{
+    if (!ctx) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    ctx->tag = tag;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_TAG_GETTER[] =
+R"__c_cb(
+int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag)
+{
+    if (!ctx || !tag) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    *tag = ctx->tag;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_GET_SENDER[] =
+R"__c_cb(
+int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender)
+{
+    if (!ctx || !sender) {
+        _E("Invalid parameter");
+        return -1;
+    }
+
+    *sender = strdup(ctx->sender);
+    if (*sender == NULL) {
+        _E("Out of memory");
+        return -1;
+    }
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_STUB_METHOD_TYPE[] =
+R"__c_cb(
+typedef int (*stub_method)(rpc_port_h, rpc_port_parcel_h, void *data);
+)__c_cb";
+
+const char CB_INTERFACE_ADD_PRIVILEGE[] =
+R"__c_cb(
+static int __$$_add_privileges(void)
+{
+$$
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_PRIVILEGE_BLOCK[] =
+R"__c_cb(r = $$;
+if (r != 0) {
+    _E("Failed to add privilege($$)");
+    return r;
+}
+)__c_cb";
+
+const char CB_INTERFACE_TRUSTED_MODE_BLOCK[] =
+R"__c_cb(r = $$;
+if (r != 0) {
+    _E("Failed to set trusted mode($$)");
+    return r;
+}
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
diff --git a/idlc/gen/c_stub_header_gen.cc b/idlc/gen/c_stub_header_gen.cc
new file mode 100644 (file)
index 0000000..426cd6d
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/c_stub_header_gen.h"
+
+namespace {
+#include "idlc/gen/c_stub_header_gen_cb.h"
+}
+
+namespace tidl {
+
+CStubHeaderGen::CStubHeaderGen(std::shared_ptr<Document> doc)
+    : CHeaderGeneratorBase(doc) {}
+
+void CStubHeaderGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  GenPragmaOnce(stream);
+  GenIncludeDefaultHeaders(stream, false);
+  GenExplicitLinkageOpen(stream);
+  GenStructures(stream);
+  GenInterfaces(stream);
+}
+
+void CStubHeaderGen::OnFiniGen(std::ofstream& stream) {
+  GenExplicitLinkageClose(stream);
+}
+
+void CStubHeaderGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+
+    const Interface &inf = static_cast<const Interface&>(*i);
+    GenInterface(stream, inf);
+  }
+}
+
+void CStubHeaderGen::GenInterface(std::ofstream& stream,
+                                  const Interface& inf) {
+  GenInterfaceContext(stream, inf);
+  GenInterfaceDelegators(stream, inf);
+  GenInterfaceDeclaration(stream, inf);
+  GenInterfaceRegister(stream, inf);
+  GenInterfaceUnregister(stream, inf);
+  GenInterfaceClientNumberGetter(stream, inf);
+}
+
+void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
+                                             const Interface& inf) {
+  stream << SmartIndent(GenTemplateString(ReplaceAll(
+        CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)),
+        [&]()->std::string {
+          std::string str;
+          for (auto& i : inf.GetDeclarations().GetDecls()) {
+            if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+              continue;
+            str += NLine(1);
+            str += GenTemplateString(CB_INTERFACE_CALLBACK,
+                [&]()->std::string {
+                  return GetReturnTypeString(i->GetType());
+                },
+                [&]()->std::string {
+                  return i->GetID();
+                },
+                [&]()->std::string {
+                  return GetInterfaceIdWithNamespace(inf);
+                },
+                [&]()->std::string {
+                  std::string s;
+                  for (auto& p : i->GetParameters().GetParams()) {
+                    if (IsDelegateType(inf, p->GetParameterType()
+                        .GetBaseType())) {
+                      s += "rpc_port_" + GetInterfaceIdWithNamespace(inf)
+                        + "_" + p->GetParameterType().GetBaseType().ToString()
+                        + "_h " + p->GetID();
+                    } else {
+                      s += GetParamTypeString(p->GetParameterType()
+                          .GetDirection(), p->GetParameterType().GetBaseType())
+                        + p->GetID();
+                    }
+                    s += ", ";
+                  }
+                  return s;
+                });
+          }
+          return str;
+        }));
+}
+
+void CStubHeaderGen::GenInterfaceContext(std::ofstream& stream,
+                                         const Interface& inf) {
+  GenInterfaceContextDeclaration(stream, inf);
+  GenInterfaceContextTagSetter(stream, inf);
+  GenInterfaceContextTagGetter(stream, inf);
+  GenInterfaceContextSenderGetter(stream, inf);
+}
+
+void CStubHeaderGen::GenInterfaceContextDeclaration(
+    std::ofstream& stream, const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceContextTagSetter(
+    std::ofstream& stream, const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceContextTagGetter(
+    std::ofstream& stream, const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceContextSenderGetter(
+    std::ofstream& stream, const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
+                                            const Interface& inf) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
+  }
+}
+
+void CStubHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
+                                           const std::string& id,
+                                           const Declaration& decl) {
+  GenInterfaceDelegatorDeclaration(stream, id, decl);
+  GenInterfaceDelegatorDestructor(stream, id, decl);
+  GenInterfaceDelegatorCloner(stream, id, decl);
+  GenInterfaceDelegatorInvoker(stream, id, decl);
+}
+
+void CStubHeaderGen::GenInterfaceDelegatorDeclaration(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << ReplaceAll(
+      CB_INTERFACE_DELEGATOR_DECL, "##", id + "_" + decl.GetID());
+}
+
+void CStubHeaderGen::GenInterfaceDelegatorDestructor(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << ReplaceAll(
+      CB_INTERFACE_DELEGATOR_DTOR, "##", id + "_" + decl.GetID());
+}
+
+void CStubHeaderGen::GenInterfaceDelegatorCloner(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << ReplaceAll(
+      CB_INTERFACE_DELEGATOR_CLONER, "##", id + "_" + decl.GetID());
+}
+
+void CStubHeaderGen::GenInterfaceDelegatorInvoker(
+    std::ofstream& stream, const std::string& id, const Declaration& decl) {
+  stream << GenTemplateString(ReplaceAll(
+      CB_INTERFACE_DELEGATOR_INVOKER, "##", id + "_" + decl.GetID()),
+      [&]()->std::string {
+        std::string str;
+        for (auto& i : decl.GetParameters().GetParams()) {
+          str += ", ";
+          str += GetParamTypeString(i->GetParameterType().GetDirection(),
+              i->GetParameterType().GetBaseType()) + i->GetID();
+        }
+        return str;
+      });
+}
+
+void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream,
+                                          const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_REGISTER, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceUnregister(std::ofstream& stream,
+                                            const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+void CStubHeaderGen::GenInterfaceClientNumberGetter(std::ofstream& stream,
+                                                    const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CLIENT_NUMBER_GETTER, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/c_stub_header_gen.h b/idlc/gen/c_stub_header_gen.h
new file mode 100644 (file)
index 0000000..43d2e53
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_STUB_HEADER_GEN_H_
+#define IDLC_C_GEN_C_STUB_HEADER_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/c_header_gen_base.h"
+
+namespace tidl {
+
+class CStubHeaderGen : public CHeaderGeneratorBase {
+ public:
+  explicit CStubHeaderGen(std::shared_ptr<Document> doc);
+  virtual ~CStubHeaderGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceRegister(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceUnregister(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceClientNumberGetter(std::ofstream& stream,
+                                       const Interface& inf);
+
+ private:
+  void GenInterfaceContextDeclaration(std::ofstream& stream,
+                                      const Interface& inf);
+  void GenInterfaceContextTagSetter(std::ofstream& stream,
+                                    const Interface& inf);
+  void GenInterfaceContextTagGetter(std::ofstream& stream,
+                                    const Interface& inf);
+  void GenInterfaceContextSenderGetter(std::ofstream& stream,
+                                       const Interface& inf);
+
+ private:
+  void GenInterfaceDelegator(std::ofstream& stream,
+                             const std::string& id,
+                             const Declaration& decl);
+  void GenInterfaceDelegatorDeclaration(std::ofstream& stream,
+                                        const std::string& id,
+                                        const Declaration& decl);
+  void GenInterfaceDelegatorDestructor(std::ofstream& stream,
+                                      const std::string& id,
+                                      const Declaration& decl);
+  void GenInterfaceDelegatorCloner(std::ofstream& stream,
+                                  const std::string& id,
+                                  const Declaration& decl);
+  void GenInterfaceDelegatorInvoker(std::ofstream& stream,
+                                   const std::string& id,
+                                   const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_C_GEN_C_STUB_HEADER_GEN_H_
diff --git a/idlc/gen/c_stub_header_gen_cb.h b/idlc/gen/c_stub_header_gen_cb.h
new file mode 100644 (file)
index 0000000..49e37f0
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
+#define IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
+
+const char CB_INTERFACE_DECL[] =
+R"__c_cb(
+typedef struct {
+    void (*create)(rpc_port_stub_##_context_h context, void *user_data);
+    void (*terminate)(rpc_port_stub_##_context_h context, void *user_data);
+$$
+} rpc_port_stub_##_callback_s;
+)__c_cb";
+
+const char CB_INTERFACE_CALLBACK[] =
+R"__c_cb($$(*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_DECL[] =
+R"__c_cb(
+typedef struct ##_context_s* rpc_port_stub_##_context_h;
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_SET_TAG[] =
+R"__c_cb(
+int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag);
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_GET_TAG[] =
+R"__c_cb(
+int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag);
+)__c_cb";
+
+const char CB_INTERFACE_CONTEXT_GET_SENDER[] =
+R"__c_cb(
+int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender);
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_DECL[] =
+R"__c_cb(
+typedef struct ##_s *rpc_port_##_h;
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_DTOR[] =
+R"__c_cb(
+int rpc_port_##_destroy(rpc_port_##_h h);
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_CLONER[] =
+R"__c_cb(
+int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone);
+)__c_cb";
+
+const char CB_INTERFACE_DELEGATOR_INVOKER[] =
+R"__c_cb(
+int rpc_port_##_invoke(rpc_port_##_h h$$);
+)__c_cb";
+
+const char CB_INTERFACE_REGISTER[] =
+R"__c_cb(
+int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_data);
+)__c_cb";
+
+const char CB_INTERFACE_UNREGISTER[] =
+R"__c_cb(
+int rpc_port_stub_##_unregister(void);
+)__c_cb";
+
+const char CB_INTERFACE_CLIENT_NUMBER_GETTER[] =
+R"__c_cb(
+int rpc_port_stub_##_get_client_number(unsigned int *n);
+)__c_cb";
+
+#endif  // IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
diff --git a/idlc/gen/cpp_gen_base.cc b/idlc/gen/cpp_gen_base.cc
new file mode 100644 (file)
index 0000000..b9ffb69
--- /dev/null
@@ -0,0 +1,703 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ctime>
+#include <vector>
+#include <utility>
+
+#include "idlc/gen/cpp_gen_base.h"
+
+namespace {
+#include "idlc/gen/cpp_gen_base_cb.h"
+}
+
+namespace tidl {
+
+CppGeneratorBase::CppGeneratorBase(std::shared_ptr<Document> doc)
+    : Generator(doc) {
+  type_map_ = {
+      {"char", "char"}, {"int", "int"}, {"short", "short"},
+      {"long", "long long"}, {"string", "std::string"}, {"bool", "bool"},
+      {"list", "std::list"}, {"float", "float"}, {"double", "double"},
+      {"bundle", "Bundle"}, {"void", "void"}, {"array", "std::vector"}
+  };
+
+  parcel_type_map_ = {
+    {"char", "byte"},
+    {"int", "int32"},
+    {"short", "int16"},
+    {"long", "int64"},
+    {"string", "string"},
+    {"bool", "bool"},
+    {"float", "float"},
+    {"double", "double"},
+    {"bundle", "bundle"},
+  };
+
+  type_init_map_ = {
+    {"char", "0"},
+    {"int", "0"},
+    {"short", "0"},
+    {"long", "0"},
+    {"bool", "false"},
+    {"float", "0.0f"},
+    {"double", "0.0"},
+  };
+}
+
+void CppGeneratorBase::GenStructuresForHeader(std::ofstream& stream) {
+  stream << CB_BUNDLE;
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenStructureForHeader(stream, st);
+    stream << std::endl;
+  }
+}
+
+void CppGeneratorBase::GenStructureForHeader(std::ofstream& stream,
+                                             const Structure& st) {
+  const char ctor[] = "  $$();\n" \
+                      "  $$($$);\n";
+  const char variable[] = "$$\n";
+
+  stream << "class " << st.GetID() << " final ";
+
+  GenBrace(stream, 0, [&]() {
+    stream << " public:" << NLine(1);
+    GenTemplate(ctor, stream,
+      [&]()->std::string {
+        return st.GetID();
+      },
+      [&]()->std::string {
+        return st.GetID();
+      },
+      [&]()->std::string {
+        std::string str;
+        int n = 1;
+        for (auto& i : st.GetElements().GetElms()) {
+          if (n != 1)
+            str += ", ";
+          str += ConvertTypeToString(i->GetType()) + " " + i->GetID();
+          n++;
+        }
+        return str;
+      });
+
+    stream << NLine(1);
+    for (auto& i : st.GetElements().GetElms()) {
+      GenSetter(stream, *i);
+      GenGetter(stream, *i);
+      stream << NLine(1);
+    }
+
+    stream << " private:";
+    GenTemplate(variable, stream,
+      [&]()->std::string {
+        std::string str;
+        for (auto& i : st.GetElements().GetElms()) {
+          str += NLine(1) + Tab(1)
+              + ConvertTypeToString(i->GetType()) + " "
+              + i->GetID() + "_";
+          if (type_init_map_.find(i->GetType().ToString())
+              == type_init_map_.end()) {
+            str += ";";
+          } else {
+            str += " = " + type_init_map_[i->GetType().ToString()] + ";";
+          }
+        }
+        str += NLine(1);
+        return str;
+      });
+  }, false, false);
+  stream << ";" << NLine(1);
+}
+
+void CppGeneratorBase::GenSetter(std::ofstream& stream, const Element& ele) {
+  const char setter[] =
+      "void Set$$($$ $$) {\n" \
+      "  $$_ = $$;\n" \
+      "}\n";
+
+  GenTemplate(AddIndent(TAB_SIZE, setter, true), stream,
+    [&]()->std::string {
+      return ele.GetID();
+    },
+    [&]()->std::string {
+      return ConvertTypeToString(ele.GetType());
+    },
+    [&]()->std::string {
+      return ele.GetID();
+    },
+    [&]()->std::string {
+      return ele.GetID();
+    },
+    [&]()->std::string {
+      if (ele.GetType().IsUserDefinedType() ||
+        ele.GetType().GetMetaType() != nullptr ||
+        ele.GetType().ToString() == "string" ||
+        ele.GetType().ToString() == "bundle") {
+        return "std::move(" + ele.GetID() + ")";
+      }
+
+      return ele.GetID();
+    });
+  stream << NLine(1);
+}
+
+void CppGeneratorBase::GenGetter(std::ofstream& stream, const Element& ele) {
+  const char getter[] =
+      "$$ Get$$() const {\n" \
+      "  return $$_;\n" \
+      "}\n";
+
+  GenTemplate(AddIndent(TAB_SIZE, getter, true), stream,
+    [&]()->std::string {
+      if (ele.GetType().IsUserDefinedType() ||
+        ele.GetType().GetMetaType() != nullptr ||
+        ele.GetType().ToString() == "string" ||
+        ele.GetType().ToString() == "bundle") {
+        return "const " + ConvertTypeToString(ele.GetType()) + "&";
+      }
+
+      return ConvertTypeToString(ele.GetType());
+    },
+    [&]()->std::string {
+      return ele.GetID();
+    },
+    [&]()->std::string {
+      return ele.GetID();
+    });
+}
+
+void CppGeneratorBase::GenStructuresForBody(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenStructureForBody(stream, st);
+    stream << std::endl;
+  }
+}
+
+void CppGeneratorBase::GenStructureForBody(std::ofstream& stream,
+    const Structure& st) {
+  std::vector<std::pair<std::string, std::string>> v;
+  const char ctor[] = "##::##() {}\n\n" \
+                      "##::##($$)\n" \
+                      "    : $$ {}";
+
+  for (auto& i : st.GetElements().GetElms()) {
+    std::pair<std::string, std::string> p;
+
+    p.first = ConvertTypeToString(i->GetType());
+    p.second = i->GetID();
+    v.push_back(p);
+  }
+
+  GenTemplate(ReplaceAll(ctor, "##", st.GetID()), stream,
+    [&]()->std::string {
+      std::string str;
+      for (auto& i : v) {
+        str += i.first + " " + i.second;
+
+        if (i != v.back())
+          str += ", ";
+      }
+      return str;
+    },
+    [&]()->std::string {
+      std::string str;
+      for (auto& i : v) {
+        str += i.second + "_(std::move(" + i.second + "))";
+
+        if (i != v.back())
+          str += ", ";
+      }
+      return str;
+    });
+  stream <<  NLine(2);
+}
+
+void CppGeneratorBase::GenSerializer(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenSerializer(stream, st);
+    stream << NLine(1);
+  }
+}
+
+void CppGeneratorBase::GenPrototype(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenSerializer(stream, st, true);
+    GenDeSerializer(stream, st, true);
+  }
+  GenListSerializer(stream, true);
+  stream << NLine(1);
+}
+
+void CppGeneratorBase::GenSerializer(std::ofstream& stream, const Structure& st,
+                                     bool proto) {
+  const char parcel_str[] = "rpc_port_parcel_h";
+
+  stream << parcel_str << " operator << ("
+         << parcel_str << " h, const " << st.GetID() << "& param)";
+  if (proto) {
+    stream << ";" << NLine(1);
+    return;
+  }
+
+  stream << " ";
+  GenBrace(stream, 0, [&]() {
+    for (auto& i : st.GetElements().GetElms()) {
+      stream << AddIndent(TAB_SIZE,
+          ConvertTypeToSerializer(i->GetType(),
+              "param.Get" + i->GetID() + "()", "h"));
+    }
+    stream << Tab(1) << "return h;" << NLine(1);
+  }, false);
+}
+
+void CppGeneratorBase::GenDeSerializer(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenDeSerializer(stream, st);
+    stream << std::endl;
+  }
+}
+
+void CppGeneratorBase::GenDeSerializer(std::ofstream& stream,
+                                       const Structure& st, bool proto) {
+  const char parcel_str[] = "rpc_port_parcel_h";
+
+  stream << parcel_str << " operator >> ("
+         << parcel_str << " h, " << st.GetID() << "& param)";
+  if (proto) {
+    stream << ";" << NLine(1);
+    return;
+  }
+
+  stream << " ";
+  GenBrace(stream, 0, [&]() {
+    for (auto& i : st.GetElements().GetElms()) {
+      stream << AddIndent(TAB_SIZE,
+          ConvertTypeToDeserializer(i->GetType(), i->GetID(), "h"));
+      stream << Tab(1) << "param.Set" << i->GetID() << "(std::move("
+             << i->GetID() << "));" << NLine(2);
+    }
+    stream << Tab(1) << "return h;" << NLine(1);
+  }, false);
+}
+
+std::string CppGeneratorBase::ConvertTypeToString(const BaseType& type) {
+  if (type.IsUserDefinedType()) {
+    if (IsDelegateType(type)) {
+      return "std::unique_ptr<" + type.ToString() + ">";
+    }
+    return type.ToString();
+  }
+
+  if (type.GetMetaType() != nullptr)
+    return type_map_[type.ToString()] + "<" +
+        ConvertTypeToString(*(type.GetMetaType())) + ">";
+
+  return type_map_[type.ToString()];
+}
+
+std::string CppGeneratorBase::Tab(int cnt) {
+  std::string t(cnt * 2, ' ');
+
+  return t;
+}
+
+std::string CppGeneratorBase::NLine(int cnt) {
+  std::string t(cnt, '\n');
+
+  return t;
+}
+
+void CppGeneratorBase::AddSerializerList(const BaseType& type) {
+  if (type.GetMetaType() != nullptr) {
+    serializer_list_[ConvertTypeToString(type)] = &type;
+    AddSerializerList(*type.GetMetaType());
+  }
+}
+
+void CppGeneratorBase::GenListSerializer(std::ofstream& stream,
+                                         const BaseType& type, bool proto) {
+  stream << "rpc_port_parcel_h operator << (rpc_port_parcel_h h, const "
+         << ConvertTypeToString(type) << "& c)";
+
+  if (proto) {
+    stream << ";" << NLine(1);
+    stream << "rpc_port_parcel_h operator >> (rpc_port_parcel_h h, "
+           << ConvertTypeToString(type) << "& c);" << NLine(1);
+    return;
+  }
+
+  stream << " ";
+  GenBrace(stream, 0, [&]() {
+    stream << Tab(1)
+           << "rpc_port_parcel_write_array_count(h, c.size());"
+           << NLine(1);
+    stream << Tab(1) << "for (const auto& i : c) ";
+    GenBrace(stream, TAB_SIZE, [&]() {
+      auto& mt = *type.GetMetaType();
+      stream << AddIndent(TAB_SIZE * 2, ConvertTypeToSerializer(mt, "i", "h"));
+    }, false);
+    stream << Tab(1) << "return h;" << NLine(1);
+  }, false);
+  stream << NLine(1);
+
+  stream << "rpc_port_parcel_h operator >> (rpc_port_parcel_h h, "
+         << ConvertTypeToString(type) << "& c) ";
+  GenBrace(stream, 0, [&]() {
+    stream << Tab(1) << "int l = 0;" << NLine(1);
+    stream << Tab(1)
+           << "rpc_port_parcel_read_array_count(h, &l);" << NLine(1);
+    stream << Tab(1) << "for (int i = 0; i < l; i++) ";
+    GenBrace(stream, TAB_SIZE, [&]() {
+      auto& mt = *type.GetMetaType();
+      stream << AddIndent(TAB_SIZE * 2,
+          ConvertTypeToDeserializer(mt, "v", "h", true));
+      stream << Tab(2) << "c.push_back(std::move(v));" << NLine(1);
+    }, false);
+    stream << Tab(1) << "return h;" << NLine(1);
+  }, false);
+}
+
+void CppGeneratorBase::GenListSerializer(std::ofstream& stream, bool proto) {
+  serializer_list_.clear();
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() == Block::TYPE_STRUCTURE) {
+      const Structure& st = static_cast<const Structure&>(*i);
+      for (auto& j : st.GetElements().GetElms()) {
+        auto& t = j->GetType();
+        AddSerializerList(t);
+      }
+    } else if (i->GetType() == Block::TYPE_INTERFACE) {
+      const Interface& iface = static_cast<const Interface&>(*i);
+      for (auto& j : iface.GetDeclarations().GetDecls()) {
+        auto& t = j->GetType();
+        AddSerializerList(t);
+        for (auto& k : j->GetParameters().GetParams()) {
+          auto& t1 = k->GetParameterType().GetBaseType();
+          AddSerializerList(t1);
+        }
+      }
+    }
+  }
+
+  for (auto& p : serializer_list_) {
+    const BaseType* t = p.second;
+    GenListSerializer(stream, *t, proto);
+  }
+}
+
+void CppGeneratorBase::GenMethodId(std::ofstream& stream,
+                                   const Interface& iface) {
+  stream << Tab(1) << "enum class MethodId : int ";
+  GenBrace(stream, TAB_SIZE, [&]() {
+    int cnt = 2;
+    stream << Tab(2) << "__Result = 0," << NLine(1);
+    stream << Tab(2) << "__Callback = 1," << NLine(1);
+    for (auto& i : iface.GetDeclarations().GetDecls()) {
+      if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+        continue;
+      stream << Tab(2)
+             << i->GetID() << " = " << cnt++ << "," << NLine(1);
+    }
+  }, false, false);
+  stream << ";" << NLine(2);
+}
+
+void CppGeneratorBase::GenDelegateId(std::ofstream& stream,
+                                     const Interface& iface) {
+  stream << Tab(1) << "enum class DelegateId : int ";
+  GenBrace(stream, TAB_SIZE, [&]() {
+    int cnt = 1;
+    for (auto& i : iface.GetDeclarations().GetDecls()) {
+        if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+          continue;
+        stream << Tab(2)
+               << i->GetID() << " = " << cnt++ << "," << NLine(1);
+    }
+  }, false, false);
+  stream << ";" << NLine(2);
+}
+
+void CppGeneratorBase::GenParameters(std::ofstream& stream,
+                                     const Parameters& ps) {
+  stream << GetParameters(ps);
+}
+
+std::string CppGeneratorBase::GetParameters(const Parameters& ps) {
+  bool first = true;
+  std::string ret;
+  for (auto& i : ps.GetParams()) {
+    if (!first) {
+      ret += ", ";
+    }
+
+    std::string ref;
+    auto dir = i->GetParameterType().GetDirection();
+    if (dir == ParameterType::Direction::OUT ||
+        dir == ParameterType::Direction::REF) {
+      ref = "&";
+    }
+
+    ret += ConvertTypeToString(i->GetParameterType().GetBaseType())
+        + ref + " " + i->GetID();
+    first = false;
+  }
+
+  return ret;
+}
+
+void CppGeneratorBase::GenDeclaration(std::ofstream& stream,
+                                     const Interface& iface,
+                                     const Declaration& decl) {
+  stream << ConvertTypeToString(decl.GetType()) << " " << iface.GetID() << "::"
+         << decl.GetID() << "(";
+  GenParameters(stream, decl.GetParameters());
+  stream << ") ";
+}
+
+std::string CppGeneratorBase::ConvertTypeToSerializer(
+    const BaseType& type, std::string id, std::string parcel) {
+  std::string ret;
+
+  if (type.ToString() == "string") {
+    ret += "rpc_port_parcel_write_"
+        + parcel_type_map_[type.ToString()]
+        + "(" + parcel + ", " + id + ".c_str());\n";
+  } else if (type.ToString() == "bundle") {
+    ret += "rpc_port_parcel_write_bundle(" + parcel + ", "
+        + id + ".GetHandle());\n";
+  } else if (type.GetMetaType() || type.IsUserDefinedType()) {
+    if (type.IsUserDefinedType() && IsDelegateType(type))
+      ret += parcel + " << *" + id + ";\n";
+    else
+      ret += parcel + " << " + id + ";\n";
+  } else {
+    ret += "rpc_port_parcel_write_"
+        + parcel_type_map_[type.ToString()]
+        + "(" + parcel + ", " + id + ");\n";
+  }
+
+  return ret;
+}
+
+std::string CppGeneratorBase::ConvertTypeToDeserializer(
+    const BaseType& type, std::string id, std::string parcel,
+    bool make_new_type) {
+  std::string ret;
+
+  if (type.ToString() == "string") {
+    ret += "char* " + id + "_raw  = nullptr;\n";
+    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
+        + "(" + parcel + ", &" + id + "_raw);\n";
+    if (make_new_type) {
+      ret += "std::string " + id + "(" + id + "_raw);\n";
+    } else {
+      ret += id + " = " + id + "_raw;\n";
+    }
+    ret += "free(" + id + "_raw);\n";
+  } else if (type.ToString() == "bundle") {
+    ret += "bundle* " + id + "_raw = nullptr;\n";
+    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
+        + "(" + parcel + ", &" + id + "_raw);\n";
+    if (make_new_type) {
+      ret += "Bundle " + id + "(" + id + "_raw);\n";
+    } else {
+      ret +=  id + " = " + id + "_raw;\n"
+          + "bundle_free(" + id + "_raw);\n";
+    }
+  } else if (type.GetMetaType() != nullptr || type.IsUserDefinedType()) {
+    std::string n;
+
+    if (type.GetMetaType() != nullptr || IsDelegateType(type))
+      n = ConvertTypeToString(type);
+    else
+      n = type.ToString();
+
+    if (make_new_type) {
+      ret += n + " ";
+      if (IsDelegateType(type)) {
+        ret += id + "(new " + type.ToString()
+            + "(callback_port, std::weak_ptr<ServiceBase>(b)));\n";
+      } else {
+        ret += id + ";\n";
+      }
+    }
+    if (IsDelegateType(type))
+      ret += parcel + " >> *" + id + ";\n";
+    else
+      ret += parcel + " >> " + id + ";\n";
+  } else {
+    if (make_new_type)
+      ret += ConvertTypeToString(type) + " " + id + ";\n";
+    ret += "rpc_port_parcel_read_" + parcel_type_map_[type.ToString()]
+        + "(" + parcel + ", &" + id + ");\n";
+  }
+
+  return ret;
+}
+
+void CppGeneratorBase::GenBodyCallbacks(std::ofstream& stream,
+                                   const Interface& iface, bool is_proxy) {
+  stream << ReplaceAll(CB_CALLBACK_BASE, "##", iface.GetID());
+
+  for (auto& i : iface.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+          continue;
+    GenBodyCallback(stream, iface, *i, is_proxy);
+  }
+}
+
+void CppGeneratorBase::GenBodyCallback(std::ofstream& stream,
+    const Interface& iface, const Declaration& decl, bool is_proxy) {
+  if (!is_proxy) {
+    GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream,
+      [&]()->std::string {
+        return iface.GetID();
+      },
+      [&]()->std::string {
+        return decl.GetID();
+      },
+      [&]()->std::string {
+        return GetParameters(decl.GetParameters());
+      },
+      [&]()->std::string {
+        std::string m;
+        for (auto& i : decl.GetParameters().GetParams()) {
+          auto& pt = i->GetParameterType();
+          m += AddIndent(TAB_SIZE,
+              ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p"));
+        }
+        return m;
+      });
+  } else {
+    GenTemplate(CB_CALLBACK_ON_RECEIVED_EVENT_METHOD, stream,
+      [&]()->std::string {
+        return iface.GetID();
+      },
+      [&]()->std::string {
+        return decl.GetID();
+      },
+      [&]()->std::string {
+        int cnt = 1;
+        std::string ret;
+        for (auto& i : decl.GetParameters().GetParams()) {
+          std::string v = "param" + std::to_string(cnt);
+          std::string c = ConvertTypeToDeserializer(
+              i->GetParameterType().GetBaseType(), v, "parcel");
+          ret += AddIndent(TAB_SIZE, c) + NLine(1);
+          cnt++;
+        }
+
+        cnt = 1;
+        ret += Tab(1) + "OnReceived(";
+        for (int i = 0; i < decl.GetParameters().GetParams().size(); i++) {
+          if (cnt != 1) {
+            ret += ", ";
+          }
+          ret += "std::move(param" + std::to_string(cnt) + ")";
+          cnt++;
+        }
+        ret += ");";
+
+        return ret;
+      });
+  }
+}
+
+void CppGeneratorBase::GenHeaderCallbacks(std::ofstream& stream,
+                                          const Interface& iface,
+                                          bool is_proxy) {
+  stream << CB_CALLBACK_BASE_HEADER_FRONT;
+  if (is_proxy) {
+    stream << Tab(1)
+           << "  virtual void OnReceivedEvent(rpc_port_parcel_h port) = 0;"
+           << NLine(1);
+  }
+  stream << CB_CALLBACK_BASE_HEADER_BACK;
+
+  for (auto& i : iface.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+          continue;
+    GenHeaderCallback(stream, *i, is_proxy);
+  }
+}
+
+void CppGeneratorBase::GenHeaderCallback(std::ofstream& stream,
+                                         const Declaration& decl,
+                                         bool is_proxy) {
+  stream << GenTemplateString(CB_CALLBACK_CLASS,
+      [&]()->std::string {
+        return decl.GetID();
+      },
+      [&]()->std::string {
+        return ReplaceAll(
+            is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB,
+            "##", decl.GetID());
+      },
+      [&]()->std::string {
+        std::string ret;
+        if (is_proxy) {
+          ret = Tab(2) + "virtual void OnReceived("
+              + GetParameters(decl.GetParameters())
+              + ") {}" + NLine(1);
+        } else {
+          ret = Tab(2) + "void Invoke("
+              + GetParameters(decl.GetParameters())
+              + ");" + NLine(1);
+        }
+
+        return ret;
+      },
+      [&]()->std::string {
+        return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB;
+      });
+}
+
+void CppGeneratorBase::GenVersion(std::ofstream& stream) {
+  GenTemplate(CB_VERSION, stream,
+    [&]()->std::string {
+      return FULLVER;
+    });
+}
+
+void CppGeneratorBase::GenLogTag(std::ofstream& stream, std::string id) {
+  GenTemplate(CB_LOG_TAG, stream,
+      [&]()->std::string {
+        return id;
+      });
+}
+
+void CppGeneratorBase::GenLogDefinition(std::ofstream& stream) {
+  stream << CB_LOG_DEF;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cpp_gen_base.h b/idlc/gen/cpp_gen_base.h
new file mode 100644 (file)
index 0000000..d0e37d1
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_GEN_BASE_H_
+#define IDLC_CPP_GEN_CPP_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/structure.h"
+#include "idlc/gen/generator.h"
+
+namespace tidl {
+
+class CppGeneratorBase : public Generator {
+ public:
+  explicit CppGeneratorBase(std::shared_ptr<Document> doc);
+  virtual ~CppGeneratorBase() = default;
+
+  void GenVersion(std::ofstream& stream);
+  void GenStructuresForHeader(std::ofstream& stream);
+  void GenStructuresForBody(std::ofstream& stream);
+  void GenSerializer(std::ofstream& stream);
+  void GenDeSerializer(std::ofstream& stream);
+  void GenListSerializer(std::ofstream& stream, bool proto = false);
+  void GenPrototype(std::ofstream& stream);
+  void GenMethodId(std::ofstream& stream, const Interface& iface);
+  void GenDelegateId(std::ofstream& stream, const Interface& iface);
+  void GenParameters(std::ofstream& stream, const Parameters& ps);
+  void GenDeclaration(std::ofstream& stream, const Interface& iface,
+                      const Declaration& decl);
+  void GenBodyCallbacks(std::ofstream& stream, const Interface& iface,
+                        bool is_proxy);
+  void GenHeaderCallbacks(std::ofstream& stream, const Interface& iface,
+                          bool is_proxy);
+  std::string ConvertTypeToString(const BaseType& type);
+  std::string Tab(int cnt);
+  std::string NLine(int cnt);
+  std::string ConvertTypeToDeserializer(const BaseType& type,
+                                        std::string id, std::string parcel,
+                                        bool make_new_type = true);
+  std::string ConvertTypeToSerializer(const BaseType& type,
+                                      std::string id, std::string parcel);
+  std::string GetParameters(const Parameters& ps);
+  void GenLogTag(std::ofstream& stream, std::string id);
+  void GenLogDefinition(std::ofstream& stream);
+
+ private:
+  void GenSetter(std::ofstream& stream, const Element& ele);
+  void GenGetter(std::ofstream& stream, const Element& ele);
+  void AddSerializerList(const BaseType& type);
+  void GenListSerializer(std::ofstream& stream, const BaseType& type,
+                         bool proto = false);
+  void GenDeSerializer(std::ofstream& stream, const Structure& st,
+                       bool proto = false);
+  void GenSerializer(std::ofstream& stream, const Structure& st,
+                     bool proto = false);
+  void GenStructureForHeader(std::ofstream& stream, const Structure& st);
+  void GenStructureForBody(std::ofstream& stream, const Structure& st);
+  void GenBodyCallback(std::ofstream& stream, const Interface& iface,
+                       const Declaration& decl, bool is_proxy);
+  void GenHeaderCallback(std::ofstream& stream, const Declaration& decl,
+                         bool is_proxy);
+
+ protected:
+  const int TAB_SIZE = 2;
+
+ private:
+  std::map<std::string, std::string> type_map_;
+  std::map<std::string, std::string> parcel_type_map_;
+  std::map<std::string, std::string> type_init_map_;
+  std::map<std::string, const BaseType*> serializer_list_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CPP_GEN_CPP_GEN_BASE_H_
diff --git a/idlc/gen/cpp_gen_base_cb.h b/idlc/gen/cpp_gen_base_cb.h
new file mode 100644 (file)
index 0000000..56216c4
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
+#define IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
+
+const char CB_BUNDLE[] = R"__cls_bundle(class Bundle final {
+ public:
+  Bundle() {
+    raw_ = bundle_create();
+  }
+
+  Bundle(bundle* b) {
+    raw_ = b;
+  }
+
+  ~Bundle() {
+    if (raw_)
+      bundle_free(raw_);
+  }
+
+  Bundle(Bundle&& b) : raw_(b.raw_) {
+    b.raw_ = nullptr;
+  }
+
+  Bundle& operator = (Bundle&& b) {
+    raw_ = b.raw_;
+    b.raw_ = nullptr;
+    return *this;
+  }
+
+  Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
+
+  Bundle& operator = (const Bundle& b) {
+    raw_ = bundle_dup(b.GetHandle());
+    return *this;
+  }
+
+  bundle* GetHandle() const {
+    return raw_;
+  }
+
+ private:
+  bundle* raw_;
+};
+
+)__cls_bundle";
+
+const char CB_CALLBACK_BASE[] =
+R"__cpp_cb(
+std::atomic<int> ##::CallbackBase::seq_num_ { 0 };
+
+##::CallbackBase::CallbackBase(int delegate_id, bool once)
+    : id_(delegate_id), once_(once) {
+  seq_id_ = seq_num_++;
+}
+
+int ##::CallbackBase::GetId() const {
+  return id_;
+}
+
+int ##::CallbackBase::GetSeqId() const {
+  return seq_id_;
+}
+
+bool ##::CallbackBase::IsOnce() const {
+  return once_;
+}
+
+std::string ##::CallbackBase::GetTag() const {
+  return std::to_string(id_) + "::" + std::to_string(seq_id_);
+}
+
+rpc_port_parcel_h operator << (rpc_port_parcel_h h, const ##::CallbackBase& cb) {
+  rpc_port_parcel_write_int32(h, cb.id_);
+  rpc_port_parcel_write_int32(h, cb.seq_id_);
+  rpc_port_parcel_write_bool(h, cb.once_);
+
+  return h;
+}
+
+rpc_port_parcel_h operator >> (rpc_port_parcel_h h, ##::CallbackBase& cb) {
+  rpc_port_parcel_read_int32(h, &cb.id_);
+  rpc_port_parcel_read_int32(h, &cb.seq_id_);
+  rpc_port_parcel_read_bool(h, &cb.once_);
+
+  return h;
+}
+)__cpp_cb";
+
+const char CB_VERSION[] =
+R"__cpp_cb(/*
+ * Generated by tidlc $$.
+ */
+)__cpp_cb";
+
+const char CB_CALLBACK_BASE_HEADER_FRONT[] =
+R"__cpp_cb(
+  class CallbackBase {
+   public:
+    CallbackBase(int delegate_id, bool once);
+    virtual ~CallbackBase() = default;
+)__cpp_cb";
+
+const char CB_CALLBACK_BASE_HEADER_BACK[] =
+R"__cpp_cb(
+    int GetId() const;
+    int GetSeqId() const;
+    bool IsOnce() const;
+    std::string GetTag() const;
+
+   private:
+    friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb);
+    friend rpc_port_parcel_h operator >> (rpc_port_parcel_h h, CallbackBase& cb);
+
+    static std::atomic<int> seq_num_;
+    int id_;
+    int seq_id_;
+    bool once_;
+  };
+)__cpp_cb";
+
+const char CB_CALLBACK_CLASS[] =
+R"__cpp_cb(
+  class $$ : public CallbackBase {
+   public:$$
+$$
+   private:$$
+  };
+)__cpp_cb";
+
+const char CB_CALLBACK_CTOR_STUB[] =
+R"__cpp_cb(
+    ##(rpc_port_h port, std::weak_ptr<ServiceBase> service)
+        : CallbackBase(static_cast<int>(DelegateId::##), false) {
+      port_ = port;
+      service_ = std::move(service);
+    }
+)__cpp_cb";
+
+const char CB_CALLBACK_CTOR_PROXY[] =
+R"__cpp_cb(
+    ##(bool once = false)
+        : CallbackBase(static_cast<int>(DelegateId::##), once) {}
+)__cpp_cb";
+
+const char CB_CALLBACK_PRIVATE_PROXY[] =
+R"__cpp_cb(
+    void OnReceivedEvent(rpc_port_parcel_h port) override;
+)__cpp_cb";
+
+const char CB_CALLBACK_PRIVATE_STUB[] =
+R"__cpp_cb(
+    rpc_port_h port_;
+    std::weak_ptr<ServiceBase> service_;
+    bool valid_ = true;
+)__cpp_cb";
+
+const char CB_CALLBACK_INVOKE_METHOD[] =
+R"__cpp_cb(
+void $$::$$::Invoke($$) {
+  if (port_ == nullptr)
+      throw NotConnectedSocketException();
+  if (service_.lock().get() == nullptr)
+      throw NotConnectedSocketException();
+
+  if (IsOnce() && !valid_)
+      throw InvalidCallbackException();
+
+  rpc_port_parcel_h p;
+  rpc_port_parcel_create(&p);
+  rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::__Callback));
+  p << *this;
+$$
+  // Send
+  set_last_result(rpc_port_parcel_send(p, port_));
+  rpc_port_parcel_destroy(p);
+  valid_ = false;
+}
+)__cpp_cb";
+
+const char CB_CALLBACK_ON_RECEIVED_EVENT_METHOD[] =
+R"__cpp_cb(
+void $$::$$::OnReceivedEvent(rpc_port_parcel_h parcel) {
+$$
+}
+)__cpp_cb";
+
+const char CB_LOG_TAG[] =
+R"__cpp_cb(
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "$$"
+)__cpp_cb";
+
+const char CB_LOG_DEF[] =
+R"__cpp_cb(
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
+)__cpp_cb";
+
+#endif  // IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
diff --git a/idlc/gen/cpp_proxy_body_gen.cc b/idlc/gen/cpp_proxy_body_gen.cc
new file mode 100644 (file)
index 0000000..c6afe03
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cpp_proxy_body_gen.h"
+
+namespace {
+#include "idlc/gen/cpp_proxy_body_gen_cb.h"
+}
+
+namespace tidl {
+
+CppProxyBodyGen::CppProxyBodyGen(std::shared_ptr<Document> doc)
+    : CppGeneratorBase(doc) {}
+
+void CppProxyBodyGen::OnInitGen(std::ofstream& stream) {
+  std::string key(".cc");
+  std::string header_file = FileName;
+
+  std::size_t found = header_file.rfind(key);
+  if (found != std::string::npos)
+    header_file.replace(found, key.length(), ".h");
+
+  GenVersion(stream);
+  stream << NLine(1);
+  stream << "#include <stdlib.h>" << NLine(1)
+         << "#include <assert.h>" << NLine(1)
+         << "#include <dlog.h>" << NLine(1)
+         <<  NLine(1)
+         << "#include \"" << header_file << "\"" << NLine(2);
+  GenLogTag(stream, "RPC_PORT_PROXY");
+  GenLogDefinition(stream);
+  stream << NLine(1);
+  GenNamespace(stream);
+}
+
+void CppProxyBodyGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CppProxyBodyGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace rpc_port ";
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << " ";
+    GenBrace(stream, 0, [&]() {
+      stream <<  NLine(1);
+      GenStructuresForBody(stream);
+      stream << "namespace proxy ";
+      GenBrace(stream, 0, [&]() {
+        GenPrototype(stream);
+        GenSerializer(stream);
+        GenDeSerializer(stream);
+        GenListSerializer(stream);
+        GenInterfaces(stream);
+      }, false, false);
+      stream << "  // namespace proxy" + NLine(1);
+    }, false, false);
+    stream << "  // namespace " + GetFileNamespace() + NLine(1);
+  }, false, false);
+  stream << "  // namespace rpc_port" + NLine(1);
+}
+
+void CppProxyBodyGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+  }
+}
+
+void CppProxyBodyGen::GenInterface(std::ofstream& stream,
+                                   const Interface& iface) {
+  GenBodyCallbacks(stream, iface, true);
+  GenConstructor(stream, iface);
+  GenDestructor(stream, iface);
+  GenHelperMethods(stream, iface);
+  GenMethods(stream, iface);
+}
+
+void CppProxyBodyGen::GenConstructor(std::ofstream& stream,
+                                     const Interface& iface) {
+  GenTemplate(CB_PROXY_INTERFACE_CTOR, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    },
+    [&]()->std::string {
+      return iface.GetID();
+    });
+}
+
+void CppProxyBodyGen::GenDestructor(std::ofstream& stream,
+                                    const Interface& iface) {
+  GenTemplate(CB_DTOR, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    },
+    [&]()->std::string {
+      return iface.GetID();
+    });
+}
+
+void CppProxyBodyGen::GenHelperMethods(std::ofstream& stream,
+                                       const Interface& iface) {
+  stream << ReplaceAll(CB_PROXY_HELPER_METHODS, "##", iface.GetID())
+         << NLine(1);
+}
+
+void CppProxyBodyGen::GenMethods(std::ofstream& stream,
+                                 const Interface& iface) {
+  auto& decls = iface.GetDeclarations();
+
+  for (auto& i : decls.GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+
+    GenDeclaration(stream, iface, *i);
+    GenBrace(stream, 0, [&]() {
+      GenInvocation(stream, *i);
+    }, false);
+    stream << NLine(1);
+  }
+}
+
+void CppProxyBodyGen::GenInvocation(std::ofstream& stream,
+    const Declaration& decl) {
+  stream << CB_INVOCATION_PRE;
+
+  // Serialize
+  stream << Tab(1)
+         << "rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::"
+         << decl.GetID() << "));" << NLine(1);
+  std::string m;
+  std::string l;
+  for (auto& i : decl.GetParameters().GetParams()) {
+    auto& pt = i->GetParameterType();
+    if (pt.GetDirection() == ParameterType::Direction::OUT)
+      continue;
+    m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
+    if (IsDelegateType(pt.GetBaseType())) {
+      l += "delegate_list_.emplace_back(" + i->GetID() + ".release());\n";
+    }
+  }
+  stream << AddIndent(TAB_SIZE, m) << NLine(1);
+
+  if (decl.GetMethodType() == Declaration::MethodType::SYNC)
+    stream << Tab(1) << "rpc_port_parcel_h parcel_received;" << NLine(1);
+  stream << Tab(1) << "do ";
+  GenBrace(stream, TAB_SIZE, [&]() {
+    stream << Tab(2) << "std::lock_guard<std::recursive_mutex> lock(mutex_);"
+           << NLine(2);
+    if (!l.empty())
+      stream << AddIndent(TAB_SIZE * 2, l);
+    stream << CB_INVOCATION_MID << NLine(1);
+    if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
+      stream << Tab(2) << "// Receive" << NLine(1);
+      stream << Tab(2)
+             << "ConsumeCommand(&parcel_received, port_);" << NLine(1);
+    }
+  }, false, false);
+  stream << " while (false);" << NLine(1);
+
+  // Deserialize
+  if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
+    stream << Tab(1) << "rpc_port_parcel_destroy(p);"
+         << NLine(1);
+    return;
+  }
+
+  stream << CB_INVOCATION_RECEIVE << NLine(1);
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN) {
+      continue;
+    }
+
+    std::string c = ConvertTypeToDeserializer(
+        i->GetParameterType().GetBaseType(),
+        i->GetID(), "parcel_received", false);
+    if (c != "")
+      stream << AddIndent(TAB_SIZE, c);
+  }
+
+  if (decl.GetType().ToString() != "void") {
+    stream << AddIndent(TAB_SIZE,
+                        ConvertTypeToDeserializer(decl.GetType(),
+                                                "ret", "parcel_received"));
+  }
+
+  stream << CB_INVOCATION_END;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cpp_proxy_body_gen.h b/idlc/gen/cpp_proxy_body_gen.h
new file mode 100644 (file)
index 0000000..b6e7c1d
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
+#define IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cpp_gen_base.h"
+
+namespace tidl {
+
+class CppProxyBodyGen : public CppGeneratorBase {
+ public:
+  explicit CppProxyBodyGen(std::shared_ptr<Document> doc);
+  virtual ~CppProxyBodyGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenStructures(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenConstructor(std::ofstream& stream, const Interface& iface);
+  void GenDestructor(std::ofstream& stream, const Interface& iface);
+  void GenHelperMethods(std::ofstream& stream, const Interface& iface);
+  void GenMethods(std::ofstream& stream, const Interface& iface);
+  void GenInvocation(std::ofstream& stream, const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_H_
diff --git a/idlc/gen/cpp_proxy_body_gen_cb.h b/idlc/gen/cpp_proxy_body_gen_cb.h
new file mode 100644 (file)
index 0000000..b5dbefd
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
+
+const char CB_DTOR[] =
+R"__cpp_cb(
+$$::~$$() {
+  if (proxy_)
+    rpc_port_proxy_destroy(proxy_);
+}
+)__cpp_cb";
+
+const char CB_INVOCATION_PRE[] =
+R"__cpp_cb(  if (port_ == nullptr) {
+    _E("Not connected");
+    throw NotConnectedSocketException();
+  }
+
+  rpc_port_parcel_h p;
+  rpc_port_parcel_create(&p);
+)__cpp_cb";
+
+const char CB_INVOCATION_MID[] =
+R"__cpp_cb(
+    // Send
+    int r = rpc_port_parcel_send(p, port_);
+    if (r != RPC_PORT_ERROR_NONE) {
+      _E("Failed to send parcel. result(%d)", r);
+      rpc_port_parcel_destroy(p);
+      throw InvalidIOException();
+    }
+)__cpp_cb";
+
+const char CB_INVOCATION_RECEIVE[] =
+R"__cpp_cb(
+  if (parcel_received == nullptr) {
+    _E("Invalid protocol");
+    throw InvalidProtocolException();
+  }
+)__cpp_cb";
+
+const char CB_INVOCATION_END[] =
+R"__cpp_cb(
+  rpc_port_parcel_destroy(p);
+  rpc_port_parcel_destroy(parcel_received);
+
+  return ret;
+)__cpp_cb";
+
+const char CB_PROXY_HELPER_METHODS[] =
+R"__cpp_cb(
+void ##::Connect() {
+  int ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "##");
+  if (ret != RPC_PORT_ERROR_NONE) {
+    _E("Failed to connect ##");
+    switch (ret) {
+      case RPC_PORT_ERROR_INVALID_PARAMETER:
+        throw InvalidIDException();
+
+      case RPC_PORT_ERROR_IO_ERROR:
+        throw InvalidIOException();
+
+      case RPC_PORT_ERROR_PERMISSION_DENIED:
+        throw PermissionDeniedException();
+    }
+  }
+}
+
+void ##::DisposeCallback(const std::string& tag) {
+  for (auto& i : delegate_list_) {
+    if (i->GetTag() == tag) {
+      delegate_list_.remove(i);
+      return;
+    }
+  }
+}
+
+void ##::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
+  int id = 0;
+  int seq_id = 0;
+  bool once = false;
+
+  rpc_port_parcel_read_int32(parcel, &id);
+  rpc_port_parcel_read_int32(parcel, &seq_id);
+  rpc_port_parcel_read_bool(parcel, &once);
+
+  for (auto& i : delegate_list_) {
+    if (i->GetId() == id && i->GetSeqId() == seq_id) {
+      i->OnReceivedEvent(parcel);
+      if (i->IsOnce())
+        delegate_list_.remove(i);
+      break;
+    }
+  }
+}
+
+void ##::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
+  do {
+    rpc_port_parcel_h p;
+    int ret = rpc_port_parcel_create_from_port(&p, port);
+    int cmd;
+
+    if (ret != 0)
+      break;
+    rpc_port_parcel_read_int32(p, &cmd);
+    if (cmd == static_cast<int>(MethodId::__Result)) {
+      *parcel = p;
+      return;
+    }
+
+    rpc_port_parcel_destroy(p);
+    *parcel = nullptr;
+  } while (true);
+  *parcel = nullptr;
+}
+
+void ##::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
+  ##* l = static_cast<##*>(data);
+  rpc_port_h cb_port;
+
+  l->port_ = port;
+  rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
+  l->callback_port_ = cb_port;
+  l->listener_->OnConnected();
+}
+
+void ##::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
+  ##* l = static_cast<##*>(data);
+  l->delegate_list_.clear();
+  l->listener_->OnDisconnected();
+}
+
+void ##::OnRejectedCB(const char *ep, const char *port_name, void *data) {
+  ##* l = static_cast<##*>(data);
+  l->listener_->OnRejected();
+}
+
+void ##::OnReceivedCB(const char *ep, const char *port_name, void *data) {
+  ##* l = static_cast<##*>(data);
+  int cmd;
+  rpc_port_parcel_h parcel_received;
+
+  if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
+    _E("Failed to create parcel from port");
+    return;
+  }
+
+  rpc_port_parcel_read_int32(parcel_received, &cmd);
+  if (cmd != static_cast<int>(MethodId::__Callback)) {
+    rpc_port_parcel_destroy(parcel_received);
+    return;
+  }
+
+  l->ProcessReceivedEvent(parcel_received);
+  rpc_port_parcel_destroy(parcel_received);
+}
+)__cpp_cb";
+
+const char CB_PROXY_INTERFACE_CTOR[] =
+R"__cpp_cb(
+$$::$$(IEventListener* listener, const std::string& target_appid)
+    : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
+      listener_(listener), target_appid_(target_appid) {
+  int r = rpc_port_proxy_create(&proxy_);
+
+  if (r != RPC_PORT_ERROR_NONE) {
+    _E("Failed to create proxy");
+    throw InvalidIOException();
+  }
+
+  rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
+  rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
+  rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
+  rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
+}
+)__cpp_cb";
+
+#endif  // IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
diff --git a/idlc/gen/cpp_proxy_header_gen.cc b/idlc/gen/cpp_proxy_header_gen.cc
new file mode 100644 (file)
index 0000000..305cabc
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cpp_proxy_header_gen.h"
+
+namespace {
+#include "idlc/gen/cpp_proxy_header_gen_cb.h"
+}
+
+namespace tidl {
+
+CppProxyHeaderGen::CppProxyHeaderGen(std::shared_ptr<Document> doc)
+    : CppGeneratorBase(doc) {}
+
+void CppProxyHeaderGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << CB_HEADER;
+  GenNamespace(stream);
+}
+
+void CppProxyHeaderGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CppProxyHeaderGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace rpc_port ";
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << " ";
+    GenBrace(stream, 0, [&]() {
+      stream <<  NLine(1);
+      GenStructuresForHeader(stream);
+      stream << "namespace proxy ";
+      GenBrace(stream, 0, [&]() {
+        GenExceptions(stream);
+        GenInterfaces(stream);
+      }, false, false);
+      stream << "  // namespace proxy" + NLine(1);
+    }, false, false);
+    stream << "  // namespace " + GetFileNamespace() + NLine(1);
+  }, false, false);
+  stream << "  // namespace rpc_port" + NLine(1);
+}
+
+void CppProxyHeaderGen::GenExceptions(std::ofstream& stream) {
+  stream << CB_EXCEPTIONS;
+}
+
+void CppProxyHeaderGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+  }
+}
+
+void CppProxyHeaderGen::GenInterface(std::ofstream& stream,
+                                     const Interface& iface) {
+  stream << NLine(1) << "class " << iface.GetID() << " ";
+  GenBrace(stream, 0, [&]() {
+    stream << " public:" << NLine(1);
+    GenHeaderCallbacks(stream, iface, true);
+    GenTemplate(CB_PUBLIC_MEMBERS, stream,
+      [&]()->std::string {
+        return iface.GetID();
+      },
+      [&]()->std::string {
+        return iface.GetID();
+      });
+    GenMethods(stream, iface);
+    stream << NLine(1) << " private:" << NLine(1);
+    GenMethodId(stream, iface);
+    GenDelegateId(stream, iface);
+    stream << CB_PRIVATE_MEMBERS;
+  }, false, false);
+  stream << ";" << NLine(1);
+}
+
+void CppProxyHeaderGen::GenMethods(std::ofstream& stream,
+                                   const Interface& iface) {
+  auto& decls = iface.GetDeclarations();
+
+  for (auto& i : decls.GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+
+    GenDeclaration(stream, *i);
+  }
+}
+
+void CppProxyHeaderGen::GenDeclaration(std::ofstream& stream,
+                                       const Declaration& decl) {
+  if (!decl.GetComments().empty())
+    stream << NLine(1) << AddIndent(TAB_SIZE, decl.GetComments());
+
+  stream << Tab(1) << ConvertTypeToString(decl.GetType()) << " "
+         << decl.GetID() << "(";
+  GenParameters(stream, decl.GetParameters());
+  stream << ");" << NLine(1);
+}
+}  // namespace tidl
diff --git a/idlc/gen/cpp_proxy_header_gen.h b/idlc/gen/cpp_proxy_header_gen.h
new file mode 100644 (file)
index 0000000..e3ac8b5
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
+#define IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cpp_gen_base.h"
+
+namespace tidl {
+
+class CppProxyHeaderGen : public CppGeneratorBase {
+ public:
+  explicit CppProxyHeaderGen(std::shared_ptr<Document> doc);
+  virtual ~CppProxyHeaderGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenExceptions(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenMethods(std::ofstream& stream, const Interface& iface);
+  void GenDeclaration(std::ofstream& stream, const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_H_
diff --git a/idlc/gen/cpp_proxy_header_gen_cb.h b/idlc/gen/cpp_proxy_header_gen_cb.h
new file mode 100644 (file)
index 0000000..0bf19ee
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
+
+const char CB_EXCEPTIONS[] =
+R"__cpp_cb(
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
+class PermissionDeniedException : public Exception {};
+class InvalidIDException : public Exception {};
+)__cpp_cb";
+
+const char CB_PUBLIC_MEMBERS[] =
+R"__cpp_cb(
+  class IEventListener {
+   public:
+    /// <summary>
+    /// This method will be invoked when the client app is connected to the servicece app.
+    /// </summary>
+    virtual void OnConnected() = 0;
+
+    /// <summary>
+    /// This method will be invoked after the client app was disconnected from the servicece app.
+    /// </summary>
+    virtual void OnDisconnected() = 0;
+
+    /// <summary>
+    /// This method will be invoked when the service app rejects the client app.
+    /// </summary>
+    virtual void OnRejected() = 0;
+  };
+
+  /// <summary>
+  /// Constructor for this class
+  /// </summary>
+  /// <param name="listener">The listener for events</param>
+  /// <param name="target_appid">The service app ID to connect</param>
+  $$(IEventListener* listener, const std::string& target_appid);
+
+  /// <summary>
+  /// Destructor for this class
+  /// </summary>
+  virtual ~$$();
+
+  /// <summary>
+  /// Connects to the service app.
+  /// </summary>
+  /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+  /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+  /// <exception cref="InvalidIDException">
+  /// Thrown when the appid to connect is invalid.
+  /// </exception>
+  /// <exception cref="InvalidIOException">
+  /// Thrown when internal I/O error happen.
+  /// </exception>
+  /// <exception cref="PermissionDeniedException">
+  /// Thrown when the permission is denied.
+  /// </exception>
+  /// <remark> If you want to use this method, you must add privileges.</remark>
+  void Connect();
+
+  /// <summary>
+  /// Disposes delegate objects in this interface
+  /// </summary>
+  /// <param name="tag">The tag string from delegate object</param>
+  void DisposeCallback(const std::string& tag);
+
+)__cpp_cb";
+
+const char CB_PRIVATE_MEMBERS[] =
+R"__cpp_cb(  void ProcessReceivedEvent(rpc_port_parcel_h parcel);
+  void ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port);
+
+  static void OnConnectedCB(const char *ep, const char *port_name,
+                            rpc_port_h port, void *data);
+  static void OnDisconnectedCB(const char *ep, const char *port_name,
+                               void *data);
+  static void OnRejectedCB(const char *ep, const char *port_name, void *data);
+  static void OnReceivedCB(const char *ep, const char *port_name, void *data);
+
+  rpc_port_h port_;
+  rpc_port_h callback_port_;
+  rpc_port_proxy_h proxy_;
+  IEventListener* listener_;
+  std::recursive_mutex mutex_;
+  std::list<std::unique_ptr<CallbackBase>> delegate_list_;
+  std::string target_appid_;
+)__cpp_cb";
+
+const char CB_HEADER[] =
+R"__cpp_cb(
+#pragma once
+
+#include <bundle.h>
+#include <rpc-port-parcel.h>
+#include <rpc-port.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <mutex>
+#include <list>
+#include <atomic>
+
+)__cpp_cb";
+
+#endif  // IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
diff --git a/idlc/gen/cpp_stub_body_gen.cc b/idlc/gen/cpp_stub_body_gen.cc
new file mode 100644 (file)
index 0000000..93308d8
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cpp_stub_body_gen.h"
+
+namespace {
+#include "idlc/gen/cpp_stub_body_gen_cb.h"
+}
+
+namespace tidl {
+
+CppStubBodyGen::CppStubBodyGen(std::shared_ptr<Document> doc)
+    : CppGeneratorBase(doc) {}
+
+void CppStubBodyGen::OnInitGen(std::ofstream& stream) {
+  std::string key(".cc");
+  std::string header_file = FileName;
+
+  std::size_t found = header_file.rfind(key);
+  if (found != std::string::npos)
+    header_file.replace(found, key.length(), ".h");
+
+  GenVersion(stream);
+  stream << NLine(1);
+  stream << "#include <stdlib.h>" << NLine(1)
+         << "#include <assert.h>" << NLine(1)
+         << "#include <libgen.h>" << NLine(1)
+         << "#include <dlog.h>" << NLine(1)
+         <<  NLine(1)
+         << "#include \"" << header_file << "\"" << NLine(2);
+  GenLogTag(stream, "RPC_PORT_STUB");
+  GenLogDefinition(stream);
+  stream << NLine(1);
+  GenNamespace(stream);
+}
+
+void CppStubBodyGen::OnFiniGen(std::ofstream& stream) {}
+
+void CppStubBodyGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace rpc_port ";
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << " ";
+    GenBrace(stream, 0, [&]() {
+      stream <<  NLine(1);
+      GenStructuresForBody(stream);
+      stream << "namespace stub ";
+      GenBrace(stream, 0, [&]() {
+        GenPrototype(stream);
+        GenSerializer(stream);
+        GenDeSerializer(stream);
+        GenListSerializer(stream);
+        GenInterfaces(stream);
+      }, false, false);
+      stream << "  // namespace stub" + NLine(1);
+    }, false, false);
+    stream << "  // namespace " + GetFileNamespace() + NLine(1);
+  }, false, false);
+  stream << "  // namespace rpc_port" + NLine(1);
+}
+
+void CppStubBodyGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+  }
+}
+
+void CppStubBodyGen::GenInterface(std::ofstream& stream,
+                                    const Interface& iface) {
+  GenServiceBase(stream, iface);
+  GenBodyCallbacks(stream, iface, false);
+  GenDefaultMethods(stream, iface);
+  GenReceivedEvent(stream, iface);
+}
+
+void CppStubBodyGen::GenServiceBase(std::ofstream& stream,
+                                    const Interface& iface) {
+  GenTemplate(CB_CTOR_SERVICE_BASE, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    });
+  stream << NLine(1);
+}
+
+void CppStubBodyGen::GenConstructor(std::ofstream& stream,
+                                    const Interface& iface) {
+  stream << ReplaceAll(CB_CTOR_FRONT, "##", iface.GetID());
+
+  for (auto& i : iface.GetAttributes().GetAttrs()) {
+    if (i->GetKey() == "privilege") {
+      stream << Tab(1) << "rpc_port_stub_add_privilege(stub_, \""
+             << i->GetValue() << "\");" << NLine(1);
+    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
+      stream << Tab(1) << "rpc_port_stub_set_trusted(stub_, "
+             << i->GetValue() << ");" << NLine(1);
+    }
+  }
+
+  stream << "}" << NLine(1);
+}
+
+void CppStubBodyGen::GenDefaultMethods(std::ofstream& stream,
+                                       const Interface& iface) {
+  GenConstructor(stream, iface);
+  stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID());
+}
+
+void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
+                                      const Interface& iface) {
+  GenTemplate(CB_ON_RECEIVED_CB_FRONT, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    },
+    [&]()->std::string {
+      return iface.GetID();
+    });
+  for (auto& i : iface.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    stream << Tab(2) << "case static_cast<int>(MethodId::"
+           << i->GetID() << "): ";
+    GenBrace(stream, TAB_SIZE * 2, [&]() {
+      GenInvocation(stream, *i);
+      stream << Tab(3) << "break;" << NLine(1);
+    }, false);
+    stream << NLine(1);
+  }
+  stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
+}
+
+void CppStubBodyGen::GenInvocation(std::ofstream& stream,
+    const Declaration& decl) {
+  int cnt = 1;
+
+  // Deserialize
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
+      cnt++;
+      continue;
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    std::string c = ConvertTypeToDeserializer(
+        i->GetParameterType().GetBaseType(), v, "p");
+    stream << AddIndent(TAB_SIZE * 3, c);
+    cnt++;
+  }
+
+  // Invoke
+  cnt = 1;
+  std::string m;
+  std::string d;
+  bool hasRet = false;
+
+  if (decl.GetType().ToString() != "void") {
+    m += "auto retVal = ";
+    hasRet = true;
+  }
+
+  m += "b->" + decl.GetID() + "(";
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (cnt != 1) {
+      m += ", ";
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    auto& pt = i->GetParameterType();
+    if (pt.GetDirection() == ParameterType::Direction::OUT) {
+      d += ConvertTypeToString(pt.GetBaseType()) + " " + v + ";\n";
+    }
+    if (IsDelegateType(pt.GetBaseType())) {
+      m += "std::move(";
+      m += v;
+      m += ")";
+    } else {
+      m += v;
+    }
+    cnt++;
+  }
+
+  m += ");\n";
+  stream << AddIndent(TAB_SIZE * 3, d);
+  stream << AddIndent(TAB_SIZE * 3, m);
+
+  // Serialize
+  if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
+    return;
+
+  cnt = 0;
+  m = "rpc_port_parcel_write_int32(" \
+      "result, static_cast<int>(MethodId::__Result));\n";
+  for (auto& i : decl.GetParameters().GetParams()) {
+    auto& pt = i->GetParameterType();
+    cnt++;
+    if (pt.GetDirection() == ParameterType::Direction::IN)
+      continue;
+    m += ConvertTypeToSerializer(pt.GetBaseType(),
+                                "param" + std::to_string(cnt), "result");
+  }
+
+  if (hasRet) {
+    m += ConvertTypeToSerializer(decl.GetType(), "retVal", "result");
+  }
+
+  m += "ret = rpc_port_parcel_send(result, port);\n";
+  stream << AddIndent(TAB_SIZE * 3, m);
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cpp_stub_body_gen.h b/idlc/gen/cpp_stub_body_gen.h
new file mode 100644 (file)
index 0000000..7db4dec
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
+#define IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cpp_gen_base.h"
+
+namespace tidl {
+
+class CppStubBodyGen : public CppGeneratorBase {
+ public:
+  explicit CppStubBodyGen(std::shared_ptr<Document> doc);
+  virtual ~CppStubBodyGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenServiceBase(std::ofstream& stream, const Interface& iface);
+  void GenDefaultMethods(std::ofstream& stream, const Interface& iface);
+  void GenReceivedEvent(std::ofstream& stream, const Interface& iface);
+  void GenInvocation(std::ofstream& stream, const Declaration& decl);
+  void GenConstructor(std::ofstream& stream, const Interface& iface);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_H_
diff --git a/idlc/gen/cpp_stub_body_gen_cb.h b/idlc/gen/cpp_stub_body_gen_cb.h
new file mode 100644 (file)
index 0000000..d3fad11
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
+
+const char CB_CTOR_FRONT[] =
+R"__cpp_cb(
+##::##() {
+  int r = rpc_port_stub_create(&stub_, "##");
+  if (r != RPC_PORT_ERROR_NONE) {
+    _E("Failed to create stub handle");
+    throw InvalidIOException();
+  }
+  rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this);
+  rpc_port_stub_add_disconnected_event_cb(stub_, OnDisconnectedCB, this);
+  rpc_port_stub_add_received_event_cb(stub_, OnReceivedCB, this);
+)__cpp_cb";
+
+const char CB_DEFAULT_METHODS[] =
+R"__cpp_cb(
+##::~##() {
+  for (auto& i : services_) {
+    i->OnTerminate();
+  }
+
+  if (stub_) {
+    rpc_port_stub_destroy(stub_);
+  }
+}
+
+void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) {
+  service_factory_ = std::move(service_factory);
+  int r = rpc_port_stub_listen(stub_);
+  if (r != RPC_PORT_ERROR_NONE) {
+    _E("Failed to listen stub");
+    switch (r) {
+      case RPC_PORT_ERROR_INVALID_PARAMETER:
+      case RPC_PORT_ERROR_IO_ERROR:
+        throw InvalidIOException();
+    }
+  }
+}
+
+void ##::OnConnectedCB(const char* sender, const char* instance, void *data) {
+  ##* stub = static_cast<##*>(data);
+  auto s = stub->service_factory_->CreateService(sender, instance);
+  s->OnCreate();
+  stub->services_.emplace_back(std::move(s));
+}
+
+void ##::OnDisconnectedCB(const char* sender, const char* instance, void *data) {
+  ##* stub = static_cast<##*>(data);
+
+  for (auto& i : stub->services_) {
+    if (i->GetInstance() == instance) {
+      i->OnTerminate();
+      stub->services_.remove(i);
+      return;
+    }
+  }
+}
+)__cpp_cb";
+
+const char CB_ON_RECEIVED_CB_FRONT[] =
+R"__cpp_cb(
+int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
+{
+  auto* cxt = static_cast<$$*>(data);
+  rpc_port_parcel_h p;
+  rpc_port_parcel_h result;
+  int cmd;
+  int ret;
+  std::shared_ptr<ServiceBase> b;
+  rpc_port_h callback_port;
+
+  for (auto& i : cxt->services_) {
+    if (i->GetInstance() == instance) {
+      b = i;
+      break;
+    }
+  }
+
+  if (b.get() == nullptr) {
+    _E("Failed to find $$ context(%s)", instance);
+    return -1;
+  }
+
+  ret = rpc_port_stub_get_port(cxt->stub_, RPC_PORT_PORT_CALLBACK, instance,
+      &callback_port);
+  if (ret != 0) {
+    _E("Failed to get callback port");
+  }
+
+  ret = rpc_port_parcel_create_from_port(&p, port);
+  if (ret != 0) {
+    _E("Failed to create parcel from port");
+    return ret;
+  }
+
+  rpc_port_parcel_create(&result);
+  rpc_port_parcel_read_int32(p, &cmd);
+
+  switch (cmd) {
+)__cpp_cb";
+
+const char CB_ON_RECEIVED_CB_BACK[] =
+R"__cpp_cb(    default:
+      _E("Unknown command(%d)", cmd);
+      rpc_port_parcel_destroy(p);
+      rpc_port_parcel_destroy(result);
+      return -1;
+  }
+
+  rpc_port_parcel_destroy(p);
+  rpc_port_parcel_destroy(result);
+
+  return ret;
+}
+)__cpp_cb";
+
+const char CB_CTOR_SERVICE_BASE[] =
+R"__cpp_cb($$::ServiceBase::ServiceBase(std::string sender, std::string instance)
+    : sender_(std::move(sender)), instance_(std::move(instance)) {})__cpp_cb";
+
+#endif  // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
diff --git a/idlc/gen/cpp_stub_header_gen.cc b/idlc/gen/cpp_stub_header_gen.cc
new file mode 100644 (file)
index 0000000..0e5689e
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cpp_stub_header_gen.h"
+
+namespace {
+#include "idlc/gen/cpp_stub_header_gen_cb.h"
+}
+
+namespace tidl {
+
+CppStubHeaderGen::CppStubHeaderGen(std::shared_ptr<Document> doc)
+    : CppGeneratorBase(doc) {}
+
+void CppStubHeaderGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << CB_HEADER;
+  GenNamespace(stream);
+}
+
+void CppStubHeaderGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CppStubHeaderGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace rpc_port ";
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << " ";
+    GenBrace(stream, 0, [&]() {
+      stream <<  NLine(1);
+      GenStructuresForHeader(stream);
+      stream << "namespace stub ";
+      GenBrace(stream, 0, [&]() {
+        GenExceptions(stream);
+        GenInterfaces(stream);
+      }, false, false);
+      stream << "  // namespace stub" + NLine(1);
+    }, false, false);
+    stream << "  // namespace " + GetFileNamespace() + NLine(1);
+  }, false, false);
+  stream << "  // namespace rpc_port" + NLine(1);
+}
+
+void CppStubHeaderGen::GenExceptions(std::ofstream& stream) {
+  stream << CB_EXCEPTIONS;
+}
+
+void CppStubHeaderGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+  }
+}
+
+void CppStubHeaderGen::GenInterface(std::ofstream& stream,
+                                    const Interface& iface) {
+  stream << NLine(1) << "class " << iface.GetID() << " final ";
+  GenBrace(stream, 0, [&]() {
+    GenPublic(stream, iface);
+    GenPrivate(stream, iface);
+  }, false, false);
+  stream << ";" << NLine(1);
+}
+
+void CppStubHeaderGen::GenPublic(std::ofstream& stream,
+                                 const Interface& iface) {
+  stream << " public:" << NLine(1);
+  stream << "  class ServiceBase;" << NLine(1);
+  GenHeaderCallbacks(stream, iface, false);
+  GenServiceBase(stream, iface);
+  GenPublicMethods(stream, iface);
+}
+
+void CppStubHeaderGen::GenPrivate(std::ofstream& stream,
+                                 const Interface& iface) {
+  stream << " private:" << NLine(1);
+  GenMethodId(stream, iface);
+  GenDelegateId(stream, iface);
+  stream << CB_PRIVATE_MEMBERS;
+}
+
+void CppStubHeaderGen::GenServiceBase(std::ofstream& stream,
+                                      const Interface& iface) {
+  stream << CB_SERVICE_BASE_FRONT;
+  auto& decls = iface.GetDeclarations();
+
+  for (auto& i : decls.GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    if (!i->GetComments().empty())
+      stream << NLine(1) << AddIndent(TAB_SIZE * 2, i->GetComments());
+    stream << Tab(2) << "virtual " << ConvertTypeToString(i->GetType())
+           << " " << i->GetID() << "(";
+    GenParameters(stream, i->GetParameters());
+    stream << ") = 0;" << NLine(1);
+  }
+
+  stream << CB_SERVICE_BASE_BACK << NLine(2);
+}
+
+void CppStubHeaderGen::GenPublicMethods(std::ofstream& stream,
+                                        const Interface& iface) {
+  stream << ReplaceAll(CB_PUBLIC_METHODS, "##", iface.GetID());
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cpp_stub_header_gen.h b/idlc/gen/cpp_stub_header_gen.h
new file mode 100644 (file)
index 0000000..db8d82b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
+#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cpp_gen_base.h"
+
+namespace tidl {
+
+class CppStubHeaderGen : public CppGeneratorBase {
+ public:
+  explicit CppStubHeaderGen(std::shared_ptr<Document> doc);
+  virtual ~CppStubHeaderGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenExceptions(std::ofstream& stream);
+  void GenNamespace(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenPublic(std::ofstream& stream, const Interface& iface);
+  void GenPrivate(std::ofstream& stream, const Interface& iface);
+  void GenServiceBase(std::ofstream& stream, const Interface& iface);
+  void GenPublicMethods(std::ofstream& stream, const Interface& iface);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_H_
diff --git a/idlc/gen/cpp_stub_header_gen_cb.h b/idlc/gen/cpp_stub_header_gen_cb.h
new file mode 100644 (file)
index 0000000..8cb4c1f
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
+
+const char CB_EXCEPTIONS[] =
+R"__cpp_cb(
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
+class InvalidCallbackException : public Exception {};
+)__cpp_cb";
+
+const char CB_PRIVATE_MEMBERS[] =
+R"__cpp_cb(  static void OnConnectedCB(const char* sender, const char* instance, void* data);
+  static void OnDisconnectedCB(const char* sender, const char* instance, void* data);
+  static int OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void* data);
+
+  rpc_port_stub_h stub_;
+  std::shared_ptr<ServiceBase::Factory> service_factory_;
+  std::list<std::shared_ptr<ServiceBase>> services_;
+)__cpp_cb";
+
+const char CB_SERVICE_BASE_FRONT[] =
+R"__cpp_cb(
+  class ServiceBase {
+   public:
+    class Factory {
+     public:
+      /// <summary>
+      /// The method for making service instances
+      /// </summary>
+      /// <param name="sender">The client app ID</param>
+      /// <param name="instance">The client instance ID</param>
+      virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
+    };
+
+    virtual ~ServiceBase() = default;
+
+    /// <summary>
+    /// Gets client app ID
+    /// </summary>
+    const std::string& GetSender() const {
+      return sender_;
+    }
+
+    /// <summary>
+    /// Gets client instance ID
+    /// </summary>
+    const std::string& GetInstance() const {
+      return instance_;
+    }
+
+    /// <summary>
+    /// This method will be called when the client is connected
+    /// </summary>
+    virtual void OnCreate() = 0;
+
+    /// <summary>
+    /// This method will be called when the client is disconnected
+    /// </summary>
+    virtual void OnTerminate() = 0;
+
+)__cpp_cb";
+
+const char CB_SERVICE_BASE_BACK[] =
+R"__cpp_cb(
+   protected:
+    ServiceBase(std::string sender, std::string instance);
+
+   private:
+    std::string sender_;
+    std::string instance_;
+  };)__cpp_cb";
+
+const char CB_PUBLIC_METHODS[] =
+R"__cpp_cb(  ##();
+  ~##();
+
+  /// <summary>
+  /// Listens to client apps
+  /// </summary>
+  /// <param name="service_factory">The factory object for making service instances</param>
+  /// <exception cref="InvalidIOException">
+  /// Thrown when internal I/O error happen.
+  /// </exception>
+  void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);
+
+  /// <summary>
+  /// Gets service objects which are connected
+  /// </summary>
+  /// <returns>The list of service objects which are connected</returns>
+  const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
+    return services_;
+  }
+
+)__cpp_cb";
+
+const char CB_HEADER[] =
+R"__cpp_cb(
+#pragma once
+
+#include <bundle.h>
+#include <rpc-port-parcel.h>
+#include <rpc-port.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+#include <list>
+#include <atomic>
+
+)__cpp_cb";
+
+#endif  // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
diff --git a/idlc/gen/cs_cb_interop.h b/idlc/gen/cs_cb_interop.h
new file mode 100644 (file)
index 0000000..4e6cf90
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_CB_INTEROP_H_
+#define IDLC_CS_GEN_CS_CB_INTEROP_H_
+
+const char cs_cb_interop[] =
+R"__cs_cb(
+internal static partial class Interop
+{
+    internal static partial class LibRPCPort
+    {
+        internal static partial class Libraries
+        {
+            public const string RpcPort = "librpc-port.so.1";
+        }
+
+        internal enum ErrorCode
+        {
+            None = Tizen.Internals.Errors.ErrorCode.None,
+            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+            OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+            IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+        }
+
+        internal enum PortType
+        {
+            Main,
+            Callback
+        }
+
+        internal static partial class Parcel
+        {
+            //int rpc_port_parcel_create(rpc_port_parcel_h *h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create")]
+            internal static extern ErrorCode Create(out IntPtr handle);
+
+            //int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_port")]
+            internal static extern ErrorCode CreateFromPort(out IntPtr parcelHandle, IntPtr portHandle);
+
+            //int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_send")]
+            internal static extern ErrorCode Send(IntPtr parcelHandle, IntPtr portHandle);
+
+            //int rpc_port_parcel_destroy(rpc_port_parcel_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_byte")]
+            internal static extern ErrorCode WriteByte(IntPtr parcelHandle, byte b);
+
+            //int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int16")]
+            internal static extern ErrorCode WriteInt16(IntPtr parcelHandle, short i);
+
+            //int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int32")]
+            internal static extern ErrorCode WriteInt32(IntPtr parcelHandle, int i);
+
+            //int rpc_port_parcel_write_int64(rpc_port_parcel_h h, int i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int64")]
+            internal static extern ErrorCode WriteInt64(IntPtr parcelHandle, long i);
+
+            //int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_float")]
+            internal static extern ErrorCode WriteFloat(IntPtr parcelHandle, float f);
+
+            //int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_double")]
+            internal static extern ErrorCode WriteDouble(IntPtr parcelHandle, double d);
+
+            //int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_string")]
+            internal static extern ErrorCode WriteString(IntPtr parcelHandle, string str);
+
+            //int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bool")]
+            internal static extern ErrorCode WriteBool(IntPtr parcelHandle, bool b);
+
+            //int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bundle")]
+            internal static extern ErrorCode WriteBundle(IntPtr parcelHandle, IntPtr b);
+
+            //int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_array_count")]
+            internal static extern ErrorCode WriteArrayCount(IntPtr parcelHandle, int count);
+
+            //int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_byte")]
+            internal static extern ErrorCode ReadByte(IntPtr parcelHandle, out byte b);
+
+            //int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int16")]
+            internal static extern ErrorCode ReadInt16(IntPtr parcelHandle, out short i);
+
+            //int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int32")]
+            internal static extern ErrorCode ReadInt32(IntPtr parcelHandle, out int i);
+
+            //int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int64")]
+            internal static extern ErrorCode ReadInt64(IntPtr parcelHandle, out long i);
+
+            //int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_float")]
+            internal static extern ErrorCode ReadFloat(IntPtr parcelHandle, out float f);
+
+            //int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_double")]
+            internal static extern ErrorCode ReadDouble(IntPtr parcelHandle, out double f);
+
+            //int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_string")]
+            internal static extern ErrorCode ReadString(IntPtr parcelHandle, out string str);
+
+            //int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bool")]
+            internal static extern ErrorCode ReadBool(IntPtr parcelHandle, out bool b);
+
+            //int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bundle")]
+            internal static extern ErrorCode ReadBundle(IntPtr parcelHandle, out IntPtr b);
+
+            //int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_array_count")]
+            internal static extern ErrorCode ReadArrayCount(IntPtr parcelHandle, out int count);
+
+            //int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, unsigned int size);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_read")]
+            internal static extern ErrorCode Read(IntPtr parcelHandle, [In, Out] byte[] buf, int size);
+
+            //int rpc_port_parcel_burst_write(rpc_port_parcel_h h, const unsigned char *buf, unsigned int size);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_write")]
+            internal static extern ErrorCode Write(IntPtr parcelHandle, byte[] buf, int size);
+        }
+
+        internal static partial class Proxy
+        {
+            //typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep, const char* port_name, rpc_port_h port, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ConnectedEventCallback(string endPoint, string port_name, IntPtr port, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void DisconnectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_rejected_event_cb) (const char* ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void RejectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_received_event_cb) (const char* ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ReceivedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //int rpc_port_proxy_create(rpc_port_proxy_h *h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_create")]
+            internal static extern ErrorCode Create(out IntPtr handle);
+
+            //int rpc_port_proxy_destroy(rpc_port_proxy_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, const char* port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect")]
+            internal static extern ErrorCode Connect(IntPtr handle, string appId, string port);
+
+            //int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_connected_event_cb")]
+            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_disconnected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_disconnected_event_cb")]
+            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_rejected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_rejected_event_cb")]
+            internal static extern ErrorCode AddRejectedEventCb(IntPtr handle, RejectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, rpc_port_proxy_received_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_received_event_cb")]
+            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, rpc_port_h* port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_get_port")]
+            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, out IntPtr port);
+        }
+
+        internal static partial class Stub
+        {
+            //typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, const char *instance, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ConnectedEventCallback(string sender, string instance, IntPtr data);
+
+            //typedef void (* rpc_port_stub_disconnected_event_cb) (const char* sender, const char *instance, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void DisconnectedEventCallback(string sender, string instance, IntPtr data);
+
+            //typedef void (* rpc_port_stub_received_event_cb) (const char* sender, const char *instance, rpc_port_h port, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate int ReceivedEventCallback(string sender, string instance, IntPtr port, IntPtr data);
+
+            //int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_create")]
+            internal static extern ErrorCode Create(out IntPtr handle, string portName);
+
+            //int rpc_port_stub_destroy(rpc_port_stub_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_stub_listen(rpc_port_stub_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_listen")]
+            internal static extern ErrorCode Listen(IntPtr handle);
+
+            //int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_connected_event_cb")]
+            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, rpc_port_stub_disconnected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_disconnected_event_cb")]
+            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_received_event_cb")]
+            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_privilege")]
+            internal static extern ErrorCode AddPrivilege(IntPtr handle, string privilege);
+
+            //int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_set_trusted")]
+            internal static extern ErrorCode SetTrusted(IntPtr handle, bool trusted);
+
+            //int rpc_port_stub_get_port(rpc_port_stub_h h, rpc_port_port_type_e type, const char* instance, rpc_port_h *port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_get_port")]
+            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, string instance, out IntPtr port);
+        }
+    }
+}
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_CB_INTEROP_H_
diff --git a/idlc/gen/cs_cb_rpc_port.h b/idlc/gen/cs_cb_rpc_port.h
new file mode 100644 (file)
index 0000000..573aebb
--- /dev/null
@@ -0,0 +1,469 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_CB_RPC_PORT_H_
+#define IDLC_CS_GEN_CS_CB_RPC_PORT_H_
+
+const char cs_cb_rpc_port[] =
+R"__cs_cb(
+namespace Tizen.Applications.RPCPort
+{
+    public class InvalidIOException : InvalidOperationException { }
+    public class InvalidIDException : InvalidOperationException { }
+    public class PermissionDeniedException : InvalidOperationException { }
+    public class InvalidProtocolException : InvalidOperationException { }
+    public class NotConnectedSocketException : InvalidOperationException { }
+    public class InvalidCallbackException : InvalidOperationException { }
+
+    public class Port
+    {
+        public enum Type
+        {
+            Main,
+            Callback
+        }
+
+        internal IntPtr Handle { get; set; }
+        internal Port() { }
+    }
+
+    public class Parcel : IDisposable
+    {
+        private IntPtr _handle;
+
+        public Parcel()
+        {
+            var r = Interop.LibRPCPort.Parcel.Create(out _handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        public Parcel(Port port)
+        {
+            var r = Interop.LibRPCPort.Parcel.CreateFromPort(out _handle, port.Handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        public void Send(Port p)
+        {
+            var r = Interop.LibRPCPort.Parcel.Send(_handle, p.Handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        public void WriteByte(byte b)
+        {
+            Interop.LibRPCPort.Parcel.WriteByte(_handle, b);
+        }
+
+        public void WriteShort(short b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt16(_handle, b);
+        }
+
+        public void WriteInt(int b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt32(_handle, b);
+        }
+
+        public void WriteLong(long b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt64(_handle, b);
+        }
+
+        public void WriteFloat(float b)
+        {
+            Interop.LibRPCPort.Parcel.WriteFloat(_handle, b);
+        }
+
+        public void WriteDouble(double b)
+        {
+            Interop.LibRPCPort.Parcel.WriteDouble(_handle, b);
+        }
+
+        public void WriteString(string b)
+        {
+            Interop.LibRPCPort.Parcel.WriteString(_handle, b);
+        }
+
+        public void WriteBool(bool b)
+        {
+            Interop.LibRPCPort.Parcel.WriteBool(_handle, b);
+        }
+
+        public void WriteBundle(Bundle b)
+        {
+            Interop.LibRPCPort.Parcel.WriteBundle(_handle, b.SafeBundleHandle.DangerousGetHandle());
+        }
+
+        public void WriteArrayCount(int cnt)
+        {
+            Interop.LibRPCPort.Parcel.WriteArrayCount(_handle, cnt);
+        }
+
+        public byte ReadByte()
+        {
+            Interop.LibRPCPort.Parcel.ReadByte(_handle, out byte b);
+            return b;
+        }
+
+        public short ReadShort()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt16(_handle, out short b);
+            return b;
+        }
+
+        public int ReadInt()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt32(_handle, out int b);
+            return b;
+        }
+
+        public long ReadLong()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt64(_handle, out long b);
+            return b;
+        }
+
+        public float ReadFloat()
+        {
+            Interop.LibRPCPort.Parcel.ReadFloat(_handle, out float b);
+            return b;
+        }
+
+        public double ReadDouble()
+        {
+            Interop.LibRPCPort.Parcel.ReadDouble(_handle, out double b);
+            return b;
+        }
+
+        public string ReadString()
+        {
+            Interop.LibRPCPort.Parcel.ReadString(_handle, out string b);
+            return b;
+        }
+
+        public bool ReadBool()
+        {
+            Interop.LibRPCPort.Parcel.ReadBool(_handle, out bool b);
+            return b;
+        }
+
+        public Bundle ReadBundle()
+        {
+            Interop.LibRPCPort.Parcel.ReadBundle(_handle, out IntPtr b);
+
+            return new Bundle(new SafeBundleHandle(b, true));
+        }
+
+        public int ReadArrayCount()
+        {
+            Interop.LibRPCPort.Parcel.ReadArrayCount(_handle, out int b);
+            return b;
+        }
+
+        public void Write(byte[] bytes)
+        {
+            Interop.LibRPCPort.Parcel.Write(_handle, bytes, bytes.Length);
+        }
+
+        public byte[] Read(int size)
+        {
+            var ret = new byte[size];
+            Interop.LibRPCPort.Parcel.Read(_handle, ret, size);
+            return ret;
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+
+                if (_handle != IntPtr.Zero)
+                {
+                    Interop.LibRPCPort.Parcel.Destroy(_handle);
+                    _handle = IntPtr.Zero;
+                }
+
+                disposedValue = true;
+            }
+        }
+
+        ~Parcel()
+        {
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+
+    public abstract class ProxyBase : IDisposable
+    {
+        private Interop.LibRPCPort.Proxy.ConnectedEventCallback _connectedEventCallback;
+        private Interop.LibRPCPort.Proxy.DisconnectedEventCallback _disconnectedEventCallback;
+        private Interop.LibRPCPort.Proxy.RejectedEventCallback _rejectedEventCallback;
+        private Interop.LibRPCPort.Proxy.ReceivedEventCallback _receivedEventCallback;
+        private IntPtr _proxy;
+
+        protected Port Port { get; private set; }
+        protected Port CallbackPort { get; private set; }
+
+        public ProxyBase()
+        {
+            if (Interop.LibRPCPort.Proxy.Create(out _proxy) != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+            _connectedEventCallback = new Interop.LibRPCPort.Proxy.ConnectedEventCallback(OnConnectedEvent);
+            _disconnectedEventCallback = new Interop.LibRPCPort.Proxy.DisconnectedEventCallback(OnDisconnectedEvent);
+            _rejectedEventCallback = new Interop.LibRPCPort.Proxy.RejectedEventCallback(OnRejectedEvent);
+            _receivedEventCallback = new Interop.LibRPCPort.Proxy.ReceivedEventCallback(OnReceivedEvent);
+            Interop.LibRPCPort.Proxy.AddConnectedEventCb(_proxy, _connectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddDisconnectedEventCb(_proxy, _disconnectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddRejectedEventCb(_proxy, _rejectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddReceivedEventCb(_proxy, _receivedEventCallback, IntPtr.Zero);
+        }
+
+        protected void Connect(string appid, string port)
+        {
+            var err = Interop.LibRPCPort.Proxy.Connect(_proxy, appid, port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIDException();
+                case Interop.LibRPCPort.ErrorCode.PermissionDenied:
+                    throw new PermissionDeniedException();
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+        }
+
+        protected Port GetPort(Port.Type t)
+        {
+            var err = Interop.LibRPCPort.Proxy.GetPort(_proxy,
+                (Interop.LibRPCPort.PortType)t, out IntPtr port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+
+            return new Port() { Handle = port };
+        }
+
+        protected abstract void OnConnectedEvent(string endPoint, string portName, Port port);
+        protected abstract void OnDisconnectedEvent(string endPoint, string portName);
+        protected abstract void OnReceivedEvent(string endPoint, string portName);
+        protected abstract void OnRejectedEvent(string endPoint, string portName);
+
+        private void OnConnectedEvent(string endPoint, string portName, IntPtr port, IntPtr data)
+        {
+            Port = new Port() { Handle = port };
+            CallbackPort = GetPort(Port.Type.Callback);
+            OnConnectedEvent(endPoint, portName, Port);
+        }
+
+        private void OnDisconnectedEvent(string endPoint, string portName, IntPtr data)
+        {
+            Port = null;
+            CallbackPort = null;
+            OnDisconnectedEvent(endPoint, portName);
+        }
+
+        private void OnReceivedEvent(string endPoint, string portName, IntPtr data)
+        {
+            OnReceivedEvent(endPoint, portName);
+        }
+
+        private void OnRejectedEvent(string endPoint, string portName, IntPtr data)
+        {
+            OnRejectedEvent(endPoint, portName);
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+                if (_proxy != IntPtr.Zero)
+                    Interop.LibRPCPort.Proxy.Destroy(_proxy);
+                _proxy = IntPtr.Zero;
+
+                disposedValue = true;
+            }
+        }
+
+        ~ProxyBase()
+        {
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+
+    public abstract class StubBase : IDisposable
+    {
+        private Interop.LibRPCPort.Stub.ConnectedEventCallback _connectedEventCallback;
+        private Interop.LibRPCPort.Stub.DisconnectedEventCallback _disconnectedEventCallback;
+        private Interop.LibRPCPort.Stub.ReceivedEventCallback _receivedEventCallback;
+        private IntPtr _stub;
+
+        public string PortName { get; private set; }
+
+        public StubBase(string portName)
+        {
+            if (Interop.LibRPCPort.Stub.Create(out _stub, portName) != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+            PortName = portName;
+            _connectedEventCallback = new Interop.LibRPCPort.Stub.ConnectedEventCallback(OnConnectedEvent);
+            _disconnectedEventCallback = new Interop.LibRPCPort.Stub.DisconnectedEventCallback(OnDisconnectedEvent);
+            _receivedEventCallback = new Interop.LibRPCPort.Stub.ReceivedEventCallback(OnReceivedEvent);
+            Interop.LibRPCPort.Stub.AddReceivedEventCb(_stub, _receivedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Stub.AddConnectedEventCb(_stub, _connectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Stub.AddDisconnectedEventCb(_stub, _disconnectedEventCallback, IntPtr.Zero);
+        }
+
+        protected void Listen()
+        {
+            var err = Interop.LibRPCPort.Stub.Listen(_stub);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+        }
+
+        protected void AddPrivilege(string privilege)
+        {
+            var err = Interop.LibRPCPort.Stub.AddPrivilege(_stub, privilege);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIOException();
+            }
+        }
+
+        protected void SetTrusted(bool trusted)
+        {
+            var err = Interop.LibRPCPort.Stub.SetTrusted(_stub, trusted);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIOException();
+            }
+        }
+
+        protected Port GetPort(Port.Type t, string instance)
+        {
+            var err = Interop.LibRPCPort.Stub.GetPort(_stub,
+                (Interop.LibRPCPort.PortType)t, instance, out IntPtr port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIDException();
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+
+            return new Port() { Handle = port };
+        }
+
+        protected abstract void OnConnectedEvent(string sender, string instance);
+
+        protected abstract void OnDisconnectedEvent(string sender, string instance);
+
+        protected abstract bool OnReceivedEvent(string sender, string instance, Port port);
+
+        protected abstract void OnTerminatedEvent();
+
+        private void OnConnectedEvent(string sender, string instance, IntPtr data)
+        {
+            OnConnectedEvent(sender, instance);
+        }
+
+        private void OnDisconnectedEvent(string sender, string instance, IntPtr data)
+        {
+            OnDisconnectedEvent(sender, instance);
+        }
+
+        private int OnReceivedEvent(string sender, string instance, IntPtr port, IntPtr data)
+        {
+            bool b = OnReceivedEvent(sender, instance, new Port() { Handle = port });
+            if (b)
+                return 0;
+            return -1;
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+
+                OnTerminatedEvent();
+
+                if (_stub != IntPtr.Zero)
+                    Interop.LibRPCPort.Stub.Destroy(_stub);
+                _stub = IntPtr.Zero;
+
+                disposedValue = true;
+            }
+        }
+
+        ~StubBase()
+        {
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+}
+
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_CB_RPC_PORT_H_
diff --git a/idlc/gen/cs_cb_version.h b/idlc/gen/cs_cb_version.h
new file mode 100644 (file)
index 0000000..c0102a4
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_CB_VERSION_H_
+#define IDLC_CS_GEN_CS_CB_VERSION_H_
+
+const char cs_cb_version[] =
+R"__cs_cb(/*
+ * Generated by tidlc $$.
+ */
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_CB_VERSION_H_
diff --git a/idlc/gen/cs_gen_base.cc b/idlc/gen/cs_gen_base.cc
new file mode 100644 (file)
index 0000000..bb1e5bb
--- /dev/null
@@ -0,0 +1,507 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ctime>
+#include <vector>
+
+#include "idlc/gen/cs_gen_base.h"
+
+namespace {
+#include "idlc/gen/cs_cb_version.h"
+#include "idlc/gen/cs_gen_base_cb.h"
+#include "idlc/gen/cs_cb_rpc_port.h"
+}
+
+namespace tidl {
+
+CsGeneratorBase::CsGeneratorBase(std::shared_ptr<Document> doc)
+    : Generator(doc) {
+  type_map_ = {
+      {"char", "byte"}, {"int", "int"}, {"short", "short"},
+      {"long", "long"}, {"string", "string"}, {"bool", "bool"},
+      {"list", "LinkedList"}, {"array", "List"}, {"float", "float"},
+      {"double", "double"}, {"bundle", "Bundle"}, {"void", "void"}
+  };
+
+  parcel_type_map_ = {
+    {"char", "Byte"},
+    {"int", "Int"},
+    {"short", "Short"},
+    {"long", "Long"},
+    {"string", "String"},
+    {"bool", "Bool"},
+    {"float", "Float"},
+    {"double", "Double"},
+    {"bundle", "Bundle"},
+  };
+}
+
+void CsGeneratorBase::GenStructures(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_STRUCTURE)
+      continue;
+    Structure& st = static_cast<Structure&>(*i);
+    GenStructure(stream, st);
+    stream << std::endl;
+  }
+}
+
+void CsGeneratorBase::GenStructure(std::ofstream& stream, const Structure& st) {
+  std::vector<std::string> v;
+
+  stream << Tab(1) <<"public sealed class " << st.GetID() << NLine(1);
+  GenBrace(stream, TAB_SIZE, [&]() {
+    for (auto& i : st.GetElements().GetElms()) {
+      GenTemplate(CB_PROPERTY, stream,
+        [&]()->std::string {
+          return ConvertTypeToString(i->GetType());
+        },
+        [&]()->std::string {
+          return i->GetID();
+        });
+      if (i->GetType().ToString() == "bundle") {
+        v.push_back(i->GetID() + " = " + "new Bundle()");
+      }
+    }
+
+    GenTemplate(CB_CTOR, stream,
+      [&]()->std::string {
+        return st.GetID();
+      },
+      [&]()->std::string {
+        std::string str;
+        for (auto& i : v) {
+          str += "            " + i + ";\n";
+        }
+        return str;
+      });
+  });
+}
+
+void CsGeneratorBase::GenSerializer(std::ofstream& stream,
+    const Structure& st) {
+  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
+                   << st.GetID() << " param)" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    for (auto& i : st.GetElements().GetElms()) {
+      auto& t = i->GetType();
+      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
+        stream << Tab(4) << "h.Write"
+                         << ConvertTypeToParcelType(t.ToString())
+                         << "(param."
+                         << i->GetID()
+                         << ");" << NLine(1);
+      } else {
+        stream << Tab(4) << "Serialize(h, param." << i->GetID()
+                         << ");" << NLine(1);
+      }
+    }
+  });
+  stream << NLine(1);
+
+  stream << Tab(3) << "private static void Deserialize(Parcel h, "
+                   << st.GetID() << " param)" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    for (auto& i : st.GetElements().GetElms()) {
+      auto& t = i->GetType();
+      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
+        stream << Tab(4) << "var " << i->GetID() << " = "
+                         << "h.Read"
+                         << ConvertTypeToParcelType(t.ToString())
+                         << "();" << NLine(1);
+        stream << Tab(4) << "param." << i->GetID() << " = " << i->GetID()
+               << ";" << NLine(1);
+      } else {
+        stream << Tab(4) << "param." << i->GetID() << " = new "
+                         << ConvertTypeToString(t)
+                         << "();" << NLine(1);
+        stream << Tab(4) << "Deserialize(h, param." << i->GetID()
+                         << ");" << NLine(1);
+      }
+    }
+  });
+}
+
+void CsGeneratorBase::GenSerializer(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() == Block::TYPE_STRUCTURE) {
+      const Structure& st = static_cast<const Structure&>(*i);
+      GenSerializer(stream, st);
+    }
+  }
+}
+
+void CsGeneratorBase::AddSerializerList(const BaseType& type) {
+  if (type.GetMetaType() != nullptr) {
+    serializer_list_[ConvertTypeToString(type)] = &type;
+    AddSerializerList(*type.GetMetaType());
+  }
+}
+
+void CsGeneratorBase::GenListSerializer(std::ofstream& stream,
+    const BaseType& type) {
+  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
+                   << ConvertTypeToString(type) << " param)" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    stream << Tab(4)
+           << "h.WriteArrayCount(param.Count);"
+           << NLine(1);
+    stream << Tab(4) << "foreach (var i in param)" << NLine(1);
+    GenBrace(stream, TAB_SIZE * 4, [&]() {
+      auto& mt = *type.GetMetaType();
+      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
+        stream << Tab(5) << "h.Write"
+                         << ConvertTypeToParcelType(mt.ToString())
+                         << "(i);" << NLine(1);
+      } else {
+        stream << Tab(5) << "Serialize(h, i);" << NLine(1);
+      }
+    });
+  });
+  stream << NLine(1);
+
+  stream << Tab(3) << "private static void Deserialize(Parcel h, "
+                   << ConvertTypeToString(type) << " param)" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    stream << Tab(4)
+           << "int l = h.ReadArrayCount();"
+           << NLine(1);
+    stream << Tab(4) << "for (int i = 0; i < l; i++)" << NLine(1);
+    GenBrace(stream, TAB_SIZE * 4, [&]() {
+      auto& mt = *type.GetMetaType();
+      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
+        stream << Tab(5) << "var v = h.Read"
+                         << ConvertTypeToParcelType(mt.ToString())
+                         << "();" << NLine(1);
+      } else {
+        stream << Tab(5) << "var v = new " << ConvertTypeToString(mt)
+               << "();" << NLine(1);
+        stream << Tab(5) << "Deserialize(h, v);" << NLine(1);
+      }
+      if (type.ToString() == "list")
+        stream << Tab(5) << "param.AddLast(v);" << NLine(1);
+      else
+        stream << Tab(5) << "param.Add(v);" << NLine(1);
+    });
+  });
+}
+
+void CsGeneratorBase::GenListSerializer(std::ofstream& stream) {
+  serializer_list_.clear();
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() == Block::TYPE_STRUCTURE) {
+      const Structure& st = static_cast<const Structure&>(*i);
+      for (auto& j : st.GetElements().GetElms()) {
+        auto& t = j->GetType();
+        AddSerializerList(t);
+      }
+    } else if (i->GetType() == Block::TYPE_INTERFACE) {
+      const Interface& iface = static_cast<const Interface&>(*i);
+      for (auto& j : iface.GetDeclarations().GetDecls()) {
+        auto& t = j->GetType();
+        AddSerializerList(t);
+        for (auto& k : j->GetParameters().GetParams()) {
+          auto& t1 = k->GetParameterType().GetBaseType();
+          AddSerializerList(t1);
+        }
+      }
+    }
+  }
+
+  for (auto& p : serializer_list_) {
+    const BaseType* t = p.second;
+    GenListSerializer(stream, *t);
+  }
+}
+
+std::string CsGeneratorBase::ConvertTypeToString(const BaseType& type) {
+  if (type.IsUserDefinedType())
+    return type.ToString();
+
+  if (type.GetMetaType() != nullptr)
+    return type_map_[type.ToString()] + "<" +
+        ConvertTypeToString(*(type.GetMetaType())) + ">";
+
+  return type_map_[type.ToString()];
+}
+
+std::string CsGeneratorBase::ConvertTypeToParcelType(const std::string& key) {
+  return parcel_type_map_[key];
+}
+
+std::string CsGeneratorBase::ConvertTypeToDeserializer(
+    const BaseType& type, std::string id, std::string parcel,
+    bool make_new_type, std::string iface_id) {
+  if (type.IsUserDefinedType() ||
+      type.GetMetaType() != nullptr) {
+    std::string n;
+
+    if (type.GetMetaType() != nullptr)
+      n = ConvertTypeToString(type);
+    else
+      n = type.ToString();
+
+    std::string ret;
+
+    if (make_new_type)
+      ret = n + " ";
+
+    if (IsDelegateType(type)) {
+      ret += id + " = new " + n
+          + "(GetPort(Port.Type.Callback, instance), new WeakReference(b));\n";
+      ret += "CallbackBase.";
+    } else {
+      ret += id + " = new " + n +"();\n";
+    }
+    if (iface_id != "")
+      ret += iface_id + ".";
+    ret += "Deserialize(" + parcel + ", " + id +");\n";
+    return ret;
+  }
+
+  std::string ret;
+  if (make_new_type) {
+    ret = ConvertTypeToString(type) + " "
+        + id + " = " + parcel + ".Read"
+        + parcel_type_map_[type.ToString()]
+        + "();\n";
+  } else {
+    ret = id + " = " + parcel + ".Read"
+        + parcel_type_map_[type.ToString()]
+        + "();\n";
+  }
+
+  return ret;
+}
+
+std::string CsGeneratorBase::ConvertTypeToSerializer(
+    const BaseType& type, std::string id, std::string parcel,
+    std::string iface_id) {
+  std::string ret;
+
+  if (type.IsUserDefinedType() ||
+      type.GetMetaType() != nullptr) {
+    if (IsDelegateType(type))
+      return "CallbackBase.Serialize(" + parcel + ", " + id + ");\n";
+    if (iface_id != "")
+      ret += iface_id + ".";
+    ret += "Serialize(" + parcel + ", " + id + ");\n";
+    return ret;
+  }
+
+  ret += parcel + ".Write"
+      + parcel_type_map_[type.ToString()] + "(" + id + ");\n";
+
+  return ret;
+}
+
+std::string CsGeneratorBase::Tab(int cnt) {
+  std::string t;
+
+  for (int i = 0; i < cnt; i++) {
+    t += "    ";
+  }
+
+  return t;
+}
+
+std::string CsGeneratorBase::NLine(int cnt) {
+  std::string t;
+
+  for (int i = 0; i < cnt; i++) {
+    t += "\n";
+  }
+
+  return t;
+}
+
+void CsGeneratorBase::GenWriteBundle(std::ofstream& stream,
+    const std::string& id) {
+  GenTemplate(CB_WRITE_BUNDLE, stream,
+    [&]()->std::string {
+      return id;
+    },
+    [&]()->std::string {
+      return id;
+    });
+}
+
+void CsGeneratorBase::GenMethodId(std::ofstream& stream,
+    const Interface& iface) {
+  stream << Tab(3) << "private enum MethodId : int" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    int cnt = 2;
+    stream << Tab(4) << "__Result = 0," << NLine(1);
+    stream << Tab(4) << "__Callback = 1," << NLine(1);
+    for (auto& i : iface.GetDeclarations().GetDecls()) {
+      if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+        continue;
+      stream << Tab(4)
+             << i->GetID() << " = " << cnt++ << "," << NLine(1);
+    }
+  });
+}
+
+void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
+    const Interface& iface) {
+  stream << Tab(3) << "private enum DelegateId : int" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    int cnt = 1;
+    for (auto& i : iface.GetDeclarations().GetDecls()) {
+        if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+          continue;
+        stream << Tab(4)
+               << i->GetID() << " = " << cnt++ << "," << NLine(1);
+    }
+  });
+  stream << NLine(1);
+}
+
+void CsGeneratorBase::GenDeclaration(std::ofstream& stream,
+                                     const Declaration& decl, bool semicol) {
+  stream << ConvertTypeToString(decl.GetType()) << " "
+         << decl.GetID() << "(";
+  GenParameters(stream, decl.GetParameters());
+  if (semicol)
+    stream << ");";
+  else
+    stream << ")";
+}
+
+void CsGeneratorBase::GenParameters(std::ofstream& stream,
+    const Parameters& ps) {
+  stream << GetParameters(ps);
+}
+
+std::string CsGeneratorBase::GetParameters(const Parameters& ps) {
+  bool first = true;
+  std::string ret;
+  for (auto& i : ps.GetParams()) {
+    if (!first) {
+      ret += ", ";
+    }
+
+    auto dir = i->GetParameterType().GetDirection();
+    if (dir == ParameterType::Direction::OUT) {
+      ret += "out ";
+    } else if (dir == ParameterType::Direction::REF) {
+      ret += "ref ";
+    }
+
+    ret += ConvertTypeToString(i->GetParameterType().GetBaseType())
+        + " " + i->GetID();
+    first = false;
+  }
+
+  return ret;
+}
+
+void CsGeneratorBase::GenCallbacks(std::ofstream& stream,
+                                   const Interface& iface, bool is_proxy) {
+  stream << CB_CALLBACK_BASE;
+
+  for (auto& i : iface.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+          continue;
+    GenCallback(stream, *i, iface.GetID(), is_proxy);
+  }
+}
+
+void CsGeneratorBase::GenCallback(std::ofstream& stream,
+                                  const Declaration& decl,
+                                  const std::string& id, bool is_proxy) {
+  stream << Tab(3) << "public sealed class " << decl.GetID()
+         << " : CallbackBase" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 3, [&]() {
+    GenTemplate(
+      is_proxy ? CB_CALLBACK_CTOR_PROXY : CB_CALLBACK_CTOR_STUB, stream,
+      [&]()->std::string {
+        return decl.GetID();
+      },
+      [&]()->std::string {
+        return decl.GetID();
+      });
+    stream << NLine(1);
+
+    if (is_proxy) {
+      stream << Tab(4) << "public delegate void Callback(";
+      GenParameters(stream, decl.GetParameters());
+      stream << ");" << NLine(1);
+      stream << Tab(4) << "public event Callback Received;" << NLine(2);
+      GenReceivedEvent(stream, decl, id);
+    } else {
+      stream << CB_CALLBACK_STUB_MEMBERS;
+      GenInvokeMethod(stream, decl, id);
+    }
+  });
+  stream << NLine(1);
+}
+
+void CsGeneratorBase::GenReceivedEvent(std::ofstream& stream,
+                                       const Declaration& decl,
+                                       const std::string& id) {
+  stream << Tab(4) << "internal override void OnReceivedEvent(Parcel parcel)"
+         << NLine(1);
+  GenBrace(stream, TAB_SIZE * 4, [&]() {
+    int cnt = 1;
+    for (auto& i : decl.GetParameters().GetParams()) {
+      std::string v = "param" + std::to_string(cnt);
+      std::string c = ConvertTypeToDeserializer(
+          i->GetParameterType().GetBaseType(), v, "parcel", true, id);
+      stream << AddIndent(TAB_SIZE * 5, c);
+      cnt++;
+    }
+
+    cnt = 1;
+    stream << Tab(5) << "Received?.Invoke(";
+    for (int i = 0; i < decl.GetParameters().GetParams().size(); i++) {
+      if (cnt != 1) {
+        stream << ", ";
+      }
+      std::string v = "param" + std::to_string(cnt);
+        stream << v;
+      cnt++;
+    }
+    stream << ");" << NLine(1);
+  });
+  stream << NLine(1);
+}
+
+void CsGeneratorBase::GenInvokeMethod(std::ofstream& stream,
+                                      const Declaration& decl,
+                                      const std::string& id) {
+  GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream,
+      [&]()->std::string {
+        return GetParameters(decl.GetParameters());
+      },
+      [&]()->std::string {
+        std::string m;
+        for (auto& i : decl.GetParameters().GetParams()) {
+          auto& pt = i->GetParameterType();
+          m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p", id);
+        }
+        return AddIndent(TAB_SIZE * 6, m);
+      });
+}
+
+void CsGeneratorBase::GenVersion(std::ofstream& stream) {
+  GenTemplate(::cs_cb_version, stream,
+    [&]()->std::string {
+      return FULLVER;
+    });
+  stream << NLine(1);
+}
+}  // namespace tidl
diff --git a/idlc/gen/cs_gen_base.h b/idlc/gen/cs_gen_base.h
new file mode 100644 (file)
index 0000000..c7c4cdd
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_GEN_BASE_H_
+#define IDLC_CS_GEN_CS_GEN_BASE_H_
+
+#include <memory>
+#include <string>
+#include <map>
+
+#include "idlc/ast/type.h"
+#include "idlc/ast/structure.h"
+#include "idlc/gen/generator.h"
+
+namespace tidl {
+
+class CsGeneratorBase : public Generator {
+ public:
+  explicit CsGeneratorBase(std::shared_ptr<Document> doc);
+  virtual ~CsGeneratorBase() = default;
+
+  void GenVersion(std::ofstream& stream);
+  void GenStructures(std::ofstream& stream);
+  void GenStructure(std::ofstream& stream, const Structure& st);
+  void GenSerializer(std::ofstream& stream);
+  void GenSerializer(std::ofstream& stream, const Structure& st);
+  void GenListSerializer(std::ofstream& stream);
+  void GenListSerializer(std::ofstream& stream, const BaseType& type);
+  void GenMethodId(std::ofstream& stream, const Interface& iface);
+  void GenDelegateId(std::ofstream& stream, const Interface& iface);
+  void GenDeclaration(std::ofstream& stream,
+                      const Declaration& decl, bool semicol = true);
+  void GenParameters(std::ofstream& stream, const Parameters& ps);
+  void GenCallbacks(std::ofstream& stream, const Interface& iface,
+                    bool is_proxy);
+
+  std::string ConvertTypeToString(const BaseType& type);
+  std::string ConvertTypeToDeserializer(const BaseType& type,
+                                        std::string id, std::string parcel,
+                                        bool make_new_type = true,
+                                        const std::string iface_id = "");
+  std::string ConvertTypeToSerializer(const BaseType& type,
+                                      std::string id, std::string parcel,
+                                      const std::string iface_id = "");
+  std::string ConvertTypeToParcelType(const std::string& key);
+  std::string GetParameters(const Parameters& ps);
+  std::string Tab(int cnt);
+  std::string NLine(int cnt);
+
+ protected:
+  const int TAB_SIZE = 4;
+
+ private:
+  void GenWriteBundle(std::ofstream& stream, const std::string& id);
+  void AddSerializerList(const BaseType& type);
+  void GenCallback(std::ofstream& stream, const Declaration& decl,
+                   const std::string& id, bool is_proxy);
+  void GenReceivedEvent(std::ofstream& stream, const Declaration& decl,
+                        const std::string& id);
+  void GenInvokeMethod(std::ofstream& stream, const Declaration& decl,
+                       const std::string& id);
+
+ private:
+  std::map<std::string, std::string> type_map_;
+  std::map<std::string, std::string> parcel_type_map_;
+  std::map<std::string, const BaseType*> serializer_list_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CS_GEN_CS_GEN_BASE_H_
diff --git a/idlc/gen/cs_gen_base_cb.h b/idlc/gen/cs_gen_base_cb.h
new file mode 100644 (file)
index 0000000..aabc490
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_GEN_BASE_CB_H_
+#define IDLC_CS_GEN_CS_GEN_BASE_CB_H_
+
+const char CB_CALLBACK_BASE[] =
+R"__cs_cb(
+            public abstract class CallbackBase
+            {
+                internal int Id;
+                internal int SeqId;
+                internal bool Once;
+                private static volatile int _seqNum = 0;
+
+                public string Tag
+                {
+                    get
+                    {
+                        return Id.ToString() + "::" + SeqId.ToString();
+                    }
+                }
+
+                public CallbackBase(int delegateId, bool once)
+                {
+                    Id = delegateId;
+                    SeqId = _seqNum++;
+                    Once = once;
+                }
+
+                internal virtual void OnReceivedEvent(Parcel p) {}
+
+                internal static void Serialize(Parcel h, CallbackBase param)
+                {
+                    h.WriteInt(param.Id);
+                    h.WriteInt(param.SeqId);
+                    h.WriteBool(param.Once);
+                }
+
+                internal static void Deserialize(Parcel h, CallbackBase param)
+                {
+                    param.Id = h.ReadInt();
+                    param.SeqId = h.ReadInt();
+                    param.Once = h.ReadBool();
+                }
+            }
+
+)__cs_cb";
+
+const char CB_CALLBACK_CTOR_PROXY[] =
+R"__cs_cb(                public $$(bool once = false) : base((int)DelegateId.$$, once)
+                {
+                }
+)__cs_cb";
+
+const char CB_CALLBACK_CTOR_STUB[] =
+R"__cs_cb(                internal $$(Port port, WeakReference service) : base((int)DelegateId.$$, false)
+                {
+                    _port = port;
+                    _service = service;
+                }
+)__cs_cb";
+
+const char CB_CALLBACK_STUB_MEMBERS[] =
+R"__cs_cb(                private Port _port;
+                private WeakReference _service;
+                private bool _valid = true;
+
+)__cs_cb";
+
+const char CB_CALLBACK_INVOKE_METHOD[] =
+R"__cs_cb(
+                public void Invoke($$)
+                {
+                    if (_port == null)
+                        throw new NotConnectedSocketException();
+                    if (!_service.IsAlive)
+                        throw new InvalidProtocolException();
+                    if (Once && !_valid)
+                        throw new InvalidCallbackException();
+
+                    using (var p = new Parcel())
+                    {
+                        p.WriteInt((int)MethodId.__Callback);
+                        Serialize(p, this);
+$$
+                        // Send
+                        p.Send(_port);
+                        _valid = false;
+                    }
+                }
+)__cs_cb";
+
+const char CB_PROPERTY[] = R"__cs_cb(        public $$ $$ { get; set; }
+)__cs_cb";
+
+const char CB_CTOR[] = R"__cs_cb(
+        public $$()
+        {
+$$
+        }
+)__cs_cb";
+
+const char CB_WRITE_BUNDLE[] =
+R"__cs_cb(
+                if (param.$$ != null)
+                {
+                    h.WriteBundle(param.$$);
+                }
+                else
+                {
+                    h.WriteBundle(new Bundle());
+                }
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_GEN_BASE_CB_H_
diff --git a/idlc/gen/cs_lib_gen.cc b/idlc/gen/cs_lib_gen.cc
new file mode 100644 (file)
index 0000000..124aa3e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cs_lib_gen.h"
+
+namespace {
+#include "idlc/gen/cs_cb_rpc_port.h"
+#include "idlc/gen/cs_cb_interop.h"
+}
+
+namespace tidl {
+
+CsLibGen::CsLibGen(std::shared_ptr<Document> doc)
+    : CsGeneratorBase(doc) {}
+
+void CsLibGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << "using System;" << NLine(1)
+         << "using System.Collections.Generic;" << NLine(1)
+         << "using System.Runtime.InteropServices;" << NLine(1)
+         << "using Tizen.Applications;" << NLine(1);
+  GenInterop(stream);
+  GenRpcPort(stream);
+}
+
+void CsLibGen::OnFiniGen(std::ofstream& stream) {}
+
+void CsLibGen::GenInterop(std::ofstream& stream) {
+  stream << cs_cb_interop;
+}
+
+void CsLibGen::GenRpcPort(std::ofstream& stream) {
+  stream << cs_cb_rpc_port;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cs_lib_gen.h b/idlc/gen/cs_lib_gen.h
new file mode 100644 (file)
index 0000000..f4c0719
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_LIB_GEN_H_
+#define IDLC_CS_GEN_CS_LIB_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cs_gen_base.h"
+
+namespace tidl {
+
+class CsLibGen : public CsGeneratorBase {
+ public:
+  explicit CsLibGen(std::shared_ptr<Document> doc);
+  virtual ~CsLibGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenInterop(std::ofstream& stream);
+  void GenRpcPort(std::ofstream& stream);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CS_GEN_CS_LIB_GEN_H_
diff --git a/idlc/gen/cs_proxy_gen.cc b/idlc/gen/cs_proxy_gen.cc
new file mode 100644 (file)
index 0000000..280decd
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cs_proxy_gen.h"
+
+namespace {
+#include "idlc/gen/cs_proxy_gen_cb.h"
+}
+
+namespace tidl {
+
+CsProxyGen::CsProxyGen(std::shared_ptr<Document> doc)
+    : CsGeneratorBase(doc) {}
+
+void CsProxyGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << "using System;" << NLine(1)
+         << "using System.Collections.Generic;" << NLine(1)
+         << "using System.Threading;" << NLine(1)
+         << "using Tizen.Applications;" << NLine(1)
+        << "using Tizen.Applications.RPCPort;" << NLine(1);
+  GenNamespace(stream);
+}
+
+void CsProxyGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CsProxyGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace RPCPort" << NLine(1);
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << NLine(1);
+    GenBrace(stream, 0, [&]() {
+      GenStructures(stream);
+      stream << Tab(1) << "namespace Proxy" << NLine(1);
+      GenBrace(stream, TAB_SIZE, [&]() {
+        GenInterfaces(stream);
+      });
+    });
+  });
+}
+
+void CsProxyGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+    stream << NLine(1);
+  }
+}
+
+void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
+  stream << Tab(2) << "public class " << iface.GetID()
+         << " : ProxyBase" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 2, [&]() {
+    stream << CB_DATA_MEMBERS;
+    GenCallbacks(stream, iface, true);
+    GenDelegateId(stream, iface);
+    GenMethodId(stream, iface);
+    stream << CB_EVENT_METHODS;
+    GenSerializer(stream);
+    GenListSerializer(stream);
+    GenCtor(stream, iface);
+    GenConnectMethod(stream, iface);
+    GenMethods(stream, iface);
+  });
+}
+
+void CsProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) {
+  const char* m = "public $$(string appId) => _appId = appId;\n";
+
+  stream << NLine(1);
+  GenTemplate(AddIndent(TAB_SIZE * 3, m), stream,
+    [&]()->std::string {
+      return iface.GetID();
+    });
+}
+
+void CsProxyGen::GenConnectMethod(std::ofstream& stream,
+    const Interface& iface) {
+  GenTemplate(CB_CONNECT_METHOD, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    });
+  stream << NLine(1);
+}
+
+void CsProxyGen::GenMethods(std::ofstream& stream, const Interface& iface) {
+  auto& decls = iface.GetDeclarations();
+
+  for (auto& i : decls.GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+
+    if (!i->GetComments().empty())
+      stream << AddIndent(TAB_SIZE * 3, i->GetComments());
+
+    stream << Tab(3) << "public ";
+    GenDeclaration(stream, *i, false);
+    stream << NLine(1);
+    GenBrace(stream, TAB_SIZE * 3, [&]() {
+      GenInvocation(stream, *i);
+    });
+    stream << NLine(1);
+  }
+}
+
+void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
+  GenTemplate(CB_INVOCATION_PRE, stream,
+    [&]()->std::string {
+      std::string st;
+      st += Tab(5)
+         + "p.WriteInt((int)MethodId." + decl.GetID() + ");" + NLine(1);
+      std::string m;
+      std::string l;
+      for (auto& i : decl.GetParameters().GetParams()) {
+        auto& pt = i->GetParameterType();
+        if (pt.GetDirection() == ParameterType::Direction::OUT)
+          continue;
+        m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
+        if (IsDelegateType(pt.GetBaseType())) {
+          l += "_delegateList.Add(" + i->GetID() + ");\n";
+        }
+      }
+
+      st += AddIndent(TAB_SIZE * 5, m) + NLine(1);
+
+      if (decl.GetMethodType() == Declaration::MethodType::SYNC)
+        st += Tab(5) + "Parcel parcelReceived;" + NLine(1);
+      st += Tab(5) + "lock (_lock)" + NLine(1);
+      st += Tab(5) + "{" + NLine(1);
+        if (!l.empty())
+          st += AddIndent(TAB_SIZE * 6, l) + NLine(1);
+        st += CB_INVOCATION_MID + NLine(1);
+        if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
+          st += Tab(6) + "// Receive" + NLine(1);
+          st += Tab(6)
+             + "ConsumeCommand(out parcelReceived, Port);" + NLine(1);
+        }
+      st += Tab(5) + "}";
+
+      // Deserialize
+      if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
+        return st;
+      }
+
+      const char* receive_block =
+          "if (parcelReceived == null)\n" \
+          "{\n" \
+          "    throw new InvalidProtocolException();\n" \
+          "}\n";
+      st += NLine(1) + AddIndent(TAB_SIZE * 5, receive_block) + NLine(1);
+
+      for (auto& i : decl.GetParameters().GetParams()) {
+        if (i->GetParameterType().GetDirection() ==
+            ParameterType::Direction::IN) {
+          continue;
+        }
+
+        std::string c = ConvertTypeToDeserializer(
+            i->GetParameterType().GetBaseType(),
+            i->GetID(), "parcelReceived", false);
+        if (c != "")
+          st += AddIndent(TAB_SIZE * 5, c);
+      }
+
+      if (decl.GetType().ToString() != "void") {
+        st += AddIndent(TAB_SIZE * 5,
+                        ConvertTypeToDeserializer(decl.GetType(),
+                                                  "ret", "parcelReceived"));
+      }
+
+      st += Tab(5) + "parcelReceived.Dispose();" + NLine(1);
+      st += Tab(5) + "return ret;";
+
+      return st;
+    });
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cs_proxy_gen.h b/idlc/gen/cs_proxy_gen.h
new file mode 100644 (file)
index 0000000..3b9b758
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_PROXY_GEN_H_
+#define IDLC_CS_GEN_CS_PROXY_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cs_gen_base.h"
+
+namespace tidl {
+
+class CsProxyGen : public CsGeneratorBase {
+ public:
+  explicit CsProxyGen(std::shared_ptr<Document> doc);
+  virtual ~CsProxyGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenCtor(std::ofstream& stream, const Interface& iface);
+  void GenConnectMethod(std::ofstream& stream, const Interface& iface);
+  void GenMethods(std::ofstream& stream, const Interface& iface);
+  void GenInvocation(std::ofstream& stream, const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CS_GEN_CS_PROXY_GEN_H_
diff --git a/idlc/gen/cs_proxy_gen_cb.h b/idlc/gen/cs_proxy_gen_cb.h
new file mode 100644 (file)
index 0000000..a9f51ff
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
+#define IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
+
+const char CB_DATA_MEMBERS[] =
+R"__cs_cb(            public event EventHandler Connected;
+            public event EventHandler Disconnected;
+            public event EventHandler Rejected;
+
+            private bool _online = false;
+            private string _appId;
+            private Object _lock = new Object();
+            private List<CallbackBase> _delegateList = new List<CallbackBase>();
+)__cs_cb";
+
+const char CB_EVENT_METHODS[] =
+R"__cs_cb(
+            protected override void OnConnectedEvent(string endPoint, string portName, Port port)
+            {
+                _online = true;
+                Connected?.Invoke(this, null);
+            }
+
+            protected override void OnDisconnectedEvent(string endPoint, string portName)
+            {
+                _online = false;
+                Disconnected?.Invoke(this, null);
+            }
+
+            protected override void OnRejectedEvent(string endPoint, string portName)
+            {
+                Rejected?.Invoke(this, null);
+            }
+
+            private void ProcessReceivedEvent(Parcel parcel)
+            {
+                int id = parcel.ReadInt();
+                int seqId = parcel.ReadInt();
+                bool once = parcel.ReadBool();
+
+                foreach (var i in _delegateList)
+                {
+                    if ((int)i.Id == id && i.SeqId == seqId)
+                    {
+                        i.OnReceivedEvent(parcel);
+                        if (i.Once)
+                            _delegateList.Remove(i);
+                        break;
+                    }
+                }
+            }
+
+            protected override void OnReceivedEvent(string endPoint, string portName)
+            {
+                Parcel parcelReceived;
+
+                parcelReceived = new Parcel(CallbackPort);
+
+                using (parcelReceived)
+                {
+                    int cmd = parcelReceived.ReadInt();
+                    if (cmd != (int)MethodId.__Callback)
+                    {
+                        return;
+                    }
+
+                    ProcessReceivedEvent(parcelReceived);
+                }
+            }
+
+            private void ConsumeCommand(out Parcel parcel, Port port)
+            {
+                do
+                {
+                    var p = new Parcel(port);
+
+                    int cmd = p.ReadInt();
+                    if (cmd == (int)MethodId.__Result)
+                    {
+                        parcel = p;
+                        return;
+                    }
+
+                    p.Dispose();
+                    parcel = null;
+                } while (true);
+            }
+)__cs_cb";
+
+const char CB_CONNECT_METHOD[] =
+R"__cs_cb(
+            /// <summary>
+            /// Connects to the service app.
+            /// </summary>
+            /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+            /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+            /// <exception cref="InvalidIDException">
+            /// Thrown when the appid to connect is invalid.
+            /// </exception>
+            /// <exception cref="InvalidIOException">
+            /// Thrown when internal I/O error happen.
+            /// </exception>
+            /// <exception cref="PermissionDeniedException">
+            /// Thrown when the permission is denied.
+            /// </exception>
+            /// <remark> If you want to use this method, you must add privileges.</remark>
+            public void Connect()
+            {
+                Connect(_appId, "$$");
+            }
+
+            /// <summary>
+            /// Disposes delegate objects in this interface
+            /// </summary>
+            /// <param name="tag">The tag string from delegate object</param>
+            void DisposeCallback(string tag)
+            {
+                foreach (var i in _delegateList)
+                {
+                    if (i.Tag.Equals(tag))
+                    {
+                        _delegateList.Remove(i);
+                        return;
+                    }
+                }
+            }
+)__cs_cb";
+
+const char CB_INVOCATION_PRE[] =
+R"__cs_cb(                if (!_online)
+                    throw new NotConnectedSocketException();
+
+                using (Parcel p = new Parcel())
+                {
+$$
+               }
+)__cs_cb";
+
+const char CB_INVOCATION_MID[] =
+R"__cs_cb(                        // Send
+                        p.Send(Port);
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
diff --git a/idlc/gen/cs_stub_gen.cc b/idlc/gen/cs_stub_gen.cc
new file mode 100644 (file)
index 0000000..04b68b3
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/gen/cs_stub_gen.h"
+
+namespace {
+#include "idlc/gen/cs_stub_gen_cb.h"
+}
+
+namespace tidl {
+
+CsStubGen::CsStubGen(std::shared_ptr<Document> doc)
+    : CsGeneratorBase(doc) {}
+
+void CsStubGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << "using System;" << NLine(1)
+         << "using System.Collections.Generic;" << NLine(1)
+         << "using Tizen.Applications;" << NLine(1)
+         << "using Tizen.Applications.RPCPort;" << NLine(1);
+
+  GenNamespace(stream);
+}
+
+void CsStubGen::OnFiniGen(std::ofstream& stream) {}
+
+void CsStubGen::GenNamespace(std::ofstream& stream) {
+  stream << "namespace RPCPort" << NLine(1);
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << NLine(1);
+    GenBrace(stream, 0, [&]() {
+      GenStructures(stream);
+      stream << Tab(1) << "namespace Stub" << NLine(1);
+      GenBrace(stream, TAB_SIZE, [&]() {
+        GenInterfaces(stream);
+      });
+    });
+  });
+}
+
+void CsStubGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+    stream << std::endl;
+  }
+}
+
+void CsStubGen::GenInterface(std::ofstream& stream, const Interface& iface) {
+  stream << Tab(2) << "public sealed class " << iface.GetID()
+         << " : StubBase" << NLine(1);
+  GenBrace(stream, TAB_SIZE * 2, [&]() {
+    stream << CB_DATA_MEMBERS;
+    GenServiceBase(stream, iface);
+    GenCallbacks(stream, iface, false);
+    GenDelegateId(stream, iface);
+    GenMethodId(stream, iface);
+    GenSerializer(stream);
+    GenListSerializer(stream);
+    GenReceivedEvent(stream, iface);
+    GenConnectedEvent(stream);
+    GenDisconnectedEvent(stream);
+    GenCtor(stream, iface);
+    GenCommonMethods(stream);
+    GenDisposable(stream, iface);
+  });
+}
+
+void CsStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) {
+  stream << CB_SERVICE_BASE_FRONT;
+  GenDeclarations(stream, iface.GetDeclarations());
+  stream << NLine(1);
+  stream << AddIndent(TAB_SIZE * 3, "}\n");
+}
+
+void CsStubGen::GenDeclarations(std::ofstream& stream,
+                                const Declarations& decls) {
+  for (auto& i : decls.GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    if (!i->GetComments().empty())
+      stream << NLine(1) << AddIndent(TAB_SIZE * 4, i->GetComments());
+    stream << Tab(4) << "public abstract ";
+    GenDeclaration(stream, *i);
+    stream << NLine(1);
+  }
+}
+
+void CsStubGen::GenReceivedEvent(std::ofstream& stream,
+    const Interface& iface) {
+  stream << CB_ON_RECEIVED_EVENT_FRONT;
+  for (auto& i : iface.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+      continue;
+    stream << Tab(7) << "case MethodId." << i->GetID() << ":" << NLine(1);
+    GenBrace(stream, TAB_SIZE * 8, [&]() {
+      GenInvocation(stream, *i);
+      stream << Tab(9) << "break;" << NLine(1);
+    });
+  }
+  stream << CB_ON_RECEIVED_EVENT_BACK;
+}
+
+void CsStubGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
+  int cnt = 1;
+
+  // Deserialize
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
+      cnt++;
+      continue;
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    std::string c = ConvertTypeToDeserializer(
+        i->GetParameterType().GetBaseType(), v, "p");
+    stream << AddIndent(TAB_SIZE * 9, c);
+    cnt++;
+  }
+
+  // Invoke
+  cnt = 1;
+  std::string m;
+  bool hasRet = false;
+
+  if (decl.GetType().ToString() != "void") {
+    m += "var retVal = ";
+    hasRet = true;
+  }
+
+  m += "b." + decl.GetID() + "(";
+  for (auto& i : decl.GetParameters().GetParams()) {
+    if (cnt != 1) {
+      m += ", ";
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    auto& pt = i->GetParameterType();
+    if (pt.GetDirection() == ParameterType::Direction::OUT) {
+      m += "out " + ConvertTypeToString(pt.GetBaseType()) + " ";
+    } else if (pt.GetDirection() == ParameterType::Direction::REF) {
+      m += "ref ";
+    }
+    m += v;
+    cnt++;
+  }
+
+  m += ");\n";
+  stream << AddIndent(TAB_SIZE * 9, m);
+
+  // Serialize
+  if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
+    return;
+
+  cnt = 0;
+  m = "result.WriteInt((int)MethodId.__Result);\n";
+  for (auto& i : decl.GetParameters().GetParams()) {
+    auto& pt = i->GetParameterType();
+    cnt++;
+    if (pt.GetDirection() == ParameterType::Direction::IN)
+      continue;
+    m += ConvertTypeToSerializer(pt.GetBaseType(),
+                                "param" + std::to_string(cnt), "result");
+  }
+
+  if (hasRet) {
+    m += ConvertTypeToSerializer(decl.GetType(), "retVal", "result");
+  }
+
+  m += "result.Send(port);\n";
+  stream << AddIndent(TAB_SIZE * 9, m);
+}
+
+void CsStubGen::GenConnectedEvent(std::ofstream& stream) {
+  stream << CB_ON_CONNECTED_EVENT;
+}
+
+void CsStubGen::GenDisconnectedEvent(std::ofstream& stream) {
+  stream << CB_ON_DISCONNECTED_EVENT;
+}
+
+void CsStubGen::GenCtor(std::ofstream& stream, const Interface& iface) {
+  GenTemplate(CB_CTOR_FRONT, stream,
+    [&]()->std::string {
+      return iface.GetID();
+    },
+    [&]()->std::string {
+      return iface.GetID();
+    });
+
+  for (auto& i : iface.GetAttributes().GetAttrs()) {
+    if (i->GetKey() == "privilege") {
+      stream << Tab(4) << "AddPrivilege(\""
+             << i->GetValue() << "\");" << NLine(1);
+    } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
+      stream << Tab(4) << "SetTrusted("
+             << i->GetValue() << ");" << NLine(1);
+    }
+  }
+  stream << Tab(3) << "}" << NLine(1);
+}
+
+void CsStubGen::GenCommonMethods(std::ofstream& stream) {
+  stream << CB_COMMON_METHODS;
+}
+
+void CsStubGen::GenDisposable(std::ofstream& stream, const Interface& iface) {
+  stream << CB_DISPOSABLE;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cs_stub_gen.h b/idlc/gen/cs_stub_gen.h
new file mode 100644 (file)
index 0000000..b697e4e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_STUB_GEN_H_
+#define IDLC_CS_GEN_CS_STUB_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cs_gen_base.h"
+
+namespace tidl {
+
+class CsStubGen : public CsGeneratorBase {
+ public:
+  explicit CsStubGen(std::shared_ptr<Document> doc);
+  virtual ~CsStubGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  void GenServiceBase(std::ofstream& stream, const Interface& iface);
+  void GenReceivedEvent(std::ofstream& stream, const Interface& iface);
+  void GenConnectedEvent(std::ofstream& stream);
+  void GenDisconnectedEvent(std::ofstream& stream);
+  void GenCtor(std::ofstream& stream, const Interface& iface);
+  void GenCommonMethods(std::ofstream& stream);
+  void GenDeclarations(std::ofstream& stream, const Declarations& decls);
+  void GenInvocation(std::ofstream& stream, const Declaration& decl);
+  void GenDisposable(std::ofstream& stream, const Interface& iface);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CS_GEN_CS_STUB_GEN_H_
diff --git a/idlc/gen/cs_stub_gen_cb.h b/idlc/gen/cs_stub_gen_cb.h
new file mode 100644 (file)
index 0000000..3be382a
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CS_GEN_CS_STUB_GEN_CB_H_
+#define IDLC_CS_GEN_CS_STUB_GEN_CB_H_
+
+const char CB_DATA_MEMBERS[] =
+R"__cs_cb(            private List<ServiceBase> _services = new List<ServiceBase>();
+            private Type _serviceType;
+)__cs_cb";
+
+const char CB_SERVICE_BASE_FRONT[] =
+R"__cs_cb(
+            public abstract class ServiceBase
+            {
+                /// <summary>
+                /// The client app ID
+                /// </summary>
+                public string Sender
+                {
+                    get; internal set;
+                }
+
+                /// <summary>
+                /// The client instance ID
+                /// </summary>
+                public string Instance
+                {
+                    get; internal set;
+                }
+
+                protected ServiceBase()
+                {
+                }
+
+                /// <summary>
+                /// This method will be called when the client is connected
+                /// </summary>
+                public abstract void OnCreate();
+
+                /// <summary>
+                /// This method will be called when the client is disconnected
+                /// </summary>
+                public abstract void OnTerminate();
+)__cs_cb";
+
+const char CB_ON_RECEIVED_EVENT_FRONT[] =
+R"__cs_cb(
+            protected override bool OnReceivedEvent(string sender, string instance, Port port)
+            {
+                var p = new Parcel(port);
+
+                try
+                {
+                    ServiceBase b = null;
+
+                    foreach (var i in  _services)
+                    {
+                        if (i.Instance.Equals(instance))
+                        {
+                            b = i;
+                            break;
+                        }
+                    }
+
+                    if (b == null)
+                    {
+                        return false;
+                    }
+
+                    using (var result = new Parcel())
+                    {
+                        int cmd = p.ReadInt();
+
+                        switch ((MethodId)cmd)
+                        {
+)__cs_cb";
+
+const char CB_ON_RECEIVED_EVENT_BACK[] =
+R"__cs_cb(
+                            default:
+                                return false;
+                        }
+                    }
+
+                    return true;
+                }
+                catch (InvalidIOException)
+                {
+                    return false;
+                }
+                finally
+                {
+                    p.Dispose();
+                }
+            }
+)__cs_cb";
+
+const char CB_ON_CONNECTED_EVENT[] =
+R"__cs_cb(
+            protected override void OnConnectedEvent(string sender, string instance)
+            {
+                ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
+                s.Sender = sender;
+                s.Instance = instance;
+                s.OnCreate();
+                _services.Add(s);
+            }
+)__cs_cb";
+
+const char CB_ON_DISCONNECTED_EVENT[] =
+R"__cs_cb(
+            protected override void OnDisconnectedEvent(string sender, string instance)
+            {
+                foreach (var i in _services)
+                {
+                    if (i.Instance.Equals(instance))
+                    {
+                        i.OnTerminate();
+                        _services.Remove(i);
+                        break;
+                    }
+                }
+            }
+)__cs_cb";
+
+const char CB_CTOR_FRONT[] =
+R"__cs_cb(
+            public $$() : base("$$")
+            {
+)__cs_cb";
+
+const char CB_COMMON_METHODS[] =
+R"__cs_cb(
+            /// <summary>
+            /// Listens to client apps
+            /// </summary>
+            /// <param name="serviceType">The type object for making service instances</param>
+            /// <exception cref="InvalidIOException">
+            /// Thrown when internal I/O error happen.
+            /// </exception>
+            /// <exception cref="ArgumentException">
+            /// Thrown when serviceType is invalid.
+            /// </exception>
+            public void Listen(Type serviceType)
+            {
+                if (!typeof(ServiceBase).IsAssignableFrom(serviceType))
+                    throw new ArgumentException("Invalid type");
+                _serviceType = serviceType;
+                Listen();
+            }
+
+            /// <summary>
+            /// Gets service objects which are connected
+            /// </summary>
+            /// <returns>The enumerable service objects which are connected</returns>
+            public IEnumerable<ServiceBase> GetServices()
+            {
+                return _services;
+            }
+)__cs_cb";
+
+const char CB_DISPOSABLE[] =
+R"__cs_cb(
+            protected override void OnTerminatedEvent()
+            {
+                foreach (var i in _services)
+                {
+                    i.OnTerminate();
+                }
+            }
+)__cs_cb";
+
+#endif  // IDLC_CS_GEN_CS_STUB_GEN_CB_H_
diff --git a/idlc/gen/generator.cc b/idlc/gen/generator.cc
new file mode 100644 (file)
index 0000000..19bcc0b
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sstream>
+
+#include "idlc/gen/generator.h"
+#include "idlc/ast/block.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/attribute.h"
+
+namespace tidl {
+
+Generator::Generator(std::shared_ptr<Document> doc) : doc_(doc) {}
+
+void Generator::Run(const std::string& file_name) {
+  FileName = file_name;
+  out_file_.open(FileName);
+
+  OnInitGen(out_file_);
+  OnFiniGen(out_file_);
+  out_file_.close();
+}
+
+std::string Generator::AddIndent(int indent, std::string lines, bool space) {
+  std::stringstream ss(lines);
+  std::string result;
+  std::string to;
+
+  while (std::getline(ss, to, '\n')) {
+    if (to.length() > 0) {
+      for (int i = 0; i < indent; i++) {
+        if (space)
+          result += " ";
+        else
+          result += "\t";
+      }
+    }
+
+    result += to;
+    result += "\n";
+  }
+
+  return result;
+}
+
+std::string Generator::GetFileNamespace() const {
+  std::string key1(".");
+  std::string key2("/");
+
+  std::size_t p2 = FileName.rfind(key1);
+  std::size_t p1 = FileName.rfind(key2);
+  if (p2 == std::string::npos)
+    p2 = 0;
+  if (p1 == std::string::npos)
+    p1 = 0;
+
+  return FileName.substr(p1, p2 - p1);
+}
+
+std::string Generator::ReplaceAll(std::string str,
+                                  const std::string& from,
+                                  const std::string& to) {
+  std::size_t pos = 0;
+  while ((pos = str.find(from, pos)) != std::string::npos) {
+    str.replace(pos, from.length(), to);
+    pos += to.length();
+  }
+  return str;
+}
+
+bool Generator::IsDelegateType(const BaseType& type) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+
+    if (IsDelegateType(iface, type))
+      return true;
+  }
+
+  return false;
+}
+
+bool Generator::IsDelegateType(const Interface& inf,
+                               const BaseType& type) {
+  for (auto& i : inf.GetDeclarations().GetDecls()) {
+    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+      continue;
+    if (i->GetID() == type.ToString())
+      return true;
+  }
+  return false;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/generator.h b/idlc/gen/generator.h
new file mode 100644 (file)
index 0000000..249b594
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_GENERATOR_H_
+#define IDLC_GENERATOR_H_
+
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <memory>
+#include <utility>
+
+#include "idlc/ast/document.h"
+#include "idlc/ast/parameter.h"
+#include "idlc/ast/type.h"
+
+namespace tidl {
+
+class Generator {
+ public:
+  explicit Generator(std::shared_ptr<Document> doc);
+  virtual ~Generator() = default;
+
+  void Run(const std::string& file_name);
+  std::string AddIndent(int indent, std::string lines, bool space = true);
+  std::string GetFileNamespace() const;
+  std::string ReplaceAll(std::string str,
+                         const std::string& from, const std::string& to);
+  bool IsDelegateType(const Interface& inf, const BaseType& type);
+  bool IsDelegateType(const BaseType& type);
+
+  void EnableNamespace(bool enable) {
+    hasNamespace_ = enable;
+  }
+
+  bool HasNamespace() const {
+    return hasNamespace_;
+  }
+
+  template<typename T, typename ...ARGS>
+  void GenTemplate(std::string templ, std::ofstream& stream,
+      T cb, ARGS... args) {
+    size_t f = templ.find("$$");
+    templ.replace(f, std::string("$$").length(), cb());
+    GenTemplate(std::move(templ), stream, args...);
+  }
+
+  template<typename T>
+  void GenTemplate(std::string templ, std::ofstream& stream, T cb) {
+    size_t f = templ.find("$$");
+    templ.replace(f, std::string("$$").length(), cb());
+    stream << templ;
+  }
+
+  template<typename T, typename ...ARGS>
+  std::string GenTemplateString(std::string templ, T cb, ARGS... args) {
+    size_t f = templ.find("$$");
+    templ.replace(f, std::string("$$").length(), cb());
+    return GenTemplateString(std::move(templ), args...);
+  }
+
+  template<typename T>
+  std::string GenTemplateString(std::string templ, T cb) {
+    size_t f = templ.find("$$");
+    templ.replace(f, std::string("$$").length(), cb());
+    return templ;
+  }
+
+  template<typename T>
+  void GenBrace(std::ofstream& stream, int indent, T cb,
+                bool start_indent = true, bool ended_new_line = true) {
+    if (start_indent) {
+      for (int i = 0; i < indent; i++)
+        stream << " ";
+    }
+    stream << "{" << std::endl;
+    cb();
+    for (int i = 0; i < indent; i++)
+        stream << " ";
+    stream << "}";
+    if (ended_new_line)
+      stream << std::endl;
+  }
+
+  virtual void OnInitGen(std::ofstream& stream) = 0;
+  virtual void OnFiniGen(std::ofstream& stream) = 0;
+
+ protected:
+  const Document& GetDocument() {
+    return *doc_;
+  }
+
+ protected:
+  std::string FileName;
+
+ private:
+  static void CallEmptyCallback(int pos) {}
+
+ private:
+  std::shared_ptr<Document> doc_;
+  std::ofstream out_file_;
+  bool hasNamespace_ = true;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_GENERATOR_H_
diff --git a/idlc/generator.cc b/idlc/generator.cc
deleted file mode 100644 (file)
index 41f41be..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sstream>
-
-#include "idlc/generator.h"
-#include "idlc/block.h"
-#include "idlc/interface.h"
-#include "idlc/structure.h"
-#include "idlc/declaration.h"
-#include "idlc/attribute.h"
-
-namespace tidl {
-
-Generator::Generator(std::shared_ptr<Document> doc) : doc_(doc) {}
-
-void Generator::Run(const std::string& file_name) {
-  FileName = file_name;
-  out_file_.open(FileName);
-
-  OnInitGen(out_file_);
-  OnFiniGen(out_file_);
-  out_file_.close();
-}
-
-std::string Generator::AddIndent(int indent, std::string lines, bool space) {
-  std::stringstream ss(lines);
-  std::string result;
-  std::string to;
-
-  while (std::getline(ss, to, '\n')) {
-    if (to.length() > 0) {
-      for (int i = 0; i < indent; i++) {
-        if (space)
-          result += " ";
-        else
-          result += "\t";
-      }
-    }
-
-    result += to;
-    result += "\n";
-  }
-
-  return result;
-}
-
-std::string Generator::GetFileNamespace() const {
-  std::string key1(".");
-  std::string key2("/");
-
-  std::size_t p2 = FileName.rfind(key1);
-  std::size_t p1 = FileName.rfind(key2);
-  if (p2 == std::string::npos)
-    p2 = 0;
-  if (p1 == std::string::npos)
-    p1 = 0;
-
-  return FileName.substr(p1, p2 - p1);
-}
-
-std::string Generator::ReplaceAll(std::string str,
-                                  const std::string& from,
-                                  const std::string& to) {
-  std::size_t pos = 0;
-  while ((pos = str.find(from, pos)) != std::string::npos) {
-    str.replace(pos, from.length(), to);
-    pos += to.length();
-  }
-  return str;
-}
-
-bool Generator::IsDelegateType(const BaseType& type) {
-  for (auto& i : GetDocument().GetBlocks()) {
-    if (i->GetType() != Block::TYPE_INTERFACE)
-      continue;
-    Interface& iface = static_cast<Interface&>(*i);
-
-    if (IsDelegateType(iface, type))
-      return true;
-  }
-
-  return false;
-}
-
-bool Generator::IsDelegateType(const Interface& inf,
-                               const BaseType& type) {
-  for (auto& i : inf.GetDeclarations().GetDecls()) {
-    if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
-      continue;
-    if (i->GetID() == type.ToString())
-      return true;
-  }
-  return false;
-}
-
-}  // namespace tidl
diff --git a/idlc/generator.h b/idlc/generator.h
deleted file mode 100644 (file)
index ed6b4ee..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_GENERATOR_H_
-#define IDLC_GENERATOR_H_
-
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <memory>
-#include <utility>
-
-#include "idlc/document.h"
-#include "idlc/parameter.h"
-#include "idlc/type.h"
-
-namespace tidl {
-
-class Generator {
- public:
-  explicit Generator(std::shared_ptr<Document> doc);
-  virtual ~Generator() = default;
-
-  void Run(const std::string& file_name);
-  std::string AddIndent(int indent, std::string lines, bool space = true);
-  std::string GetFileNamespace() const;
-  std::string ReplaceAll(std::string str,
-                         const std::string& from, const std::string& to);
-  bool IsDelegateType(const Interface& inf, const BaseType& type);
-  bool IsDelegateType(const BaseType& type);
-
-  void EnableNamespace(bool enable) {
-    hasNamespace_ = enable;
-  }
-
-  bool HasNamespace() const {
-    return hasNamespace_;
-  }
-
-  template<typename T, typename ...ARGS>
-  void GenTemplate(std::string templ, std::ofstream& stream,
-      T cb, ARGS... args) {
-    size_t f = templ.find("$$");
-    templ.replace(f, std::string("$$").length(), cb());
-    GenTemplate(std::move(templ), stream, args...);
-  }
-
-  template<typename T>
-  void GenTemplate(std::string templ, std::ofstream& stream, T cb) {
-    size_t f = templ.find("$$");
-    templ.replace(f, std::string("$$").length(), cb());
-    stream << templ;
-  }
-
-  template<typename T, typename ...ARGS>
-  std::string GenTemplateString(std::string templ, T cb, ARGS... args) {
-    size_t f = templ.find("$$");
-    templ.replace(f, std::string("$$").length(), cb());
-    return GenTemplateString(std::move(templ), args...);
-  }
-
-  template<typename T>
-  std::string GenTemplateString(std::string templ, T cb) {
-    size_t f = templ.find("$$");
-    templ.replace(f, std::string("$$").length(), cb());
-    return templ;
-  }
-
-  template<typename T>
-  void GenBrace(std::ofstream& stream, int indent, T cb,
-                bool start_indent = true, bool ended_new_line = true) {
-    if (start_indent) {
-      for (int i = 0; i < indent; i++)
-        stream << " ";
-    }
-    stream << "{" << std::endl;
-    cb();
-    for (int i = 0; i < indent; i++)
-        stream << " ";
-    stream << "}";
-    if (ended_new_line)
-      stream << std::endl;
-  }
-
-  virtual void OnInitGen(std::ofstream& stream) = 0;
-  virtual void OnFiniGen(std::ofstream& stream) = 0;
-
- protected:
-  const Document& GetDocument() {
-    return *doc_;
-  }
-
- protected:
-  std::string FileName;
-
- private:
-  static void CallEmptyCallback(int pos) {}
-
- private:
-  std::shared_ptr<Document> doc_;
-  std::ofstream out_file_;
-  bool hasNamespace_ = true;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_GENERATOR_H_
diff --git a/idlc/interface.cc b/idlc/interface.cc
deleted file mode 100644 (file)
index 6a4b3a4..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/declaration.h"
-#include "idlc/attribute.h"
-#include "idlc/interface.h"
-#include "idlc/block.h"
-
-namespace tidl {
-
-Interface::Interface(std::string id, Declarations* decls, std::string comments,
-                     Attributes* attrs, unsigned line)
-    : Block::Block(std::move(id), Block::TYPE_INTERFACE,
-                   std::move(comments), line),
-      decls_(decls),
-      attrs_(attrs) {}
-
-const Declarations& Interface::GetDeclarations() const {
-  return *decls_;
-}
-
-const Attributes& Interface::GetAttributes() const {
-  return *attrs_;
-}
-
-}  // namespace tidl
diff --git a/idlc/interface.h b/idlc/interface.h
deleted file mode 100644 (file)
index b110872..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_INTERFACE_H_
-#define IDLC_INTERFACE_H_
-
-#include <string>
-#include <memory>
-
-#include "idlc/block.h"
-#include "idlc/declaration.h"
-#include "idlc/attribute.h"
-
-namespace tidl {
-
-class Interface : public Block {
- public:
-  Interface(std::string id, Declarations* decls, std::string comments,
-            Attributes* attrs, unsigned line);
-
-  const Declarations& GetDeclarations() const;
-  const Attributes& GetAttributes() const;
-
- private:
-  std::unique_ptr<Declarations> decls_;
-  std::unique_ptr<Attributes> attrs_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_INTERFACE_H_
-
diff --git a/idlc/location.hh b/idlc/location.hh
deleted file mode 100644 (file)
index dffe666..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-// A Bison parser, made by GNU Bison 3.0.2.
-
-// Locations for Bison parsers in C++
-
-// Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-// As a special exception, you may create a larger work that contains
-// part or all of the Bison parser skeleton and distribute that work
-// under terms of your choice, so long as that work isn't itself a
-// parser generator using the skeleton or a modified version thereof
-// as a parser skeleton.  Alternatively, if you modify or redistribute
-// the parser skeleton itself, you may (at your option) remove this
-// special exception, which will cause the skeleton and the resulting
-// Bison output files to be licensed under the GNU General Public
-// License without this special exception.
-
-// This special exception was added by the Free Software Foundation in
-// version 2.2 of Bison.
-
-/**
- ** \file ./idlc/location.hh
- ** Define the yy::location class.
- */
-
-#ifndef YY_YY_IDLC_LOCATION_HH_INCLUDED
-# define YY_YY_IDLC_LOCATION_HH_INCLUDED
-
-# include "position.hh"
-
-
-namespace yy {
-#line 46 "./idlc/location.hh" // location.cc:291
-  /// Abstract a location.
-  class location
-  {
-  public:
-
-    /// Initialization.
-    void initialize (std::string* f = YY_NULLPTR,
-                     unsigned int l = 1u,
-                     unsigned int c = 1u)
-    {
-      begin.initialize (f, l, c);
-      end = begin;
-    }
-
-    /** \name Line and Column related manipulators
-     ** \{ */
-  public:
-    /// Reset initial location to final location.
-    void step ()
-    {
-      begin = end;
-    }
-
-    /// Extend the current location to the COUNT next columns.
-    void columns (int count = 1)
-    {
-      end += count;
-    }
-
-    /// Extend the current location to the COUNT next lines.
-    void lines (int count = 1)
-    {
-      end.lines (count);
-    }
-    /** \} */
-
-
-  public:
-    /// Beginning of the located region.
-    position begin;
-    /// End of the located region.
-    position end;
-  };
-
-  /// Join two location objects to create a location.
-  inline location operator+ (location res, const location& end)
-  {
-    res.end = end.end;
-    return res;
-  }
-
-  /// Change end position in place.
-  inline location& operator+= (location& res, int width)
-  {
-    res.columns (width);
-    return res;
-  }
-
-  /// Change end position.
-  inline location operator+ (location res, int width)
-  {
-    return res += width;
-  }
-
-  /// Change end position in place.
-  inline location& operator-= (location& res, int width)
-  {
-    return res += -width;
-  }
-
-  /// Change end position.
-  inline location operator- (const location& begin, int width)
-  {
-    return begin + -width;
-  }
-
-  /// Compare two location objects.
-  inline bool
-  operator== (const location& loc1, const location& loc2)
-  {
-    return loc1.begin == loc2.begin && loc1.end == loc2.end;
-  }
-
-  /// Compare two location objects.
-  inline bool
-  operator!= (const location& loc1, const location& loc2)
-  {
-    return !(loc1 == loc2);
-  }
-
-  /** \brief Intercept output stream redirection.
-   ** \param ostr the destination output stream
-   ** \param loc a reference to the location to redirect
-   **
-   ** Avoid duplicate information.
-   */
-  template <typename YYChar>
-  inline std::basic_ostream<YYChar>&
-  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
-  {
-    unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
-    ostr << loc.begin// << "(" << loc.end << ") "
-;
-    if (loc.end.filename
-        && (!loc.begin.filename
-            || *loc.begin.filename != *loc.end.filename))
-      ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
-    else if (loc.begin.line < loc.end.line)
-      ostr << '-' << loc.end.line << '.' << end_col;
-    else if (loc.begin.column < end_col)
-      ostr << '-' << end_col;
-    return ostr;
-  }
-
-
-} // yy
-#line 163 "./idlc/location.hh" // location.cc:291
-#endif // !YY_YY_IDLC_LOCATION_HH_INCLUDED
index 19b4df5a2bcf374733eeb7f04caa1e6e86315c31..2c405dd22d74b829587724e56399f3196e9799bc 100644 (file)
 #include <cstring>
 #include <memory>
 
-#include "idlc/parser.h"
-#include "idlc/cs_gen/cs_proxy_gen.h"
-#include "idlc/cs_gen/cs_stub_gen.h"
-#include "idlc/cs_gen/cs_lib_gen.h"
-#include "idlc/c_gen/c_proxy_header_gen.h"
-#include "idlc/c_gen/c_proxy_body_gen.h"
-#include "idlc/c_gen/c_stub_header_gen.h"
-#include "idlc/c_gen/c_stub_body_gen.h"
-#include "idlc/cpp_gen/cpp_proxy_header_gen.h"
-#include "idlc/cpp_gen/cpp_proxy_body_gen.h"
-#include "idlc/cpp_gen/cpp_stub_header_gen.h"
-#include "idlc/cpp_gen/cpp_stub_body_gen.h"
+#include "idlc/ast/parser.h"
+#include "idlc/gen/cs_proxy_gen.h"
+#include "idlc/gen/cs_stub_gen.h"
+#include "idlc/gen/cs_lib_gen.h"
+#include "idlc/gen/c_proxy_header_gen.h"
+#include "idlc/gen/c_proxy_body_gen.h"
+#include "idlc/gen/c_stub_header_gen.h"
+#include "idlc/gen/c_stub_body_gen.h"
+#include "idlc/gen/cpp_proxy_header_gen.h"
+#include "idlc/gen/cpp_proxy_body_gen.h"
+#include "idlc/gen/cpp_stub_header_gen.h"
+#include "idlc/gen/cpp_stub_body_gen.h"
 
 namespace {
 
diff --git a/idlc/parameter.cc b/idlc/parameter.cc
deleted file mode 100644 (file)
index 9634626..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/parameter.h"
-#include "idlc/type.h"
-
-namespace tidl {
-
-Parameter::Parameter(std::string id, ParameterType* type, unsigned line)
-    : type_(type), id_(std::move(id)), line_(line) {}
-
-const std::string& Parameter::GetID() const {
-  return id_;
-}
-
-const ParameterType& Parameter::GetParameterType() const {
-  return *type_;
-}
-
-const unsigned Parameter::GetLine() const {
-  return line_;
-}
-
-void Parameters::Add(Parameter* param) {
-  params_.emplace_back(param);
-}
-
-const std::list<std::unique_ptr<Parameter>>& Parameters::GetParams() const {
-  return params_;
-}
-
-bool Parameters::Exist(Parameter* param) const {
-  for (auto& p : params_) {
-    if (p->GetID() == param->GetID())
-      return true;
-  }
-
-  return false;
-}
-
-}  // namespace tidl
-
diff --git a/idlc/parameter.h b/idlc/parameter.h
deleted file mode 100644 (file)
index c4feeaf..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_PARAMETER_H_
-#define IDLC_PARAMETER_H_
-
-#include <string>
-#include <list>
-#include <memory>
-
-#include "idlc/type.h"
-
-namespace tidl {
-
-class Parameter {
- public:
-  Parameter(std::string id, ParameterType* type, unsigned line);
-
-  const std::string& GetID() const;
-  const ParameterType& GetParameterType() const;
-  const unsigned GetLine() const;
-
- private:
-  std::unique_ptr<ParameterType> type_;
-  std::string id_;
-  unsigned line_;
-};
-
-class Parameters {
- public:
-  void Add(Parameter* param);
-  const std::list<std::unique_ptr<Parameter>>& GetParams() const;
-  bool Exist(Parameter* param) const;
-
- private:
-  std::list<std::unique_ptr<Parameter>> params_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_PARAMETER_H_
diff --git a/idlc/parser.cc b/idlc/parser.cc
deleted file mode 100644 (file)
index 706c461..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fstream>
-#include <string>
-
-#include "idlc/parser.h"
-#include "idlc/document.h"
-#include "idlc/declaration.h"
-#include "idlc/parameter.h"
-#include "idlc/type.h"
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/tidlc_y.hpp"
-
-struct yy_buffer_state;
-yy_buffer_state* yy_scan_buffer(char*, size_t, void*);
-void yylex_init(void**);
-void yylex_destroy(void*);
-
-namespace tidl {
-
-Parser::Parser() : scanner_(nullptr), error_(false) {
-  yylex_init(&scanner_);
-}
-
-Parser::~Parser() {
-  yylex_destroy(scanner_);
-}
-
-void Parser::SetDoc(Document* doc) {
-  doc_ = std::shared_ptr<Document>(doc);
-}
-
-std::shared_ptr<Document> Parser::GetDoc() {
-  return doc_;
-}
-
-bool Parser::Parse(const std::string& input) {
-  std::string in = input;
-  error_ = false;
-
-  in.append(2u, '\0');
-  yy_scan_buffer(&in[0], in.length(), scanner_);
-  if (yy::parser(this).parse() != 0 || error_ != false) {
-    std::cerr << "[TIDL:Parser] error" << std::endl;
-    return false;
-  }
-
-  return true;
-}
-
-bool Parser::ParseFromFile(const std::string& path) {
-  std::ifstream inFile(path);
-  std::string str((std::istreambuf_iterator<char>(inFile)),
-      std::istreambuf_iterator<char>());
-  path_ = path;
-  return Parse(str);
-}
-
-void Parser::ReportError(const std::string& err, unsigned line) {
-  std::cerr << path_ << ":" << line << ": " << err << std::endl;
-  error_ = true;
-}
-
-}  // namespace tidl
diff --git a/idlc/parser.h b/idlc/parser.h
deleted file mode 100644 (file)
index e90ff8c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_PARSER_H_
-#define IDLC_PARSER_H_
-
-#include <memory>
-#include <string>
-#include <list>
-
-#include "idlc/document.h"
-
-namespace tidl {
-
-class Parser {
- public:
-  Parser();
-  ~Parser();
-
-  void* Scanner() const { return scanner_; }
-  bool Parse(const std::string& input);
-  bool ParseFromFile(const std::string& path);
-  void SetDoc(Document* doc);
-  std::shared_ptr<Document> GetDoc();
-  void ReportError(const std::string& err, unsigned line);
-
- private:
-  void* scanner_;
-  std::shared_ptr<Document> doc_;
-  std::string path_;
-  bool error_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_PARSER_H_
diff --git a/idlc/position.hh b/idlc/position.hh
deleted file mode 100644 (file)
index 2154d82..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-// A Bison parser, made by GNU Bison 3.0.2.
-
-// Positions for Bison parsers in C++
-
-// Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-// As a special exception, you may create a larger work that contains
-// part or all of the Bison parser skeleton and distribute that work
-// under terms of your choice, so long as that work isn't itself a
-// parser generator using the skeleton or a modified version thereof
-// as a parser skeleton.  Alternatively, if you modify or redistribute
-// the parser skeleton itself, you may (at your option) remove this
-// special exception, which will cause the skeleton and the resulting
-// Bison output files to be licensed under the GNU General Public
-// License without this special exception.
-
-// This special exception was added by the Free Software Foundation in
-// version 2.2 of Bison.
-
-/**
- ** \file ./idlc/position.hh
- ** Define the yy::position class.
- */
-
-#ifndef YY_YY_IDLC_POSITION_HH_INCLUDED
-# define YY_YY_IDLC_POSITION_HH_INCLUDED
-
-# include <algorithm> // std::max
-# include <iostream>
-# include <string>
-
-# ifndef YY_NULLPTR
-#  if defined __cplusplus && 201103L <= __cplusplus
-#   define YY_NULLPTR nullptr
-#  else
-#   define YY_NULLPTR 0
-#  endif
-# endif
-
-
-namespace yy {
-#line 56 "./idlc/position.hh" // location.cc:291
-  /// Abstract a position.
-  class position
-  {
-  public:
-    /// Initialization.
-    void initialize (std::string* fn = YY_NULLPTR,
-                     unsigned int l = 1u,
-                     unsigned int c = 1u)
-    {
-      filename = fn;
-      line = l;
-      column = c;
-    }
-
-    /** \name Line and Column related manipulators
-     ** \{ */
-    /// (line related) Advance to the COUNT next lines.
-    void lines (int count = 1)
-    {
-      if (count)
-        {
-          column = 1u;
-          line = add_ (line, count, 1);
-        }
-    }
-
-    /// (column related) Advance to the COUNT next columns.
-    void columns (int count = 1)
-    {
-      column = add_ (column, count, 1);
-    }
-    /** \} */
-
-    /// File name to which this position refers.
-    std::string* filename;
-    /// Current line number.
-    unsigned int line;
-    /// Current column number.
-    unsigned int column;
-
-  private:
-    /// Compute max(min, lhs+rhs) (provided min <= lhs).
-    static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
-    {
-      return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
-              ? rhs + lhs
-              : min);
-    }
-  };
-
-  /// Add and assign a position.
-  inline position&
-  operator+= (position& res, int width)
-  {
-    res.columns (width);
-    return res;
-  }
-
-  /// Add two position objects.
-  inline position
-  operator+ (position res, int width)
-  {
-    return res += width;
-  }
-
-  /// Add and assign a position.
-  inline position&
-  operator-= (position& res, int width)
-  {
-    return res += -width;
-  }
-
-  /// Add two position objects.
-  inline position
-  operator- (position res, int width)
-  {
-    return res -= width;
-  }
-
-  /// Compare two position objects.
-  inline bool
-  operator== (const position& pos1, const position& pos2)
-  {
-    return (pos1.line == pos2.line
-            && pos1.column == pos2.column
-            && (pos1.filename == pos2.filename
-                || (pos1.filename && pos2.filename
-                    && *pos1.filename == *pos2.filename)));
-  }
-
-  /// Compare two position objects.
-  inline bool
-  operator!= (const position& pos1, const position& pos2)
-  {
-    return !(pos1 == pos2);
-  }
-
-  /** \brief Intercept output stream redirection.
-   ** \param ostr the destination output stream
-   ** \param pos a reference to the position to redirect
-   */
-  template <typename YYChar>
-  inline std::basic_ostream<YYChar>&
-  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
-  {
-    if (pos.filename)
-      ostr << *pos.filename << ':';
-    return ostr << pos.line << '.' << pos.column;
-  }
-
-
-} // yy
-#line 169 "./idlc/position.hh" // location.cc:291
-#endif // !YY_YY_IDLC_POSITION_HH_INCLUDED
diff --git a/idlc/structure.cc b/idlc/structure.cc
deleted file mode 100644 (file)
index b3d7777..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <utility>
-
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/block.h"
-
-namespace tidl {
-
-Structure::Structure(std::string id, Elements* elms, std::string comments,
-                     unsigned line)
-    : Block::Block(std::move(id), Block::TYPE_STRUCTURE,
-                   std::move(comments), line), elms_(elms) {}
-
-const Elements& Structure::GetElements() const {
-  return *elms_;
-}
-
-}  // namespace tidl
diff --git a/idlc/structure.h b/idlc/structure.h
deleted file mode 100644 (file)
index 8ed36e9..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_STRUCTURE_H_
-#define IDLC_STRUCTURE_H_
-
-#include <string>
-#include <memory>
-
-#include "idlc/block.h"
-#include "idlc/element.h"
-
-namespace tidl {
-
-class Structure : public Block {
- public:
-  Structure(std::string id, Elements* elms, std::string comments,
-            unsigned line);
-
-  const Elements& GetElements() const;
-
- private:
-  std::unique_ptr<Elements> elms_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_STRUCTURE_H_
-
diff --git a/idlc/tidlc.ll b/idlc/tidlc.ll
deleted file mode 100644 (file)
index a81e5af..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-%{
-#include <stdio.h>
-#include <string>
-
-#include "idlc/parser.h"
-#include "idlc/document.h"
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-#include "idlc/interface.h"
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/block.h"
-#include "idlc/attribute.h"
-#include "idlc/tidlc_y.hpp"
-
-#define YY_USER_ACTION yylloc->columns(yyleng);
-%}
-
-%x COMMENT VALUE
-
-%option yylineno
-%option noyywrap
-%option reentrant
-%option bison-bridge
-%option bison-locations
-
-%%
-%{
-  std::string comments;
-  std::string values;
-%}
-
-"/*"                    { comments += yytext; BEGIN(COMMENT); }
-<COMMENT>"*/"+\/        { comments += yytext; yylloc->step(); BEGIN(INITIAL); }
-<COMMENT>"*/"           { comments += yytext; comments += "\n"; BEGIN(INITIAL); }
-<COMMENT>"*/"\n+        { comments += yytext; yylloc->step(); BEGIN(INITIAL); }
-<COMMENT>\n+            { comments += yytext; yylloc->lines(yyleng); }
-<COMMENT>([^*]\n)+|.    { comments += yytext; yylloc->step(); }
-<COMMENT><<EOF>>        { return 0; }
-
-"//".*\n                { comments += yytext; yylloc->step(); }
-
-"\""                    { BEGIN(VALUE); }
-<VALUE>"\""             {
-                          BEGIN(INITIAL);
-                          yylval->token = new tidl::Token(values, comments);
-                          return yy::parser::token::T_VALUE;
-                        }
-<VALUE>([^*]\n)+|.      { values += yytext; yylloc->step(); }
-
-[\n]+                   { yylloc->lines(yyleng); yylloc->step(); }
-
-[ \t\r\n] ; // ignore all whitespace
-","                     { return yy::parser::token::T_COMMA; }
-"{"                     { return yy::parser::token::T_BRACE_OPEN; }
-"}"                     { return yy::parser::token::T_BRACE_CLOSE; }
-"("                     { return yy::parser::token::T_LEFT; }
-")"                     { return yy::parser::token::T_RIGHT; }
-";"                     { return yy::parser::token::T_SEMICOLON; }
-"void"                  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_VOID;
-                        }
-"char"                  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_CHAR;
-                        }
-"short"                 {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SHORT;
-                        }
-"int"                   {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_INT;
-                        }
-"long"                  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_LONG;
-                        }
-"float"                 {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_FLOAT;
-                        }
-"double"                {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_DOUBLE;
-                        }
-"bundle"                {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_BUNDLE;
-                        }
-"string"                {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_STRING;
-                        }
-"bool"                  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_BOOL;
-                        }
-"in"                    { return yy::parser::token::T_IN; }
-"out"                   { return yy::parser::token::T_OUT; }
-"ref"                   { return yy::parser::token::T_REF; }
-"async"                 { return yy::parser::token::T_ASYNC; }
-"delegate"              { return yy::parser::token::T_DELEGATE; }
-"<"                     { return yy::parser::token::T_META_OPEN; }
-">"                     { return yy::parser::token::T_META_CLOSE; }
-"list"                  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_LIST;
-                        }
-"array"                 {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_ARRAY;
-                        }
-"struct"                {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_STRUCTURE;
-                        }
-"interface"             {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_INTERFACE;
-                        }
-[A-Za-z_][A-Za-z0-9_]*  {
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_ID;
-                        }
-"["                     { // Square Bracket
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SB_OPEN;
-                        }
-"]"                     { // Square Bracket
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SB_CLOSE;
-                        }
-"="                     { return yy::parser::token::T_EQUAL; }
-.                       { return yy::parser::token::T_UNKNOWN; }
-
-%%
-
diff --git a/idlc/tidlc.yy b/idlc/tidlc.yy
deleted file mode 100644 (file)
index b3cc1d6..0000000
+++ /dev/null
@@ -1,476 +0,0 @@
-%{
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "idlc/parser.h"
-#include "idlc/document.h"
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-#include "idlc/interface.h"
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/block.h"
-#include "idlc/attribute.h"
-#include "idlc/tidlc_y.hpp"
-
-int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
-
-#define lex_scanner ps->Scanner()
-
-%}
-
-%parse-param { tidl::Parser* ps }
-%lex-param { void *lex_scanner }
-
-%token T_LEFT T_RIGHT T_COMMA T_SEMICOLON T_BRACE_OPEN T_BRACE_CLOSE
-%token T_IN T_OUT T_REF T_ASYNC
-%token T_META_OPEN T_META_CLOSE
-%token T_EQUAL T_DELEGATE T_UNKNOWN
-
-
-%start start
-
-%skeleton "glr.cc"
-
-%union {
-  tidl::Document* doc;
-  tidl::Interface* interf;
-  tidl::Declaration* decl;
-  tidl::Declarations* decls;
-  tidl::BaseType* b_type;
-  tidl::ParameterType* p_type;
-  tidl::Token* direction;
-  tidl::Parameter* param;
-  tidl::Parameters* params;
-  tidl::Token* token;
-  tidl::Structure* structure;
-  tidl::Element* elm;
-  tidl::Elements* elms;
-  tidl::Block* blk;
-  tidl::Attribute* attr;
-  tidl::Attributes* attrs;
-}
-
-%token<token> T_ID
-%token<token> T_STRUCTURE
-%token<token> T_INTERFACE
-%token<token> T_CHAR
-%token<token> T_SHORT
-%token<token> T_INT
-%token<token> T_LONG
-%token<token> T_FLOAT
-%token<token> T_DOUBLE
-%token<token> T_VOID
-%token<token> T_BUNDLE
-%token<token> T_STRING
-%token<token> T_BOOL
-%token<token> T_LIST
-%token<token> T_ARRAY
-%token<token> T_VALUE
-%token<token> T_SB_OPEN
-%token<token> T_SB_CLOSE
-%type<doc> blocks
-%type<blk> block
-%type<structure> structure_block
-%type<interf> interface_block
-%type<decls> declarations
-%type<decl> declaration
-%type<p_type> parameter_type
-%type<b_type> base_type
-%type<b_type> container_type
-%type<param> parameter
-%type<params> parameter_list
-%type<direction> direction_specifier
-%type<token> container_type_name
-%type<elm> element
-%type<elms> elements
-%type<attr> attribute
-%type<attrs> attributes
-
-%%
-
-start: blocks {
-     ps->SetDoc($1);
-  }
-;
-
-blocks: block {
-    $$ = new tidl::Document();
-    if ($1 != NULL)
-      $$->AddBlock($1);
-  }
-  | blocks block {
-    $$ = $1;
-
-    if ($2 != NULL) {
-      if ($$->ExistBlock($2)) {
-        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
-        delete $2;
-      } else {
-        $$->AddBlock($2);
-      }
-    }
-  }
-;
-
-block: interface_block {
-    $$ = $1;
-  }
-  | structure_block {
-    $$ = $1;
-  }
-;
-
-structure_block: T_STRUCTURE T_ID T_BRACE_OPEN elements T_BRACE_CLOSE {
-    $$ = new tidl::Structure($2->ToString(), $4, $1->GetComments(),
-        @1.begin.line);
-    delete $1;
-    delete $2;
-  }
-  | T_STRUCTURE T_BRACE_OPEN elements T_BRACE_CLOSE {
-    ps->ReportError("syntax error. \"No identifier\".", @1.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-  | T_STRUCTURE error T_BRACE_OPEN elements T_BRACE_CLOSE {
-    ps->ReportError("syntax error. \"Please check it before an open brace.\"",
-        @2.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-  | T_STRUCTURE error T_BRACE_CLOSE {
-    ps->ReportError("syntax error in structure declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-;
-
-elements: element {
-    $$ = new (std::nothrow) tidl::Elements();
-    if ($$ != nullptr) {
-      $$->Add($1);
-    }
-  }
-  | elements element {
-    $$ = $1;
-    if ($2 != nullptr) {
-      if ($$->Exist($2)) {
-        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
-        delete $2;
-      } else {
-        $$->Add($2);
-      }
-    }
-  }
-  | elements error T_SEMICOLON {
-    ps->ReportError("syntax error in elements declarations.", @1.begin.line);
-    $$ = $1;
-  }
-;
-
-element: base_type T_ID T_SEMICOLON {
-    $$ = new tidl::Element($2->ToString(), $1, $1->GetComments(),
-        @1.begin.line);
-    delete $2;
-  }
-  | base_type T_SEMICOLON {
-    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
-    $$ = NULL;
-  }
-  | base_type error T_SEMICOLON {
-    ps->ReportError("syntax error in element declaration.", @2.begin.line);
-    $$ = NULL;
-  }
-  | error {
-    ps->ReportError("syntax error in element declaration.", @1.begin.line);
-    $$ = NULL;
-  }
-;
-
-attributes: attribute {
-    $$ = new (std::nothrow) tidl::Attributes();
-    if ($$ != nullptr) {
-      $$->Add($1);
-    }
-  }
-  | attributes T_COMMA attribute {
-    $$ = $1;
-    if ($3 != nullptr) {
-      if ($$->Exist($3)) {
-        ps->ReportError("syntax error. \"Already Exist\".", $3->GetLine());
-        delete $3;
-      } else {
-        $$->Add($3);
-      }
-    }
-  }
-  | error {
-    ps->ReportError("syntax error in attributes", @1.begin.line);
-    $$ = new tidl::Attributes();
-  }
-;
-
-attribute: T_ID T_EQUAL T_VALUE {
-    $$ = new tidl::Attribute($1->ToString(), $3->ToString(), @1.begin.line);
-    delete $1;
-    delete $3;
-  }
-  | T_ID error T_VALUE  {
-    ps->ReportError("syntax error in attribute declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $1;
-    delete $3;
-  }
-  | T_ID T_EQUAL error {
-    ps->ReportError("syntax error in attribute declaration.", @3.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-;
-
-interface_block: T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE {
-    $$ = new tidl::Interface($2->ToString(), $4, $1->GetComments(),
-        new tidl::Attributes(), @1.begin.line);
-    delete $1;
-    delete $2;
-  }
-  | T_SB_OPEN attributes T_SB_CLOSE T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE {
-    $$ = new tidl::Interface($5->ToString(), $7, $1->GetComments(), $2,
-        @1.begin.line);
-    delete $1;
-    delete $3;
-    delete $4;
-    delete $5;
-  }
-  | T_INTERFACE T_BRACE_OPEN declarations T_BRACE_CLOSE {
-    ps->ReportError("syntax error. \"No identifier\".", @1.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-  | T_INTERFACE error T_BRACE_OPEN declarations T_BRACE_CLOSE {
-    ps->ReportError("syntax error in interface declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-  | T_INTERFACE error T_BRACE_CLOSE {
-    ps->ReportError("syntax error in interface declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $1;
-  }
-;
-
-declarations: declaration {
-    $$ = new (std::nothrow) tidl::Declarations();
-    if ($$ != nullptr) {
-      $$->Add($1);
-    }
-  }
-  | declarations declaration {
-    $$ = $1;
-    if ($2 != nullptr) {
-      if ($$->Exist($2)) {
-        ps->ReportError("syntax error. \"Already Exists\".", $2->GetLine());
-        delete $2;
-      } else {
-        $$->Add($2);
-      }
-    }
-  }
-  | declarations error T_SEMICOLON {
-    ps->ReportError("syntax error in methods declaration.", @2.begin.line);
-    $$ = $1;
-  }
-;
-
-declaration: base_type T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON {
-    $$ = new tidl::Declaration($2->ToString(), $1, $4, $1->GetComments(),
-        @1.begin.line, tidl::Declaration::MethodType::SYNC);
-    delete $2;
-  }
-  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
-    $$ = new tidl::Declaration($2->ToString(),
-        new tidl::BaseType("void", $1->GetComments()), $4,
-        $1->GetComments(), @1.begin.line, tidl::Declaration::MethodType::ASYNC);
-    delete $1;
-    delete $2;
-  }
-  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
-    $$ = new tidl::Declaration($2->ToString(),
-        new tidl::BaseType("void", $1->GetComments()), $4,
-        $1->GetComments(), @1.begin.line,
-        tidl::Declaration::MethodType::DELEGATE);
-    delete $1;
-    delete $2;
-  }
-  | base_type T_ID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
-    ps->ReportError("syntax error in method declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $2;
-  }
-  | base_type T_ID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
-    ps->ReportError("syntax error in method declaration.", @2.begin.line);
-    $$ = NULL;
-    delete $2;
-  }
-  | T_VOID T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON {
-    ps->ReportError("syntax error. \"No async\".", @6.begin.line);
-    $$ = NULL;
-    delete $2;
-  }
-  | base_type T_LEFT parameter_list T_RIGHT T_SEMICOLON {
-    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
-    $$ = NULL;
-  }
-  | T_VOID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON {
-    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
-    $$ = NULL;
-  }
-  | T_VOID T_LEFT parameter_list T_RIGHT T_DELEGATE T_SEMICOLON {
-    ps->ReportError("syntax error. \"No identifier\".", @2.begin.line);
-    $$ = NULL;
-  }
-  | base_type error T_SEMICOLON {
-    ps->ReportError("syntax error in method declaration.", @2.begin.line);
-    $$ = NULL;
-  }
-  | T_VOID error T_SEMICOLON {
-    ps->ReportError("syntax error in method declaration.", @2.begin.line);
-    $$ = NULL;
-  }
-;
-
-parameter_list: parameter {
-    $$ = new tidl::Parameters();
-    if ($1 != nullptr) {
-      $$->Add($1);
-    }
-  }
-  | parameter_list T_COMMA parameter {
-    $$ = $1;
-    if ($3 != nullptr) {
-      if ($$->Exist($3)) {
-        ps->ReportError("syntax error. \"Already Exists\".", $3->GetLine());
-        delete $3;
-      } else {
-        $$->Add($3);
-      }
-    }
-  }
-  | error {
-    ps->ReportError("syntax error in parameter list", @1.begin.line);
-    $$ = new tidl::Parameters();
-  }
-;
-
-direction_specifier: T_IN {
-    $$ = new tidl::Token("in", "");
-  }
-  | T_OUT {
-    $$ = new tidl::Token("out", "");
-  }
-  | T_REF {
-    $$ = new tidl::Token("ref", "");
-  }
-;
-
-parameter: {
-    $$ = nullptr;
-  }
-  | T_VOID {
-    $$ = nullptr;
-    delete $1;
-  }
-  | parameter_type T_ID {
-    $$ = new tidl::Parameter($2->ToString(), $1, @1.begin.line);
-    delete $2;
-  }
-;
-
-parameter_type: base_type {
-      $$ = new tidl::ParameterType($1);
-    }
-    | direction_specifier base_type {
-      $$ = new tidl::ParameterType($2, $1->ToString());
-      delete $1;
-    }
-;
-
-base_type: container_type {
-      $$ = $1;
-    }
-    | T_VOID {
-      $$ = new tidl::BaseType("void", $1->GetComments());
-      delete $1;
-    }
-    | T_CHAR {
-      $$ = new tidl::BaseType("char", $1->GetComments());
-      delete $1;
-    }
-    | T_SHORT {
-      $$ = new tidl::BaseType("short", $1->GetComments());
-      delete $1;
-    }
-    | T_INT {
-      $$ = new tidl::BaseType("int", $1->GetComments());
-      delete $1;
-    }
-    | T_LONG {
-      $$ = new tidl::BaseType("long", $1->GetComments());
-      delete $1;
-    }
-    | T_FLOAT {
-      $$ = new tidl::BaseType("float", $1->GetComments());
-      delete $1;
-    }
-    | T_DOUBLE {
-      $$ = new tidl::BaseType("double", $1->GetComments());
-      delete $1;
-    }
-    | T_BUNDLE {
-      $$ = new tidl::BaseType("bundle", $1->GetComments());
-      delete $1;
-    }
-    | T_STRING {
-      $$ = new tidl::BaseType("string", $1->GetComments());
-      delete $1;
-    }
-    | T_BOOL {
-      $$ = new tidl::BaseType("bool", $1->GetComments());
-      delete $1;
-    }
-    | T_ID {
-      $$ = new tidl::BaseType($1->ToString(), $1->GetComments(), true);
-      delete $1;
-    }
-;
-
-container_type: container_type_name T_META_OPEN base_type T_META_CLOSE {
-      $$ = new tidl::BaseType($1->ToString(), $1->GetComments());
-      $$->SetMetaType($3);
-      delete $1;
-    }
-;
-
-container_type_name: T_LIST {
-      $$ = new tidl::Token("list", $1->GetComments());
-      delete $1;
-    }
-    | T_ARRAY {
-      $$ = new tidl::Token("array", $1->GetComments());
-      delete $1;
-    }
-;
-
-%%
-
-#include <ctype.h>
-#include <stdio.h>
-
-void yy::parser::error(const yy::parser::location_type& l,
-                       const std::string& errstr) {
-  ps->ReportError(errstr, l.begin.line);
-}
-
-
diff --git a/idlc/tidlc_l.cpp b/idlc/tidlc_l.cpp
deleted file mode 100644 (file)
index 888d35b..0000000
+++ /dev/null
@@ -1,2414 +0,0 @@
-#line 2 "./idlc/tidlc_l.cpp"
-
-#line 4 "./idlc/tidlc_l.cpp"
-
-#define  YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 39
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* First, we deal with  platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-
-/* end standard C headers. */
-
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types. 
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t; 
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN               (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN              (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN              (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX               (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX              (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX              (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX              (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX             (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX             (4294967295U)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else  /* ! __cplusplus */
-
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
-
-#define YY_USE_CONST
-
-#endif /* defined (__STDC__) */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index.  If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-
-/* An opaque pointer. */
-#ifndef YY_TYPEDEF_YY_SCANNER_T
-#define YY_TYPEDEF_YY_SCANNER_T
-typedef void* yyscan_t;
-#endif
-
-/* For convenience, these vars (plus the bison vars far below)
-   are macros in the reentrant scanner. */
-#define yyin yyg->yyin_r
-#define yyout yyg->yyout_r
-#define yyextra yyg->yyextra_r
-#define yyleng yyg->yyleng_r
-#define yytext yyg->yytext_r
-#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
-#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
-#define yy_flex_debug yyg->yy_flex_debug_r
-
-/* Enter a start condition.  This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN yyg->yy_start = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state.  The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START ((yyg->yy_start - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart(yyin ,yyscanner )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
-#define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
-    /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
-     *       access to the local variable yy_act. Since yyless() is a macro, it would break
-     *       existing scanners that call yyless() from OUTSIDE yylex. 
-     *       One obvious solution it to make yy_act a global. I tried that, and saw
-     *       a 5% performance hit in a non-yylineno scanner, because yy_act is
-     *       normally declared as a register variable-- so it is not worth it.
-     */
-    #define  YY_LESS_LINENO(n) \
-            do { \
-                int yyl;\
-                for ( yyl = n; yyl < yyleng; ++yyl )\
-                    if ( yytext[yyl] == '\n' )\
-                        --yylineno;\
-            }while(0)
-    #define YY_LINENO_REWIND_TO(dst) \
-            do {\
-                const char *p;\
-                for ( p = yy_cp-1; p >= (dst); --p)\
-                    if ( *p == '\n' )\
-                        --yylineno;\
-            }while(0)
-    
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
-       do \
-               { \
-               /* Undo effects of setting up yytext. */ \
-        int yyless_macro_arg = (n); \
-        YY_LESS_LINENO(yyless_macro_arg);\
-               *yy_cp = yyg->yy_hold_char; \
-               YY_RESTORE_YY_MORE_OFFSET \
-               yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
-               YY_DO_BEFORE_ACTION; /* set up yytext again */ \
-               } \
-       while ( 0 )
-
-#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
-       {
-       FILE *yy_input_file;
-
-       char *yy_ch_buf;                /* input buffer */
-       char *yy_buf_pos;               /* current position in input buffer */
-
-       /* Size of input buffer in bytes, not including room for EOB
-        * characters.
-        */
-       yy_size_t yy_buf_size;
-
-       /* Number of characters read into yy_ch_buf, not including EOB
-        * characters.
-        */
-       yy_size_t yy_n_chars;
-
-       /* Whether we "own" the buffer - i.e., we know we created it,
-        * and can realloc() it to grow it, and should free() it to
-        * delete it.
-        */
-       int yy_is_our_buffer;
-
-       /* Whether this is an "interactive" input source; if so, and
-        * if we're using stdio for input, then we want to use getc()
-        * instead of fread(), to make sure we stop fetching input after
-        * each newline.
-        */
-       int yy_is_interactive;
-
-       /* Whether we're considered to be at the beginning of a line.
-        * If so, '^' rules will be active on the next match, otherwise
-        * not.
-        */
-       int yy_at_bol;
-
-    int yy_bs_lineno; /**< The line count. */
-    int yy_bs_column; /**< The column count. */
-    
-       /* Whether to try to fill the input buffer when we reach the
-        * end of it.
-        */
-       int yy_fill_buffer;
-
-       int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
-       /* When an EOF's been seen but there's still some text to process
-        * then we mark the buffer as YY_EOF_PENDING, to indicate that we
-        * shouldn't try reading from the input source any more.  We might
-        * still have a bunch of tokens to match, though, because of
-        * possible backing-up.
-        *
-        * When we actually see the EOF, we change the status to "new"
-        * (via yyrestart()), so that the user can continue scanning by
-        * just pointing yyin at a new input file.
-        */
-#define YY_BUFFER_EOF_PENDING 2
-
-       };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
-                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
-                          : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
-
-void yyrestart (FILE *input_file ,yyscan_t yyscanner );
-void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
-void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-void yypop_buffer_state (yyscan_t yyscanner );
-
-static void yyensure_buffer_stack (yyscan_t yyscanner );
-static void yy_load_buffer_state (yyscan_t yyscanner );
-static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
-
-#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
-
-YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
-YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
-
-void *yyalloc (yy_size_t ,yyscan_t yyscanner );
-void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
-void yyfree (void * ,yyscan_t yyscanner );
-
-#define yy_new_buffer yy_create_buffer
-
-#define yy_set_interactive(is_interactive) \
-       { \
-       if ( ! YY_CURRENT_BUFFER ){ \
-        yyensure_buffer_stack (yyscanner); \
-               YY_CURRENT_BUFFER_LVALUE =    \
-            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
-       } \
-       YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
-       }
-
-#define yy_set_bol(at_bol) \
-       { \
-       if ( ! YY_CURRENT_BUFFER ){\
-        yyensure_buffer_stack (yyscanner); \
-               YY_CURRENT_BUFFER_LVALUE =    \
-            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
-       } \
-       YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
-       }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* Begin user sect3 */
-
-#define yywrap(yyscanner) 1
-#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
-
-typedef int yy_state_type;
-
-#define yytext_ptr yytext_r
-
-static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state  ,yyscan_t yyscanner);
-static int yy_get_next_buffer (yyscan_t yyscanner );
-static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up yytext.
- */
-#define YY_DO_BEFORE_ACTION \
-       yyg->yytext_ptr = yy_bp; \
-       yyleng = (size_t) (yy_cp - yy_bp); \
-       yyg->yy_hold_char = *yy_cp; \
-       *yy_cp = '\0'; \
-       yyg->yy_c_buf_p = yy_cp;
-
-#define YY_NUM_RULES 45
-#define YY_END_OF_BUFFER 46
-/* This struct is not used in this scanner,
-   but its presence is necessary. */
-struct yy_trans_info
-       {
-       flex_int32_t yy_verify;
-       flex_int32_t yy_nxt;
-       };
-static yyconst flex_int16_t yy_accept[129] =
-    {   0,
-        0,    0,    0,    0,    0,    0,   46,   44,   12,   11,
-        8,   16,   17,   13,   44,   18,   34,   43,   35,   40,
-       41,   42,   40,   40,   40,   40,   40,   40,   40,   40,
-       40,   40,   40,   14,   15,    6,    5,    6,   10,   45,
-        9,   10,   11,    1,    0,   40,   40,   40,   40,   40,
-       40,   40,   40,   40,   29,   40,   40,   40,   40,   40,
-       40,   40,    6,    5,    3,   10,    0,    7,   40,   40,
-       40,   40,   40,   40,   40,   40,   22,   40,   40,   30,
-       31,   40,   40,   40,    0,    5,    4,    0,    2,    0,
-       40,   40,   28,   40,   20,   40,   40,   40,   40,   36,
-
-       23,   40,   40,   40,   19,    0,   37,   32,   40,   40,
-       40,   24,   40,   21,   40,   40,   26,   40,   25,   40,
-       27,   38,   40,   40,   33,   40,   39,    0
-    } ;
-
-static yyconst flex_int32_t yy_ec[256] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
-        1,    1,    2,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    1,    4,    1,    1,    1,    1,    1,    5,
-        6,    7,    1,    8,    1,    1,    9,   10,   10,   10,
-       10,   10,   10,   10,   10,   10,   10,    1,   11,   12,
-       13,   14,    1,    1,   15,   15,   15,   15,   15,   15,
-       15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
-       15,   15,   15,   15,   15,   15,   15,   15,   15,   15,
-       16,    1,   17,    1,   15,    1,   18,   19,   20,   21,
-
-       22,   23,   24,   25,   26,   15,   15,   27,   15,   28,
-       29,   15,   15,   30,   31,   32,   33,   34,   15,   15,
-       35,   15,   36,    1,   37,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1
-    } ;
-
-static yyconst flex_int32_t yy_meta[38] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    2,    1,    1,    3,
-        1,    1,    1,    1,    3,    1,    1,    3,    3,    3,
-        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
-        3,    3,    3,    3,    3,    1,    1
-    } ;
-
-static yyconst flex_int16_t yy_base[135] =
-    {   0,
-        0,    0,   35,   36,   37,   42,  153,  154,  154,  149,
-      154,  154,  154,  154,   41,  154,  154,  154,  154,    0,
-      154,  154,   21,   24,  126,   25,  123,  121,   29,  115,
-      125,   31,  117,  154,  154,  142,  141,  134,  139,  138,
-      137,  154,  136,  154,  135,    0,  107,  101,  106,  106,
-      115,  105,   98,  101,   97,   97,   99,   94,  102,   95,
-       93,   96,    0,  118,   57,    0,  117,  154,  101,   90,
-       90,   95,   85,   92,   94,   94,   89,   78,   85,    0,
-        0,   78,   35,   86,  103,  102,  101,   94,  154,   99,
-       66,   80,    0,   72,    0,   74,   70,   64,   65,    0,
-
-        0,   62,   65,   72,    0,   58,    0,    0,   69,   72,
-       67,    0,   65,    0,   63,   54,    0,   53,    0,   66,
-        0,    0,   60,   59,    0,   40,    0,  154,   68,   71,
-       56,   74,   77,   80
-    } ;
-
-static yyconst flex_int16_t yy_def[135] =
-    {   0,
-      128,    1,  129,  129,  130,  130,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  131,
-      128,  128,  131,  131,  131,  131,  131,  131,  131,  131,
-      131,  131,  131,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  132,  131,  131,  131,  131,  131,
-      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
-      131,  131,  133,  133,  128,  134,  132,  128,  131,  131,
-      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
-      131,  131,  131,  131,  128,  128,  128,  128,  128,  128,
-      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
-
-      131,  131,  131,  131,  131,  128,  131,  131,  131,  131,
-      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
-      131,  131,  131,  131,  131,  131,  131,    0,  128,  128,
-      128,  128,  128,  128
-    } ;
-
-static yyconst flex_int16_t yy_nxt[192] =
-    {   0,
-        8,    9,   10,   11,   12,   13,    8,   14,   15,    8,
-       16,   17,   18,   19,   20,   21,   22,   23,   24,   25,
-       26,   20,   27,   20,   20,   28,   29,   20,   30,   31,
-       32,   20,   20,   33,   20,   34,   35,   37,   37,   40,
-       41,   38,   38,   42,   40,   41,   52,   44,   42,   45,
-       47,   48,   49,   53,   56,   60,   50,   57,   46,   87,
-      103,  127,   61,   88,   88,   89,   89,  104,   36,   36,
-       36,   39,   39,   39,   67,   67,   67,   85,  126,   85,
-       90,  125,   90,  124,  123,  122,  121,  120,  119,  118,
-      117,  116,  115,  114,  113,  112,  111,  110,  109,  108,
-
-      107,   66,  106,   87,   64,   63,  105,  102,  101,  100,
-       99,   98,   97,   96,   95,   94,   93,   92,   91,   68,
-       86,   84,   83,   82,   81,   80,   79,   78,   77,   76,
-       75,   74,   73,   72,   71,   70,   69,   68,   43,   66,
-       66,   66,   65,   64,   63,   62,   59,   58,   55,   54,
-       51,   43,  128,    7,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128
-
-    } ;
-
-static yyconst flex_int16_t yy_chk[192] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    3,    4,    5,
-        5,    3,    4,    5,    6,    6,   26,   15,    6,   15,
-       23,   23,   24,   26,   29,   32,   24,   29,  131,   65,
-       83,  126,   32,   65,  106,   65,  106,   83,  129,  129,
-      129,  130,  130,  130,  132,  132,  132,  133,  124,  133,
-      134,  123,  134,  120,  118,  116,  115,  113,  111,  110,
-      109,  104,  103,  102,   99,   98,   97,   96,   94,   92,
-
-       91,   90,   88,   87,   86,   85,   84,   82,   79,   78,
-       77,   76,   75,   74,   73,   72,   71,   70,   69,   67,
-       64,   62,   61,   60,   59,   58,   57,   56,   55,   54,
-       53,   52,   51,   50,   49,   48,   47,   45,   43,   41,
-       40,   39,   38,   37,   36,   33,   31,   30,   28,   27,
-       25,   10,    7,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128,  128,  128,  128,  128,  128,  128,  128,  128,  128,
-      128
-
-    } ;
-
-/* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[46] =
-    {   0,
-0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-    0, 0, 0, 0, 0, 0,     };
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-#line 1 "./idlc/tidlc.ll"
-#line 2 "./idlc/tidlc.ll"
-#include <stdio.h>
-#include <string>
-
-#include "idlc/parser.h"
-#include "idlc/document.h"
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-#include "idlc/interface.h"
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/block.h"
-#include "idlc/attribute.h"
-#include "idlc/tidlc_y.hpp"
-
-#define YY_USER_ACTION yylloc->columns(yyleng);
-
-#line 572 "./idlc/tidlc_l.cpp"
-
-#define INITIAL 0
-#define COMMENT 1
-#define VALUE 2
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-#include <unistd.h>
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* Holds the entire state of the reentrant scanner. */
-struct yyguts_t
-    {
-
-    /* User-defined. Not touched by flex. */
-    YY_EXTRA_TYPE yyextra_r;
-
-    /* The rest are the same as the globals declared in the non-reentrant scanner. */
-    FILE *yyin_r, *yyout_r;
-    size_t yy_buffer_stack_top; /**< index of top of stack. */
-    size_t yy_buffer_stack_max; /**< capacity of stack. */
-    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
-    char yy_hold_char;
-    yy_size_t yy_n_chars;
-    yy_size_t yyleng_r;
-    char *yy_c_buf_p;
-    int yy_init;
-    int yy_start;
-    int yy_did_buffer_switch_on_eof;
-    int yy_start_stack_ptr;
-    int yy_start_stack_depth;
-    int *yy_start_stack;
-    yy_state_type yy_last_accepting_state;
-    char* yy_last_accepting_cpos;
-
-    int yylineno_r;
-    int yy_flex_debug_r;
-
-    char *yytext_r;
-    int yy_more_flag;
-    int yy_more_len;
-
-    YYSTYPE * yylval_r;
-
-    YYLTYPE * yylloc_r;
-
-    }; /* end struct yyguts_t */
-
-static int yy_init_globals (yyscan_t yyscanner );
-
-    /* This must go here because YYSTYPE and YYLTYPE are included
-     * from bison output in section 1.*/
-    #    define yylval yyg->yylval_r
-    
-    #    define yylloc yyg->yylloc_r
-    
-int yylex_init (yyscan_t* scanner);
-
-int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
-
-/* Accessor methods to globals.
-   These are made visible to non-reentrant scanners for convenience. */
-
-int yylex_destroy (yyscan_t yyscanner );
-
-int yyget_debug (yyscan_t yyscanner );
-
-void yyset_debug (int debug_flag ,yyscan_t yyscanner );
-
-YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner );
-
-void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
-
-FILE *yyget_in (yyscan_t yyscanner );
-
-void yyset_in  (FILE * in_str ,yyscan_t yyscanner );
-
-FILE *yyget_out (yyscan_t yyscanner );
-
-void yyset_out  (FILE * out_str ,yyscan_t yyscanner );
-
-yy_size_t yyget_leng (yyscan_t yyscanner );
-
-char *yyget_text (yyscan_t yyscanner );
-
-int yyget_lineno (yyscan_t yyscanner );
-
-void yyset_lineno (int line_number ,yyscan_t yyscanner );
-
-int yyget_column  (yyscan_t yyscanner );
-
-void yyset_column (int column_no ,yyscan_t yyscanner );
-
-YYSTYPE * yyget_lval (yyscan_t yyscanner );
-
-void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
-
-       YYLTYPE *yyget_lloc (yyscan_t yyscanner );
-    
-        void yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
-    
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int yywrap (yyscan_t yyscanner );
-#else
-extern int yywrap (yyscan_t yyscanner );
-#endif
-#endif
-
-    static void yyunput (int c,char *buf_ptr  ,yyscan_t yyscanner);
-    
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
-#endif
-
-#ifndef YY_NO_INPUT
-
-#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
-#else
-static int input (yyscan_t yyscanner );
-#endif
-
-#endif
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
-#define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
-#endif
-
-/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-       if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
-               { \
-               int c = '*'; \
-               size_t n; \
-               for ( n = 0; n < max_size && \
-                            (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
-                       buf[n] = (char) c; \
-               if ( c == '\n' ) \
-                       buf[n++] = (char) c; \
-               if ( c == EOF && ferror( yyin ) ) \
-                       YY_FATAL_ERROR( "input in flex scanner failed" ); \
-               result = n; \
-               } \
-       else \
-               { \
-               errno=0; \
-               while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
-                       { \
-                       if( errno != EINTR) \
-                               { \
-                               YY_FATAL_ERROR( "input in flex scanner failed" ); \
-                               break; \
-                               } \
-                       errno=0; \
-                       clearerr(yyin); \
-                       } \
-               }\
-\
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
-#endif
-
-/* end tables serialization structures and prototypes */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-
-extern int yylex \
-               (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
-
-#define YY_DECL int yylex \
-               (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after yytext and yyleng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-#define YY_RULE_SETUP \
-       YY_USER_ACTION
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
-       register yy_state_type yy_current_state;
-       register char *yy_cp, *yy_bp;
-       register int yy_act;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-    yylval = yylval_param;
-
-    yylloc = yylloc_param;
-
-       if ( !yyg->yy_init )
-               {
-               yyg->yy_init = 1;
-
-#ifdef YY_USER_INIT
-               YY_USER_INIT;
-#endif
-
-               if ( ! yyg->yy_start )
-                       yyg->yy_start = 1;      /* first start state */
-
-               if ( ! yyin )
-                       yyin = stdin;
-
-               if ( ! yyout )
-                       yyout = stdout;
-
-               if ( ! YY_CURRENT_BUFFER ) {
-                       yyensure_buffer_stack (yyscanner);
-                       YY_CURRENT_BUFFER_LVALUE =
-                               yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
-               }
-
-               yy_load_buffer_state(yyscanner );
-               }
-
-       {
-#line 28 "./idlc/tidlc.ll"
-
-
-  std::string comments;
-  std::string values;
-
-
-#line 862 "./idlc/tidlc_l.cpp"
-
-       while ( 1 )             /* loops until end-of-file is reached */
-               {
-               yy_cp = yyg->yy_c_buf_p;
-
-               /* Support of yytext. */
-               *yy_cp = yyg->yy_hold_char;
-
-               /* yy_bp points to the position in yy_ch_buf of the start of
-                * the current run.
-                */
-               yy_bp = yy_cp;
-
-               yy_current_state = yyg->yy_start;
-yy_match:
-               do
-                       {
-                       register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
-                       if ( yy_accept[yy_current_state] )
-                               {
-                               yyg->yy_last_accepting_state = yy_current_state;
-                               yyg->yy_last_accepting_cpos = yy_cp;
-                               }
-                       while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-                               {
-                               yy_current_state = (int) yy_def[yy_current_state];
-                               if ( yy_current_state >= 129 )
-                                       yy_c = yy_meta[(unsigned int) yy_c];
-                               }
-                       yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-                       ++yy_cp;
-                       }
-               while ( yy_base[yy_current_state] != 154 );
-
-yy_find_action:
-               yy_act = yy_accept[yy_current_state];
-               if ( yy_act == 0 )
-                       { /* have to back up */
-                       yy_cp = yyg->yy_last_accepting_cpos;
-                       yy_current_state = yyg->yy_last_accepting_state;
-                       yy_act = yy_accept[yy_current_state];
-                       }
-
-               YY_DO_BEFORE_ACTION;
-
-               if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
-                       {
-                       yy_size_t yyl;
-                       for ( yyl = 0; yyl < yyleng; ++yyl )
-                               if ( yytext[yyl] == '\n' )
-                                          
-    do{ yylineno++;
-        yycolumn=0;
-    }while(0)
-;
-                       }
-
-do_action:     /* This label is used only to access EOF actions. */
-
-               switch ( yy_act )
-       { /* beginning of action switch */
-                       case 0: /* must back up */
-                       /* undo the effects of YY_DO_BEFORE_ACTION */
-                       *yy_cp = yyg->yy_hold_char;
-                       yy_cp = yyg->yy_last_accepting_cpos;
-                       yy_current_state = yyg->yy_last_accepting_state;
-                       goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 34 "./idlc/tidlc.ll"
-{ comments += yytext; BEGIN(COMMENT); }
-       YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 35 "./idlc/tidlc.ll"
-{ comments += yytext; yylloc->step(); BEGIN(INITIAL); }
-       YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 36 "./idlc/tidlc.ll"
-{ comments += yytext; comments += "\n"; BEGIN(INITIAL); }
-       YY_BREAK
-case 4:
-/* rule 4 can match eol */
-YY_RULE_SETUP
-#line 37 "./idlc/tidlc.ll"
-{ comments += yytext; yylloc->step(); BEGIN(INITIAL); }
-       YY_BREAK
-case 5:
-/* rule 5 can match eol */
-YY_RULE_SETUP
-#line 38 "./idlc/tidlc.ll"
-{ comments += yytext; yylloc->lines(yyleng); }
-       YY_BREAK
-case 6:
-/* rule 6 can match eol */
-YY_RULE_SETUP
-#line 39 "./idlc/tidlc.ll"
-{ comments += yytext; yylloc->step(); }
-       YY_BREAK
-case YY_STATE_EOF(COMMENT):
-#line 40 "./idlc/tidlc.ll"
-{ return 0; }
-       YY_BREAK
-case 7:
-/* rule 7 can match eol */
-YY_RULE_SETUP
-#line 42 "./idlc/tidlc.ll"
-{ comments += yytext; yylloc->step(); }
-       YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 44 "./idlc/tidlc.ll"
-{ BEGIN(VALUE); }
-       YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 45 "./idlc/tidlc.ll"
-{
-                          BEGIN(INITIAL);
-                          yylval->token = new tidl::Token(values, comments);
-                          return yy::parser::token::T_VALUE;
-                        }
-       YY_BREAK
-case 10:
-/* rule 10 can match eol */
-YY_RULE_SETUP
-#line 50 "./idlc/tidlc.ll"
-{ values += yytext; yylloc->step(); }
-       YY_BREAK
-case 11:
-/* rule 11 can match eol */
-YY_RULE_SETUP
-#line 52 "./idlc/tidlc.ll"
-{ yylloc->lines(yyleng); yylloc->step(); }
-       YY_BREAK
-case 12:
-/* rule 12 can match eol */
-YY_RULE_SETUP
-#line 54 "./idlc/tidlc.ll"
-; // ignore all whitespace
-       YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 55 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_COMMA; }
-       YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 56 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_BRACE_OPEN; }
-       YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 57 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_BRACE_CLOSE; }
-       YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 58 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_LEFT; }
-       YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 59 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_RIGHT; }
-       YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 60 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_SEMICOLON; }
-       YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 61 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_VOID;
-                        }
-       YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 65 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_CHAR;
-                        }
-       YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 69 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SHORT;
-                        }
-       YY_BREAK
-case 22:
-YY_RULE_SETUP
-#line 73 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_INT;
-                        }
-       YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 77 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_LONG;
-                        }
-       YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 81 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_FLOAT;
-                        }
-       YY_BREAK
-case 25:
-YY_RULE_SETUP
-#line 85 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_DOUBLE;
-                        }
-       YY_BREAK
-case 26:
-YY_RULE_SETUP
-#line 89 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_BUNDLE;
-                        }
-       YY_BREAK
-case 27:
-YY_RULE_SETUP
-#line 93 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_STRING;
-                        }
-       YY_BREAK
-case 28:
-YY_RULE_SETUP
-#line 97 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_BOOL;
-                        }
-       YY_BREAK
-case 29:
-YY_RULE_SETUP
-#line 101 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_IN; }
-       YY_BREAK
-case 30:
-YY_RULE_SETUP
-#line 102 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_OUT; }
-       YY_BREAK
-case 31:
-YY_RULE_SETUP
-#line 103 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_REF; }
-       YY_BREAK
-case 32:
-YY_RULE_SETUP
-#line 104 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_ASYNC; }
-       YY_BREAK
-case 33:
-YY_RULE_SETUP
-#line 105 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_DELEGATE; }
-       YY_BREAK
-case 34:
-YY_RULE_SETUP
-#line 106 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_META_OPEN; }
-       YY_BREAK
-case 35:
-YY_RULE_SETUP
-#line 107 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_META_CLOSE; }
-       YY_BREAK
-case 36:
-YY_RULE_SETUP
-#line 108 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_LIST;
-                        }
-       YY_BREAK
-case 37:
-YY_RULE_SETUP
-#line 112 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_ARRAY;
-                        }
-       YY_BREAK
-case 38:
-YY_RULE_SETUP
-#line 116 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_STRUCTURE;
-                        }
-       YY_BREAK
-case 39:
-YY_RULE_SETUP
-#line 120 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_INTERFACE;
-                        }
-       YY_BREAK
-case 40:
-YY_RULE_SETUP
-#line 124 "./idlc/tidlc.ll"
-{
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_ID;
-                        }
-       YY_BREAK
-case 41:
-YY_RULE_SETUP
-#line 128 "./idlc/tidlc.ll"
-{ // Square Bracket
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SB_OPEN;
-                        }
-       YY_BREAK
-case 42:
-YY_RULE_SETUP
-#line 132 "./idlc/tidlc.ll"
-{ // Square Bracket
-                          yylval->token = new tidl::Token(yytext, comments);
-                          return yy::parser::token::T_SB_CLOSE;
-                        }
-       YY_BREAK
-case 43:
-YY_RULE_SETUP
-#line 136 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_EQUAL; }
-       YY_BREAK
-case 44:
-YY_RULE_SETUP
-#line 137 "./idlc/tidlc.ll"
-{ return yy::parser::token::T_UNKNOWN; }
-       YY_BREAK
-case 45:
-YY_RULE_SETUP
-#line 139 "./idlc/tidlc.ll"
-ECHO;
-       YY_BREAK
-#line 1222 "./idlc/tidlc_l.cpp"
-case YY_STATE_EOF(INITIAL):
-case YY_STATE_EOF(VALUE):
-       yyterminate();
-
-       case YY_END_OF_BUFFER:
-               {
-               /* Amount of text matched not including the EOB char. */
-               int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
-
-               /* Undo the effects of YY_DO_BEFORE_ACTION. */
-               *yy_cp = yyg->yy_hold_char;
-               YY_RESTORE_YY_MORE_OFFSET
-
-               if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
-                       {
-                       /* We're scanning a new file or input source.  It's
-                        * possible that this happened because the user
-                        * just pointed yyin at a new source and called
-                        * yylex().  If so, then we have to assure
-                        * consistency between YY_CURRENT_BUFFER and our
-                        * globals.  Here is the right place to do so, because
-                        * this is the first action (other than possibly a
-                        * back-up) that will match for the new input source.
-                        */
-                       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
-                       YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
-                       YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
-                       }
-
-               /* Note that here we test for yy_c_buf_p "<=" to the position
-                * of the first EOB in the buffer, since yy_c_buf_p will
-                * already have been incremented past the NUL character
-                * (since all states make transitions on EOB to the
-                * end-of-buffer state).  Contrast this with the test
-                * in input().
-                */
-               if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
-                       { /* This was really a NUL. */
-                       yy_state_type yy_next_state;
-
-                       yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
-
-                       yy_current_state = yy_get_previous_state( yyscanner );
-
-                       /* Okay, we're now positioned to make the NUL
-                        * transition.  We couldn't have
-                        * yy_get_previous_state() go ahead and do it
-                        * for us because it doesn't know how to deal
-                        * with the possibility of jamming (and we don't
-                        * want to build jamming into it because then it
-                        * will run more slowly).
-                        */
-
-                       yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
-
-                       yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
-
-                       if ( yy_next_state )
-                               {
-                               /* Consume the NUL. */
-                               yy_cp = ++yyg->yy_c_buf_p;
-                               yy_current_state = yy_next_state;
-                               goto yy_match;
-                               }
-
-                       else
-                               {
-                               yy_cp = yyg->yy_c_buf_p;
-                               goto yy_find_action;
-                               }
-                       }
-
-               else switch ( yy_get_next_buffer( yyscanner ) )
-                       {
-                       case EOB_ACT_END_OF_FILE:
-                               {
-                               yyg->yy_did_buffer_switch_on_eof = 0;
-
-                               if ( yywrap(yyscanner ) )
-                                       {
-                                       /* Note: because we've taken care in
-                                        * yy_get_next_buffer() to have set up
-                                        * yytext, we can now set up
-                                        * yy_c_buf_p so that if some total
-                                        * hoser (like flex itself) wants to
-                                        * call the scanner after we return the
-                                        * YY_NULL, it'll still work - another
-                                        * YY_NULL will get returned.
-                                        */
-                                       yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
-
-                                       yy_act = YY_STATE_EOF(YY_START);
-                                       goto do_action;
-                                       }
-
-                               else
-                                       {
-                                       if ( ! yyg->yy_did_buffer_switch_on_eof )
-                                               YY_NEW_FILE;
-                                       }
-                               break;
-                               }
-
-                       case EOB_ACT_CONTINUE_SCAN:
-                               yyg->yy_c_buf_p =
-                                       yyg->yytext_ptr + yy_amount_of_matched_text;
-
-                               yy_current_state = yy_get_previous_state( yyscanner );
-
-                               yy_cp = yyg->yy_c_buf_p;
-                               yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
-                               goto yy_match;
-
-                       case EOB_ACT_LAST_MATCH:
-                               yyg->yy_c_buf_p =
-                               &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
-
-                               yy_current_state = yy_get_previous_state( yyscanner );
-
-                               yy_cp = yyg->yy_c_buf_p;
-                               yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
-                               goto yy_find_action;
-                       }
-               break;
-               }
-
-       default:
-               YY_FATAL_ERROR(
-                       "fatal flex scanner internal error--no action found" );
-       } /* end of action switch */
-               } /* end of scanning one token */
-       } /* end of user's declarations */
-} /* end of yylex */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- *     EOB_ACT_LAST_MATCH -
- *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- *     EOB_ACT_END_OF_FILE - end of file
- */
-static int yy_get_next_buffer (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-       register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
-       register char *source = yyg->yytext_ptr;
-       register int number_to_move, i;
-       int ret_val;
-
-       if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
-               YY_FATAL_ERROR(
-               "fatal flex scanner internal error--end of buffer missed" );
-
-       if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
-               { /* Don't try to fill the buffer, so this is an EOF. */
-               if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
-                       {
-                       /* We matched a single character, the EOB, so
-                        * treat this as a final EOF.
-                        */
-                       return EOB_ACT_END_OF_FILE;
-                       }
-
-               else
-                       {
-                       /* We matched some text prior to the EOB, first
-                        * process it.
-                        */
-                       return EOB_ACT_LAST_MATCH;
-                       }
-               }
-
-       /* Try to read more data. */
-
-       /* First move last chars to start of buffer. */
-       number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
-
-       for ( i = 0; i < number_to_move; ++i )
-               *(dest++) = *(source++);
-
-       if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
-               /* don't do the read, it's not guaranteed to return an EOF,
-                * just force an EOF
-                */
-               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
-
-       else
-               {
-                       yy_size_t num_to_read =
-                       YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
-               while ( num_to_read <= 0 )
-                       { /* Not enough room in the buffer - grow it. */
-
-                       /* just a shorter name for the current buffer */
-                       YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
-
-                       int yy_c_buf_p_offset =
-                               (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
-
-                       if ( b->yy_is_our_buffer )
-                               {
-                               yy_size_t new_size = b->yy_buf_size * 2;
-
-                               if ( new_size <= 0 )
-                                       b->yy_buf_size += b->yy_buf_size / 8;
-                               else
-                                       b->yy_buf_size *= 2;
-
-                               b->yy_ch_buf = (char *)
-                                       /* Include room in for 2 EOB chars. */
-                                       yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
-                               }
-                       else
-                               /* Can't grow it, we don't own it. */
-                               b->yy_ch_buf = 0;
-
-                       if ( ! b->yy_ch_buf )
-                               YY_FATAL_ERROR(
-                               "fatal error - scanner input buffer overflow" );
-
-                       yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
-
-                       num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
-                                               number_to_move - 1;
-
-                       }
-
-               if ( num_to_read > YY_READ_BUF_SIZE )
-                       num_to_read = YY_READ_BUF_SIZE;
-
-               /* Read in more data. */
-               YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
-                       yyg->yy_n_chars, num_to_read );
-
-               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
-               }
-
-       if ( yyg->yy_n_chars == 0 )
-               {
-               if ( number_to_move == YY_MORE_ADJ )
-                       {
-                       ret_val = EOB_ACT_END_OF_FILE;
-                       yyrestart(yyin  ,yyscanner);
-                       }
-
-               else
-                       {
-                       ret_val = EOB_ACT_LAST_MATCH;
-                       YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
-                               YY_BUFFER_EOF_PENDING;
-                       }
-               }
-
-       else
-               ret_val = EOB_ACT_CONTINUE_SCAN;
-
-       if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
-               /* Extend the array by 50%, plus the number we really need. */
-               yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
-               YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
-               if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
-                       YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
-       }
-
-       yyg->yy_n_chars += number_to_move;
-       YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
-       YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
-
-       yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
-       return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
-{
-       register yy_state_type yy_current_state;
-       register char *yy_cp;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       yy_current_state = yyg->yy_start;
-
-       for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
-               {
-               register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
-               if ( yy_accept[yy_current_state] )
-                       {
-                       yyg->yy_last_accepting_state = yy_current_state;
-                       yyg->yy_last_accepting_cpos = yy_cp;
-                       }
-               while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-                       {
-                       yy_current_state = (int) yy_def[yy_current_state];
-                       if ( yy_current_state >= 129 )
-                               yy_c = yy_meta[(unsigned int) yy_c];
-                       }
-               yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-               }
-
-       return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- *     next_state = yy_try_NUL_trans( current_state );
- */
-    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
-{
-       register int yy_is_jam;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
-       register char *yy_cp = yyg->yy_c_buf_p;
-
-       register YY_CHAR yy_c = 1;
-       if ( yy_accept[yy_current_state] )
-               {
-               yyg->yy_last_accepting_state = yy_current_state;
-               yyg->yy_last_accepting_cpos = yy_cp;
-               }
-       while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-               {
-               yy_current_state = (int) yy_def[yy_current_state];
-               if ( yy_current_state >= 129 )
-                       yy_c = yy_meta[(unsigned int) yy_c];
-               }
-       yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-       yy_is_jam = (yy_current_state == 128);
-
-       (void)yyg;
-       return yy_is_jam ? 0 : yy_current_state;
-}
-
-    static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
-{
-       register char *yy_cp;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-    yy_cp = yyg->yy_c_buf_p;
-
-       /* undo effects of setting up yytext */
-       *yy_cp = yyg->yy_hold_char;
-
-       if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
-               { /* need to shift things up to make room */
-               /* +2 for EOB chars. */
-               register yy_size_t number_to_move = yyg->yy_n_chars + 2;
-               register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
-                                       YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
-               register char *source =
-                               &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
-
-               while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
-                       *--dest = *--source;
-
-               yy_cp += (int) (dest - source);
-               yy_bp += (int) (dest - source);
-               YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
-                       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
-
-               if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
-                       YY_FATAL_ERROR( "flex scanner push-back overflow" );
-               }
-
-       *--yy_cp = (char) c;
-
-    if ( c == '\n' ){
-        --yylineno;
-    }
-
-       yyg->yytext_ptr = yy_bp;
-       yyg->yy_hold_char = *yy_cp;
-       yyg->yy_c_buf_p = yy_cp;
-}
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
-    static int yyinput (yyscan_t yyscanner)
-#else
-    static int input  (yyscan_t yyscanner)
-#endif
-
-{
-       int c;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       *yyg->yy_c_buf_p = yyg->yy_hold_char;
-
-       if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
-               {
-               /* yy_c_buf_p now points to the character we want to return.
-                * If this occurs *before* the EOB characters, then it's a
-                * valid NUL; if not, then we've hit the end of the buffer.
-                */
-               if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
-                       /* This was really a NUL. */
-                       *yyg->yy_c_buf_p = '\0';
-
-               else
-                       { /* need more input */
-                       yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
-                       ++yyg->yy_c_buf_p;
-
-                       switch ( yy_get_next_buffer( yyscanner ) )
-                               {
-                               case EOB_ACT_LAST_MATCH:
-                                       /* This happens because yy_g_n_b()
-                                        * sees that we've accumulated a
-                                        * token and flags that we need to
-                                        * try matching the token before
-                                        * proceeding.  But for input(),
-                                        * there's no matching to consider.
-                                        * So convert the EOB_ACT_LAST_MATCH
-                                        * to EOB_ACT_END_OF_FILE.
-                                        */
-
-                                       /* Reset buffer status. */
-                                       yyrestart(yyin ,yyscanner);
-
-                                       /*FALLTHROUGH*/
-
-                               case EOB_ACT_END_OF_FILE:
-                                       {
-                                       if ( yywrap(yyscanner ) )
-                                               return EOF;
-
-                                       if ( ! yyg->yy_did_buffer_switch_on_eof )
-                                               YY_NEW_FILE;
-#ifdef __cplusplus
-                                       return yyinput(yyscanner);
-#else
-                                       return input(yyscanner);
-#endif
-                                       }
-
-                               case EOB_ACT_CONTINUE_SCAN:
-                                       yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
-                                       break;
-                               }
-                       }
-               }
-
-       c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
-       *yyg->yy_c_buf_p = '\0';        /* preserve yytext */
-       yyg->yy_hold_char = *++yyg->yy_c_buf_p;
-
-       if ( c == '\n' )
-                  
-    do{ yylineno++;
-        yycolumn=0;
-    }while(0)
-;
-
-       return c;
-}
-#endif /* ifndef YY_NO_INPUT */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
- * @param yyscanner The scanner object.
- * @note This function does not reset the start condition to @c INITIAL .
- */
-    void yyrestart  (FILE * input_file , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       if ( ! YY_CURRENT_BUFFER ){
-        yyensure_buffer_stack (yyscanner);
-               YY_CURRENT_BUFFER_LVALUE =
-            yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
-       }
-
-       yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
-       yy_load_buffer_state(yyscanner );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
- * @param yyscanner The scanner object.
- */
-    void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       /* TODO. We should be able to replace this entire function body
-        * with
-        *              yypop_buffer_state();
-        *              yypush_buffer_state(new_buffer);
-     */
-       yyensure_buffer_stack (yyscanner);
-       if ( YY_CURRENT_BUFFER == new_buffer )
-               return;
-
-       if ( YY_CURRENT_BUFFER )
-               {
-               /* Flush out information for old buffer. */
-               *yyg->yy_c_buf_p = yyg->yy_hold_char;
-               YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
-               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
-               }
-
-       YY_CURRENT_BUFFER_LVALUE = new_buffer;
-       yy_load_buffer_state(yyscanner );
-
-       /* We don't actually know whether we did this switch during
-        * EOF (yywrap()) processing, but the only time this flag
-        * is looked at is after yywrap() is called, so it's safe
-        * to go ahead and always set it.
-        */
-       yyg->yy_did_buffer_switch_on_eof = 1;
-}
-
-static void yy_load_buffer_state  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-       yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
-       yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
-       yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
-       yyg->yy_hold_char = *yyg->yy_c_buf_p;
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
- * @param yyscanner The scanner object.
- * @return the allocated buffer state.
- */
-    YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
-{
-       YY_BUFFER_STATE b;
-    
-       b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
-       if ( ! b )
-               YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
-       b->yy_buf_size = size;
-
-       /* yy_ch_buf has to be 2 characters longer than the size given because
-        * we need to put in 2 end-of-buffer characters.
-        */
-       b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner );
-       if ( ! b->yy_ch_buf )
-               YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
-       b->yy_is_our_buffer = 1;
-
-       yy_init_buffer(b,file ,yyscanner);
-
-       return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with yy_create_buffer()
- * @param yyscanner The scanner object.
- */
-    void yy_delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       if ( ! b )
-               return;
-
-       if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
-               YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
-       if ( b->yy_is_our_buffer )
-               yyfree((void *) b->yy_ch_buf ,yyscanner );
-
-       yyfree((void *) b ,yyscanner );
-}
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a yyrestart() or at EOF.
- */
-    static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)
-
-{
-       int oerrno = errno;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       yy_flush_buffer(b ,yyscanner);
-
-       b->yy_input_file = file;
-       b->yy_fill_buffer = 1;
-
-    /* If b is the current buffer, then yy_init_buffer was _probably_
-     * called from yyrestart() or through yy_get_next_buffer.
-     * In that case, we don't want to reset the lineno or column.
-     */
-    if (b != YY_CURRENT_BUFFER){
-        b->yy_bs_lineno = 1;
-        b->yy_bs_column = 0;
-    }
-
-        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-    
-       errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- * @param yyscanner The scanner object.
- */
-    void yy_flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-       if ( ! b )
-               return;
-
-       b->yy_n_chars = 0;
-
-       /* We always need two end-of-buffer characters.  The first causes
-        * a transition to the end-of-buffer state.  The second causes
-        * a jam in that state.
-        */
-       b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
-       b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
-       b->yy_buf_pos = &b->yy_ch_buf[0];
-
-       b->yy_at_bol = 1;
-       b->yy_buffer_status = YY_BUFFER_NEW;
-
-       if ( b == YY_CURRENT_BUFFER )
-               yy_load_buffer_state(yyscanner );
-}
-
-/** Pushes the new state onto the stack. The new state becomes
- *  the current state. This function will allocate the stack
- *  if necessary.
- *  @param new_buffer The new state.
- *  @param yyscanner The scanner object.
- */
-void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-       if (new_buffer == NULL)
-               return;
-
-       yyensure_buffer_stack(yyscanner);
-
-       /* This block is copied from yy_switch_to_buffer. */
-       if ( YY_CURRENT_BUFFER )
-               {
-               /* Flush out information for old buffer. */
-               *yyg->yy_c_buf_p = yyg->yy_hold_char;
-               YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
-               YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
-               }
-
-       /* Only push if top exists. Otherwise, replace top. */
-       if (YY_CURRENT_BUFFER)
-               yyg->yy_buffer_stack_top++;
-       YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
-       /* copied from yy_switch_to_buffer. */
-       yy_load_buffer_state(yyscanner );
-       yyg->yy_did_buffer_switch_on_eof = 1;
-}
-
-/** Removes and deletes the top of the stack, if present.
- *  The next element becomes the new top.
- *  @param yyscanner The scanner object.
- */
-void yypop_buffer_state (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-       if (!YY_CURRENT_BUFFER)
-               return;
-
-       yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
-       YY_CURRENT_BUFFER_LVALUE = NULL;
-       if (yyg->yy_buffer_stack_top > 0)
-               --yyg->yy_buffer_stack_top;
-
-       if (YY_CURRENT_BUFFER) {
-               yy_load_buffer_state(yyscanner );
-               yyg->yy_did_buffer_switch_on_eof = 1;
-       }
-}
-
-/* Allocates the stack if it does not exist.
- *  Guarantees space for at least one push.
- */
-static void yyensure_buffer_stack (yyscan_t yyscanner)
-{
-       yy_size_t num_to_alloc;
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-       if (!yyg->yy_buffer_stack) {
-
-               /* First allocation is just for 2 elements, since we don't know if this
-                * scanner will even need a stack. We use 2 instead of 1 to avoid an
-                * immediate realloc on the next call.
-         */
-               num_to_alloc = 1;
-               yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
-                                                               (num_to_alloc * sizeof(struct yy_buffer_state*)
-                                                               , yyscanner);
-               if ( ! yyg->yy_buffer_stack )
-                       YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-                                                                 
-               memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-                               
-               yyg->yy_buffer_stack_max = num_to_alloc;
-               yyg->yy_buffer_stack_top = 0;
-               return;
-       }
-
-       if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
-
-               /* Increase the buffer to prepare for a possible push. */
-               int grow_size = 8 /* arbitrary grow size */;
-
-               num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
-               yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
-                                                               (yyg->yy_buffer_stack,
-                                                               num_to_alloc * sizeof(struct yy_buffer_state*)
-                                                               , yyscanner);
-               if ( ! yyg->yy_buffer_stack )
-                       YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-
-               /* zero only the new slots.*/
-               memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
-               yyg->yy_buffer_stack_max = num_to_alloc;
-       }
-}
-
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object. 
- */
-YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
-{
-       YY_BUFFER_STATE b;
-    
-       if ( size < 2 ||
-            base[size-2] != YY_END_OF_BUFFER_CHAR ||
-            base[size-1] != YY_END_OF_BUFFER_CHAR )
-               /* They forgot to leave room for the EOB's. */
-               return 0;
-
-       b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
-       if ( ! b )
-               YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
-
-       b->yy_buf_size = size - 2;      /* "- 2" to take care of EOB's */
-       b->yy_buf_pos = b->yy_ch_buf = base;
-       b->yy_is_our_buffer = 0;
-       b->yy_input_file = 0;
-       b->yy_n_chars = b->yy_buf_size;
-       b->yy_is_interactive = 0;
-       b->yy_at_bol = 1;
-       b->yy_fill_buffer = 0;
-       b->yy_buffer_status = YY_BUFFER_NEW;
-
-       yy_switch_to_buffer(b ,yyscanner );
-
-       return b;
-}
-
-/** Setup the input buffer state to scan a string. The next call to yylex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- *       yy_scan_bytes() instead.
- */
-YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
-{
-    
-       return yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
-}
-
-/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len , yyscan_t yyscanner)
-{
-       YY_BUFFER_STATE b;
-       char *buf;
-       yy_size_t n;
-       yy_size_t i;
-    
-       /* Get memory for full buffer, including space for trailing EOB's. */
-       n = _yybytes_len + 2;
-       buf = (char *) yyalloc(n ,yyscanner );
-       if ( ! buf )
-               YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
-
-       for ( i = 0; i < _yybytes_len; ++i )
-               buf[i] = yybytes[i];
-
-       buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
-       b = yy_scan_buffer(buf,n ,yyscanner);
-       if ( ! b )
-               YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
-
-       /* It's okay to grow etc. this buffer, and we should throw it
-        * away when we're done.
-        */
-       b->yy_is_our_buffer = 1;
-
-       return b;
-}
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
-{
-       (void) fprintf( stderr, "%s\n", msg );
-       exit( YY_EXIT_FAILURE );
-}
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
-       do \
-               { \
-               /* Undo effects of setting up yytext. */ \
-        int yyless_macro_arg = (n); \
-        YY_LESS_LINENO(yyless_macro_arg);\
-               yytext[yyleng] = yyg->yy_hold_char; \
-               yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
-               yyg->yy_hold_char = *yyg->yy_c_buf_p; \
-               *yyg->yy_c_buf_p = '\0'; \
-               yyleng = yyless_macro_arg; \
-               } \
-       while ( 0 )
-
-/* Accessor  methods (get/set functions) to struct members. */
-
-/** Get the user-defined data for this scanner.
- * @param yyscanner The scanner object.
- */
-YY_EXTRA_TYPE yyget_extra  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yyextra;
-}
-
-/** Get the current line number.
- * @param yyscanner The scanner object.
- */
-int yyget_lineno  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    
-        if (! YY_CURRENT_BUFFER)
-            return 0;
-    
-    return yylineno;
-}
-
-/** Get the current column number.
- * @param yyscanner The scanner object.
- */
-int yyget_column  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    
-        if (! YY_CURRENT_BUFFER)
-            return 0;
-    
-    return yycolumn;
-}
-
-/** Get the input stream.
- * @param yyscanner The scanner object.
- */
-FILE *yyget_in  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yyin;
-}
-
-/** Get the output stream.
- * @param yyscanner The scanner object.
- */
-FILE *yyget_out  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yyout;
-}
-
-/** Get the length of the current token.
- * @param yyscanner The scanner object.
- */
-yy_size_t yyget_leng  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yyleng;
-}
-
-/** Get the current token.
- * @param yyscanner The scanner object.
- */
-
-char *yyget_text  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yytext;
-}
-
-/** Set the user-defined data. This data is never touched by the scanner.
- * @param user_defined The data to be associated with this scanner.
- * @param yyscanner The scanner object.
- */
-void yyset_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yyextra = user_defined ;
-}
-
-/** Set the current line number.
- * @param line_number
- * @param yyscanner The scanner object.
- */
-void yyset_lineno (int  line_number , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-        /* lineno is only valid if an input buffer exists. */
-        if (! YY_CURRENT_BUFFER )
-           YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
-    
-    yylineno = line_number;
-}
-
-/** Set the current column.
- * @param line_number
- * @param yyscanner The scanner object.
- */
-void yyset_column (int  column_no , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-        /* column is only valid if an input buffer exists. */
-        if (! YY_CURRENT_BUFFER )
-           YY_FATAL_ERROR( "yyset_column called with no buffer" );
-    
-    yycolumn = column_no;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- * @param yyscanner The scanner object.
- * @see yy_switch_to_buffer
- */
-void yyset_in (FILE *  in_str , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yyin = in_str ;
-}
-
-void yyset_out (FILE *  out_str , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yyout = out_str ;
-}
-
-int yyget_debug  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yy_flex_debug;
-}
-
-void yyset_debug (int  bdebug , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yy_flex_debug = bdebug ;
-}
-
-/* Accessor methods for yylval and yylloc */
-
-YYSTYPE * yyget_lval  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yylval;
-}
-
-void yyset_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yylval = yylval_param;
-}
-
-YYLTYPE *yyget_lloc  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    return yylloc;
-}
-    
-void yyset_lloc (YYLTYPE *  yylloc_param , yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    yylloc = yylloc_param;
-}
-    
-/* User-visible API */
-
-/* yylex_init is special because it creates the scanner itself, so it is
- * the ONLY reentrant function that doesn't take the scanner as the last argument.
- * That's why we explicitly handle the declaration, instead of using our macros.
- */
-
-int yylex_init(yyscan_t* ptr_yy_globals)
-
-{
-    if (ptr_yy_globals == NULL){
-        errno = EINVAL;
-        return 1;
-    }
-
-    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
-
-    if (*ptr_yy_globals == NULL){
-        errno = ENOMEM;
-        return 1;
-    }
-
-    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
-    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
-
-    return yy_init_globals ( *ptr_yy_globals );
-}
-
-/* yylex_init_extra has the same functionality as yylex_init, but follows the
- * convention of taking the scanner as the last argument. Note however, that
- * this is a *pointer* to a scanner, as it will be allocated by this call (and
- * is the reason, too, why this function also must handle its own declaration).
- * The user defined value in the first argument will be available to yyalloc in
- * the yyextra field.
- */
-
-int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
-{
-    struct yyguts_t dummy_yyguts;
-
-    yyset_extra (yy_user_defined, &dummy_yyguts);
-
-    if (ptr_yy_globals == NULL){
-        errno = EINVAL;
-        return 1;
-    }
-       
-    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
-       
-    if (*ptr_yy_globals == NULL){
-        errno = ENOMEM;
-        return 1;
-    }
-    
-    /* By setting to 0xAA, we expose bugs in
-    yy_init_globals. Leave at 0x00 for releases. */
-    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
-    
-    yyset_extra (yy_user_defined, *ptr_yy_globals);
-    
-    return yy_init_globals ( *ptr_yy_globals );
-}
-
-static int yy_init_globals (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-    /* Initialization is the same as for the non-reentrant scanner.
-     * This function is called from yylex_destroy(), so don't allocate here.
-     */
-
-    yyg->yy_buffer_stack = 0;
-    yyg->yy_buffer_stack_top = 0;
-    yyg->yy_buffer_stack_max = 0;
-    yyg->yy_c_buf_p = (char *) 0;
-    yyg->yy_init = 0;
-    yyg->yy_start = 0;
-
-    yyg->yy_start_stack_ptr = 0;
-    yyg->yy_start_stack_depth = 0;
-    yyg->yy_start_stack =  NULL;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
-    yyin = stdin;
-    yyout = stdout;
-#else
-    yyin = (FILE *) 0;
-    yyout = (FILE *) 0;
-#endif
-
-    /* For future reference: Set errno on error, since we are called by
-     * yylex_init()
-     */
-    return 0;
-}
-
-/* yylex_destroy is for both reentrant and non-reentrant scanners. */
-int yylex_destroy  (yyscan_t yyscanner)
-{
-    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
-    /* Pop the buffer stack, destroying each element. */
-       while(YY_CURRENT_BUFFER){
-               yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
-               YY_CURRENT_BUFFER_LVALUE = NULL;
-               yypop_buffer_state(yyscanner);
-       }
-
-       /* Destroy the stack itself. */
-       yyfree(yyg->yy_buffer_stack ,yyscanner);
-       yyg->yy_buffer_stack = NULL;
-
-    /* Destroy the start condition stack. */
-        yyfree(yyg->yy_start_stack ,yyscanner );
-        yyg->yy_start_stack = NULL;
-
-    /* Reset the globals. This is important in a non-reentrant scanner so the next time
-     * yylex() is called, initialization will occur. */
-    yy_init_globals( yyscanner);
-
-    /* Destroy the main struct (reentrant only). */
-    yyfree ( yyscanner , yyscanner );
-    yyscanner = NULL;
-    return 0;
-}
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
-{
-       register int i;
-       for ( i = 0; i < n; ++i )
-               s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
-{
-       register int n;
-       for ( n = 0; s[n]; ++n )
-               ;
-
-       return n;
-}
-#endif
-
-void *yyalloc (yy_size_t  size , yyscan_t yyscanner)
-{
-       return (void *) malloc( size );
-}
-
-void *yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
-{
-       /* The cast to (char *) in the following accommodates both
-        * implementations that use char* generic pointers, and those
-        * that use void* generic pointers.  It works with the latter
-        * because both ANSI C and C++ allow castless assignment from
-        * any pointer type to void*, and deal with argument conversions
-        * as though doing an assignment.
-        */
-       return (void *) realloc( (char *) ptr, size );
-}
-
-void yyfree (void * ptr , yyscan_t yyscanner)
-{
-       free( (char *) ptr );   /* see yyrealloc() for (char *) cast */
-}
-
-#define YYTABLES_NAME "yytables"
-
-#line 138 "./idlc/tidlc.ll"
-
-
-
-
diff --git a/idlc/tidlc_y.cpp b/idlc/tidlc_y.cpp
deleted file mode 100644 (file)
index 5a21a4e..0000000
+++ /dev/null
@@ -1,3633 +0,0 @@
-// A Bison parser, made by GNU Bison 3.0.2.
-
-// Skeleton implementation for Bison GLR parsers in C
-
-// Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-// As a special exception, you may create a larger work that contains
-// part or all of the Bison parser skeleton and distribute that work
-// under terms of your choice, so long as that work isn't itself a
-// parser generator using the skeleton or a modified version thereof
-// as a parser skeleton.  Alternatively, if you modify or redistribute
-// the parser skeleton itself, you may (at your option) remove this
-// special exception, which will cause the skeleton and the resulting
-// Bison output files to be licensed under the GNU General Public
-// License without this special exception.
-
-// This special exception was added by the Free Software Foundation in
-// version 2.2 of Bison.
-
-/* C GLR parser skeleton written by Paul Hilfinger.  */
-
-/* Identify Bison output.  */
-#define YYBISON 1
-
-/* Bison version.  */
-#define YYBISON_VERSION "3.0.2"
-
-/* Skeleton name.  */
-#define YYSKELETON_NAME "glr.cc"
-
-/* Pure parsers.  */
-#define YYPURE 1
-
-
-
-
-
-
-/* First part of user declarations.  */
-#line 1 "./idlc/tidlc.yy" // glr.c:207
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "idlc/parser.h"
-#include "idlc/document.h"
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
-#include "idlc/interface.h"
-#include "idlc/element.h"
-#include "idlc/structure.h"
-#include "idlc/block.h"
-#include "idlc/attribute.h"
-#include "idlc/tidlc_y.hpp"
-
-int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
-
-#define lex_scanner ps->Scanner()
-
-
-#line 77 "./idlc/tidlc_y.cpp" // glr.c:207
-
-# ifndef YY_NULLPTR
-#  if defined __cplusplus && 201103L <= __cplusplus
-#   define YY_NULLPTR nullptr
-#  else
-#   define YY_NULLPTR 0
-#  endif
-# endif
-
-#include "tidlc_y.hpp"
-
-/* Enabling verbose error messages.  */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 0
-#endif
-
-/* Default (constant) value used for initialization for null
-   right-hand sides.  Unlike the standard yacc.c template, here we set
-   the default value of $$ to a zeroed-out value.  Since the default
-   value is undefined, this behavior is technically correct.  */
-static YYSTYPE yyval_default;
-static YYLTYPE yyloc_default
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-  = { 1, 1, 1, 1 }
-# endif
-;
-
-/* Copy the second part of user declarations.  */
-#line 109 "./idlc/tidlc_y.cpp" // glr.c:230
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
-   If N is 0, then set CURRENT to the empty location which ends
-   the previous symbol: RHS[0] (always defined).  */
-
-# ifndef YYLLOC_DEFAULT
-#  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
-    do                                                                  \
-      if (N)                                                            \
-        {                                                               \
-          (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
-          (Current).end    = YYRHSLOC (Rhs, N).end;                     \
-        }                                                               \
-      else                                                              \
-        {                                                               \
-          (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
-        }                                                               \
-    while (/*CONSTCOND*/ false)
-# endif
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
-static void yyerror (const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps, const char* msg);
-#line 131 "./idlc/tidlc_y.cpp" // glr.c:230
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-#  if ENABLE_NLS
-#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
-#  endif
-# endif
-# ifndef YY_
-#  define YY_(Msgid) Msgid
-# endif
-#endif
-
-#ifndef YYFREE
-# define YYFREE free
-#endif
-#ifndef YYMALLOC
-# define YYMALLOC malloc
-#endif
-#ifndef YYREALLOC
-# define YYREALLOC realloc
-#endif
-
-#define YYSIZEMAX ((size_t) -1)
-
-#ifdef __cplusplus
-   typedef bool yybool;
-#else
-   typedef unsigned char yybool;
-#endif
-#define yytrue 1
-#define yyfalse 0
-
-#ifndef YYSETJMP
-# include <setjmp.h>
-# define YYJMP_BUF jmp_buf
-# define YYSETJMP(Env) setjmp (Env)
-/* Pacify clang.  */
-# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
-#endif
-
-#ifndef YY_ATTRIBUTE
-# if (defined __GNUC__                                               \
-      && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
-     || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
-#  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
-# else
-#  define YY_ATTRIBUTE(Spec) /* empty */
-# endif
-#endif
-
-#ifndef YY_ATTRIBUTE_PURE
-# define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
-#endif
-
-#ifndef YY_ATTRIBUTE_UNUSED
-# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
-#endif
-
-#if !defined _Noreturn \
-     && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
-# if defined _MSC_VER && 1200 <= _MSC_VER
-#  define _Noreturn __declspec (noreturn)
-# else
-#  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
-# endif
-#endif
-
-/* Suppress unused-variable warnings by "using" E.  */
-#if ! defined lint || defined __GNUC__
-# define YYUSE(E) ((void) (E))
-#else
-# define YYUSE(E) /* empty */
-#endif
-
-#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
-/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
-    _Pragma ("GCC diagnostic push") \
-    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
-    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
-    _Pragma ("GCC diagnostic pop")
-#else
-# define YY_INITIAL_VALUE(Value) Value
-#endif
-#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END
-#endif
-#ifndef YY_INITIAL_VALUE
-# define YY_INITIAL_VALUE(Value) /* Nothing. */
-#endif
-
-
-#ifndef YYASSERT
-# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
-#endif
-
-/* YYFINAL -- State number of the termination state.  */
-#define YYFINAL  19
-/* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   409
-
-/* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  36
-/* YYNNTS -- Number of nonterminals.  */
-#define YYNNTS  19
-/* YYNRULES -- Number of rules.  */
-#define YYNRULES  68
-/* YYNRULES -- Number of states.  */
-#define YYNSTATES  133
-/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule.  */
-#define YYMAXRHS 8
-/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
-   accessed by $0, $-1, etc., in any rule.  */
-#define YYMAXLEFT 0
-
-/* YYTRANSLATE(X) -- Bison symbol number corresponding to X.  */
-#define YYUNDEFTOK  2
-#define YYMAXUTOK   290
-
-#define YYTRANSLATE(YYX)                                                \
-  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const unsigned char yytranslate[] =
-{
-       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
-       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
-      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
-      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
-      35
-};
-
-#if YYDEBUG
-/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const unsigned short int yyrline[] =
-{
-       0,    94,    94,    99,   104,   118,   121,   126,   132,   137,
-     143,   150,   154,   163,   169,   174,   178,   182,   188,   192,
-     201,   207,   212,   218,   225,   231,   239,   244,   249,   256,
-     260,   269,   275,   280,   287,   295,   300,   305,   310,   314,
-     318,   322,   326,   332,   337,   346,   352,   355,   358,   363,
-     366,   370,   376,   379,   385,   388,   392,   396,   400,   404,
-     408,   412,   416,   420,   424,   428,   434,   441,   445
-};
-#endif
-
-#if YYDEBUG || YYERROR_VERBOSE || 0
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
-   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
-static const char *const yytname[] =
-{
-  "$end", "error", "$undefined", "T_LEFT", "T_RIGHT", "T_COMMA",
-  "T_SEMICOLON", "T_BRACE_OPEN", "T_BRACE_CLOSE", "T_IN", "T_OUT", "T_REF",
-  "T_ASYNC", "T_META_OPEN", "T_META_CLOSE", "T_EQUAL", "T_DELEGATE",
-  "T_UNKNOWN", "T_ID", "T_STRUCTURE", "T_INTERFACE", "T_CHAR", "T_SHORT",
-  "T_INT", "T_LONG", "T_FLOAT", "T_DOUBLE", "T_VOID", "T_BUNDLE",
-  "T_STRING", "T_BOOL", "T_LIST", "T_ARRAY", "T_VALUE", "T_SB_OPEN",
-  "T_SB_CLOSE", "$accept", "start", "blocks", "block", "structure_block",
-  "elements", "element", "attributes", "attribute", "interface_block",
-  "declarations", "declaration", "parameter_list", "direction_specifier",
-  "parameter", "parameter_type", "base_type", "container_type",
-  "container_type_name", YY_NULLPTR
-};
-#endif
-
-#define YYPACT_NINF -68
-#define YYTABLE_NINF -56
-
-  // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
-  // STATE-NUM.
-static const short int yypact[] =
-{
-      26,     6,    13,    41,    10,    26,   -68,   -68,   -68,    40,
-     323,    31,    55,   362,    43,   -68,    42,     1,   -68,   -68,
-     -68,   323,   -68,   -68,   -68,   -68,   -68,   -68,   -68,   -68,
-     -68,   -68,   -68,   -68,   -68,   -68,   -68,   116,   -68,    15,
-     -68,     4,   323,   362,   -68,    22,   148,   -68,    38,   362,
-     -11,     2,    36,    47,   180,    72,   -68,   -68,    73,   -68,
-      74,   377,   212,   244,    75,    84,    79,    78,   -68,   -68,
-      80,    84,    87,   276,   -68,   -68,   -68,   -68,    59,   -68,
-     -68,   -68,   -68,    83,   -68,   -68,   -68,   -68,   -68,   -68,
-     -68,    81,    61,   377,   -68,    82,   -68,    84,   -68,   -68,
-      65,    84,   -68,    85,   -68,    37,   347,   -68,   -68,    68,
-      92,    71,   362,    95,    97,   -68,     3,   -68,    52,   308,
-     -68,   -68,   -68,    98,   112,   -68,   113,   114,   -68,   -68,
-     -68,   -68,   -68
-};
-
-  // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
-  // Performed when YYTABLE does not specify something else to do.  Zero
-  // means the default is an error.
-static const unsigned char yydefact[] =
-{
-       0,     0,     0,     0,     0,     2,     3,     6,     5,     0,
-       0,     0,     0,     0,     0,    20,     0,     0,    18,     1,
-       4,     0,    10,    17,    65,    56,    57,    58,    59,    60,
-      61,    55,    62,    63,    64,    67,    68,     0,    11,     0,
-      54,     0,     0,     0,    28,     0,     0,    29,     0,     0,
-       0,     0,     0,     0,     0,    17,     8,    12,     0,    15,
-       0,     0,     0,     0,     0,     0,     0,     0,    26,    30,
-       0,     0,     0,     0,    22,    23,    21,    19,     0,     9,
-      13,    16,    14,     0,     7,    27,    42,    45,    46,    47,
-      48,    50,     0,     0,    43,     0,    52,     0,    31,    41,
-       0,     0,    24,     0,    66,     0,    49,    53,    51,     0,
-       0,     0,     0,     0,     0,    44,     0,    38,     0,     0,
-      39,    40,    37,     0,     0,    32,     0,     0,    25,    33,
-      34,    35,    36
-};
-
-  // YYPGOTO[NTERM-NUM].
-static const signed char yypgoto[] =
-{
-     -68,   -68,   -68,   117,   -68,   -16,   -25,   -68,    69,   -68,
-     -41,   -45,   -67,   -68,    17,   -68,   -10,   -68,   -68
-};
-
-  // YYDEFGOTO[NTERM-NUM].
-static const signed char yydefgoto[] =
-{
-      -1,     4,     5,     6,     7,    37,    38,    17,    18,     8,
-      46,    47,    92,    93,    94,    95,    48,    40,    41
-};
-
-  // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
-  // positive, shift that token.  If negative, reduce the rule whose
-  // number is the opposite.  If YYTABLE_NINF, syntax error.
-static const short int yytable[] =
-{
-      39,    69,    63,    75,   100,    54,    52,     9,    73,   122,
-      19,    39,    57,    10,    12,   123,    58,    61,    69,   124,
-      13,    59,    74,    64,    11,    65,    62,    39,    69,    57,
-     109,    14,    39,    60,   111,    76,    53,    57,    42,    70,
-      66,    71,    15,    50,    39,     1,     2,    21,    22,   113,
-      49,    83,    39,   114,    16,    96,    72,    51,   125,    16,
-       3,    96,    43,    44,   126,   105,   106,    78,   127,   110,
-     106,   119,   116,   106,    69,   118,   106,   103,    80,    81,
-      82,    86,    97,   107,    98,    87,    99,    96,   -49,   -49,
-     101,    96,   112,    88,    89,    90,    96,   104,   117,   -55,
-     108,   120,    24,   121,   129,    25,    26,    27,    28,    29,
-      30,    91,    32,    33,    34,    35,    36,    55,   130,   131,
-     132,    77,    20,   115,    56,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,    24,     0,     0,    25,    26,    27,
-      28,    29,    30,    31,    32,    33,    34,    35,    36,    67,
-       0,     0,     0,     0,     0,     0,    68,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,    24,     0,     0,    25,
-      26,    27,    28,    29,    30,    45,    32,    33,    34,    35,
-      36,    55,     0,     0,     0,     0,     0,     0,    79,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,    24,     0,
-       0,    25,    26,    27,    28,    29,    30,    31,    32,    33,
-      34,    35,    36,    55,     0,     0,     0,     0,     0,     0,
-      84,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-      24,     0,     0,    25,    26,    27,    28,    29,    30,    31,
-      32,    33,    34,    35,    36,    67,     0,     0,     0,     0,
-       0,     0,    85,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,    24,     0,     0,    25,    26,    27,    28,    29,
-      30,    45,    32,    33,    34,    35,    36,    67,     0,     0,
-       0,     0,     0,     0,   102,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,    24,     0,     0,    25,    26,    27,
-      28,    29,    30,    45,    32,    33,    34,    35,    36,    67,
-       0,     0,     0,     0,     0,     0,   128,     0,     0,     0,
-       0,     0,     0,     0,    23,     0,    24,     0,     0,    25,
-      26,    27,    28,    29,    30,    45,    32,    33,    34,    35,
-      36,    24,     0,     0,    25,    26,    27,    28,    29,    30,
-      31,    32,    33,    34,    35,    36,    88,    89,    90,     0,
-       0,     0,     0,     0,     0,    24,     0,     0,    25,    26,
-      27,    28,    29,    30,    91,    32,    33,    34,    35,    36,
-      24,     0,     0,    25,    26,    27,    28,    29,    30,    45,
-      32,    33,    34,    35,    36,    24,     0,     0,    25,    26,
-      27,    28,    29,    30,    31,    32,    33,    34,    35,    36
-};
-
-static const signed char yycheck[] =
-{
-      10,    46,    43,     1,    71,    21,     5,     1,    49,     6,
-       0,    21,    37,     7,     1,    12,     1,    13,    63,    16,
-       7,     6,    33,     1,    18,     3,    42,    37,    73,    54,
-      97,    18,    42,    18,   101,    33,    35,    62,     7,     1,
-      18,     3,     1,     1,    54,    19,    20,     7,     8,    12,
-       7,    61,    62,    16,    18,    65,    18,    15,     6,    18,
-      34,    71,     7,     8,    12,     4,     5,    20,    16,     4,
-       5,   112,     4,     5,   119,     4,     5,    18,     6,     6,
-       6,     6,     3,    93,     6,     1,     6,    97,     4,     5,
-       3,   101,     7,     9,    10,    11,   106,    14,     6,    18,
-      18,     6,    18,     6,     6,    21,    22,    23,    24,    25,
-      26,    27,    28,    29,    30,    31,    32,     1,     6,     6,
-       6,    52,     5,   106,     8,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,     1,
-      -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    18,    -1,    -1,    21,
-      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
-      32,     1,    -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,
-      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    18,    -1,
-      -1,    21,    22,    23,    24,    25,    26,    27,    28,    29,
-      30,    31,    32,     1,    -1,    -1,    -1,    -1,    -1,    -1,
-       8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      18,    -1,    -1,    21,    22,    23,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,     1,    -1,    -1,    -1,    -1,
-      -1,    -1,     8,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    18,    -1,    -1,    21,    22,    23,    24,    25,
-      26,    27,    28,    29,    30,    31,    32,     1,    -1,    -1,
-      -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,    23,
-      24,    25,    26,    27,    28,    29,    30,    31,    32,     1,
-      -1,    -1,    -1,    -1,    -1,    -1,     8,    -1,    -1,    -1,
-      -1,    -1,    -1,    -1,     1,    -1,    18,    -1,    -1,    21,
-      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
-      32,    18,    -1,    -1,    21,    22,    23,    24,    25,    26,
-      27,    28,    29,    30,    31,    32,     9,    10,    11,    -1,
-      -1,    -1,    -1,    -1,    -1,    18,    -1,    -1,    21,    22,
-      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
-      18,    -1,    -1,    21,    22,    23,    24,    25,    26,    27,
-      28,    29,    30,    31,    32,    18,    -1,    -1,    21,    22,
-      23,    24,    25,    26,    27,    28,    29,    30,    31,    32
-};
-
-  // YYSTOS[STATE-NUM] -- The (internal number of the) accessing
-  // symbol of state STATE-NUM.
-static const unsigned char yystos[] =
-{
-       0,    19,    20,    34,    37,    38,    39,    40,    45,     1,
-       7,    18,     1,     7,    18,     1,    18,    43,    44,     0,
-      39,     7,     8,     1,    18,    21,    22,    23,    24,    25,
-      26,    27,    28,    29,    30,    31,    32,    41,    42,    52,
-      53,    54,     7,     7,     8,    27,    46,    47,    52,     7,
-       1,    15,     5,    35,    41,     1,     8,    42,     1,     6,
-      18,    13,    41,    46,     1,     3,    18,     1,     8,    47,
-       1,     3,    18,    46,    33,     1,    33,    44,    20,     8,
-       6,     6,     6,    52,     8,     8,     6,     1,     9,    10,
-      11,    27,    48,    49,    50,    51,    52,     3,     6,     6,
-      48,     3,     8,    18,    14,     4,     5,    52,    18,    48,
-       4,    48,     7,    12,    16,    50,     4,     6,     4,    46,
-       6,     6,     6,    12,    16,     6,    12,    16,     8,     6,
-       6,     6,     6
-};
-
-  // YYR1[YYN] -- Symbol number of symbol that rule YYN derives.
-static const unsigned char yyr1[] =
-{
-       0,    36,    37,    38,    38,    39,    39,    40,    40,    40,
-      40,    41,    41,    41,    42,    42,    42,    42,    43,    43,
-      43,    44,    44,    44,    45,    45,    45,    45,    45,    46,
-      46,    46,    47,    47,    47,    47,    47,    47,    47,    47,
-      47,    47,    47,    48,    48,    48,    49,    49,    49,    50,
-      50,    50,    51,    51,    52,    52,    52,    52,    52,    52,
-      52,    52,    52,    52,    52,    52,    53,    54,    54
-};
-
-  // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.
-static const unsigned char yyr2[] =
-{
-       0,     2,     1,     1,     2,     1,     1,     5,     4,     5,
-       3,     1,     2,     3,     3,     2,     3,     1,     1,     3,
-       1,     3,     3,     3,     5,     8,     4,     5,     3,     1,
-       2,     3,     6,     7,     7,     7,     7,     6,     5,     6,
-       6,     3,     3,     1,     3,     1,     1,     1,     1,     0,
-       1,     2,     1,     2,     1,     1,     1,     1,     1,     1,
-       1,     1,     1,     1,     1,     1,     4,     1,     1
-};
-
-
-/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none).  */
-static const unsigned char yydprec[] =
-{
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0
-};
-
-/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM.  */
-static const unsigned char yymerger[] =
-{
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0
-};
-
-/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
-   in the case of predicates.  */
-static const yybool yyimmediate[] =
-{
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0
-};
-
-/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
-   list of conflicting reductions corresponding to action entry for
-   state STATE-NUM in yytable.  0 means no conflicts.  The list in
-   yyconfl is terminated by a rule number of 0.  */
-static const unsigned char yyconflp[] =
-{
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,     0,     0,     0,     0,     0
-};
-
-/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
-   0, pointed into by YYCONFLP.  */
-static const short int yyconfl[] =
-{
-       0
-};
-
-/* Error token number */
-#define YYTERROR 1
-
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
-   If N is 0, then set CURRENT to the empty location which ends
-   the previous symbol: RHS[0] (always defined).  */
-
-# ifndef YYLLOC_DEFAULT
-#  define YYLLOC_DEFAULT(Current, Rhs, N)                               \
-    do                                                                  \
-      if (N)                                                            \
-        {                                                               \
-          (Current).begin  = YYRHSLOC (Rhs, 1).begin;                   \
-          (Current).end    = YYRHSLOC (Rhs, N).end;                     \
-        }                                                               \
-      else                                                              \
-        {                                                               \
-          (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;      \
-        }                                                               \
-    while (/*CONSTCOND*/ false)
-# endif
-
-# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
-
-
-
-#undef yynerrs
-#define yynerrs (yystackp->yyerrcnt)
-#undef yychar
-#define yychar (yystackp->yyrawchar)
-#undef yylval
-#define yylval (yystackp->yyval)
-#undef yylloc
-#define yylloc (yystackp->yyloc)
-
-
-static const int YYEOF = 0;
-static const int YYEMPTY = -2;
-
-typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
-
-#define YYCHK(YYE)                              \
-  do {                                          \
-    YYRESULTTAG yychk_flag = YYE;               \
-    if (yychk_flag != yyok)                     \
-      return yychk_flag;                        \
-  } while (0)
-
-#if YYDEBUG
-
-# ifndef YYFPRINTF
-#  define YYFPRINTF fprintf
-# endif
-
-
-/* YY_LOCATION_PRINT -- Print the location on the stream.
-   This macro was not mandated originally: define only if we know
-   we won't break user code: when these are the locations we know.  */
-
-#ifndef YY_LOCATION_PRINT
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-
-/* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
-
-YY_ATTRIBUTE_UNUSED
-static unsigned
-yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
-{
-  unsigned res = 0;
-  int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
-  if (0 <= yylocp->first_line)
-    {
-      res += YYFPRINTF (yyo, "%d", yylocp->first_line);
-      if (0 <= yylocp->first_column)
-        res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
-    }
-  if (0 <= yylocp->last_line)
-    {
-      if (yylocp->first_line < yylocp->last_line)
-        {
-          res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
-          if (0 <= end_col)
-            res += YYFPRINTF (yyo, ".%d", end_col);
-        }
-      else if (0 <= end_col && yylocp->first_column < end_col)
-        res += YYFPRINTF (yyo, "-%d", end_col);
-    }
-  return res;
- }
-
-#  define YY_LOCATION_PRINT(File, Loc)          \
-  yy_location_print_ (File, &(Loc))
-
-# else
-#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif
-
-
-# define YYDPRINTF(Args)                        \
-  do {                                          \
-    if (yydebug)                                \
-      YYFPRINTF Args;                           \
-  } while (0)
-
-
-/*--------------------.
-| Print this symbol.  |
-`--------------------*/
-
-static void
-yy_symbol_print (FILE *, int yytype, const yy::parser::semantic_type *yyvaluep, const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  YYUSE (yyparser);
-  YYUSE (ps);
-  yyparser.yy_symbol_print_ (yytype, yyvaluep, yylocationp);
-}
-
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                  \
-  do {                                                                  \
-    if (yydebug)                                                        \
-      {                                                                 \
-        YYFPRINTF (stderr, "%s ", Title);                               \
-        yy_symbol_print (stderr, Type, Value, Location, yyparser, ps);        \
-        YYFPRINTF (stderr, "\n");                                       \
-      }                                                                 \
-  } while (0)
-
-/* Nonzero means print parse trace.  It is left uninitialized so that
-   multiple parsers can coexist.  */
-int yydebug;
-
-struct yyGLRStack;
-static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
-  YY_ATTRIBUTE_UNUSED;
-static void yypdumpstack (struct yyGLRStack* yystackp)
-  YY_ATTRIBUTE_UNUSED;
-
-#else /* !YYDEBUG */
-
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-
-#endif /* !YYDEBUG */
-
-/* YYINITDEPTH -- initial size of the parser's stacks.  */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
-   if the built-in stack extension method is used).
-
-   Do not make this value too large; the results are undefined if
-   SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
-   evaluated with infinite-precision integer arithmetic.  */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-/* Minimum number of free items on the stack allowed after an
-   allocation.  This is to allow allocation and initialization
-   to be completed by functions that call yyexpandGLRStack before the
-   stack is expanded, thus insuring that all necessary pointers get
-   properly redirected to new data.  */
-#define YYHEADROOM 2
-
-#ifndef YYSTACKEXPANDABLE
-#  define YYSTACKEXPANDABLE 1
-#endif
-
-#if YYSTACKEXPANDABLE
-# define YY_RESERVE_GLRSTACK(Yystack)                   \
-  do {                                                  \
-    if (Yystack->yyspaceLeft < YYHEADROOM)              \
-      yyexpandGLRStack (Yystack);                       \
-  } while (0)
-#else
-# define YY_RESERVE_GLRSTACK(Yystack)                   \
-  do {                                                  \
-    if (Yystack->yyspaceLeft < YYHEADROOM)              \
-      yyMemoryExhausted (Yystack);                      \
-  } while (0)
-#endif
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystpcpy
-#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
-#   define yystpcpy stpcpy
-#  else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
-   YYDEST.  */
-static char *
-yystpcpy (char *yydest, const char *yysrc)
-{
-  char *yyd = yydest;
-  const char *yys = yysrc;
-
-  while ((*yyd++ = *yys++) != '\0')
-    continue;
-
-  return yyd - 1;
-}
-#  endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
-   quotes and backslashes, so that it's suitable for yyerror.  The
-   heuristic is that double-quoting is unnecessary unless the string
-   contains an apostrophe, a comma, or backslash (other than
-   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
-   null, do not copy; instead, return the length of what the result
-   would have been.  */
-static size_t
-yytnamerr (char *yyres, const char *yystr)
-{
-  if (*yystr == '"')
-    {
-      size_t yyn = 0;
-      char const *yyp = yystr;
-
-      for (;;)
-        switch (*++yyp)
-          {
-          case '\'':
-          case ',':
-            goto do_not_strip_quotes;
-
-          case '\\':
-            if (*++yyp != '\\')
-              goto do_not_strip_quotes;
-            /* Fall through.  */
-          default:
-            if (yyres)
-              yyres[yyn] = *yyp;
-            yyn++;
-            break;
-
-          case '"':
-            if (yyres)
-              yyres[yyn] = '\0';
-            return yyn;
-          }
-    do_not_strip_quotes: ;
-    }
-
-  if (! yyres)
-    return strlen (yystr);
-
-  return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-#endif /* !YYERROR_VERBOSE */
-
-/** State numbers, as in LALR(1) machine */
-typedef int yyStateNum;
-
-/** Rule numbers, as in LALR(1) machine */
-typedef int yyRuleNum;
-
-/** Grammar symbol */
-typedef int yySymbol;
-
-/** Item references, as in LALR(1) machine */
-typedef short int yyItemNum;
-
-typedef struct yyGLRState yyGLRState;
-typedef struct yyGLRStateSet yyGLRStateSet;
-typedef struct yySemanticOption yySemanticOption;
-typedef union yyGLRStackItem yyGLRStackItem;
-typedef struct yyGLRStack yyGLRStack;
-
-struct yyGLRState {
-  /** Type tag: always true.  */
-  yybool yyisState;
-  /** Type tag for yysemantics.  If true, yysval applies, otherwise
-   *  yyfirstVal applies.  */
-  yybool yyresolved;
-  /** Number of corresponding LALR(1) machine state.  */
-  yyStateNum yylrState;
-  /** Preceding state in this stack */
-  yyGLRState* yypred;
-  /** Source position of the last token produced by my symbol */
-  size_t yyposn;
-  union {
-    /** First in a chain of alternative reductions producing the
-     *  non-terminal corresponding to this state, threaded through
-     *  yynext.  */
-    yySemanticOption* yyfirstVal;
-    /** Semantic value for this state.  */
-    YYSTYPE yysval;
-  } yysemantics;
-  /** Source location for this state.  */
-  YYLTYPE yyloc;
-};
-
-struct yyGLRStateSet {
-  yyGLRState** yystates;
-  /** During nondeterministic operation, yylookaheadNeeds tracks which
-   *  stacks have actually needed the current lookahead.  During deterministic
-   *  operation, yylookaheadNeeds[0] is not maintained since it would merely
-   *  duplicate yychar != YYEMPTY.  */
-  yybool* yylookaheadNeeds;
-  size_t yysize, yycapacity;
-};
-
-struct yySemanticOption {
-  /** Type tag: always false.  */
-  yybool yyisState;
-  /** Rule number for this reduction */
-  yyRuleNum yyrule;
-  /** The last RHS state in the list of states to be reduced.  */
-  yyGLRState* yystate;
-  /** The lookahead for this reduction.  */
-  int yyrawchar;
-  YYSTYPE yyval;
-  YYLTYPE yyloc;
-  /** Next sibling in chain of options.  To facilitate merging,
-   *  options are chained in decreasing order by address.  */
-  yySemanticOption* yynext;
-};
-
-/** Type of the items in the GLR stack.  The yyisState field
- *  indicates which item of the union is valid.  */
-union yyGLRStackItem {
-  yyGLRState yystate;
-  yySemanticOption yyoption;
-};
-
-struct yyGLRStack {
-  int yyerrState;
-  /* To compute the location of the error token.  */
-  yyGLRStackItem yyerror_range[3];
-
-  int yyerrcnt;
-  int yyrawchar;
-  YYSTYPE yyval;
-  YYLTYPE yyloc;
-
-  YYJMP_BUF yyexception_buffer;
-  yyGLRStackItem* yyitems;
-  yyGLRStackItem* yynextFree;
-  size_t yyspaceLeft;
-  yyGLRState* yysplitPoint;
-  yyGLRState* yylastDeleted;
-  yyGLRStateSet yytops;
-};
-
-#if YYSTACKEXPANDABLE
-static void yyexpandGLRStack (yyGLRStack* yystackp);
-#endif
-
-static _Noreturn void
-yyFail (yyGLRStack* yystackp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps, const char* yymsg)
-{
-  if (yymsg != YY_NULLPTR)
-    yyerror (yylocp, yyparser, ps, yymsg);
-  YYLONGJMP (yystackp->yyexception_buffer, 1);
-}
-
-static _Noreturn void
-yyMemoryExhausted (yyGLRStack* yystackp)
-{
-  YYLONGJMP (yystackp->yyexception_buffer, 2);
-}
-
-#if YYDEBUG || YYERROR_VERBOSE
-/** A printable representation of TOKEN.  */
-static inline const char*
-yytokenName (yySymbol yytoken)
-{
-  if (yytoken == YYEMPTY)
-    return "";
-
-  return yytname[yytoken];
-}
-#endif
-
-/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
- *  at YYVSP[YYLOW0].yystate.yypred.  Leaves YYVSP[YYLOW1].yystate.yypred
- *  containing the pointer to the next state in the chain.  */
-static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED;
-static void
-yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
-{
-  int i;
-  yyGLRState *s = yyvsp[yylow0].yystate.yypred;
-  for (i = yylow0-1; i >= yylow1; i -= 1)
-    {
-#if YYDEBUG
-      yyvsp[i].yystate.yylrState = s->yylrState;
-#endif
-      yyvsp[i].yystate.yyresolved = s->yyresolved;
-      if (s->yyresolved)
-        yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
-      else
-        /* The effect of using yysval or yyloc (in an immediate rule) is
-         * undefined.  */
-        yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;
-      yyvsp[i].yystate.yyloc = s->yyloc;
-      s = yyvsp[i].yystate.yypred = s->yypred;
-    }
-}
-
-/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1.  Otherwise, fill in
- * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
- * For convenience, always return YYLOW1.  */
-static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
-     YY_ATTRIBUTE_UNUSED;
-static inline int
-yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
-{
-  if (!yynormal && yylow1 < *yylow)
-    {
-      yyfillin (yyvsp, *yylow, yylow1);
-      *yylow = yylow1;
-    }
-  return yylow1;
-}
-
-/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
- *  and top stack item YYVSP.  YYLVALP points to place to put semantic
- *  value ($$), and yylocp points to place for location information
- *  (@$).  Returns yyok for normal return, yyaccept for YYACCEPT,
- *  yyerr for YYERROR, yyabort for YYABORT.  */
-static YYRESULTTAG
-yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
-              yyGLRStack* yystackp,
-              YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
-  int yylow;
-  YYUSE (yyvalp);
-  YYUSE (yylocp);
-  YYUSE (yyparser);
-  YYUSE (ps);
-  YYUSE (yyrhslen);
-# undef yyerrok
-# define yyerrok (yystackp->yyerrState = 0)
-# undef YYACCEPT
-# define YYACCEPT return yyaccept
-# undef YYABORT
-# define YYABORT return yyabort
-# undef YYERROR
-# define YYERROR return yyerrok, yyerr
-# undef YYRECOVERING
-# define YYRECOVERING() (yystackp->yyerrState != 0)
-# undef yyclearin
-# define yyclearin (yychar = YYEMPTY)
-# undef YYFILL
-# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
-# undef YYBACKUP
-# define YYBACKUP(Token, Value)                                              \
-  return yyerror (yylocp, yyparser, ps, YY_("syntax error: cannot back up")),     \
-         yyerrok, yyerr
-
-  yylow = 1;
-  if (yyrhslen == 0)
-    *yyvalp = yyval_default;
-  else
-    *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
-  YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
-  yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
-
-  switch (yyn)
-    {
-        case 2:
-#line 94 "./idlc/tidlc.yy" // glr.c:783
-    {
-     ps->SetDoc((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.doc));
-  }
-#line 1096 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 3:
-#line 99 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).doc) = new tidl::Document();
-    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk) != NULL)
-      ((*yyvalp).doc)->AddBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk));
-  }
-#line 1106 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 4:
-#line 104 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).doc) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.doc);
-
-    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk) != NULL) {
-      if (((*yyvalp).doc)->ExistBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk))) {
-        ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk)->GetLine());
-        delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk);
-      } else {
-        ((*yyvalp).doc)->AddBlock((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.blk));
-      }
-    }
-  }
-#line 1123 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 5:
-#line 118 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).blk) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.interf);
-  }
-#line 1131 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 6:
-#line 121 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).blk) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.structure);
-  }
-#line 1139 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 7:
-#line 126 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).structure) = new tidl::Structure((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.elms), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->GetComments(),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-  }
-#line 1150 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 8:
-#line 132 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
-    ((*yyvalp).structure) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-  }
-#line 1160 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 9:
-#line 137 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"Please check it before an open brace.\"",
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
-    ((*yyvalp).structure) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-  }
-#line 1171 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 10:
-#line 143 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in structure declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).structure) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
-  }
-#line 1181 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 11:
-#line 150 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).elms) = new tidl::Elements();
-    ((*yyvalp).elms)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm));
-  }
-#line 1190 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 12:
-#line 154 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).elms) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.elms);
-    if (((*yyvalp).elms)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm))) {
-      ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm)->GetLine());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm);
-    } else {
-      ((*yyvalp).elms)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.elm));
-    }
-  }
-#line 1204 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 13:
-#line 163 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in elements declarations.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
-    ((*yyvalp).elms) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.elms);
-  }
-#line 1213 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 14:
-#line 169 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).elm) = new tidl::Element((((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.b_type)->GetComments(),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.token);
-  }
-#line 1223 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 15:
-#line 174 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).elm) = NULL;
-  }
-#line 1232 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 16:
-#line 178 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in element declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).elm) = NULL;
-  }
-#line 1241 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 17:
-#line 182 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in element declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).elm) = NULL;
-  }
-#line 1250 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 18:
-#line 188 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).attrs) = new tidl::Attributes();
-    ((*yyvalp).attrs)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr));
-  }
-#line 1259 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 19:
-#line 192 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).attrs) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.attrs);
-    if (((*yyvalp).attrs)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr))) {
-      ps->ReportError("syntax error. \"Already Exist\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr)->GetLine());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr);
-    } else {
-      ((*yyvalp).attrs)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.attr));
-    }
-  }
-#line 1273 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 20:
-#line 201 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in attributes", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).attrs) = new tidl::Attributes();
-  }
-#line 1282 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 21:
-#line 207 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).attr) = new tidl::Attribute((((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-  }
-#line 1292 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 22:
-#line 212 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in attribute declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).attr) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-  }
-#line 1303 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 23:
-#line 218 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in attribute declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).attr) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
-  }
-#line 1313 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 24:
-#line 225 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).interf) = new tidl::Interface((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->GetComments(),
-        new tidl::Attributes(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-  }
-#line 1324 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 25:
-#line 231 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).interf) = new tidl::Interface((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls), (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.attrs),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-7)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-  }
-#line 1337 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 26:
-#line 239 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
-    ((*yyvalp).interf) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-  }
-#line 1347 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 27:
-#line 244 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in interface declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
-    ((*yyvalp).interf) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-  }
-#line 1357 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 28:
-#line 249 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in interface declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).interf) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.token);
-  }
-#line 1367 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 29:
-#line 256 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).decls) = new tidl::Declarations();
-    ((*yyvalp).decls)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl));
-  }
-#line 1376 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 30:
-#line 260 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).decls) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.decls);
-    if (((*yyvalp).decls)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl))) {
-      ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl)->GetLine());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl);
-    } else {
-      ((*yyvalp).decls)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.decl));
-    }
-  }
-#line 1390 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 31:
-#line 269 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in methods declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).decls) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.decls);
-  }
-#line 1399 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 32:
-#line 275 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.params), (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.b_type)->GetComments(),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line, tidl::Declaration::MethodType::SYNC);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-  }
-#line 1409 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 33:
-#line 280 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString(),
-        new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments()), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.params),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yyloc).begin.line, tidl::Declaration::MethodType::ASYNC);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
-  }
-#line 1421 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 34:
-#line 287 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).decl) = new tidl::Declaration((((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token)->ToString(),
-        new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments()), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.params),
-        (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token)->GetComments(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yyloc).begin.line,
-        tidl::Declaration::MethodType::DELEGATE);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-6)].yystate.yysemantics.yysval.token);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
-  }
-#line 1434 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 35:
-#line 295 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
-  }
-#line 1444 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 36:
-#line 300 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-5)].yystate.yysemantics.yysval.token);
-  }
-#line 1454 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 37:
-#line 305 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No async\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yysemantics.yysval.token);
-  }
-#line 1464 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 38:
-#line 310 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-  }
-#line 1473 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 39:
-#line 314 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-  }
-#line 1482 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 40:
-#line 318 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error. \"No identifier\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (-4)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-  }
-#line 1491 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 41:
-#line 322 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-  }
-#line 1500 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 42:
-#line 326 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in method declaration.", (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    ((*yyvalp).decl) = NULL;
-  }
-#line 1509 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 43:
-#line 332 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).params) = new tidl::Parameters();
-    if ((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param) != nullptr)
-      ((*yyvalp).params)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param));
-  }
-#line 1519 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 44:
-#line 337 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).params) = (((yyGLRStackItem const *)yyvsp)[YYFILL (-2)].yystate.yysemantics.yysval.params);
-    if (((*yyvalp).params)->Exist((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param))) {
-      ps->ReportError("syntax error. \"Already Exists\".", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param)->GetLine());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param);
-    } else {
-      ((*yyvalp).params)->Add((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.param));
-    }
-  }
-#line 1533 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 45:
-#line 346 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ps->ReportError("syntax error in parameter list", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yyloc).begin.line);
-    ((*yyvalp).params) = new tidl::Parameters();
-  }
-#line 1542 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 46:
-#line 352 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).direction) = new tidl::Token("in", "");
-  }
-#line 1550 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 47:
-#line 355 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).direction) = new tidl::Token("out", "");
-  }
-#line 1558 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 48:
-#line 358 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).direction) = new tidl::Token("ref", "");
-  }
-#line 1566 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 49:
-#line 363 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).param) = nullptr;
-  }
-#line 1574 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 50:
-#line 366 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).param) = nullptr;
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-  }
-#line 1583 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 51:
-#line 370 "./idlc/tidlc.yy" // glr.c:783
-    {
-    ((*yyvalp).param) = new tidl::Parameter((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.p_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yyloc).begin.line);
-    delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-  }
-#line 1592 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 52:
-#line 376 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).p_type) = new tidl::ParameterType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type));
-    }
-#line 1600 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 53:
-#line 379 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).p_type) = new tidl::ParameterType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type), (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.direction)->ToString());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.direction);
-    }
-#line 1609 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 54:
-#line 385 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.b_type);
-    }
-#line 1617 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 55:
-#line 388 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("void", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1626 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 56:
-#line 392 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("char", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1635 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 57:
-#line 396 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("short", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1644 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 58:
-#line 400 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("int", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1653 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 59:
-#line 404 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("long", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1662 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 60:
-#line 408 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("float", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1671 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 61:
-#line 412 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("double", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1680 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 62:
-#line 416 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("bundle", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1689 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 63:
-#line 420 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("string", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1698 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 64:
-#line 424 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType("bool", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1707 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 65:
-#line 428 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType((((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments(), true);
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1716 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 66:
-#line 434 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).b_type) = new tidl::BaseType((((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->ToString(), (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token)->GetComments());
-      ((*yyvalp).b_type)->SetMetaType((((yyGLRStackItem const *)yyvsp)[YYFILL (-1)].yystate.yysemantics.yysval.b_type));
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (-3)].yystate.yysemantics.yysval.token);
-    }
-#line 1726 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 67:
-#line 441 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).token) = new tidl::Token("list", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1735 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-  case 68:
-#line 445 "./idlc/tidlc.yy" // glr.c:783
-    {
-      ((*yyvalp).token) = new tidl::Token("array", (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token)->GetComments());
-      delete (((yyGLRStackItem const *)yyvsp)[YYFILL (0)].yystate.yysemantics.yysval.token);
-    }
-#line 1744 "./idlc/tidlc_y.cpp" // glr.c:783
-    break;
-
-
-#line 1748 "./idlc/tidlc_y.cpp" // glr.c:783
-      default: break;
-    }
-
-  return yyok;
-# undef yyerrok
-# undef YYABORT
-# undef YYACCEPT
-# undef YYERROR
-# undef YYBACKUP
-# undef yyclearin
-# undef YYRECOVERING
-}
-
-
-static void
-yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
-{
-  YYUSE (yy0);
-  YYUSE (yy1);
-
-  switch (yyn)
-    {
-
-      default: break;
-    }
-}
-
-                              /* Bison grammar-table manipulation.  */
-
-/*-----------------------------------------------.
-| Release the memory associated to this symbol.  |
-`-----------------------------------------------*/
-
-static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  YYUSE (yyvaluep);
-  YYUSE (yylocationp);
-  YYUSE (yyparser);
-  YYUSE (ps);
-  if (!yymsg)
-    yymsg = "Deleting";
-  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
-  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-  YYUSE (yytype);
-  YY_IGNORE_MAYBE_UNINITIALIZED_END
-}
-
-/** Number of symbols composing the right hand side of rule #RULE.  */
-static inline int
-yyrhsLength (yyRuleNum yyrule)
-{
-  return yyr2[yyrule];
-}
-
-static void
-yydestroyGLRState (char const *yymsg, yyGLRState *yys, yy::parser& yyparser, tidl::Parser* ps)
-{
-  if (yys->yyresolved)
-    yydestruct (yymsg, yystos[yys->yylrState],
-                &yys->yysemantics.yysval, &yys->yyloc, yyparser, ps);
-  else
-    {
-#if YYDEBUG
-      if (yydebug)
-        {
-          if (yys->yysemantics.yyfirstVal)
-            YYFPRINTF (stderr, "%s unresolved", yymsg);
-          else
-            YYFPRINTF (stderr, "%s incomplete", yymsg);
-          YY_SYMBOL_PRINT ("", yystos[yys->yylrState], YY_NULLPTR, &yys->yyloc);
-        }
-#endif
-
-      if (yys->yysemantics.yyfirstVal)
-        {
-          yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
-          yyGLRState *yyrh;
-          int yyn;
-          for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
-               yyn > 0;
-               yyrh = yyrh->yypred, yyn -= 1)
-            yydestroyGLRState (yymsg, yyrh, yyparser, ps);
-        }
-    }
-}
-
-/** Left-hand-side symbol for rule #YYRULE.  */
-static inline yySymbol
-yylhsNonterm (yyRuleNum yyrule)
-{
-  return yyr1[yyrule];
-}
-
-#define yypact_value_is_default(Yystate) \
-  (!!((Yystate) == (-68)))
-
-/** True iff LR state YYSTATE has only a default reduction (regardless
- *  of token).  */
-static inline yybool
-yyisDefaultedState (yyStateNum yystate)
-{
-  return yypact_value_is_default (yypact[yystate]);
-}
-
-/** The default reduction for YYSTATE, assuming it has one.  */
-static inline yyRuleNum
-yydefaultAction (yyStateNum yystate)
-{
-  return yydefact[yystate];
-}
-
-#define yytable_value_is_error(Yytable_value) \
-  0
-
-/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
- *  Result R means
- *    R < 0:  Reduce on rule -R.
- *    R = 0:  Error.
- *    R > 0:  Shift to state R.
- *  Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
- *  of conflicting reductions.
- */
-static inline void
-yygetLRActions (yyStateNum yystate, int yytoken,
-                int* yyaction, const short int** yyconflicts)
-{
-  int yyindex = yypact[yystate] + yytoken;
-  if (yypact_value_is_default (yypact[yystate])
-      || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
-    {
-      *yyaction = -yydefact[yystate];
-      *yyconflicts = yyconfl;
-    }
-  else if (! yytable_value_is_error (yytable[yyindex]))
-    {
-      *yyaction = yytable[yyindex];
-      *yyconflicts = yyconfl + yyconflp[yyindex];
-    }
-  else
-    {
-      *yyaction = 0;
-      *yyconflicts = yyconfl + yyconflp[yyindex];
-    }
-}
-
-/** Compute post-reduction state.
- * \param yystate   the current state
- * \param yysym     the nonterminal to push on the stack
- */
-static inline yyStateNum
-yyLRgotoState (yyStateNum yystate, yySymbol yysym)
-{
-  int yyr = yypgoto[yysym - YYNTOKENS] + yystate;
-  if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
-    return yytable[yyr];
-  else
-    return yydefgoto[yysym - YYNTOKENS];
-}
-
-static inline yybool
-yyisShiftAction (int yyaction)
-{
-  return 0 < yyaction;
-}
-
-static inline yybool
-yyisErrorAction (int yyaction)
-{
-  return yyaction == 0;
-}
-
-                                /* GLRStates */
-
-/** Return a fresh GLRStackItem in YYSTACKP.  The item is an LR state
- *  if YYISSTATE, and otherwise a semantic option.  Callers should call
- *  YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
- *  headroom.  */
-
-static inline yyGLRStackItem*
-yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
-{
-  yyGLRStackItem* yynewItem = yystackp->yynextFree;
-  yystackp->yyspaceLeft -= 1;
-  yystackp->yynextFree += 1;
-  yynewItem->yystate.yyisState = yyisState;
-  return yynewItem;
-}
-
-/** Add a new semantic action that will execute the action for rule
- *  YYRULE on the semantic values in YYRHS to the list of
- *  alternative actions for YYSTATE.  Assumes that YYRHS comes from
- *  stack #YYK of *YYSTACKP. */
-static void
-yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
-                     yyGLRState* yyrhs, yyRuleNum yyrule)
-{
-  yySemanticOption* yynewOption =
-    &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
-  YYASSERT (!yynewOption->yyisState);
-  yynewOption->yystate = yyrhs;
-  yynewOption->yyrule = yyrule;
-  if (yystackp->yytops.yylookaheadNeeds[yyk])
-    {
-      yynewOption->yyrawchar = yychar;
-      yynewOption->yyval = yylval;
-      yynewOption->yyloc = yylloc;
-    }
-  else
-    yynewOption->yyrawchar = YYEMPTY;
-  yynewOption->yynext = yystate->yysemantics.yyfirstVal;
-  yystate->yysemantics.yyfirstVal = yynewOption;
-
-  YY_RESERVE_GLRSTACK (yystackp);
-}
-
-                                /* GLRStacks */
-
-/** Initialize YYSET to a singleton set containing an empty stack.  */
-static yybool
-yyinitStateSet (yyGLRStateSet* yyset)
-{
-  yyset->yysize = 1;
-  yyset->yycapacity = 16;
-  yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
-  if (! yyset->yystates)
-    return yyfalse;
-  yyset->yystates[0] = YY_NULLPTR;
-  yyset->yylookaheadNeeds =
-    (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
-  if (! yyset->yylookaheadNeeds)
-    {
-      YYFREE (yyset->yystates);
-      return yyfalse;
-    }
-  return yytrue;
-}
-
-static void yyfreeStateSet (yyGLRStateSet* yyset)
-{
-  YYFREE (yyset->yystates);
-  YYFREE (yyset->yylookaheadNeeds);
-}
-
-/** Initialize *YYSTACKP to a single empty stack, with total maximum
- *  capacity for all stacks of YYSIZE.  */
-static yybool
-yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
-{
-  yystackp->yyerrState = 0;
-  yynerrs = 0;
-  yystackp->yyspaceLeft = yysize;
-  yystackp->yyitems =
-    (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
-  if (!yystackp->yyitems)
-    return yyfalse;
-  yystackp->yynextFree = yystackp->yyitems;
-  yystackp->yysplitPoint = YY_NULLPTR;
-  yystackp->yylastDeleted = YY_NULLPTR;
-  return yyinitStateSet (&yystackp->yytops);
-}
-
-
-#if YYSTACKEXPANDABLE
-# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
-  &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
-
-/** If *YYSTACKP is expandable, extend it.  WARNING: Pointers into the
-    stack from outside should be considered invalid after this call.
-    We always expand when there are 1 or fewer items left AFTER an
-    allocation, so that we can avoid having external pointers exist
-    across an allocation.  */
-static void
-yyexpandGLRStack (yyGLRStack* yystackp)
-{
-  yyGLRStackItem* yynewItems;
-  yyGLRStackItem* yyp0, *yyp1;
-  size_t yynewSize;
-  size_t yyn;
-  size_t yysize = yystackp->yynextFree - yystackp->yyitems;
-  if (YYMAXDEPTH - YYHEADROOM < yysize)
-    yyMemoryExhausted (yystackp);
-  yynewSize = 2*yysize;
-  if (YYMAXDEPTH < yynewSize)
-    yynewSize = YYMAXDEPTH;
-  yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
-  if (! yynewItems)
-    yyMemoryExhausted (yystackp);
-  for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
-       0 < yyn;
-       yyn -= 1, yyp0 += 1, yyp1 += 1)
-    {
-      *yyp1 = *yyp0;
-      if (*(yybool *) yyp0)
-        {
-          yyGLRState* yys0 = &yyp0->yystate;
-          yyGLRState* yys1 = &yyp1->yystate;
-          if (yys0->yypred != YY_NULLPTR)
-            yys1->yypred =
-              YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
-          if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR)
-            yys1->yysemantics.yyfirstVal =
-              YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
-        }
-      else
-        {
-          yySemanticOption* yyv0 = &yyp0->yyoption;
-          yySemanticOption* yyv1 = &yyp1->yyoption;
-          if (yyv0->yystate != YY_NULLPTR)
-            yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
-          if (yyv0->yynext != YY_NULLPTR)
-            yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
-        }
-    }
-  if (yystackp->yysplitPoint != YY_NULLPTR)
-    yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
-                                      yystackp->yysplitPoint, yystate);
-
-  for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
-    if (yystackp->yytops.yystates[yyn] != YY_NULLPTR)
-      yystackp->yytops.yystates[yyn] =
-        YYRELOC (yystackp->yyitems, yynewItems,
-                 yystackp->yytops.yystates[yyn], yystate);
-  YYFREE (yystackp->yyitems);
-  yystackp->yyitems = yynewItems;
-  yystackp->yynextFree = yynewItems + yysize;
-  yystackp->yyspaceLeft = yynewSize - yysize;
-}
-#endif
-
-static void
-yyfreeGLRStack (yyGLRStack* yystackp)
-{
-  YYFREE (yystackp->yyitems);
-  yyfreeStateSet (&yystackp->yytops);
-}
-
-/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
- *  splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
- *  YYS.  */
-static inline void
-yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
-{
-  if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys)
-    yystackp->yysplitPoint = yys;
-}
-
-/** Invalidate stack #YYK in *YYSTACKP.  */
-static inline void
-yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
-{
-  if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
-    yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
-  yystackp->yytops.yystates[yyk] = YY_NULLPTR;
-}
-
-/** Undelete the last stack in *YYSTACKP that was marked as deleted.  Can
-    only be done once after a deletion, and only when all other stacks have
-    been deleted.  */
-static void
-yyundeleteLastStack (yyGLRStack* yystackp)
-{
-  if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0)
-    return;
-  yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
-  yystackp->yytops.yysize = 1;
-  YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
-  yystackp->yylastDeleted = YY_NULLPTR;
-}
-
-static inline void
-yyremoveDeletes (yyGLRStack* yystackp)
-{
-  size_t yyi, yyj;
-  yyi = yyj = 0;
-  while (yyj < yystackp->yytops.yysize)
-    {
-      if (yystackp->yytops.yystates[yyi] == YY_NULLPTR)
-        {
-          if (yyi == yyj)
-            {
-              YYDPRINTF ((stderr, "Removing dead stacks.\n"));
-            }
-          yystackp->yytops.yysize -= 1;
-        }
-      else
-        {
-          yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
-          /* In the current implementation, it's unnecessary to copy
-             yystackp->yytops.yylookaheadNeeds[yyi] since, after
-             yyremoveDeletes returns, the parser immediately either enters
-             deterministic operation or shifts a token.  However, it doesn't
-             hurt, and the code might evolve to need it.  */
-          yystackp->yytops.yylookaheadNeeds[yyj] =
-            yystackp->yytops.yylookaheadNeeds[yyi];
-          if (yyj != yyi)
-            {
-              YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
-                          (unsigned long int) yyi, (unsigned long int) yyj));
-            }
-          yyj += 1;
-        }
-      yyi += 1;
-    }
-}
-
-/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
- * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
- * value *YYVALP and source location *YYLOCP.  */
-static inline void
-yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
-            size_t yyposn,
-            YYSTYPE* yyvalp, YYLTYPE* yylocp)
-{
-  yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
-
-  yynewState->yylrState = yylrState;
-  yynewState->yyposn = yyposn;
-  yynewState->yyresolved = yytrue;
-  yynewState->yypred = yystackp->yytops.yystates[yyk];
-  yynewState->yysemantics.yysval = *yyvalp;
-  yynewState->yyloc = *yylocp;
-  yystackp->yytops.yystates[yyk] = yynewState;
-
-  YY_RESERVE_GLRSTACK (yystackp);
-}
-
-/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
- *  state YYLRSTATE, at input position YYPOSN, with the (unresolved)
- *  semantic value of YYRHS under the action for YYRULE.  */
-static inline void
-yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
-                 size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
-{
-  yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
-  YYASSERT (yynewState->yyisState);
-
-  yynewState->yylrState = yylrState;
-  yynewState->yyposn = yyposn;
-  yynewState->yyresolved = yyfalse;
-  yynewState->yypred = yystackp->yytops.yystates[yyk];
-  yynewState->yysemantics.yyfirstVal = YY_NULLPTR;
-  yystackp->yytops.yystates[yyk] = yynewState;
-
-  /* Invokes YY_RESERVE_GLRSTACK.  */
-  yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
-}
-
-#if !YYDEBUG
-# define YY_REDUCE_PRINT(Args)
-#else
-# define YY_REDUCE_PRINT(Args)          \
-do {                                    \
-  if (yydebug)                          \
-    yy_reduce_print Args;               \
-} while (0)
-
-/*----------------------------------------------------------------------.
-| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
-`----------------------------------------------------------------------*/
-
-static inline void
-yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
-                 yyRuleNum yyrule, yy::parser& yyparser, tidl::Parser* ps)
-{
-  int yynrhs = yyrhsLength (yyrule);
-  int yylow = 1;
-  int yyi;
-  YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
-             (unsigned long int) yyk, yyrule - 1,
-             (unsigned long int) yyrline[yyrule]);
-  if (! yynormal)
-    yyfillin (yyvsp, 1, -yynrhs);
-  /* The symbols being reduced.  */
-  for (yyi = 0; yyi < yynrhs; yyi++)
-    {
-      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
-      yy_symbol_print (stderr,
-                       yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
-                       &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
-                       , &(((yyGLRStackItem const *)yyvsp)[YYFILL ((yyi + 1) - (yynrhs))].yystate.yyloc)                       , yyparser, ps);
-      if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
-        YYFPRINTF (stderr, " (unresolved)");
-      YYFPRINTF (stderr, "\n");
-    }
-}
-#endif
-
-/** Pop the symbols consumed by reduction #YYRULE from the top of stack
- *  #YYK of *YYSTACKP, and perform the appropriate semantic action on their
- *  semantic values.  Assumes that all ambiguities in semantic values
- *  have been previously resolved.  Set *YYVALP to the resulting value,
- *  and *YYLOCP to the computed location (if any).  Return value is as
- *  for userAction.  */
-static inline YYRESULTTAG
-yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
-            YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  int yynrhs = yyrhsLength (yyrule);
-
-  if (yystackp->yysplitPoint == YY_NULLPTR)
-    {
-      /* Standard special case: single stack.  */
-      yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
-      YYASSERT (yyk == 0);
-      yystackp->yynextFree -= yynrhs;
-      yystackp->yyspaceLeft += yynrhs;
-      yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
-      YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule, yyparser, ps));
-      return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
-                           yyvalp, yylocp, yyparser, ps);
-    }
-  else
-    {
-      int yyi;
-      yyGLRState* yys;
-      yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
-      yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
-        = yystackp->yytops.yystates[yyk];
-      if (yynrhs == 0)
-        /* Set default location.  */
-        yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;
-      for (yyi = 0; yyi < yynrhs; yyi += 1)
-        {
-          yys = yys->yypred;
-          YYASSERT (yys);
-        }
-      yyupdateSplit (yystackp, yys);
-      yystackp->yytops.yystates[yyk] = yys;
-      YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule, yyparser, ps));
-      return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
-                           yystackp, yyvalp, yylocp, yyparser, ps);
-    }
-}
-
-/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
- *  and push back on the resulting nonterminal symbol.  Perform the
- *  semantic action associated with YYRULE and store its value with the
- *  newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
- *  unambiguous.  Otherwise, store the deferred semantic action with
- *  the new state.  If the new state would have an identical input
- *  position, LR state, and predecessor to an existing state on the stack,
- *  it is identified with that existing state, eliminating stack #YYK from
- *  *YYSTACKP.  In this case, the semantic value is
- *  added to the options for the existing state's semantic value.
- */
-static inline YYRESULTTAG
-yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
-             yybool yyforceEval, yy::parser& yyparser, tidl::Parser* ps)
-{
-  size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
-
-  if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
-    {
-      YYSTYPE yysval;
-      YYLTYPE yyloc;
-
-      YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval, &yyloc, yyparser, ps);
-      if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
-        {
-          YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
-                     (unsigned long int) yyk, yyrule - 1));
-        }
-      if (yyflag != yyok)
-        return yyflag;
-      YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
-      yyglrShift (yystackp, yyk,
-                  yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
-                                 yylhsNonterm (yyrule)),
-                  yyposn, &yysval, &yyloc);
-    }
-  else
-    {
-      size_t yyi;
-      int yyn;
-      yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
-      yyStateNum yynewLRState;
-
-      for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
-           0 < yyn; yyn -= 1)
-        {
-          yys = yys->yypred;
-          YYASSERT (yys);
-        }
-      yyupdateSplit (yystackp, yys);
-      yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
-      YYDPRINTF ((stderr,
-                  "Reduced stack %lu by rule #%d; action deferred.  "
-                  "Now in state %d.\n",
-                  (unsigned long int) yyk, yyrule - 1, yynewLRState));
-      for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
-        if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
-          {
-            yyGLRState *yysplit = yystackp->yysplitPoint;
-            yyGLRState *yyp = yystackp->yytops.yystates[yyi];
-            while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
-              {
-                if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
-                  {
-                    yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
-                    yymarkStackDeleted (yystackp, yyk);
-                    YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
-                                (unsigned long int) yyk,
-                                (unsigned long int) yyi));
-                    return yyok;
-                  }
-                yyp = yyp->yypred;
-              }
-          }
-      yystackp->yytops.yystates[yyk] = yys;
-      yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
-    }
-  return yyok;
-}
-
-static size_t
-yysplitStack (yyGLRStack* yystackp, size_t yyk)
-{
-  if (yystackp->yysplitPoint == YY_NULLPTR)
-    {
-      YYASSERT (yyk == 0);
-      yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
-    }
-  if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
-    {
-      yyGLRState** yynewStates;
-      yybool* yynewLookaheadNeeds;
-
-      yynewStates = YY_NULLPTR;
-
-      if (yystackp->yytops.yycapacity
-          > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
-        yyMemoryExhausted (yystackp);
-      yystackp->yytops.yycapacity *= 2;
-
-      yynewStates =
-        (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
-                                  (yystackp->yytops.yycapacity
-                                   * sizeof yynewStates[0]));
-      if (yynewStates == YY_NULLPTR)
-        yyMemoryExhausted (yystackp);
-      yystackp->yytops.yystates = yynewStates;
-
-      yynewLookaheadNeeds =
-        (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
-                             (yystackp->yytops.yycapacity
-                              * sizeof yynewLookaheadNeeds[0]));
-      if (yynewLookaheadNeeds == YY_NULLPTR)
-        yyMemoryExhausted (yystackp);
-      yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
-    }
-  yystackp->yytops.yystates[yystackp->yytops.yysize]
-    = yystackp->yytops.yystates[yyk];
-  yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
-    = yystackp->yytops.yylookaheadNeeds[yyk];
-  yystackp->yytops.yysize += 1;
-  return yystackp->yytops.yysize-1;
-}
-
-/** True iff YYY0 and YYY1 represent identical options at the top level.
- *  That is, they represent the same rule applied to RHS symbols
- *  that produce the same terminal symbols.  */
-static yybool
-yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
-{
-  if (yyy0->yyrule == yyy1->yyrule)
-    {
-      yyGLRState *yys0, *yys1;
-      int yyn;
-      for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
-           yyn = yyrhsLength (yyy0->yyrule);
-           yyn > 0;
-           yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
-        if (yys0->yyposn != yys1->yyposn)
-          return yyfalse;
-      return yytrue;
-    }
-  else
-    return yyfalse;
-}
-
-/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
- *  alternative semantic values for the RHS-symbols of YYY1 and YYY0.  */
-static void
-yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
-{
-  yyGLRState *yys0, *yys1;
-  int yyn;
-  for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
-       yyn = yyrhsLength (yyy0->yyrule);
-       yyn > 0;
-       yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
-    {
-      if (yys0 == yys1)
-        break;
-      else if (yys0->yyresolved)
-        {
-          yys1->yyresolved = yytrue;
-          yys1->yysemantics.yysval = yys0->yysemantics.yysval;
-        }
-      else if (yys1->yyresolved)
-        {
-          yys0->yyresolved = yytrue;
-          yys0->yysemantics.yysval = yys1->yysemantics.yysval;
-        }
-      else
-        {
-          yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
-          yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
-          while (yytrue)
-            {
-              if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR)
-                break;
-              else if (*yyz0p == YY_NULLPTR)
-                {
-                  *yyz0p = yyz1;
-                  break;
-                }
-              else if (*yyz0p < yyz1)
-                {
-                  yySemanticOption* yyz = *yyz0p;
-                  *yyz0p = yyz1;
-                  yyz1 = yyz1->yynext;
-                  (*yyz0p)->yynext = yyz;
-                }
-              yyz0p = &(*yyz0p)->yynext;
-            }
-          yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
-        }
-    }
-}
-
-/** Y0 and Y1 represent two possible actions to take in a given
- *  parsing state; return 0 if no combination is possible,
- *  1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred.  */
-static int
-yypreference (yySemanticOption* y0, yySemanticOption* y1)
-{
-  yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
-  int p0 = yydprec[r0], p1 = yydprec[r1];
-
-  if (p0 == p1)
-    {
-      if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
-        return 0;
-      else
-        return 1;
-    }
-  if (p0 == 0 || p1 == 0)
-    return 0;
-  if (p0 < p1)
-    return 3;
-  if (p1 < p0)
-    return 2;
-  return 0;
-}
-
-static YYRESULTTAG yyresolveValue (yyGLRState* yys,
-                                   yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps);
-
-
-/** Resolve the previous YYN states starting at and including state YYS
- *  on *YYSTACKP. If result != yyok, some states may have been left
- *  unresolved possibly with empty semantic option chains.  Regardless
- *  of whether result = yyok, each state has been left with consistent
- *  data so that yydestroyGLRState can be invoked if necessary.  */
-static YYRESULTTAG
-yyresolveStates (yyGLRState* yys, int yyn,
-                 yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  if (0 < yyn)
-    {
-      YYASSERT (yys->yypred);
-      YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp, yyparser, ps));
-      if (! yys->yyresolved)
-        YYCHK (yyresolveValue (yys, yystackp, yyparser, ps));
-    }
-  return yyok;
-}
-
-/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
- *  user action, and return the semantic value and location in *YYVALP
- *  and *YYLOCP.  Regardless of whether result = yyok, all RHS states
- *  have been destroyed (assuming the user action destroys all RHS
- *  semantic values if invoked).  */
-static YYRESULTTAG
-yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
-                 YYSTYPE* yyvalp, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
-  int yynrhs = yyrhsLength (yyopt->yyrule);
-  YYRESULTTAG yyflag =
-    yyresolveStates (yyopt->yystate, yynrhs, yystackp, yyparser, ps);
-  if (yyflag != yyok)
-    {
-      yyGLRState *yys;
-      for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
-        yydestroyGLRState ("Cleanup: popping", yys, yyparser, ps);
-      return yyflag;
-    }
-
-  yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
-  if (yynrhs == 0)
-    /* Set default location.  */
-    yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;
-  {
-    int yychar_current = yychar;
-    YYSTYPE yylval_current = yylval;
-    YYLTYPE yylloc_current = yylloc;
-    yychar = yyopt->yyrawchar;
-    yylval = yyopt->yyval;
-    yylloc = yyopt->yyloc;
-    yyflag = yyuserAction (yyopt->yyrule, yynrhs,
-                           yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
-                           yystackp, yyvalp, yylocp, yyparser, ps);
-    yychar = yychar_current;
-    yylval = yylval_current;
-    yylloc = yylloc_current;
-  }
-  return yyflag;
-}
-
-#if YYDEBUG
-static void
-yyreportTree (yySemanticOption* yyx, int yyindent)
-{
-  int yynrhs = yyrhsLength (yyx->yyrule);
-  int yyi;
-  yyGLRState* yys;
-  yyGLRState* yystates[1 + YYMAXRHS];
-  yyGLRState yyleftmost_state;
-
-  for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
-    yystates[yyi] = yys;
-  if (yys == YY_NULLPTR)
-    {
-      yyleftmost_state.yyposn = 0;
-      yystates[0] = &yyleftmost_state;
-    }
-  else
-    yystates[0] = yys;
-
-  if (yyx->yystate->yyposn < yys->yyposn + 1)
-    YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
-               yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
-               yyx->yyrule - 1);
-  else
-    YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
-               yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
-               yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
-               (unsigned long int) yyx->yystate->yyposn);
-  for (yyi = 1; yyi <= yynrhs; yyi += 1)
-    {
-      if (yystates[yyi]->yyresolved)
-        {
-          if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
-            YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
-                       yytokenName (yystos[yystates[yyi]->yylrState]));
-          else
-            YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
-                       yytokenName (yystos[yystates[yyi]->yylrState]),
-                       (unsigned long int) (yystates[yyi-1]->yyposn + 1),
-                       (unsigned long int) yystates[yyi]->yyposn);
-        }
-      else
-        yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
-    }
-}
-#endif
-
-static YYRESULTTAG
-yyreportAmbiguity (yySemanticOption* yyx0,
-                   yySemanticOption* yyx1, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  YYUSE (yyx0);
-  YYUSE (yyx1);
-
-#if YYDEBUG
-  YYFPRINTF (stderr, "Ambiguity detected.\n");
-  YYFPRINTF (stderr, "Option 1,\n");
-  yyreportTree (yyx0, 2);
-  YYFPRINTF (stderr, "\nOption 2,\n");
-  yyreportTree (yyx1, 2);
-  YYFPRINTF (stderr, "\n");
-#endif
-
-  yyerror (yylocp, yyparser, ps, YY_("syntax is ambiguous"));
-  return yyabort;
-}
-
-/** Resolve the locations for each of the YYN1 states in *YYSTACKP,
- *  ending at YYS1.  Has no effect on previously resolved states.
- *  The first semantic option of a state is always chosen.  */
-static void
-yyresolveLocations (yyGLRState* yys1, int yyn1,
-                    yyGLRStack *yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  if (0 < yyn1)
-    {
-      yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp, yyparser, ps);
-      if (!yys1->yyresolved)
-        {
-          yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
-          int yynrhs;
-          yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
-          YYASSERT (yyoption != YY_NULLPTR);
-          yynrhs = yyrhsLength (yyoption->yyrule);
-          if (yynrhs > 0)
-            {
-              yyGLRState *yys;
-              int yyn;
-              yyresolveLocations (yyoption->yystate, yynrhs,
-                                  yystackp, yyparser, ps);
-              for (yys = yyoption->yystate, yyn = yynrhs;
-                   yyn > 0;
-                   yys = yys->yypred, yyn -= 1)
-                yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
-            }
-          else
-            {
-              /* Both yyresolveAction and yyresolveLocations traverse the GSS
-                 in reverse rightmost order.  It is only necessary to invoke
-                 yyresolveLocations on a subforest for which yyresolveAction
-                 would have been invoked next had an ambiguity not been
-                 detected.  Thus the location of the previous state (but not
-                 necessarily the previous state itself) is guaranteed to be
-                 resolved already.  */
-              yyGLRState *yyprevious = yyoption->yystate;
-              yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
-            }
-          {
-            int yychar_current = yychar;
-            YYSTYPE yylval_current = yylval;
-            YYLTYPE yylloc_current = yylloc;
-            yychar = yyoption->yyrawchar;
-            yylval = yyoption->yyval;
-            yylloc = yyoption->yyloc;
-            YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
-            yychar = yychar_current;
-            yylval = yylval_current;
-            yylloc = yylloc_current;
-          }
-        }
-    }
-}
-
-/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
- *  perform the indicated actions, and set the semantic value of YYS.
- *  If result != yyok, the chain of semantic options in YYS has been
- *  cleared instead or it has been left unmodified except that
- *  redundant options may have been removed.  Regardless of whether
- *  result = yyok, YYS has been left with consistent data so that
- *  yydestroyGLRState can be invoked if necessary.  */
-static YYRESULTTAG
-yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
-  yySemanticOption* yybest = yyoptionList;
-  yySemanticOption** yypp;
-  yybool yymerge = yyfalse;
-  YYSTYPE yysval;
-  YYRESULTTAG yyflag;
-  YYLTYPE *yylocp = &yys->yyloc;
-
-  for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; )
-    {
-      yySemanticOption* yyp = *yypp;
-
-      if (yyidenticalOptions (yybest, yyp))
-        {
-          yymergeOptionSets (yybest, yyp);
-          *yypp = yyp->yynext;
-        }
-      else
-        {
-          switch (yypreference (yybest, yyp))
-            {
-            case 0:
-              yyresolveLocations (yys, 1, yystackp, yyparser, ps);
-              return yyreportAmbiguity (yybest, yyp, yylocp, yyparser, ps);
-              break;
-            case 1:
-              yymerge = yytrue;
-              break;
-            case 2:
-              break;
-            case 3:
-              yybest = yyp;
-              yymerge = yyfalse;
-              break;
-            default:
-              /* This cannot happen so it is not worth a YYASSERT (yyfalse),
-                 but some compilers complain if the default case is
-                 omitted.  */
-              break;
-            }
-          yypp = &yyp->yynext;
-        }
-    }
-
-  if (yymerge)
-    {
-      yySemanticOption* yyp;
-      int yyprec = yydprec[yybest->yyrule];
-      yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp, yyparser, ps);
-      if (yyflag == yyok)
-        for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext)
-          {
-            if (yyprec == yydprec[yyp->yyrule])
-              {
-                YYSTYPE yysval_other;
-                YYLTYPE yydummy;
-                yyflag = yyresolveAction (yyp, yystackp, &yysval_other, &yydummy, yyparser, ps);
-                if (yyflag != yyok)
-                  {
-                    yydestruct ("Cleanup: discarding incompletely merged value for",
-                                yystos[yys->yylrState],
-                                &yysval, yylocp, yyparser, ps);
-                    break;
-                  }
-                yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
-              }
-          }
-    }
-  else
-    yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp, yyparser, ps);
-
-  if (yyflag == yyok)
-    {
-      yys->yyresolved = yytrue;
-      yys->yysemantics.yysval = yysval;
-    }
-  else
-    yys->yysemantics.yyfirstVal = YY_NULLPTR;
-  return yyflag;
-}
-
-static YYRESULTTAG
-yyresolveStack (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  if (yystackp->yysplitPoint != YY_NULLPTR)
-    {
-      yyGLRState* yys;
-      int yyn;
-
-      for (yyn = 0, yys = yystackp->yytops.yystates[0];
-           yys != yystackp->yysplitPoint;
-           yys = yys->yypred, yyn += 1)
-        continue;
-      YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
-                             , yyparser, ps));
-    }
-  return yyok;
-}
-
-static void
-yycompressStack (yyGLRStack* yystackp)
-{
-  yyGLRState* yyp, *yyq, *yyr;
-
-  if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR)
-    return;
-
-  for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR;
-       yyp != yystackp->yysplitPoint;
-       yyr = yyp, yyp = yyq, yyq = yyp->yypred)
-    yyp->yypred = yyr;
-
-  yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
-  yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
-  yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
-  yystackp->yysplitPoint = YY_NULLPTR;
-  yystackp->yylastDeleted = YY_NULLPTR;
-
-  while (yyr != YY_NULLPTR)
-    {
-      yystackp->yynextFree->yystate = *yyr;
-      yyr = yyr->yypred;
-      yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
-      yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
-      yystackp->yynextFree += 1;
-      yystackp->yyspaceLeft -= 1;
-    }
-}
-
-static YYRESULTTAG
-yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
-                   size_t yyposn, YYLTYPE *yylocp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
-    {
-      yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
-      YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
-                  (unsigned long int) yyk, yystate));
-
-      YYASSERT (yystate != YYFINAL);
-
-      if (yyisDefaultedState (yystate))
-        {
-          YYRESULTTAG yyflag;
-          yyRuleNum yyrule = yydefaultAction (yystate);
-          if (yyrule == 0)
-            {
-              YYDPRINTF ((stderr, "Stack %lu dies.\n",
-                          (unsigned long int) yyk));
-              yymarkStackDeleted (yystackp, yyk);
-              return yyok;
-            }
-          yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule], yyparser, ps);
-          if (yyflag == yyerr)
-            {
-              YYDPRINTF ((stderr,
-                          "Stack %lu dies "
-                          "(predicate failure or explicit user error).\n",
-                          (unsigned long int) yyk));
-              yymarkStackDeleted (yystackp, yyk);
-              return yyok;
-            }
-          if (yyflag != yyok)
-            return yyflag;
-        }
-      else
-        {
-          yySymbol yytoken;
-          int yyaction;
-          const short int* yyconflicts;
-
-          yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
-          if (yychar == YYEMPTY)
-            {
-              YYDPRINTF ((stderr, "Reading a token: "));
-              yychar = yylex (&yylval, &yylloc, lex_scanner);
-            }
-
-          if (yychar <= YYEOF)
-            {
-              yychar = yytoken = YYEOF;
-              YYDPRINTF ((stderr, "Now at end of input.\n"));
-            }
-          else
-            {
-              yytoken = YYTRANSLATE (yychar);
-              YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
-            }
-
-          yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
-
-          while (*yyconflicts != 0)
-            {
-              YYRESULTTAG yyflag;
-              size_t yynewStack = yysplitStack (yystackp, yyk);
-              YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
-                          (unsigned long int) yynewStack,
-                          (unsigned long int) yyk));
-              yyflag = yyglrReduce (yystackp, yynewStack,
-                                    *yyconflicts,
-                                    yyimmediate[*yyconflicts], yyparser, ps);
-              if (yyflag == yyok)
-                YYCHK (yyprocessOneStack (yystackp, yynewStack,
-                                          yyposn, yylocp, yyparser, ps));
-              else if (yyflag == yyerr)
-                {
-                  YYDPRINTF ((stderr, "Stack %lu dies.\n",
-                              (unsigned long int) yynewStack));
-                  yymarkStackDeleted (yystackp, yynewStack);
-                }
-              else
-                return yyflag;
-              yyconflicts += 1;
-            }
-
-          if (yyisShiftAction (yyaction))
-            break;
-          else if (yyisErrorAction (yyaction))
-            {
-              YYDPRINTF ((stderr, "Stack %lu dies.\n",
-                          (unsigned long int) yyk));
-              yymarkStackDeleted (yystackp, yyk);
-              break;
-            }
-          else
-            {
-              YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
-                                                yyimmediate[-yyaction], yyparser, ps);
-              if (yyflag == yyerr)
-                {
-                  YYDPRINTF ((stderr,
-                              "Stack %lu dies "
-                              "(predicate failure or explicit user error).\n",
-                              (unsigned long int) yyk));
-                  yymarkStackDeleted (yystackp, yyk);
-                  break;
-                }
-              else if (yyflag != yyok)
-                return yyflag;
-            }
-        }
-    }
-  return yyok;
-}
-
-static void
-yyreportSyntaxError (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  if (yystackp->yyerrState != 0)
-    return;
-#if ! YYERROR_VERBOSE
-  yyerror (&yylloc, yyparser, ps, YY_("syntax error"));
-#else
-  {
-  yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
-  size_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
-  size_t yysize = yysize0;
-  yybool yysize_overflow = yyfalse;
-  char* yymsg = YY_NULLPTR;
-  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
-  /* Internationalized format string. */
-  const char *yyformat = YY_NULLPTR;
-  /* Arguments of yyformat. */
-  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-  /* Number of reported tokens (one for the "unexpected", one per
-     "expected").  */
-  int yycount = 0;
-
-  /* There are many possibilities here to consider:
-     - If this state is a consistent state with a default action, then
-       the only way this function was invoked is if the default action
-       is an error action.  In that case, don't check for expected
-       tokens because there are none.
-     - The only way there can be no lookahead present (in yychar) is if
-       this state is a consistent state with a default action.  Thus,
-       detecting the absence of a lookahead is sufficient to determine
-       that there is no unexpected or expected token to report.  In that
-       case, just report a simple "syntax error".
-     - Don't assume there isn't a lookahead just because this state is a
-       consistent state with a default action.  There might have been a
-       previous inconsistent state, consistent state with a non-default
-       action, or user semantic action that manipulated yychar.
-     - Of course, the expected token list depends on states to have
-       correct lookahead information, and it depends on the parser not
-       to perform extra reductions after fetching a lookahead from the
-       scanner and before detecting a syntax error.  Thus, state merging
-       (from LALR or IELR) and default reductions corrupt the expected
-       token list.  However, the list is correct for canonical LR with
-       one exception: it will still contain any token that will not be
-       accepted due to an error action in a later state.
-  */
-  if (yytoken != YYEMPTY)
-    {
-      int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
-      yyarg[yycount++] = yytokenName (yytoken);
-      if (!yypact_value_is_default (yyn))
-        {
-          /* Start YYX at -YYN if negative to avoid negative indexes in
-             YYCHECK.  In other words, skip the first -YYN actions for this
-             state because they are default actions.  */
-          int yyxbegin = yyn < 0 ? -yyn : 0;
-          /* Stay within bounds of both yycheck and yytname.  */
-          int yychecklim = YYLAST - yyn + 1;
-          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
-          int yyx;
-          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
-                && !yytable_value_is_error (yytable[yyx + yyn]))
-              {
-                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
-                  {
-                    yycount = 1;
-                    yysize = yysize0;
-                    break;
-                  }
-                yyarg[yycount++] = yytokenName (yyx);
-                {
-                  size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
-                  yysize_overflow |= yysz < yysize;
-                  yysize = yysz;
-                }
-              }
-        }
-    }
-
-  switch (yycount)
-    {
-#define YYCASE_(N, S)                   \
-      case N:                           \
-        yyformat = S;                   \
-      break
-      YYCASE_(0, YY_("syntax error"));
-      YYCASE_(1, YY_("syntax error, unexpected %s"));
-      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
-      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
-      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
-      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
-#undef YYCASE_
-    }
-
-  {
-    size_t yysz = yysize + strlen (yyformat);
-    yysize_overflow |= yysz < yysize;
-    yysize = yysz;
-  }
-
-  if (!yysize_overflow)
-    yymsg = (char *) YYMALLOC (yysize);
-
-  if (yymsg)
-    {
-      char *yyp = yymsg;
-      int yyi = 0;
-      while ((*yyp = *yyformat))
-        {
-          if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
-            {
-              yyp += yytnamerr (yyp, yyarg[yyi++]);
-              yyformat += 2;
-            }
-          else
-            {
-              yyp++;
-              yyformat++;
-            }
-        }
-      yyerror (&yylloc, yyparser, ps, yymsg);
-      YYFREE (yymsg);
-    }
-  else
-    {
-      yyerror (&yylloc, yyparser, ps, YY_("syntax error"));
-      yyMemoryExhausted (yystackp);
-    }
-  }
-#endif /* YYERROR_VERBOSE */
-  yynerrs += 1;
-}
-
-/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
-   yylval, and yylloc are the syntactic category, semantic value, and location
-   of the lookahead.  */
-static void
-yyrecoverSyntaxError (yyGLRStack* yystackp, yy::parser& yyparser, tidl::Parser* ps)
-{
-  size_t yyk;
-  int yyj;
-
-  if (yystackp->yyerrState == 3)
-    /* We just shifted the error token and (perhaps) took some
-       reductions.  Skip tokens until we can proceed.  */
-    while (yytrue)
-      {
-        yySymbol yytoken;
-        if (yychar == YYEOF)
-          yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
-        if (yychar != YYEMPTY)
-          {
-            /* We throw away the lookahead, but the error range
-               of the shifted error token must take it into account.  */
-            yyGLRState *yys = yystackp->yytops.yystates[0];
-            yyGLRStackItem yyerror_range[3];
-            yyerror_range[1].yystate.yyloc = yys->yyloc;
-            yyerror_range[2].yystate.yyloc = yylloc;
-            YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);
-            yytoken = YYTRANSLATE (yychar);
-            yydestruct ("Error: discarding",
-                        yytoken, &yylval, &yylloc, yyparser, ps);
-          }
-        YYDPRINTF ((stderr, "Reading a token: "));
-        yychar = yylex (&yylval, &yylloc, lex_scanner);
-        if (yychar <= YYEOF)
-          {
-            yychar = yytoken = YYEOF;
-            YYDPRINTF ((stderr, "Now at end of input.\n"));
-          }
-        else
-          {
-            yytoken = YYTRANSLATE (yychar);
-            YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
-          }
-        yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
-        if (yypact_value_is_default (yyj))
-          return;
-        yyj += yytoken;
-        if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
-          {
-            if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
-              return;
-          }
-        else if (! yytable_value_is_error (yytable[yyj]))
-          return;
-      }
-
-  /* Reduce to one stack.  */
-  for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
-    if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
-      break;
-  if (yyk >= yystackp->yytops.yysize)
-    yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
-  for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
-    yymarkStackDeleted (yystackp, yyk);
-  yyremoveDeletes (yystackp);
-  yycompressStack (yystackp);
-
-  /* Now pop stack until we find a state that shifts the error token.  */
-  yystackp->yyerrState = 3;
-  while (yystackp->yytops.yystates[0] != YY_NULLPTR)
-    {
-      yyGLRState *yys = yystackp->yytops.yystates[0];
-      yyj = yypact[yys->yylrState];
-      if (! yypact_value_is_default (yyj))
-        {
-          yyj += YYTERROR;
-          if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
-              && yyisShiftAction (yytable[yyj]))
-            {
-              /* Shift the error token.  */
-              /* First adjust its location.*/
-              YYLTYPE yyerrloc;
-              yystackp->yyerror_range[2].yystate.yyloc = yylloc;
-              YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);
-              YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
-                               &yylval, &yyerrloc);
-              yyglrShift (yystackp, 0, yytable[yyj],
-                          yys->yyposn, &yylval, &yyerrloc);
-              yys = yystackp->yytops.yystates[0];
-              break;
-            }
-        }
-      yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;
-      if (yys->yypred != YY_NULLPTR)
-        yydestroyGLRState ("Error: popping", yys, yyparser, ps);
-      yystackp->yytops.yystates[0] = yys->yypred;
-      yystackp->yynextFree -= 1;
-      yystackp->yyspaceLeft += 1;
-    }
-  if (yystackp->yytops.yystates[0] == YY_NULLPTR)
-    yyFail (yystackp, &yylloc, yyparser, ps, YY_NULLPTR);
-}
-
-#define YYCHK1(YYE)                                                          \
-  do {                                                                       \
-    switch (YYE) {                                                           \
-    case yyok:                                                               \
-      break;                                                                 \
-    case yyabort:                                                            \
-      goto yyabortlab;                                                       \
-    case yyaccept:                                                           \
-      goto yyacceptlab;                                                      \
-    case yyerr:                                                              \
-      goto yyuser_error;                                                     \
-    default:                                                                 \
-      goto yybuglab;                                                         \
-    }                                                                        \
-  } while (0)
-
-/*----------.
-| yyparse.  |
-`----------*/
-
-int
-yyparse (yy::parser& yyparser, tidl::Parser* ps)
-{
-  int yyresult;
-  yyGLRStack yystack;
-  yyGLRStack* const yystackp = &yystack;
-  size_t yyposn;
-
-  YYDPRINTF ((stderr, "Starting parse\n"));
-
-  yychar = YYEMPTY;
-  yylval = yyval_default;
-  yylloc = yyloc_default;
-
-  /* User initialization code.  */
-  yylloc.initialize ();
-#line 3223 "./idlc/tidlc_y.cpp" // glr.c:2237
-
-  if (! yyinitGLRStack (yystackp, YYINITDEPTH))
-    goto yyexhaustedlab;
-  switch (YYSETJMP (yystack.yyexception_buffer))
-    {
-    case 0: break;
-    case 1: goto yyabortlab;
-    case 2: goto yyexhaustedlab;
-    default: goto yybuglab;
-    }
-  yyglrShift (&yystack, 0, 0, 0, &yylval, &yylloc);
-  yyposn = 0;
-
-  while (yytrue)
-    {
-      /* For efficiency, we have two loops, the first of which is
-         specialized to deterministic operation (single stack, no
-         potential ambiguity).  */
-      /* Standard mode */
-      while (yytrue)
-        {
-          yyRuleNum yyrule;
-          int yyaction;
-          const short int* yyconflicts;
-
-          yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
-          YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-          if (yystate == YYFINAL)
-            goto yyacceptlab;
-          if (yyisDefaultedState (yystate))
-            {
-              yyrule = yydefaultAction (yystate);
-              if (yyrule == 0)
-                {
-               yystack.yyerror_range[1].yystate.yyloc = yylloc;
-                  yyreportSyntaxError (&yystack, yyparser, ps);
-                  goto yyuser_error;
-                }
-              YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue, yyparser, ps));
-            }
-          else
-            {
-              yySymbol yytoken;
-              if (yychar == YYEMPTY)
-                {
-                  YYDPRINTF ((stderr, "Reading a token: "));
-                  yychar = yylex (&yylval, &yylloc, lex_scanner);
-                }
-
-              if (yychar <= YYEOF)
-                {
-                  yychar = yytoken = YYEOF;
-                  YYDPRINTF ((stderr, "Now at end of input.\n"));
-                }
-              else
-                {
-                  yytoken = YYTRANSLATE (yychar);
-                  YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
-                }
-
-              yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
-              if (*yyconflicts != 0)
-                break;
-              if (yyisShiftAction (yyaction))
-                {
-                  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-                  yychar = YYEMPTY;
-                  yyposn += 1;
-                  yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
-                  if (0 < yystack.yyerrState)
-                    yystack.yyerrState -= 1;
-                }
-              else if (yyisErrorAction (yyaction))
-                {
-               yystack.yyerror_range[1].yystate.yyloc = yylloc;
-                  yyreportSyntaxError (&yystack, yyparser, ps);
-                  goto yyuser_error;
-                }
-              else
-                YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue, yyparser, ps));
-            }
-        }
-
-      while (yytrue)
-        {
-          yySymbol yytoken_to_shift;
-          size_t yys;
-
-          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
-            yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
-
-          /* yyprocessOneStack returns one of three things:
-
-              - An error flag.  If the caller is yyprocessOneStack, it
-                immediately returns as well.  When the caller is finally
-                yyparse, it jumps to an error label via YYCHK1.
-
-              - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
-                (&yystack, yys), which sets the top state of yys to NULL.  Thus,
-                yyparse's following invocation of yyremoveDeletes will remove
-                the stack.
-
-              - yyok, when ready to shift a token.
-
-             Except in the first case, yyparse will invoke yyremoveDeletes and
-             then shift the next token onto all remaining stacks.  This
-             synchronization of the shift (that is, after all preceding
-             reductions on all stacks) helps prevent double destructor calls
-             on yylval in the event of memory exhaustion.  */
-
-          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
-            YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, &yylloc, yyparser, ps));
-          yyremoveDeletes (&yystack);
-          if (yystack.yytops.yysize == 0)
-            {
-              yyundeleteLastStack (&yystack);
-              if (yystack.yytops.yysize == 0)
-                yyFail (&yystack, &yylloc, yyparser, ps, YY_("syntax error"));
-              YYCHK1 (yyresolveStack (&yystack, yyparser, ps));
-              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-           yystack.yyerror_range[1].yystate.yyloc = yylloc;
-              yyreportSyntaxError (&yystack, yyparser, ps);
-              goto yyuser_error;
-            }
-
-          /* If any yyglrShift call fails, it will fail after shifting.  Thus,
-             a copy of yylval will already be on stack 0 in the event of a
-             failure in the following loop.  Thus, yychar is set to YYEMPTY
-             before the loop to make sure the user destructor for yylval isn't
-             called twice.  */
-          yytoken_to_shift = YYTRANSLATE (yychar);
-          yychar = YYEMPTY;
-          yyposn += 1;
-          for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
-            {
-              int yyaction;
-              const short int* yyconflicts;
-              yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
-              yygetLRActions (yystate, yytoken_to_shift, &yyaction,
-                              &yyconflicts);
-              /* Note that yyconflicts were handled by yyprocessOneStack.  */
-              YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
-              YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
-              yyglrShift (&yystack, yys, yyaction, yyposn,
-                          &yylval, &yylloc);
-              YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
-                          (unsigned long int) yys,
-                          yystack.yytops.yystates[yys]->yylrState));
-            }
-
-          if (yystack.yytops.yysize == 1)
-            {
-              YYCHK1 (yyresolveStack (&yystack, yyparser, ps));
-              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-              yycompressStack (&yystack);
-              break;
-            }
-        }
-      continue;
-    yyuser_error:
-      yyrecoverSyntaxError (&yystack, yyparser, ps);
-      yyposn = yystack.yytops.yystates[0]->yyposn;
-    }
-
- yyacceptlab:
-  yyresult = 0;
-  goto yyreturn;
-
- yybuglab:
-  YYASSERT (yyfalse);
-  goto yyabortlab;
-
- yyabortlab:
-  yyresult = 1;
-  goto yyreturn;
-
- yyexhaustedlab:
-  yyerror (&yylloc, yyparser, ps, YY_("memory exhausted"));
-  yyresult = 2;
-  goto yyreturn;
-
- yyreturn:
-  if (yychar != YYEMPTY)
-    yydestruct ("Cleanup: discarding lookahead",
-                YYTRANSLATE (yychar), &yylval, &yylloc, yyparser, ps);
-
-  /* If the stack is well-formed, pop the stack until it is empty,
-     destroying its entries as we go.  But free the stack regardless
-     of whether it is well-formed.  */
-  if (yystack.yyitems)
-    {
-      yyGLRState** yystates = yystack.yytops.yystates;
-      if (yystates)
-        {
-          size_t yysize = yystack.yytops.yysize;
-          size_t yyk;
-          for (yyk = 0; yyk < yysize; yyk += 1)
-            if (yystates[yyk])
-              {
-                while (yystates[yyk])
-                  {
-                    yyGLRState *yys = yystates[yyk];
-                 yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;
-                  if (yys->yypred != YY_NULLPTR)
-                      yydestroyGLRState ("Cleanup: popping", yys, yyparser, ps);
-                    yystates[yyk] = yys->yypred;
-                    yystack.yynextFree -= 1;
-                    yystack.yyspaceLeft += 1;
-                  }
-                break;
-              }
-        }
-      yyfreeGLRStack (&yystack);
-    }
-
-  return yyresult;
-}
-
-/* DEBUGGING ONLY */
-#if YYDEBUG
-static void
-yy_yypstack (yyGLRState* yys)
-{
-  if (yys->yypred)
-    {
-      yy_yypstack (yys->yypred);
-      YYFPRINTF (stderr, " -> ");
-    }
-  YYFPRINTF (stderr, "%d@%lu", yys->yylrState,
-             (unsigned long int) yys->yyposn);
-}
-
-static void
-yypstates (yyGLRState* yyst)
-{
-  if (yyst == YY_NULLPTR)
-    YYFPRINTF (stderr, "<null>");
-  else
-    yy_yypstack (yyst);
-  YYFPRINTF (stderr, "\n");
-}
-
-static void
-yypstack (yyGLRStack* yystackp, size_t yyk)
-{
-  yypstates (yystackp->yytops.yystates[yyk]);
-}
-
-#define YYINDEX(YYX)                                                         \
-    ((YYX) == YY_NULLPTR ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
-
-
-static void
-yypdumpstack (yyGLRStack* yystackp)
-{
-  yyGLRStackItem* yyp;
-  size_t yyi;
-  for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
-    {
-      YYFPRINTF (stderr, "%3lu. ",
-                 (unsigned long int) (yyp - yystackp->yyitems));
-      if (*(yybool *) yyp)
-        {
-          YYASSERT (yyp->yystate.yyisState);
-          YYASSERT (yyp->yyoption.yyisState);
-          YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
-                     yyp->yystate.yyresolved, yyp->yystate.yylrState,
-                     (unsigned long int) yyp->yystate.yyposn,
-                     (long int) YYINDEX (yyp->yystate.yypred));
-          if (! yyp->yystate.yyresolved)
-            YYFPRINTF (stderr, ", firstVal: %ld",
-                       (long int) YYINDEX (yyp->yystate
-                                             .yysemantics.yyfirstVal));
-        }
-      else
-        {
-          YYASSERT (!yyp->yystate.yyisState);
-          YYASSERT (!yyp->yyoption.yyisState);
-          YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
-                     yyp->yyoption.yyrule - 1,
-                     (long int) YYINDEX (yyp->yyoption.yystate),
-                     (long int) YYINDEX (yyp->yyoption.yynext));
-        }
-      YYFPRINTF (stderr, "\n");
-    }
-  YYFPRINTF (stderr, "Tops:");
-  for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
-    YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
-               (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
-  YYFPRINTF (stderr, "\n");
-}
-#endif
-
-#undef yylval
-#undef yychar
-#undef yynerrs
-#undef yylloc
-
-
-
-#line 451 "./idlc/tidlc.yy" // glr.c:2551
-
-
-#include <ctype.h>
-#include <stdio.h>
-
-void yy::parser::error(const yy::parser::location_type& l,
-                       const std::string& errstr) {
-  ps->ReportError(errstr, l.begin.line);
-}
-
-
-#line 3536 "./idlc/tidlc_y.cpp" // glr.c:2551
-
-/*------------------.
-| Report an error.  |
-`------------------*/
-
-static void
-yyerror (const yy::parser::location_type *yylocationp, yy::parser& yyparser, tidl::Parser* ps, const char* msg)
-{
-  YYUSE (yyparser);
-  YYUSE (ps);
-  yyparser.error (*yylocationp, msg);
-}
-
-
-
-namespace yy {
-#line 3553 "./idlc/tidlc_y.cpp" // glr.c:2551
-  /// Build a parser object.
-  parser::parser (tidl::Parser* ps_yyarg)
-    :
-#if YYDEBUG
-      yycdebug_ (&std::cerr),
-#endif
-      ps (ps_yyarg)
-  {
-  }
-
-  parser::~parser ()
-  {
-  }
-
-  int
-  parser::parse ()
-  {
-    return ::yyparse (*this, ps);
-  }
-
-#if YYDEBUG
-  /*--------------------.
-  | Print this symbol.  |
-  `--------------------*/
-
-  inline void
-  parser::yy_symbol_value_print_ (int yytype,
-                           const semantic_type* yyvaluep,
-                           const location_type* yylocationp)
-  {
-    YYUSE (yylocationp);
-    YYUSE (yyvaluep);
-    std::ostream& yyoutput = debug_stream ();
-    std::ostream& yyo = yyoutput;
-    YYUSE (yyo);
-    YYUSE (yytype);
-  }
-
-
-  void
-  parser::yy_symbol_print_ (int yytype,
-                           const semantic_type* yyvaluep,
-                           const location_type* yylocationp)
-  {
-    *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
-               << ' ' << yytname[yytype] << " ("
-               << *yylocationp << ": ";
-    yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
-    *yycdebug_ << ')';
-  }
-
-  std::ostream&
-  parser::debug_stream () const
-  {
-    return *yycdebug_;
-  }
-
-  void
-  parser::set_debug_stream (std::ostream& o)
-  {
-    yycdebug_ = &o;
-  }
-
-
-  parser::debug_level_type
-  parser::debug_level () const
-  {
-    return yydebug;
-  }
-
-  void
-  parser::set_debug_level (debug_level_type l)
-  {
-    // Actually, it is yydebug which is really used.
-    yydebug = l;
-  }
-
-#endif
-
-} // yy
-#line 3634 "./idlc/tidlc_y.cpp" // glr.c:2551
diff --git a/idlc/tidlc_y.hpp b/idlc/tidlc_y.hpp
deleted file mode 100644 (file)
index 6dc7a6f..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-// A Bison parser, made by GNU Bison 3.0.2.
-
-// Skeleton interface for Bison GLR parsers in C++
-
-// Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-// As a special exception, you may create a larger work that contains
-// part or all of the Bison parser skeleton and distribute that work
-// under terms of your choice, so long as that work isn't itself a
-// parser generator using the skeleton or a modified version thereof
-// as a parser skeleton.  Alternatively, if you modify or redistribute
-// the parser skeleton itself, you may (at your option) remove this
-// special exception, which will cause the skeleton and the resulting
-// Bison output files to be licensed under the GNU General Public
-// License without this special exception.
-
-// This special exception was added by the Free Software Foundation in
-// version 2.2 of Bison.
-
-// C++ GLR parser skeleton written by Akim Demaille.
-
-#ifndef YY_YY_IDLC_TIDLC_Y_HPP_INCLUDED
-# define YY_YY_IDLC_TIDLC_Y_HPP_INCLUDED
-
-
-#include <stdexcept>
-#include <string>
-#include <iostream>
-#include "location.hh"
-
-/* Debug traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
-
-namespace yy {
-#line 52 "./idlc/tidlc_y.hpp" // glr.cc:329
-
-
-  /// A Bison parser.
-  class parser
-  {
-  public:
-#ifndef YYSTYPE
-    /// Symbol semantic values.
-    union semantic_type
-    {
-    #line 37 "./idlc/tidlc.yy" // glr.cc:329
-
-  tidl::Document* doc;
-  tidl::Interface* interf;
-  tidl::Declaration* decl;
-  tidl::Declarations* decls;
-  tidl::BaseType* b_type;
-  tidl::ParameterType* p_type;
-  tidl::Token* direction;
-  tidl::Parameter* param;
-  tidl::Parameters* params;
-  tidl::Token* token;
-  tidl::Structure* structure;
-  tidl::Element* elm;
-  tidl::Elements* elms;
-  tidl::Block* blk;
-  tidl::Attribute* attr;
-  tidl::Attributes* attrs;
-
-#line 82 "./idlc/tidlc_y.hpp" // glr.cc:329
-    };
-#else
-    typedef YYSTYPE semantic_type;
-#endif
-    /// Symbol locations.
-    typedef location location_type;
-
-    /// Syntax errors thrown from user actions.
-    struct syntax_error : std::runtime_error
-    {
-      syntax_error (const location_type& l, const std::string& m);
-      location_type location;
-    };
-
-    /// Tokens.
-    struct token
-    {
-      enum yytokentype
-      {
-        T_LEFT = 258,
-        T_RIGHT = 259,
-        T_COMMA = 260,
-        T_SEMICOLON = 261,
-        T_BRACE_OPEN = 262,
-        T_BRACE_CLOSE = 263,
-        T_IN = 264,
-        T_OUT = 265,
-        T_REF = 266,
-        T_ASYNC = 267,
-        T_META_OPEN = 268,
-        T_META_CLOSE = 269,
-        T_EQUAL = 270,
-        T_DELEGATE = 271,
-        T_UNKNOWN = 272,
-        T_ID = 273,
-        T_STRUCTURE = 274,
-        T_INTERFACE = 275,
-        T_CHAR = 276,
-        T_SHORT = 277,
-        T_INT = 278,
-        T_LONG = 279,
-        T_FLOAT = 280,
-        T_DOUBLE = 281,
-        T_VOID = 282,
-        T_BUNDLE = 283,
-        T_STRING = 284,
-        T_BOOL = 285,
-        T_LIST = 286,
-        T_ARRAY = 287,
-        T_VALUE = 288,
-        T_SB_OPEN = 289,
-        T_SB_CLOSE = 290
-      };
-    };
-
-    /// (External) token type, as returned by yylex.
-    typedef token::yytokentype token_type;
-
-    /// Internal symbol number.
-    typedef int symbol_number_type;
-
-    /// Internal symbol number for tokens (subsumed by symbol_number_type).
-    typedef unsigned char token_number_type;
-
-    /// A complete symbol.
-    ///
-    /// Expects its Base type to provide access to the symbol type
-    /// via type_get().
-    ///
-    /// Provide access to semantic value and location.
-    template <typename Base>
-    struct basic_symbol : Base
-    {
-      /// Alias to Base.
-      typedef Base super_type;
-
-      /// Default constructor.
-      basic_symbol ();
-
-      /// Copy constructor.
-      basic_symbol (const basic_symbol& other);
-
-      /// Constructor for valueless symbols.
-      basic_symbol (typename Base::kind_type t,
-                    const location_type& l);
-
-      /// Constructor for symbols with semantic value.
-      basic_symbol (typename Base::kind_type t,
-                    const semantic_type& v,
-                    const location_type& l);
-
-      ~basic_symbol ();
-
-      /// Destructive move, \a s is emptied into this.
-      void move (basic_symbol& s);
-
-      /// The semantic value.
-      semantic_type value;
-
-      /// The location.
-      location_type location;
-
-    private:
-      /// Assignment operator.
-      basic_symbol& operator= (const basic_symbol& other);
-    };
-
-    /// Type access provider for token (enum) based symbols.
-    struct by_type
-    {
-      /// Default constructor.
-      by_type ();
-
-      /// Copy constructor.
-      by_type (const by_type& other);
-
-      /// The symbol type as needed by the constructor.
-      typedef token_type kind_type;
-
-      /// Constructor from (external) token numbers.
-      by_type (kind_type t);
-
-      /// Steal the symbol type from \a that.
-      void move (by_type& that);
-
-      /// The (internal) type number (corresponding to \a type).
-      /// -1 when this symbol is empty.
-      symbol_number_type type_get () const;
-
-      /// The token.
-      token_type token () const;
-
-      enum { empty = 0 };
-
-      /// The symbol type.
-      /// -1 when this symbol is empty.
-      token_number_type type;
-    };
-
-    /// "External" symbols: returned by the scanner.
-    typedef basic_symbol<by_type> symbol_type;
-
-
-
-    /// Build a parser object.
-    parser (tidl::Parser* ps_yyarg);
-    virtual ~parser ();
-
-    /// Parse.
-    /// \returns  0 iff parsing succeeded.
-    virtual int parse ();
-
-    /// The current debugging stream.
-    std::ostream& debug_stream () const;
-    /// Set the current debugging stream.
-    void set_debug_stream (std::ostream &);
-
-    /// Type for debugging levels.
-    typedef int debug_level_type;
-    /// The current debugging level.
-    debug_level_type debug_level () const;
-    /// Set the current debugging level.
-    void set_debug_level (debug_level_type l);
-
-  public:
-    /// Report a syntax error.
-    /// \param loc    where the syntax error is found.
-    /// \param msg    a description of the syntax error.
-    virtual void error (const location_type& loc, const std::string& msg);
-
-# if YYDEBUG
-  public:
-    /// \brief Report a symbol value on the debug stream.
-    /// \param yytype       The token type.
-    /// \param yyvaluep     Its semantic value.
-    /// \param yylocationp  Its location.
-    virtual void yy_symbol_value_print_ (int yytype,
-                                         const semantic_type* yyvaluep,
-                                         const location_type* yylocationp);
-    /// \brief Report a symbol on the debug stream.
-    /// \param yytype       The token type.
-    /// \param yyvaluep     Its semantic value.
-    /// \param yylocationp  Its location.
-    virtual void yy_symbol_print_ (int yytype,
-                                   const semantic_type* yyvaluep,
-                                   const location_type* yylocationp);
-  private:
-    // Debugging.
-    std::ostream* yycdebug_;
-#endif
-
-
-    // User arguments.
-    tidl::Parser* ps;
-  };
-
-
-
-#ifndef YYSTYPE
-# define YYSTYPE yy::parser::semantic_type
-#endif
-#ifndef YYLTYPE
-# define YYLTYPE yy::parser::location_type
-#endif
-
-
-} // yy
-#line 290 "./idlc/tidlc_y.hpp" // glr.cc:329
-
-
-#endif // !YY_YY_IDLC_TIDLC_Y_HPP_INCLUDED
diff --git a/idlc/type.cc b/idlc/type.cc
deleted file mode 100644 (file)
index e070533..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <iostream>
-#include <utility>
-
-#include "idlc/type.h"
-
-namespace tidl {
-
-Token::Token(std::string name, std::string comments)
-    : name_(std::move(name)), comments_(std::move(comments)) {
-}
-
-BaseType::BaseType(std::string name, std::string comments,
-                   bool user_defined)
-    : Token(std::move(name), std::move(comments)), user_defined_(user_defined) {
-}
-
-BaseType::BaseType(const BaseType& type)
-  : Token(type.ToString(), type.GetComments()),
-    user_defined_(type.IsUserDefinedType()) {
-  if (type.GetMetaType() != nullptr) {
-    SetMetaType(new BaseType(*type.GetMetaType()));
-  }
-}
-
-void BaseType::SetMetaType(BaseType* type) {
-  meta_type_.reset(type);
-}
-
-ParameterType::ParameterType(BaseType* type)
-    : type_(type),
-    dir_(Direction::IN) {
-}
-
-ParameterType::ParameterType(BaseType* type, const std::string& dir)
-    : type_(type) {
-  if (dir == "in")
-    dir_ = Direction::IN;
-  else if (dir == "out")
-    dir_ = Direction::OUT;
-  else if (dir == "ref")
-    dir_ = Direction::REF;
-  else
-    dir_ = Direction::IN;
-}
-
-}  // namespace tidl
diff --git a/idlc/type.h b/idlc/type.h
deleted file mode 100644 (file)
index e3cf288..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef IDLC_TYPE_H_
-#define IDLC_TYPE_H_
-
-#include <string>
-#include <memory>
-
-namespace tidl {
-
-class Token {
- public:
-  Token(std::string name, std::string comments);
-  virtual ~Token() = default;
-
-  virtual std::string ToString() const { return name_; }
-  virtual std::string GetComments() const { return comments_; }
-
- private:
-  std::string name_;
-  std::string comments_;
-};
-
-class BaseType : public Token {
- public:
-  explicit BaseType(std::string name, std::string comments,
-                    bool user_defined = false);
-  BaseType(const BaseType& type);
-
-  void SetMetaType(BaseType* type);
-  const BaseType* GetMetaType() const {
-    return meta_type_.get();
-  }
-
-  std::string GetFullName() const {
-    std::string str = ToString();
-
-    if (meta_type_.get() != nullptr) {
-      str += "<";
-      str += meta_type_->GetFullName();
-      str += ">";
-    }
-
-    return str;
-  }
-
-  bool IsUserDefinedType() const {
-    return user_defined_;
-  }
-
- private:
-  std::unique_ptr<BaseType> meta_type_;
-  bool user_defined_;
-};
-
-class ParameterType {
- public:
-  enum class Direction {
-    IN,
-    OUT,
-    REF
-  };
-
-  ParameterType(BaseType* type, const std::string& dir);
-  explicit ParameterType(BaseType* type);
-  Direction GetDirection() const { return dir_; }
-  const BaseType& GetBaseType() const { return *type_; }
-
- private:
-  std::unique_ptr<BaseType> type_;
-  Direction dir_;
-};
-
-}  // namespace tidl
-
-#endif  // IDLC_TYPE_H_
index a56a7d2a53bf3c459d2a80eb171b9c505ec8a031..96849aa04e5fa873ad19998412a0ea048543a9c5 100644 (file)
@@ -14,27 +14,27 @@ INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
 LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS})
 
 SET(TIDLC_SOURCES
-       ${CMAKE_SOURCE_DIR}/idlc/document.cc
-       ${CMAKE_SOURCE_DIR}/idlc/declaration.cc
-       ${CMAKE_SOURCE_DIR}/idlc/interface.cc
-       ${CMAKE_SOURCE_DIR}/idlc/type.cc
-       ${CMAKE_SOURCE_DIR}/idlc/parameter.cc
-       ${CMAKE_SOURCE_DIR}/idlc/element.cc
-       ${CMAKE_SOURCE_DIR}/idlc/structure.cc
-       ${CMAKE_SOURCE_DIR}/idlc/block.cc
-       ${CMAKE_SOURCE_DIR}/idlc/generator.cc
-       ${CMAKE_SOURCE_DIR}/idlc/parser.cc
-       ${CMAKE_SOURCE_DIR}/idlc/attribute.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/document.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/declaration.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/interface.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/type.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/parameter.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/element.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/structure.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/block.cc
+       ${CMAKE_SOURCE_DIR}/idlc/gen/generator.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/parser.cc
+       ${CMAKE_SOURCE_DIR}/idlc/ast/attribute.cc
        )
 
 ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
 
 AUX_SOURCE_DIRECTORY(. UNIT_TESTS_SOURCES)
 AUX_SOURCE_DIRECTORY(cs_gen CS_GEN_UNIT_TESTS_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/idlc/cs_gen CS_GEN_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/idlc/gen CS_GEN_SOURCES)
 
-FLEX_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/tidlc.ll ${CMAKE_SOURCE_DIR}/idlc/tidlc_l.cpp)
-BISON_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/tidlc.yy ${CMAKE_SOURCE_DIR}/idlc/tidlc_y.cpp)
+FLEX_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.ll ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_l.cpp)
+BISON_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.yy ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_y.cpp)
 
 ADD_EXECUTABLE(${TIDL_UNIT_TESTS}
        ${BISON_TIDLC_OUTPUTS}
index 506a2b71db0b629562075f4755a274f723655f07..e001f4cbc1f14e22ae8ea4c02fdced126ae9e769 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/attribute.h"
+#include "idlc/ast/attribute.h"
 
 class AttributeTest : public testing::Test {
  public:
index 589b378fc5eef1f6010b279a3979caa002822d5e..0659344d2343ff7fc8539bd980d9979107111e06 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/block.h"
+#include "idlc/ast/block.h"
 
 class BlockTest : public testing::Test {
  public:
index b9b898cff91edafea88ee62b83acf4d17761593f..fd247cfad759f48bcc041364b9a6c493e70a1492 100644 (file)
@@ -18,8 +18,8 @@
 
 #include <iostream>
 
-#include "idlc/parser.h"
-#include "idlc/cs_gen/cs_proxy_gen.h"
+#include "idlc/ast/parser.h"
+#include "idlc/gen/cs_proxy_gen.h"
 
 class CsProxyGenTest : public testing::Test {
  public:
index ea5643e0f3cb13aa659412eae342d7d852d9ce04..512c6de78e94a28081831f02d635a9fc9ea71e69 100644 (file)
@@ -18,8 +18,8 @@
 
 #include <iostream>
 
-#include "idlc/parser.h"
-#include "idlc/cs_gen/cs_stub_gen.h"
+#include "idlc/ast/parser.h"
+#include "idlc/gen/cs_stub_gen.h"
 
 class CsStubGenTest : public testing::Test {
  public:
index 2e5c9a4ce0209eea90241a89d749102ca3d66b06..776341d2e5232abece7a171c7811c221dcf9352a 100644 (file)
@@ -18,9 +18,9 @@
 
 #include <iostream>
 
-#include "idlc/declaration.h"
-#include "idlc/type.h"
-#include "idlc/parameter.h"
+#include "idlc/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/parameter.h"
 
 class DeclarationTest : public testing::Test {
  public:
index b27ed0b8f20a7162d2008d26506dffcc62697a59..31e6c1b55d7ba4c58eb303d5d6ff806ccb878b0e 100644 (file)
@@ -18,8 +18,8 @@
 
 #include <iostream>
 
-#include "idlc/document.h"
-#include "idlc/block.h"
+#include "idlc/ast/document.h"
+#include "idlc/ast/block.h"
 
 class DocumentTest : public testing::Test {
  public:
index fb399a89c842dfe013a208d61cc034b341c65865..8ef351ce24827133f972ee3fce6075df80130cbf 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/element.h"
+#include "idlc/ast/element.h"
 
 class ElementTest : public testing::Test {
  public:
index dd15a1c3b1b02c4db7e26c15245193a51ee080d3..7573025c75324430ba67a2f68294d306c06656af 100644 (file)
 #include <iostream>
 #include <memory>
 
-#include "idlc/generator.h"
-#include "idlc/interface.h"
-#include "idlc/structure.h"
-#include "idlc/attribute.h"
+#include "idlc/gen/generator.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/attribute.h"
 
 class SampleGenerator : public tidl::Generator {
  public:
index c31778fa2d541b41ed559f93f6a2d4adf7e60d25..780aca5e50ef3c8eefe15aa8421c374d2f25c171 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/interface.h"
+#include "idlc/ast/interface.h"
 
 class InterfaceTest : public testing::Test {
  public:
index e838957ceef490a36e6b04366f8c24ba9a740d0e..748e33aaeb882bb38ec64ba943b2a77cef78787b 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/parser.h"
+#include "idlc/ast/parser.h"
 
 extern int gargc;
 extern char** gargv;
index 563e85185399caed5a68b83315a2dc9266e5e3fc..4e68e98882c93269b03865aff2fec59572cc556d 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/structure.h"
+#include "idlc/ast/structure.h"
 
 class StructureTest : public testing::Test {
  public:
index fe07b47fdbad407ca06e0deeece371f5c38d3ef0..f08e7b36c42a99fea94fa628ac59d1ab1a01185b 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <iostream>
 
-#include "idlc/type.h"
+#include "idlc/ast/type.h"
 
 class TokenTest : public testing::Test {
  public: