--- /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 <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
--- /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_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_
#include "idlc/interface.h"
#include "idlc/structure.h"
#include "idlc/declaration.h"
+#include "idlc/attribute.h"
namespace tidl {
#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,
- unsigned line)
+ Attributes* attrs, unsigned line)
: Block::Block(std::move(id), Block::TYPE_INTERFACE,
- std::move(comments), line), decls_(decls) {}
+ std::move(comments), line),
+ decls_(decls),
+ attrs_(attrs) {}
const Declarations& Interface::GetDeclarations() const {
return *decls_;
}
+const Attributes& Interface::GetAttributes() const {
+ return *attrs_;
+}
+
} // namespace tidl
#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,
- unsigned line);
+ 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
#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
+%x COMMENT VALUE
%option yylineno
%option noyywrap
%%
%{
std::string comments;
+ std::string values;
%}
"/*" { comments += yytext; BEGIN(COMMENT); }
"//".*\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
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; }
%%
#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 *);
%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
%start start
tidl::Element* elm;
tidl::Elements* elms;
tidl::Block* blk;
+ tidl::Attribute* attr;
+ tidl::Attributes* attrs;
}
%token<token> T_ID
%token<token> T_STRING
%token<token> T_BOOL
%token<token> T_LIST
+%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<token> container_type_name
%type<elm> element
%type<elms> elements
+%type<attr> attribute
+%type<attrs> attributes
%%
}
;
+attributes: attribute {
+ $$ = new tidl::Attributes();
+ $$->Add($1);
+ }
+ | attributes T_COMMA attribute {
+ $$ = $1;
+ 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(),
- @1.begin.line);
+ 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;
../idlc/block.cc
../idlc/generator.cc
../idlc/parser.cc
+ ../idlc/attribute.cc
)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../idlc/cs_gen CS_GEN_SOURCES)
--- /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 <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/attribute.h"
+
+class AttributeTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AttributeTest, Attribute_Constructor) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetKey) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetKey(), "key");
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetValue) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetValue(), "value");
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", line);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetLine(), line);
+ delete attr;
+}
+
+class AttributesTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AttributesTest, Attributes_Constructor) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_Add) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("key", "value", __LINE__));
+
+ bool flag = false;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetKey() == "key" &&
+ attr->GetValue() == "value")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_GetAttrs) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("key1", "value1", __LINE__));
+ attrs->Add(new tidl::Attribute("key2", "value2", __LINE__));
+
+ int count = 0;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetKey() == "key1" &&
+ attr->GetValue() == "value1")
+ count++;
+ if (attr->GetKey() == "key2" &&
+ attr->GetValue() == "value2")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_Exist) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("key", "value", __LINE__));
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attrs->Exist(attr), true);
+ delete attr;
+ delete attrs;
+}
#include "idlc/generator.h"
#include "idlc/interface.h"
#include "idlc/structure.h"
+#include "idlc/attribute.h"
class SampleGenerator : public tidl::Generator {
public:
TEST_F(InterfaceTest, Interface_Constructor) {
tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", __LINE__);
+ "", new tidl::Attributes(), __LINE__);
EXPECT_NE(interface, nullptr);
delete interface;
}
TEST_F(InterfaceTest, Interface_GetDeclrations) {
tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", __LINE__);
+ "", new tidl::Attributes(), __LINE__);
EXPECT_NE(interface, nullptr);
bool flag = false;
TEST_F(InterfaceTest, Interface_GetID) {
tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", __LINE__);
+ "", new tidl::Attributes(), __LINE__);
EXPECT_NE(interface, nullptr);
EXPECT_EQ(interface->GetID(), "TestInterface");
delete interface;
TEST_F(InterfaceTest, Interface_GetType) {
tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", __LINE__);
+ "", new tidl::Attributes(), __LINE__);
EXPECT_NE(interface, nullptr);
EXPECT_EQ(interface->GetType(), tidl::Interface::TYPE_INTERFACE);
delete interface;
TEST_F(InterfaceTest, Interface_GetLine) {
unsigned line = __LINE__;
tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", line);
+ "", new tidl::Attributes(), 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__);
+ comments, new tidl::Attributes(), __LINE__);
EXPECT_NE(interface, nullptr);
EXPECT_EQ(interface->GetComments(), comments);
delete interface;
}
/* Interface School! */
+[privilege = "http://tizen.org/privilege/appmanager.launch", privilege = "http://tizen.org/privilege/appmanager.kill"]
interface School {
/* Method section */
/* Method AddClass */