From: Hwankyu Jhun Date: Thu, 7 Dec 2017 00:34:27 +0000 (+0900) Subject: Support annotations X-Git-Tag: accepted/tizen/unified/20180302.061550~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F162994%2F7;p=platform%2Fcore%2Fappfw%2Ftidl.git Support annotations Change-Id: Iab176142fa6cb5bded66f01ea8092732a84b01a6 Signed-off-by: Hwankyu Jhun --- diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fbd6883 --- /dev/null +++ b/build.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +#--------------------------------------------------------# +# Tizen Interface Definition Langauge Compiler # +#--------------------------------------------------------# + +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +SCRIPT_FILE=$(readlink -f $0) +SCRIPT_DIR=$(dirname $SCRIPT_FILE) +BUILD_DIR=build + +usage() { + echo "Usage: $0 [command]" + echo "Commands:" + echo " build Build the package" + echo " clean Clean all artifacts" + echo " clean_build Clean & Build the package" +} + +cmd_build() { + echo "[TIDL] Build the package" + mkdir -p $SCRIPT_DIR/$BUILD_DIR + cd $SCRIPT_DIR/$BUILD_DIR + cmake .. + make clean + make +} + +cmd_clean() { + echo "[TIDL] Clean all artifacts" + cd $SCRIPT_DIR/$BUILD_DIR + make clean + cd .. + rm -rf $SCRIPT_DIR/$BUILD_DIR + rm -rf $SCRIPT_DIR/idlc/location* + rm -rf $SCRIPT_DIR/idlc/position* +} + +cmd_clean_build() { + cmd_clean + cmd_build +} + +cmd=$1; shift; +case "$cmd" in + build|--build|-b) cmd_build $@ ;; + clean|--clean|-c) cmd_clean $@ ;; + clean_build |--clean_build |-cb) cmd_clean_build $@ ;; + *) usage ;; + +esac diff --git a/idlc/attribute.cc b/idlc/attribute.cc index 52ed3c0..19a3dc0 100644 --- a/idlc/attribute.cc +++ b/idlc/attribute.cc @@ -19,8 +19,9 @@ namespace tidl { -Attribute::Attribute(const std::string& id, BaseType* type, unsigned line) - : id_(id), type_(type), line_(line) {} +Attribute::Attribute(const std::string& id, BaseType* type, + const std::string& comments, unsigned line) + : id_(id), type_(type), comments_(comments), line_(line) {} const std::string& Attribute::GetID() const { return id_; @@ -34,6 +35,10 @@ const unsigned Attribute::GetLine() const { return line_; } +const std::string& Attribute::GetComments() const { + return comments_; +} + void Attributes::Add(Attribute* attr) { attrs_.emplace_back(attr); } diff --git a/idlc/attribute.h b/idlc/attribute.h index 582ec71..fb3ea7c 100644 --- a/idlc/attribute.h +++ b/idlc/attribute.h @@ -28,15 +28,18 @@ namespace tidl { class Attribute { public: - Attribute(const std::string& id, BaseType* type, unsigned line); + Attribute(const std::string& id, BaseType* type, + const 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 type_; + std::string comments_; unsigned line_; }; diff --git a/idlc/block.cc b/idlc/block.cc index 3454072..82a8bc4 100644 --- a/idlc/block.cc +++ b/idlc/block.cc @@ -19,8 +19,9 @@ namespace tidl { -Block::Block(const std::string& id, Block::Type type, unsigned line) - : id_(id), type_(type), line_(line) { +Block::Block(const std::string& id, Block::Type type, + const std::string& comments, unsigned line) + : id_(id), type_(type), comments_(comments), line_(line) { } const std::string& Block::GetID() const { @@ -35,4 +36,8 @@ 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 index f1d95cd..50c3054 100644 --- a/idlc/block.h +++ b/idlc/block.h @@ -31,16 +31,19 @@ class Block { TYPE_STRUCTURE, }; - Block(const std::string& id, Block::Type type, unsigned line); + Block(const std::string& id, Block::Type type, const 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_; }; diff --git a/idlc/declaration.cc b/idlc/declaration.cc index 4283f12..5963fef 100644 --- a/idlc/declaration.cc +++ b/idlc/declaration.cc @@ -21,10 +21,12 @@ namespace tidl { Declaration::Declaration(const std::string& id, BaseType* ret_type, - Parameters* params, unsigned line, bool async) + Parameters* params, const std::string& comments, + unsigned line, bool async) : id_(id), ret_type_(ret_type), params_(params), + comments_(comments), line_(line), async_(async) {} @@ -48,6 +50,10 @@ const unsigned Declaration::GetLine() const { return line_; } +const std::string& Declaration::GetComments() const { + return comments_; +} + void Declarations::Add(Declaration* decl) { decls_.emplace_back(decl); } diff --git a/idlc/declaration.h b/idlc/declaration.h index c30cb1c..6ec9e47 100644 --- a/idlc/declaration.h +++ b/idlc/declaration.h @@ -29,18 +29,20 @@ namespace tidl { class Declaration { public: Declaration(const std::string& id, BaseType* ret_type, Parameters* params, - unsigned line, bool async = false); + const std::string& comments, unsigned line, bool async = false); const std::string& GetID() const; const BaseType& GetType() const; const Parameters& GetParameters() const; bool IsAsync() const; const unsigned GetLine() const; + const std::string& GetComments() const; private: std::string id_; std::unique_ptr ret_type_; std::unique_ptr params_; + std::string comments_; unsigned line_; bool async_; }; diff --git a/idlc/generator.cc b/idlc/generator.cc index 5642bdc..ab408df 100644 --- a/idlc/generator.cc +++ b/idlc/generator.cc @@ -33,17 +33,18 @@ void Generator::Run(const std::string& file_name) { for (auto& block : doc_->GetBlocks()) { if (block->GetType() == Block::TYPE_INTERFACE) { Interface* interface = static_cast(block.get()); - OnInterfaceBegin(interface->GetID()); + OnInterfaceBegin(out_file_, interface->GetID(), interface->GetComments()); for (auto& decl : interface->GetDeclarations().GetDecls()) { OnDeclarationGen(out_file_, decl->GetID(), decl->GetParameters(), - decl->GetType()); + decl->GetType(), decl->GetComments()); } - OnInterfaceEnd(interface->GetID()); + OnInterfaceEnd(out_file_, interface->GetID()); } else if (block->GetType() == Block::TYPE_STRUCTURE) { Structure* structure = static_cast(block.get()); - OnStructureBegin(out_file_, structure->GetID()); + OnStructureBegin(out_file_, structure->GetID(), structure->GetComments()); for (auto& attr : structure->GetAttributes().GetAttrs()) { - OnAttributeGen(out_file_, attr->GetID(), attr->GetType()); + OnAttributeGen(out_file_, attr->GetID(), attr->GetType(), + attr->GetComments()); } OnStructureEnd(out_file_, structure->GetID()); } diff --git a/idlc/generator.h b/idlc/generator.h index cce4b0e..f89e2b1 100644 --- a/idlc/generator.h +++ b/idlc/generator.h @@ -34,16 +34,21 @@ class Generator { virtual ~Generator() = default; void Run(const std::string& file_name); - virtual void OnInterfaceBegin(const std::string& id) = 0; - virtual void OnInterfaceEnd(const std::string& id) = 0; + virtual void OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) = 0; + virtual void OnInterfaceEnd(std::ofstream& stream, const std::string& id) = 0; virtual void OnDeclarationGen(std::ofstream& stream, const std::string& id, const Parameters& args, - const BaseType& ret) = 0; + const BaseType& ret, + const std::string& comments) = 0; virtual void OnStructureBegin(std::ofstream& stream, - const std::string& id) = 0; + const std::string& id, + const std::string& comments) = 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; + const BaseType& type, + const std::string& comments) = 0; virtual void OnInitGen(std::ofstream& stream) = 0; virtual void OnFiniGen(std::ofstream& stream) = 0; diff --git a/idlc/interface.cc b/idlc/interface.cc index fcdf441..e76c3ae 100644 --- a/idlc/interface.cc +++ b/idlc/interface.cc @@ -20,8 +20,9 @@ namespace tidl { -Interface::Interface(const std::string& id, Declarations* decls, unsigned line) - : Block::Block(id, Block::TYPE_INTERFACE, line), decls_(decls) { +Interface::Interface(const std::string& id, Declarations* decls, + const std::string& comments, unsigned line) + : Block::Block(id, Block::TYPE_INTERFACE, comments, line), decls_(decls) { } const Declarations& Interface::GetDeclarations() const { diff --git a/idlc/interface.h b/idlc/interface.h index 28ce29d..a762ca9 100644 --- a/idlc/interface.h +++ b/idlc/interface.h @@ -27,7 +27,8 @@ namespace tidl { class Interface : public Block { public: - Interface(const std::string& id, Declarations* decls, unsigned line); + Interface(const std::string& id, Declarations* decls, + const std::string& comments, unsigned line); const Declarations& GetDeclarations() const; diff --git a/idlc/proxy_gen.cc b/idlc/proxy_gen.cc index 8d14a38..ebad3eb 100644 --- a/idlc/proxy_gen.cc +++ b/idlc/proxy_gen.cc @@ -23,7 +23,10 @@ ProxyGen::ProxyGen(std::shared_ptr doc) void ProxyGen::OnDeclarationGen(std::ofstream& stream, const std::string& id, const Parameters& args, - const BaseType& ret) { + const BaseType& ret, + const std::string& comments) { + if (comments != "") + stream << comments; stream << ret.ToString() << " " << interface_name_ + "_" + id << "("; bool first = true; @@ -55,20 +58,30 @@ void ProxyGen::OnInitGen(std::ofstream& stream) { void ProxyGen::OnFiniGen(std::ofstream& stream) { } -void ProxyGen::OnInterfaceBegin(const std::string& id) { +void ProxyGen::OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) { + if (comments != "") + stream << comments; interface_name_ = id; } -void ProxyGen::OnInterfaceEnd(const std::string& id) { +void ProxyGen::OnInterfaceEnd(std::ofstream& stream, const std::string& id) { interface_name_ = ""; } void ProxyGen::OnAttributeGen(std::ofstream& stream, const std::string& id, - const BaseType& type) { + const BaseType& type, + const std::string& comments) { + if (comments != "") + stream << "\t" << comments; stream << "\t" << type.GetFullName() << " " << id << ";" << std::endl; } -void ProxyGen::OnStructureBegin(std::ofstream& stream, const std::string& id) { +void ProxyGen::OnStructureBegin(std::ofstream& stream, const std::string& id, + const std::string& comments) { + if (comments != "") + stream << comments; stream << "typedef struct" << " " << id + "_t" << " " << "{" << std::endl; } diff --git a/idlc/proxy_gen.h b/idlc/proxy_gen.h index 6fb9178..d85b9d8 100644 --- a/idlc/proxy_gen.h +++ b/idlc/proxy_gen.h @@ -30,14 +30,19 @@ class ProxyGen : public Generator { virtual ~ProxyGen() = default; void OnDeclarationGen(std::ofstream& stream, const std::string& id, - const Parameters& args, const BaseType& ret) override; + const Parameters& args, const BaseType& ret, + const std::string& comments) 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 OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) override; + void OnInterfaceEnd(std::ofstream& stream, 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; + const BaseType& type, + const std::string& comments) override; + void OnStructureBegin(std::ofstream& stream, const std::string& id, + const std::string& comments) override; void OnStructureEnd(std::ofstream& stream, const std::string& id) override; private: diff --git a/idlc/structure.cc b/idlc/structure.cc index b617f36..2f99af9 100644 --- a/idlc/structure.cc +++ b/idlc/structure.cc @@ -20,8 +20,9 @@ namespace tidl { -Structure::Structure(const std::string& id, Attributes* attrs, unsigned line) - : Block::Block(id, Block::TYPE_STRUCTURE, line), attrs_(attrs) { +Structure::Structure(const std::string& id, Attributes* attrs, + const std::string& comments, unsigned line) + : Block::Block(id, Block::TYPE_STRUCTURE, comments, line), attrs_(attrs) { } const Attributes& Structure::GetAttributes() const { diff --git a/idlc/structure.h b/idlc/structure.h index 5549de5..d9dffa7 100644 --- a/idlc/structure.h +++ b/idlc/structure.h @@ -27,7 +27,8 @@ namespace tidl { class Structure : public Block { public: - Structure(const std::string& id, Attributes* attrs, unsigned line); + Structure(const std::string& id, Attributes* attrs, + const std::string& comments, unsigned line); const Attributes& GetAttributes() const; diff --git a/idlc/stub_gen.cc b/idlc/stub_gen.cc index ab2e032..50bf552 100644 --- a/idlc/stub_gen.cc +++ b/idlc/stub_gen.cc @@ -22,20 +22,26 @@ StubGen::StubGen(std::shared_ptr doc) : Generator(doc) {} void StubGen::OnDeclarationGen(std::ofstream& stream, const std::string& id, - const Parameters& args, const BaseType& ret) {} + const Parameters& args, const BaseType& ret, + const std::string& comments) {} void StubGen::OnInitGen(std::ofstream& stream) {} void StubGen::OnFiniGen(std::ofstream& stream) {} -void StubGen::OnInterfaceBegin(const std::string& id) {} +void StubGen::OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) {} -void StubGen::OnInterfaceEnd(const std::string& id) {} +void StubGen::OnInterfaceEnd(std::ofstream& stream, const std::string& id) {} void StubGen::OnAttributeGen(std::ofstream& stream, const std::string& id, - const BaseType& type) {} + const BaseType& type, + const std::string& comments) {} -void StubGen::OnStructureBegin(std::ofstream& stream, const std::string& id) {} +void StubGen::OnStructureBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) {} void StubGen::OnStructureEnd(std::ofstream& stream, const std::string& id) {} diff --git a/idlc/stub_gen.h b/idlc/stub_gen.h index b302d97..e28a26a 100644 --- a/idlc/stub_gen.h +++ b/idlc/stub_gen.h @@ -30,14 +30,20 @@ class StubGen : public Generator { virtual ~StubGen() = default; void OnDeclarationGen(std::ofstream& stream, const std::string& id, - const Parameters& args, const BaseType& ret) override; + const Parameters& args, const BaseType& ret, + const std::string& comments) 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 OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) override; + void OnInterfaceEnd(std::ofstream& stream, 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; + const BaseType& type, + const std::string& comments) override; + void OnStructureBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) override; void OnStructureEnd(std::ofstream& stream, const std::string& id) override; }; diff --git a/idlc/tidlc.ll b/idlc/tidlc.ll index 53b7ec3..45788c0 100644 --- a/idlc/tidlc.ll +++ b/idlc/tidlc.ll @@ -1,5 +1,6 @@ %{ #include +#include #include "idlc/parser.h" #include "idlc/document.h" @@ -15,6 +16,8 @@ #define YY_USER_ACTION yylloc->columns(yyleng); %} +%x COMMENT + %option yylineno %option noyywrap %option reentrant @@ -22,9 +25,21 @@ %option bison-locations %% +%{ + std::string comments; +%} +"/*" { comments += yytext; BEGIN(COMMENT); } +"*/"+\/ { comments += yytext; yylloc->step(); BEGIN(INITIAL); } +"*/" { comments += yytext; comments += "\n"; BEGIN(INITIAL); } +"*/"\n+ { comments += yytext; yylloc->step(); BEGIN(INITIAL); } +\n+ { comments += yytext; yylloc->lines(yyleng); } +([^*]\n)+|. { comments += yytext; yylloc->step(); } +<> { return 0; } -[\n] { yylloc->lines(yyleng); yylloc->step(); } +"//".*\n { comments += yytext; yylloc->step(); } + +[\n]+ { yylloc->lines(yyleng); yylloc->step(); } [ \t\r\n] ; // ignore all whitespace "," { return yy::parser::token::T_COMMA; } @@ -33,28 +48,66 @@ "(" { return yy::parser::token::T_LEFT; } ")" { return yy::parser::token::T_RIGHT; } ";" { return yy::parser::token::T_SEMICOLON; } -"void" { return yy::parser::token::T_VOID; } -"char" { return yy::parser::token::T_CHAR; } -"short" { return yy::parser::token::T_SHORT; } -"int" { return yy::parser::token::T_INT; } -"long" { return yy::parser::token::T_LONG; } -"float" { return yy::parser::token::T_FLOAT; } -"double" { return yy::parser::token::T_DOUBLE; } -"bundle" { return yy::parser::token::T_BUNDLE; } -"string" { return yy::parser::token::T_STRING; } -"bool" { return yy::parser::token::T_BOOL; } +"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; } -"interface" { return yy::parser::token::T_INTERFACE; } "<" { 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; } - +"list" { + yylval->token = new tidl::Token(yytext, comments); + return yy::parser::token::T_LIST; + } +"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); + yylval->token = new tidl::Token(yytext, comments); return yy::parser::token::T_ID; } diff --git a/idlc/tidlc.yy b/idlc/tidlc.yy index c13d666..9b3a0c7 100644 --- a/idlc/tidlc.yy +++ b/idlc/tidlc.yy @@ -24,10 +24,8 @@ int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *); %lex-param { void *lex_scanner } %token T_LEFT T_RIGHT 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 -%token T_STRING T_BOOL -%token T_IN T_OUT T_REF T_ASYNC T_INTERFACE T_STRUCTURE -%token T_META_OPEN T_META_CLOSE T_LIST +%token T_IN T_OUT T_REF T_ASYNC +%token T_META_OPEN T_META_CLOSE %start start @@ -52,6 +50,19 @@ int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *); } %token T_ID +%token T_STRUCTURE +%token T_INTERFACE +%token T_CHAR +%token T_SHORT +%token T_INT +%token T_LONG +%token T_FLOAT +%token T_DOUBLE +%token T_VOID +%token T_BUNDLE +%token T_STRING +%token T_BOOL +%token T_LIST %type blocks %type block %type structure_block @@ -103,21 +114,26 @@ block: interface_block { ; structure_block: T_STRUCTURE T_ID T_BRACE_OPEN attributes T_BRACE_CLOSE { - $$ = new tidl::Structure($2->ToString(), $4, @1.begin.line); + $$ = new tidl::Structure($2->ToString(), $4, $1->GetComments(), + @1.begin.line); + delete $1; delete $2; } | T_STRUCTURE T_BRACE_OPEN attributes T_BRACE_CLOSE { ps->ReportError("syntax error. \"No identifier\".", @1.begin.line); $$ = NULL; + delete $1; } | T_STRUCTURE error T_BRACE_OPEN attributes 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; } ; @@ -141,7 +157,8 @@ attributes: attribute { ; attribute: base_type T_ID T_SEMICOLON { - $$ = new tidl::Attribute($2->ToString(), $1, @1.begin.line); + $$ = new tidl::Attribute($2->ToString(), $1, $1->GetComments(), + @1.begin.line); delete $2; } | base_type T_SEMICOLON { @@ -159,20 +176,25 @@ attribute: base_type T_ID T_SEMICOLON { ; interface_block: T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE { - $$ = new tidl::Interface($2->ToString(), $4, @1.begin.line); + $$ = new tidl::Interface($2->ToString(), $4, $1->GetComments(), + @1.begin.line); + delete $1; delete $2; } | 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; } ; @@ -196,12 +218,15 @@ declarations: declaration { ; declaration: base_type T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON { - $$ = new tidl::Declaration($2->ToString(), $1, $4, @1.begin.line); + $$ = new tidl::Declaration($2->ToString(), $1, $4, $1->GetComments(), + @1.begin.line); 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"), $4, - @1.begin.line, true); + $$ = new tidl::Declaration($2->ToString(), + new tidl::BaseType("void", $1->GetComments()), $4, + $1->GetComments(), @1.begin.line, true); + delete $1; delete $2; } | base_type T_ID T_LEFT parameter_list T_RIGHT T_ASYNC T_SEMICOLON { @@ -252,19 +277,21 @@ parameter_list: parameter { ; direction_specifier: T_IN { - $$ = new tidl::Token("in"); + $$ = new tidl::Token("in", ""); } | T_OUT { - $$ = new tidl::Token("out"); + $$ = new tidl::Token("out", ""); } | T_REF { - $$ = new tidl::Token("ref"); + $$ = new tidl::Token("ref", ""); } ; parameter: T_VOID { $$ = new tidl::Parameter("empty", - new tidl::ParameterType(new tidl::BaseType("void")), @1.begin.line); + new tidl::ParameterType(new tidl::BaseType("void", $1->GetComments())), + @1.begin.line); + delete $1; } | parameter_type T_ID { $$ = new tidl::Parameter($2->ToString(), $1, @1.begin.line); @@ -285,49 +312,61 @@ base_type: container_type { $$ = $1; } | T_VOID { - $$ = new tidl::BaseType("void"); + $$ = new tidl::BaseType("void", $1->GetComments()); + delete $1; } | T_CHAR { - $$ = new tidl::BaseType("char"); + $$ = new tidl::BaseType("char", $1->GetComments()); + delete $1; } | T_SHORT { - $$ = new tidl::BaseType("short"); + $$ = new tidl::BaseType("short", $1->GetComments()); + delete $1; } | T_INT { - $$ = new tidl::BaseType("int"); + $$ = new tidl::BaseType("int", $1->GetComments()); + delete $1; } | T_LONG { - $$ = new tidl::BaseType("long"); + $$ = new tidl::BaseType("long", $1->GetComments()); + delete $1; } | T_FLOAT { - $$ = new tidl::BaseType("float"); + $$ = new tidl::BaseType("float", $1->GetComments()); + delete $1; } | T_DOUBLE { - $$ = new tidl::BaseType("double"); + $$ = new tidl::BaseType("double", $1->GetComments()); + delete $1; } | T_BUNDLE { - $$ = new tidl::BaseType("bundle"); + $$ = new tidl::BaseType("bundle", $1->GetComments()); + delete $1; } | T_STRING { - $$ = new tidl::BaseType("string"); + $$ = new tidl::BaseType("string", $1->GetComments()); + delete $1; } | T_BOOL { - $$ = new tidl::BaseType("bool"); + $$ = new tidl::BaseType("bool", $1->GetComments()); + delete $1; } | T_ID { - $$ = new tidl::BaseType($1->ToString(), true); + $$ = 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()); + $$ = new tidl::BaseType($1->ToString(), $1->GetComments()); $$->SetMetaType($3); + delete $1; } ; container_type_name: T_LIST { - $$ = new tidl::Token("list"); + $$ = new tidl::Token("list", $1->GetComments()); + delete $1; } ; diff --git a/idlc/type.cc b/idlc/type.cc index e78216e..6f9595d 100644 --- a/idlc/type.cc +++ b/idlc/type.cc @@ -14,15 +14,18 @@ * limitations under the License. */ +#include #include "idlc/type.h" namespace tidl { -Token::Token(const std::string& name) : name_(name) { +Token::Token(const std::string& name, const std::string& comments) + : name_(name), comments_(comments) { } -BaseType::BaseType(const std::string& name, bool user_defined) - : Token(name), user_defined_(user_defined) { +BaseType::BaseType(const std::string& name, const std::string& comments, + bool user_defined) + : Token(name, comments), user_defined_(user_defined) { } void BaseType::SetMetaType(BaseType* type) { diff --git a/idlc/type.h b/idlc/type.h index 6116cd8..529eb0d 100644 --- a/idlc/type.h +++ b/idlc/type.h @@ -24,18 +24,21 @@ namespace tidl { class Token { public: - explicit Token(const std::string& name); + Token(const std::string& name, const 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(const std::string& name, bool user_defined = false); + explicit BaseType(const std::string& name, const std::string& comments, + bool user_defined = false); void SetMetaType(BaseType* type); const BaseType& GetMetaType() const { return *meta_type_; diff --git a/unit_tests/attribute_unittest.cc b/unit_tests/attribute_unittest.cc index d1df9e3..9246f0b 100644 --- a/unit_tests/attribute_unittest.cc +++ b/unit_tests/attribute_unittest.cc @@ -28,14 +28,14 @@ class AttributeTest : public testing::Test { TEST_F(AttributeTest, Attribute_Contstructor) { tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); delete attr; } TEST_F(AttributeTest, Attribute_GetID) { tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); EXPECT_EQ(attr->GetID(), "test"); delete attr; @@ -43,7 +43,7 @@ TEST_F(AttributeTest, Attribute_GetID) { TEST_F(AttributeTest, Attribute_GetType) { tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); EXPECT_EQ(attr->GetType().ToString(), "int"); delete attr; @@ -52,12 +52,21 @@ TEST_F(AttributeTest, Attribute_GetType) { TEST_F(AttributeTest, Attribute_GetLine) { unsigned line = __LINE__; tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), line); + new tidl::BaseType("int", ""), "", line); EXPECT_NE(attr, nullptr); EXPECT_EQ(attr->GetLine(), line); delete attr; } +TEST_F(AttributeTest, Attribute_GetComments) { + std::string comments = "Test comments"; + tidl::Attribute* attr = new tidl::Attribute("test", + new tidl::BaseType("int", ""), comments, __LINE__); + EXPECT_NE(attr, nullptr); + EXPECT_EQ(attr->GetComments(), comments); + delete attr; +} + class AttributesTest : public testing::Test { public: virtual void SetUp() {} @@ -72,7 +81,7 @@ TEST_F(AttributesTest, Attributes_Constructor) { TEST_F(AttributesTest, Attributes_Add) { tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); @@ -91,9 +100,10 @@ TEST_F(AttributesTest, Attributes_Add) { TEST_F(AttributesTest, Attributes_GetAttrs) { tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); - attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int"), __LINE__)); - attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *"), - __LINE__)); + attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int", ""), + "", __LINE__)); + attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *", ""), + "", __LINE__)); int count = 0; for (auto& attr : attrs->GetAttrs()) { @@ -110,13 +120,13 @@ TEST_F(AttributesTest, Attributes_GetAttrs) { TEST_F(AttributesTest, Attributes_Exist) { tidl::Attribute* attr = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); attrs->Add(attr); tidl::Attribute* attr2 = new tidl::Attribute("test", - new tidl::BaseType("int"), __LINE__); + new tidl::BaseType("int", ""), "", __LINE__); EXPECT_NE(attr, nullptr); EXPECT_EQ(attrs->Exist(attr2), true); delete attr2; diff --git a/unit_tests/block_unittest.cc b/unit_tests/block_unittest.cc index 8b52f88..589b378 100644 --- a/unit_tests/block_unittest.cc +++ b/unit_tests/block_unittest.cc @@ -25,7 +25,8 @@ class BlockTest : public testing::Test { tidl::Block* testBlock; virtual void SetUp() { - testBlock = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE, 28); + testBlock = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE, + "", 28); } virtual void TearDown() { delete testBlock; @@ -34,7 +35,7 @@ class BlockTest : public testing::Test { TEST_F(BlockTest, Block_Constructor) { tidl::Block* block = new tidl::Block("StructureBlock", - tidl::Block::TYPE_STRUCTURE, 37); + tidl::Block::TYPE_STRUCTURE, "", __LINE__); EXPECT_NE(block, nullptr); delete block; } @@ -50,3 +51,12 @@ TEST_F(BlockTest, Block_GetType) { TEST_F(BlockTest, Block_GetLine) { EXPECT_EQ(testBlock->GetLine(), 28); } + +TEST_F(BlockTest, Block_GetComments) { + std::string comments = "Test Block"; + tidl::Block* block = new tidl::Block("StructureBlock", + tidl::Block::TYPE_STRUCTURE, comments, __LINE__); + EXPECT_NE(block, nullptr); + EXPECT_EQ(block->GetComments(), comments); + delete block; +} diff --git a/unit_tests/declaration_unittest.cc b/unit_tests/declaration_unittest.cc index 82619db..8915e06 100644 --- a/unit_tests/declaration_unittest.cc +++ b/unit_tests/declaration_unittest.cc @@ -30,23 +30,23 @@ class DeclarationTest : public testing::Test { params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test1", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); params->Add(new tidl::Parameter("test2", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); } virtual void TearDown() {} }; TEST_F(DeclarationTest, Declaration_Constructor) { tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); delete decl; } TEST_F(DeclarationTest, Declaration_GetID) { tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); EXPECT_EQ(decl->GetID(), "test"); delete decl; @@ -54,7 +54,7 @@ TEST_F(DeclarationTest, Declaration_GetID) { TEST_F(DeclarationTest, Declaration_GetType) { tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); EXPECT_EQ(decl->GetType().ToString(), "int"); delete decl; @@ -62,7 +62,7 @@ TEST_F(DeclarationTest, Declaration_GetType) { TEST_F(DeclarationTest, Declaration_GetParameters) { tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); int count = 0; @@ -81,16 +81,25 @@ TEST_F(DeclarationTest, Declaration_GetParameters) { TEST_F(DeclarationTest, Declaration_IsAsync) { tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); EXPECT_EQ(decl->IsAsync(), false); delete decl; } +TEST_F(DeclarationTest, Declaration_GetComments) { + std::string comments = "Test Declaration"; + tidl::Declaration* decl = new tidl::Declaration("test", + new tidl::BaseType("int", ""), params, comments, __LINE__); + EXPECT_NE(decl, nullptr); + EXPECT_EQ(decl->GetComments(), comments); + delete decl; +} + TEST_F(DeclarationTest, Declaration_GetLine) { unsigned line = __LINE__; tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, line); + new tidl::BaseType("int", ""), params, "", line); EXPECT_NE(decl, nullptr); EXPECT_EQ(decl->GetLine(), line); delete decl; @@ -106,11 +115,11 @@ class DeclarationsTest : public testing::Test { tidl::Parameters* params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test1", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); params->Add(new tidl::Parameter("test2", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); } }; @@ -159,9 +168,9 @@ TEST_F(DeclarationsTest, Declarations_Exist) { tidl::Parameters* testParams = new tidl::Parameters(); EXPECT_NE(testParams, nullptr); testParams->Add(new tidl::Parameter("test1", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); tidl::Declaration* testDecl = new tidl::Declaration("test", - new tidl::BaseType("int"), testParams, __LINE__); + new tidl::BaseType("int", ""), testParams, "", __LINE__); EXPECT_NE(testDecl, nullptr); EXPECT_EQ(decls->Exist(testDecl), true); delete testDecl; diff --git a/unit_tests/document_unittest.cc b/unit_tests/document_unittest.cc index c27c193..b27ed0b 100644 --- a/unit_tests/document_unittest.cc +++ b/unit_tests/document_unittest.cc @@ -28,7 +28,8 @@ class DocumentTest : public testing::Test { virtual void SetUp() { document = new tidl::Document(); - block = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE, __LINE__); + block = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE, + "", __LINE__); } virtual void TearDown() { } @@ -63,7 +64,7 @@ TEST_F(DocumentTest, Document_GetBlocks) { TEST_F(DocumentTest, Document_ExistBlock) { document->AddBlock(block); tidl::Block* testBlock = new tidl::Block("TestBlock", - tidl::Block::TYPE_INTERFACE, __LINE__); + tidl::Block::TYPE_INTERFACE, "", __LINE__); EXPECT_NE(testBlock, nullptr); EXPECT_EQ(document->ExistBlock(testBlock), true); delete testBlock; diff --git a/unit_tests/generator_unittest.cc b/unit_tests/generator_unittest.cc index e4fda49..6725e75 100644 --- a/unit_tests/generator_unittest.cc +++ b/unit_tests/generator_unittest.cc @@ -24,23 +24,28 @@ class SampleGenerator : public tidl::Generator { public: - SampleGenerator(std::shared_ptr doc) + explicit SampleGenerator(std::shared_ptr doc) : tidl::Generator(doc), count_(0) {} ~SampleGenerator() {} - void OnInterfaceBegin(const std::string& id) override { + void OnInterfaceBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) override { interfaceID_ = id; count_++; } - void OnInterfaceEnd(const std::string& id) override { + void OnInterfaceEnd(std::ofstream& stream, const std::string& id) override { count_++; } void OnDeclarationGen(std::ofstream& stream, const std::string& id, const tidl::Parameters& args, - const tidl::BaseType& ret) override { + const tidl::BaseType& ret, + const std::string& comments) override { count_++; } - void OnStructureBegin(std::ofstream& stream, const std::string& id) override { + void OnStructureBegin(std::ofstream& stream, + const std::string& id, + const std::string& comments) override { structureID_ = id; count_++; } @@ -48,7 +53,8 @@ class SampleGenerator : public tidl::Generator { count_++; } void OnAttributeGen(std::ofstream& stream, const std::string& id, - const tidl::BaseType& type) override { + const tidl::BaseType& type, + const std::string& comments) override { count_++; } void OnInitGen(std::ofstream& stream) override { @@ -84,10 +90,10 @@ class GeneratorTest : public testing::Test { tidl::Parameters* params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); tidl::Declarations* decls = new tidl::Declarations(); @@ -96,13 +102,13 @@ class GeneratorTest : public testing::Test { tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); - attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int"), - __LINE__)); + attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int", ""), + "", __LINE__)); doc = new tidl::Document(); EXPECT_NE(doc, nullptr); - doc->AddBlock(new tidl::Interface("TestInterface", decls, __LINE__)); - doc->AddBlock(new tidl::Structure("TestStructure", attrs, __LINE__)); + doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__)); + doc->AddBlock(new tidl::Structure("TestStructure", attrs, "", __LINE__)); } virtual void TearDown() {} }; diff --git a/unit_tests/interface_unittest.cc b/unit_tests/interface_unittest.cc index ef3fcda..d5fddd5 100644 --- a/unit_tests/interface_unittest.cc +++ b/unit_tests/interface_unittest.cc @@ -28,11 +28,11 @@ class InterfaceTest : public testing::Test { tidl::Parameters* params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test1", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); params->Add(new tidl::Parameter("test2", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); decls = new tidl::Declarations(); EXPECT_NE(decls, nullptr); @@ -43,14 +43,14 @@ class InterfaceTest : public testing::Test { TEST_F(InterfaceTest, Interface_Constructor) { tidl::Interface* interface = new tidl::Interface("TestInterface", decls, - __LINE__); + "", __LINE__); EXPECT_NE(interface, nullptr); delete interface; } TEST_F(InterfaceTest, Interface_GetDeclrations) { tidl::Interface* interface = new tidl::Interface("TestInterface", decls, - __LINE__); + "", __LINE__); EXPECT_NE(interface, nullptr); bool flag = false; @@ -64,7 +64,7 @@ TEST_F(InterfaceTest, Interface_GetDeclrations) { TEST_F(InterfaceTest, Interface_GetID) { tidl::Interface* interface = new tidl::Interface("TestInterface", decls, - __LINE__); + "", __LINE__); EXPECT_NE(interface, nullptr); EXPECT_EQ(interface->GetID(), "TestInterface"); delete interface; @@ -72,7 +72,7 @@ TEST_F(InterfaceTest, Interface_GetID) { TEST_F(InterfaceTest, Interface_GetType) { tidl::Interface* interface = new tidl::Interface("TestInterface", decls, - __LINE__); + "", __LINE__); EXPECT_NE(interface, nullptr); EXPECT_EQ(interface->GetType(), tidl::Interface::TYPE_INTERFACE); delete interface; @@ -81,8 +81,18 @@ TEST_F(InterfaceTest, Interface_GetType) { TEST_F(InterfaceTest, Interface_GetLine) { unsigned line = __LINE__; tidl::Interface* interface = new tidl::Interface("TestInterface", decls, - line); + "", line); EXPECT_NE(interface, nullptr); EXPECT_EQ(interface->GetLine(), line); delete interface; } + +TEST_F(InterfaceTest, Interface_GetComments) { + std::string comments = "Test Interface"; + tidl::Interface* interface = new tidl::Interface("TestInterface", decls, + comments, __LINE__); + EXPECT_NE(interface, nullptr); + EXPECT_EQ(interface->GetComments(), comments); + delete interface; +} + diff --git a/unit_tests/proxy_gen_unittest.cc b/unit_tests/proxy_gen_unittest.cc index 9597978..3e78d5b 100644 --- a/unit_tests/proxy_gen_unittest.cc +++ b/unit_tests/proxy_gen_unittest.cc @@ -30,10 +30,10 @@ class ProxyGenTest : public testing::Test { tidl::Parameters* params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); tidl::Declarations* decls = new tidl::Declarations(); @@ -42,13 +42,13 @@ class ProxyGenTest : public testing::Test { tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); - attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int"), - __LINE__)); + attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int", ""), + "", __LINE__)); doc = new tidl::Document(); EXPECT_NE(doc, nullptr); - doc->AddBlock(new tidl::Interface("TestInterface", decls, __LINE__)); - doc->AddBlock(new tidl::Structure("TestStructure", attrs, __LINE__)); + doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__)); + doc->AddBlock(new tidl::Structure("TestStructure", attrs, "", __LINE__)); } virtual void TearDown() {} diff --git a/unit_tests/structure_unittest.cc b/unit_tests/structure_unittest.cc index 8f91d8e..c3ddb0a 100644 --- a/unit_tests/structure_unittest.cc +++ b/unit_tests/structure_unittest.cc @@ -27,24 +27,24 @@ class StructureTest : public testing::Test { virtual void SetUp() { attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); - attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int"), - __LINE__)); - attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *"), - __LINE__)); + attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int", ""), + "", __LINE__)); + attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *", ""), + "", __LINE__)); } virtual void TearDown() {} }; TEST_F(StructureTest, Structure_Constructor) { tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, - __LINE__); + "", __LINE__); EXPECT_NE(structure, nullptr); delete structure; } TEST_F(StructureTest, Structure_GetAttributes) { tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, - __LINE__); + "", __LINE__); EXPECT_NE(structure, nullptr); int count = 0; @@ -62,7 +62,7 @@ TEST_F(StructureTest, Structure_GetAttributes) { TEST_F(StructureTest, Structure_GetID) { tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, - __LINE__); + "", __LINE__); EXPECT_NE(structure, nullptr); EXPECT_EQ(structure->GetID(), "TestStructure"); delete structure; @@ -70,7 +70,7 @@ TEST_F(StructureTest, Structure_GetID) { TEST_F(StructureTest, Structure_GetType) { tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, - __LINE__); + "", __LINE__); EXPECT_NE(structure, nullptr); EXPECT_EQ(structure->GetType(), tidl::Structure::TYPE_STRUCTURE); delete structure; @@ -79,8 +79,17 @@ TEST_F(StructureTest, Structure_GetType) { TEST_F(StructureTest, Structure_GetLine) { unsigned line = __LINE__; tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, - line); + "", line); EXPECT_NE(structure, nullptr); EXPECT_EQ(structure->GetLine(), line); delete structure; } + +TEST_F(StructureTest, Structure_GetComments) { + std::string comments = "Test Structure"; + tidl::Structure* structure = new tidl::Structure("TestStructure", attrs, + comments, __LINE__); + EXPECT_NE(structure, nullptr); + EXPECT_EQ(structure->GetComments(), comments); + delete structure; +} diff --git a/unit_tests/stub_gen_unittest.cc b/unit_tests/stub_gen_unittest.cc index 8c4ec3d..4a45c66 100644 --- a/unit_tests/stub_gen_unittest.cc +++ b/unit_tests/stub_gen_unittest.cc @@ -30,10 +30,10 @@ class StubGenTest : public testing::Test { tidl::Parameters* params = new tidl::Parameters(); EXPECT_NE(params, nullptr); params->Add(new tidl::Parameter("test", - new tidl::ParameterType(new tidl::BaseType("int")), __LINE__)); + new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__)); tidl::Declaration* decl = new tidl::Declaration("test", - new tidl::BaseType("int"), params, __LINE__); + new tidl::BaseType("int", ""), params, "", __LINE__); EXPECT_NE(decl, nullptr); tidl::Declarations* decls = new tidl::Declarations(); @@ -42,13 +42,13 @@ class StubGenTest : public testing::Test { tidl::Attributes* attrs = new tidl::Attributes(); EXPECT_NE(attrs, nullptr); - attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int"), - __LINE__)); + attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int", ""), + "", __LINE__)); doc = new tidl::Document(); EXPECT_NE(doc, nullptr); - doc->AddBlock(new tidl::Interface("TestInterface", decls, __LINE__)); - doc->AddBlock(new tidl::Structure("TestStructure", attrs, __LINE__)); + doc->AddBlock(new tidl::Interface("TestInterface", decls, "", __LINE__)); + doc->AddBlock(new tidl::Structure("TestStructure", attrs, "", __LINE__)); } virtual void TearDown() {} }; diff --git a/unit_tests/test.tidl b/unit_tests/test.tidl index f4ef03f..75113b1 100644 --- a/unit_tests/test.tidl +++ b/unit_tests/test.tidl @@ -1,15 +1,38 @@ +/* + * 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. + */ + struct Student { string name; int num; bundle data; } +// Annotation Test!! +// Structure Class struct Class { + /* string name attr */ string name; list students; } +/* Interface School! */ interface School { + /* Method section */ + /* Method AddClass */ int AddClass(in Class cls); + /* Method GetStudent */ int GetStudent(in string c_name, in string s_name, out Student student); } diff --git a/unit_tests/type_unittest.cc b/unit_tests/type_unittest.cc index b0a0629..9cffdd1 100644 --- a/unit_tests/type_unittest.cc +++ b/unit_tests/type_unittest.cc @@ -25,7 +25,7 @@ class TokenTest : public testing::Test { tidl::Token* testToken; virtual void SetUp() { - testToken = new tidl::Token("TestToken"); + testToken = new tidl::Token("TestToken", "Test Token"); } virtual void TearDown() { delete testToken; @@ -33,7 +33,7 @@ class TokenTest : public testing::Test { }; TEST_F(TokenTest, Token_Constructor) { - tidl::Token* token = new tidl::Token("TestToken"); + tidl::Token* token = new tidl::Token("TestToken", ""); EXPECT_NE(token, nullptr); delete token; } @@ -42,6 +42,10 @@ TEST_F(TokenTest, Token_ToString) { EXPECT_EQ(testToken->ToString(), "TestToken"); } +TEST_F(TokenTest, Token_GetComments) { + EXPECT_EQ(testToken->GetComments(), "Test Token"); +} + class BaseTypeTest : public testing::Test { public: virtual void SetUp() {} @@ -49,38 +53,46 @@ class BaseTypeTest : public testing::Test { }; TEST_F(BaseTypeTest, BaseType_Constructor) { - tidl::BaseType* baseType = new tidl::BaseType("BaseType"); + tidl::BaseType* baseType = new tidl::BaseType("BaseType", ""); EXPECT_NE(baseType, nullptr); delete baseType; } TEST_F(BaseTypeTest, BaseType_SetMetaType) { - tidl::BaseType* customType = new tidl::BaseType("CustomType", true); - customType->SetMetaType(new tidl::BaseType("int")); + tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true); + customType->SetMetaType(new tidl::BaseType("int", "")); EXPECT_EQ(customType->GetMetaType().ToString(), "int"); delete customType; } TEST_F(BaseTypeTest, BaseType_GetMetaType) { - tidl::BaseType* customType = new tidl::BaseType("CustomType", true); - customType->SetMetaType(new tidl::BaseType("string")); + tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true); + customType->SetMetaType(new tidl::BaseType("string", "")); EXPECT_EQ(customType->GetMetaType().ToString(), "string"); delete customType; } TEST_F(BaseTypeTest, BaseType_GetFullName) { - tidl::BaseType* customType = new tidl::BaseType("CustomType", true); - customType->SetMetaType(new tidl::BaseType("string")); + tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true); + customType->SetMetaType(new tidl::BaseType("string", "")); EXPECT_EQ(customType->GetFullName(), "CustomType"); delete customType; } TEST_F(BaseTypeTest, BaseType_IsUserDefinedType) { - tidl::BaseType* testType = new tidl::BaseType("TestType", true); + tidl::BaseType* testType = new tidl::BaseType("TestType", "", true); EXPECT_EQ(testType->IsUserDefinedType(), true); delete testType; } +TEST_F(BaseTypeTest, BaseType_GetComments) { + std::string comments = "Test BaseType"; + tidl::BaseType* testType = new tidl::BaseType("TestType", comments, true); + EXPECT_NE(testType, nullptr); + EXPECT_EQ(testType->GetComments(), comments); + delete testType; +} + class ParameterTypeTest : public testing::Test { public: virtual void SetUp() {} @@ -89,29 +101,29 @@ class ParameterTypeTest : public testing::Test { TEST_F(ParameterTypeTest, ParameterType_Constructor) { tidl::ParameterType *parameterType = new tidl::ParameterType( - new tidl::BaseType("int")); + new tidl::BaseType("int", "")); EXPECT_NE(parameterType, nullptr); delete parameterType; } TEST_F(ParameterTypeTest, ParameterType_Constructor_With_Direction) { tidl::ParameterType *parameterType = new tidl::ParameterType( - new tidl::BaseType("int"), "in"); + new tidl::BaseType("int", ""), "in"); EXPECT_NE(parameterType, nullptr); delete parameterType; } TEST_F(ParameterTypeTest, ParameterType_GetDirection) { tidl::ParameterType *parameterType = new tidl::ParameterType( - new tidl::BaseType("int"), "out"); + new tidl::BaseType("int", ""), "out"); EXPECT_NE(parameterType, nullptr); EXPECT_EQ(parameterType->GetDirection(), tidl::ParameterType::Direction::OUT); delete parameterType; } TEST_F(ParameterTypeTest, ParameterType_GetBaseType) { - tidl::ParameterType *parameterType = new tidl::ParameterType( - new tidl::BaseType("string"), "ref"); + tidl::ParameterType *parameterType = new tidl::ParameterType( + new tidl::BaseType("string", ""), "ref"); EXPECT_NE(parameterType, nullptr); EXPECT_EQ(parameterType->GetBaseType().ToString(), "string");