src/interface.cc
src/type.cc
src/parameter.cc
+ src/attribute.cc
+ src/structure.cc
+ src/block.cc
src/generator.cc
src/proxy_gen.cc
src/stub_gen.cc
--- /dev/null
+/*
+ * 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_INC_ATTRIBUTE_H_
+#define IDLC_INC_ATTRIBUTE_H_
+
+#include <string>
+#include <list>
+#include <memory>
+
+#include "type.h"
+#include "parameter.h"
+
+namespace tidl {
+
+class Attribute {
+ public:
+ Attribute(const std::string& id, BaseType* type);
+
+ const std::string& GetID() const;
+ const BaseType& GetType() const;
+
+ private:
+ std::string id_;
+ std::unique_ptr<BaseType> type_;
+};
+
+class Attributes {
+ public:
+ void Add(Attribute* decl);
+ const std::list<std::unique_ptr<Attribute>>& GetAttrs() const;
+
+ private:
+ std::list<std::unique_ptr<Attribute>> attrs_;
+};
+
+} // namespace tidl
+
+#endif // IDLC_INC_ATTRIBUTE_H_
* limitations under the License.
*/
-#ifndef IDLC_INC_INTERFACE_H_
-#define IDLC_INC_INTERFACE_H_
+#ifndef IDLC_INC_BLOCK_H_
+#define IDLC_INC_BLOCK_H_
#include <string>
#include <memory>
namespace tidl {
-class Interface {
+class Block {
public:
- Interface(const std::string& id, Declarations* decls);
-
+ enum Type {
+ TYPE_INTERFACE = 0,
+ TYPE_STRUCTURE,
+ };
+
+ Block(const std::string& id, Block::Type type);
+ virtual ~Block() = default;
+
const std::string& GetID() const;
- const Declarations& GetDeclarations() const;
+ const Block::Type& GetType() const;
private:
std::string id_;
- std::unique_ptr<Declarations> decls_;
+ Block::Type type_;
};
} // namespace tidl
-#endif // IDLC_INC_INTERFACE_H_
+#endif // IDLC_INC_BLOCK_H_
class Document {
public:
- void AddInterface(Interface* interface);
- const std::list<std::unique_ptr<Interface>>& GetInterfaces() const;
+ Document();
+
+ void AddBlock(Block* block);
+ const std::list<std::unique_ptr<Block>>& GetBlocks() const;
private:
- std::list<std::unique_ptr<Interface>> interfaces_;
+ std::list<std::unique_ptr<Block>> blocks_;
};
} // namespace tidl
virtual void OnInterfaceBegin(const std::string& id) = 0;
virtual void OnInterfaceEnd(const std::string& id) = 0;
virtual void OnDeclartionGen(std::ofstream& stream, const std::string& id,
- const Parameters& args, const BaseType& ret) = 0;
+ const Parameters& args, const BaseType& ret) = 0;
+ virtual void OnStructureBegin(std::ofstream& stream,
+ const std::string& id) = 0;
+ virtual void OnStructureEnd(std::ofstream& stream, const std::string& id) = 0;
+ virtual void OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const BaseType& type) = 0;
virtual void OnInitGen(std::ofstream& stream) = 0;
virtual void OnFiniGen(std::ofstream& stream) = 0;
#include <string>
#include <memory>
+#include "block.h"
#include "declaration.h"
namespace tidl {
-class Interface {
+class Interface : public Block {
public:
Interface(const std::string& id, Declarations* decls);
-
- const std::string& GetID() const;
+
const Declarations& GetDeclarations() const;
private:
- std::string id_;
std::unique_ptr<Declarations> decls_;
};
void* Scanner() const { return scanner_; }
bool Parse(const std::string& input);
bool ParseFromFile(const std::string& path);
- void AttachDoc(Document* doc);
- std::shared_ptr<Document> DetachDoc();
+ void SetDoc(Document* doc);
+ std::shared_ptr<Document> GetDoc();
private:
void* scanner_;
virtual ~ProxyGen() = default;
void OnDeclartionGen(std::ofstream& stream, const std::string& id,
- const Parameters& args, const BaseType& ret) override;
+ const Parameters& args, const BaseType& ret) override;
void OnInitGen(std::ofstream& stream) override;
void OnFiniGen(std::ofstream& stream) override;
void OnInterfaceBegin(const std::string& id) override;
void OnInterfaceEnd(const std::string& id) override;
+ void OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const BaseType& type) override;
+ void OnStructureBegin(std::ofstream& stream, const std::string& id) override;
+ void OnStructureEnd(std::ofstream& stream, const std::string& id) override;
private:
std::string ConvertTypeToCType(const BaseType& type);
--- /dev/null
+/*
+ * 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_INC_STRUCTURE_H_
+#define IDLC_INC_STRUCTURE_H_
+
+#include <string>
+#include <memory>
+
+#include "block.h"
+#include "attribute.h"
+
+namespace tidl {
+
+class Structure : public Block {
+ public:
+ Structure(const std::string& id, Attributes* attrs);
+
+ const Attributes& GetAttributes() const;
+
+ private:
+ std::unique_ptr<Attributes> attrs_;
+};
+
+} // namespace tidl
+
+#endif // IDLC_INC_STRUCTURE_H_
+
void OnFiniGen(std::ofstream& stream) override;
void OnInterfaceBegin(const std::string& id) override;
void OnInterfaceEnd(const std::string& id) override;
+ void OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const BaseType& type) override;
+ void OnStructureBegin(std::ofstream& stream, const std::string& id) override;
+ void OnStructureEnd(std::ofstream& stream, const std::string& id) override;
};
} // namespace tidl
--- /dev/null
+/*
+ * 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 "attribute.h"
+#include "type.h"
+
+namespace tidl {
+
+Attribute::Attribute(const std::string& id, BaseType* type)
+ : id_(id), type_(type) {}
+
+const std::string& Attribute::GetID() const {
+ return id_;
+}
+
+const BaseType& Attribute::GetType() const {
+ return *type_;
+}
+
+void Attributes::Add(Attribute* attr) {
+ attrs_.emplace_back(attr);
+}
+
+const std::list<std::unique_ptr<Attribute>>& Attributes::GetAttrs() const {
+ return attrs_;
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * 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 "type.h"
+#include "block.h"
+
+namespace tidl {
+
+Block::Block(const std::string& id, Block::Type type)
+ : id_(id), type_(type) {
+}
+
+const std::string& Block::GetID() const {
+ return id_;
+}
+
+const Block::Type& Block::GetType() const {
+ return type_;
+}
+
+} // namespace tidl
namespace tidl {
-void Document::AddInterface(Interface* interface) {
- interfaces_.emplace_back(interface);
+Document::Document() {}
+
+void Document::AddBlock(Block* block) {
+ blocks_.emplace_back(block);
}
-const std::list<std::unique_ptr<Interface>>& Document::GetInterfaces() const {
- return interfaces_;
+const std::list<std::unique_ptr<Block>>& Document::GetBlocks() const {
+ return blocks_;
}
} // namespace tidl
*/
#include "generator.h"
+#include "block.h"
#include "interface.h"
+#include "structure.h"
#include "declaration.h"
namespace tidl {
out_file_.open(FileName);
OnInitGen(out_file_);
- for (auto& interface : doc_->GetInterfaces()) {
- OnInterfaceBegin(interface->GetID());
- for (auto& decl : interface->GetDeclarations().GetDecls()) {
- OnDeclartionGen(out_file_, decl->GetID(), decl->GetParameters(),
- decl->GetType());
+ for (auto& block : doc_->GetBlocks()) {
+ if (block->GetType() == Block::TYPE_INTERFACE) {
+ Interface* interface = static_cast<Interface*>(block.get());
+ OnInterfaceBegin(interface->GetID());
+ for (auto& decl : interface->GetDeclarations().GetDecls()) {
+ OnDeclartionGen(out_file_, decl->GetID(), decl->GetParameters(),
+ decl->GetType());
+ }
+ OnInterfaceEnd(interface->GetID());
+ } else if (block->GetType() == Block::TYPE_STRUCTURE) {
+ Structure* structure = static_cast<Structure*>(block.get());
+ OnStructureBegin(out_file_, structure->GetID());
+ for (auto& attr : structure->GetAttributes().GetAttrs()) {
+ OnAttributeGen(out_file_, attr->GetID(), attr->GetType());
+ }
+ OnStructureEnd(out_file_, structure->GetID());
}
- OnInterfaceEnd(interface->GetID());
}
OnFiniGen(out_file_);
#include "declaration.h"
#include "interface.h"
+#include "block.h"
namespace tidl {
Interface::Interface(const std::string& id, Declarations* decls)
- : id_(id), decls_(decls) {
-}
-
-const std::string& Interface::GetID() const {
- return id_;
+ : Block::Block(id, Block::TYPE_INTERFACE), decls_(decls) {
}
const Declarations& Interface::GetDeclarations() const {
ps.ParseFromFile(path);
if (opt == ::Option::PROXY) {
- tidl::ProxyGen proxy(ps.DetachDoc());
+ tidl::ProxyGen proxy(ps.GetDoc());
proxy.Run(argv[3]);
} else {
- tidl::StubGen stub(ps.DetachDoc());
+ tidl::StubGen stub(ps.GetDoc());
stub.Run(argv[3]);
}
#include "declaration.h"
#include "parameter.h"
#include "type.h"
+#include "attribute.h"
+#include "structure.h"
#include "../tidlc_y.hpp"
struct yy_buffer_state;
yylex_destroy(scanner_);
}
-void Parser::AttachDoc(Document* doc) {
+void Parser::SetDoc(Document* doc) {
doc_ = std::shared_ptr<Document>(doc);
}
-std::shared_ptr<Document> Parser::DetachDoc() {
+std::shared_ptr<Document> Parser::GetDoc() {
return doc_;
}
interface_name_ = "";
}
+void ProxyGen::OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const BaseType& type) {
+ stream << "\t" << type.GetFullName() << " " << id << ";" << std::endl;
+}
+
+void ProxyGen::OnStructureBegin(std::ofstream& stream, const std::string& id) {
+ stream << "typedef struct" << " " << id + "_t" << " " << "{" << std::endl;
+}
+
+void ProxyGen::OnStructureEnd(std::ofstream& stream, const std::string& id) {
+ stream << "}" << " " << id << ";" << std::endl;
+ stream << std::endl;
+}
+
} // namespace tidl
--- /dev/null
+/*
+ * 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 "attribute.h"
+#include "structure.h"
+#include "block.h"
+
+namespace tidl {
+
+Structure::Structure(const std::string& id, Attributes* attrs)
+ : Block::Block(id, Block::TYPE_STRUCTURE), attrs_(attrs) {
+}
+
+const Attributes& Structure::GetAttributes() const {
+ return *attrs_;
+}
+
+} // namespace tidl
void StubGen::OnInterfaceEnd(const std::string& id) {}
+void StubGen::OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const BaseType& type) {}
+
+void StubGen::OnStructureBegin(std::ofstream& stream, const std::string& id) {}
+
+void StubGen::OnStructureEnd(std::ofstream& stream, const std::string& id) {}
+
} // namespace tidl
#include "type.h"
#include "parameter.h"
#include "interface.h"
+#include "attribute.h"
+#include "structure.h"
+#include "block.h"
#include "tidlc_y.hpp"
#define YY_USER_ACTION yylloc->columns(yyleng);
"<" {return yy::parser::token::T_META_OPEN;}
">" {return yy::parser::token::T_META_CLOSE;}
"list" {return yy::parser::token::T_LIST;}
+"struct" {return yy::parser::token::T_STRUCTURE;}
[A-Za-z_][A-Za-z0-9_]* {
yylval->token = new tidl::Token(yytext);
#include "type.h"
#include "parameter.h"
#include "interface.h"
+#include "attribute.h"
+#include "structure.h"
+#include "block.h"
#include "tidlc_y.hpp"
int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *);
%token T_LEFT T_RIGHT T_ID T_COMMA T_SEMICOLON T_BRACE_OPEN T_BRACE_CLOSE
%token T_CHAR T_SHORT T_INT T_LONG T_FLOAT T_DOUBLE T_VOID T_BUNDLE T_STRING T_BOOL
-%token T_IN T_OUT T_REF T_ASYNC T_INTERFACE
+%token T_IN T_OUT T_REF T_ASYNC T_INTERFACE T_STRUCTURE
%token T_META_OPEN T_META_CLOSE T_LIST
tidl::Parameter* param;
tidl::Parameters* params;
tidl::Token* token;
+ tidl::Structure* structure;
+ tidl::Attribute* attr;
+ tidl::Attributes* attrs;
+ tidl::Block* blk;
}
%token<token> T_ID
-%type<doc> interface_blocks
+%type<doc> blocks
+%type<blk> block
+%type<structure> structure_block
%type<interf> interface_block
%type<decls> declarations
%type<decl> declaration
%type<params> parameter_list
%type<direction> direction_specifier
%type<token> container_type_name
+%type<attr> attribute
+%type<attrs> attributes
%%
-start: interface_blocks {
- ps->AttachDoc($1);
+start: blocks {
+ ps->SetDoc($1);
}
;
-interface_blocks: interface_block {
+blocks: block {
$$ = new tidl::Document();
- $$->AddInterface($1);
+ $$->AddBlock($1);
}
- | interface_blocks interface_block {
+ | blocks block {
$$ = $1;
- $$->AddInterface($2);
+ $$->AddBlock($2);
+ }
+;
+
+block: interface_block {
+ $$ = $1;
+ }
+ | structure_block {
+ $$ = $1;
+ }
+;
+
+structure_block: T_STRUCTURE T_ID T_BRACE_OPEN attributes T_BRACE_CLOSE {
+ $$ = new tidl::Structure($2->ToString(), $4);
+ delete $2;
+ }
+;
+
+attributes: attribute {
+ $$ = new tidl::Attributes();
+ $$->Add($1);
+ }
+ | attributes attribute {
+ $$ = $1;
+ $$->Add($2);
+ }
+;
+
+attribute: base_type T_ID T_SEMICOLON {
+ $$ = new tidl::Attribute($2->ToString(), $1);
+ delete $2;
}
;