From e7da4057f9e514f691ff278507fe92698d929031 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 18 Sep 2013 09:09:16 +0200 Subject: [PATCH] Implement support for work queues. --- components/cluster/clustercomponent.cpp | 60 ++- components/cluster/clustercomponent.h | 10 + lib/base/Makefile.am | 2 + lib/base/workqueue.cpp | 80 ++++ lib/base/workqueue.h | 59 +++ lib/config/config_parser.cc | 548 ++++++++++++------------ 6 files changed, 465 insertions(+), 294 deletions(-) create mode 100644 lib/base/workqueue.cpp create mode 100644 lib/base/workqueue.h diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp index ae6f1a42e..09b3a5c37 100644 --- a/components/cluster/clustercomponent.cpp +++ b/components/cluster/clustercomponent.cpp @@ -239,33 +239,46 @@ void ClusterComponent::AddConnection(const String& node, const String& service) void ClusterComponent::RelayMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message, bool persistent) { - double ts = Utility::GetTime(); - message->Set("ts", ts); + m_RelayQueue.Enqueue(boost::bind(&ClusterComponent::RealRelayMessage, this, source, message, persistent)); +} - if (persistent) { - Dictionary::Ptr pmessage = boost::make_shared(); - pmessage->Set("timestamp", ts); +void ClusterComponent::PersistMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message) +{ + double ts = message->Get("ts"); - if (source) - pmessage->Set("source", source->GetName()); + ASSERT(ts != 0); - pmessage->Set("message", Value(message).Serialize()); - pmessage->Set("security", message->Get("security")); + Dictionary::Ptr pmessage = boost::make_shared(); + pmessage->Set("timestamp", ts); - ObjectLock olock(this); - if (m_LogFile) { - String json = Value(pmessage).Serialize(); - NetString::WriteStringToStream(m_LogFile, json); - m_LogMessageCount++; - m_LogMessageTimestamp = ts; - - if (m_LogMessageCount > 50000) { - CloseLogFile(); - RotateLogFile(); - OpenLogFile(); - } + if (source) + pmessage->Set("source", source->GetName()); + + pmessage->Set("message", Value(message).Serialize()); + pmessage->Set("security", message->Get("security")); + + ObjectLock olock(this); + if (m_LogFile) { + String json = Value(pmessage).Serialize(); + NetString::WriteStringToStream(m_LogFile, json); + m_LogMessageCount++; + m_LogMessageTimestamp = ts; + + if (m_LogMessageCount > 50000) { + CloseLogFile(); + RotateLogFile(); + OpenLogFile(); } } +} + +void ClusterComponent::RealRelayMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message, bool persistent) +{ + double ts = Utility::GetTime(); + message->Set("ts", ts); + + if (persistent) + m_LogQueue.Enqueue(boost::bind(&ClusterComponent::PersistMessage, this, source, message)); Dictionary::Ptr security = message->Get("security"); DynamicObject::Ptr secobj; @@ -971,6 +984,11 @@ void ClusterComponent::AcknowledgementClearedHandler(const Service::Ptr& service } void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message) +{ + m_MessageQueue.Enqueue(boost::bind(&ClusterComponent::RealMessageHandler, this, sender, message)); +} + +void ClusterComponent::RealMessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message) { sender->SetSeen(Utility::GetTime()); diff --git a/components/cluster/clustercomponent.h b/components/cluster/clustercomponent.h index 97ddd617b..fba7aa230 100644 --- a/components/cluster/clustercomponent.h +++ b/components/cluster/clustercomponent.h @@ -28,6 +28,7 @@ #include "base/utility.h" #include "base/tlsutility.h" #include "base/stdiostream.h" +#include "base/workqueue.h" #include "icinga/service.h" #include "cluster/endpoint.h" @@ -70,6 +71,10 @@ private: shared_ptr m_SSLContext; String m_Identity; + WorkQueue m_RelayQueue; + WorkQueue m_MessageQueue; + WorkQueue m_LogQueue; + Timer::Ptr m_ClusterTimer; void ClusterTimerHandler(void); @@ -84,6 +89,7 @@ private: void ListenerThreadProc(const Socket::Ptr& server); void RelayMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message, bool persistent); + void RealRelayMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message, bool persistent); void OpenLogFile(void); void RotateLogFile(void); @@ -110,7 +116,9 @@ private: void DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority); void AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority); void AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority); + void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message); + void RealMessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message); bool IsAuthority(const DynamicObject::Ptr& object, const String& type); void UpdateAuthority(void); @@ -119,6 +127,8 @@ private: static bool SupportsNotifications(void); void SetSecurityInfo(const Dictionary::Ptr& message, const DynamicObject::Ptr& object, int privs); + + void PersistMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message); }; } diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 8c8f938d8..52f0f447c 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -95,6 +95,8 @@ libbase_la_SOURCES = \ value.cpp \ value.h \ win32.h \ + workqueue.cpp \ + workqueue.h \ zlibstream.cpp \ zlibstream.h diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp new file mode 100644 index 000000000..bc7a3b0c2 --- /dev/null +++ b/lib/base/workqueue.cpp @@ -0,0 +1,80 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * 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 2 * + * 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, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "base/workqueue.h" +#include "base/utility.h" +#include + +using namespace icinga; + +WorkQueue::~WorkQueue(void) +{ + Join(); +} + +/** + * Enqueues a work item. Work items are guaranteed to be executed in the order + * they were enqueued in. + */ +void WorkQueue::Enqueue(const WorkCallback& item) +{ + boost::mutex::scoped_lock lock(m_Mutex); + m_Items.push_back(item); + m_CV.notify_all(); + + if (!m_Executing) + Utility::QueueAsyncCallback(boost::bind(&WorkQueue::ExecuteItem, this)); +} + +void WorkQueue::Join(void) +{ + boost::mutex::scoped_lock lock(m_Mutex); + while (m_Executing || !m_Items.empty()) + m_CV.wait(lock); +} + +void WorkQueue::Clear(void) +{ + boost::mutex::scoped_lock lock(m_Mutex); + m_Items.clear(); + m_CV.notify_all(); +} + +void WorkQueue::ExecuteItem(void) +{ + boost::mutex::scoped_lock lock(m_Mutex); + m_Executing = true; + + while (!m_Items.empty()) { + try { + WorkCallback wi = m_Items.front(); + m_Items.pop_front(); + + lock.unlock(); + wi(); + lock.lock(); + } catch (...) { + lock.lock(); + m_Executing = false; + throw; + } + } + + m_Executing = false; +} diff --git a/lib/base/workqueue.h b/lib/base/workqueue.h new file mode 100644 index 000000000..4572384f1 --- /dev/null +++ b/lib/base/workqueue.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * 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 2 * + * 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, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef WORKQUEUE_H +#define WORKQUEUE_H + +#include "base/i2-base.h" +#include +#include +#include +#include + +namespace icinga +{ + +/** + * A workqueue. + * + * @ingroup base + */ +class I2_BASE_API WorkQueue +{ +public: + typedef boost::function WorkCallback; + + ~WorkQueue(void); + + void Enqueue(const WorkCallback& item); + void Join(void); + void Clear(void); + +private: + boost::mutex m_Mutex; + boost::condition_variable m_CV; + bool m_Executing; + std::deque m_Items; + + void ExecuteItem(void); +}; + +} + +#endif /* WORKQUEUE_H */ diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index e0a7970e3..3b88ea5cf 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.7.12-4996. */ +/* A Bison parser, made by GNU Bison 2.5. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.7.12-4996" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,21 +58,21 @@ /* Pull parsers. */ #define YYPULL 1 +/* Using locations. */ +#define YYLSP_NEEDED 1 /* Copy the first part of user declarations. */ -/* Line 371 of yacc.c */ -#line 68 "config_parser.cc" -# ifndef YY_NULL -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULL nullptr -# else -# define YY_NULL 0 -# endif -# endif +/* Line 268 of yacc.c */ +#line 71 "../../../lib/config/config_parser.cc" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -82,19 +82,14 @@ # define YYERROR_VERBOSE 1 #endif -/* In a future release of Bison, this section will be replaced - by #include "y.tab.h". */ -#ifndef YY_YY_CONFIG_PARSER_HH_INCLUDED -# define YY_YY_CONFIG_PARSER_HH_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int yydebug; +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 #endif + /* "%code requires" blocks. */ -/* Line 387 of yacc.c */ + +/* Line 288 of yacc.c */ #line 1 "config_parser.yy" /****************************************************************************** @@ -140,8 +135,9 @@ using namespace icinga; -/* Line 387 of yacc.c */ -#line 145 "config_parser.cc" + +/* Line 288 of yacc.c */ +#line 141 "../../../lib/config/config_parser.cc" /* Tokens. */ #ifndef YYTOKENTYPE @@ -217,10 +213,12 @@ using namespace icinga; + #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 387 of yacc.c */ + +/* Line 293 of yacc.c */ #line 54 "config_parser.yy" char *text; @@ -234,8 +232,9 @@ typedef union YYSTYPE Array *array; -/* Line 387 of yacc.c */ -#line 239 "config_parser.cc" + +/* Line 293 of yacc.c */ +#line 238 "../../../lib/config/config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -256,24 +255,9 @@ typedef struct YYLTYPE #endif -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (ConfigCompiler *context); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - -#endif /* !YY_YY_CONFIG_PARSER_HH_INCLUDED */ - /* Copy the second part of user declarations. */ -/* Line 390 of yacc.c */ + +/* Line 343 of yacc.c */ #line 119 "config_parser.yy" @@ -306,8 +290,9 @@ void ConfigCompiler::Compile(void) #define scanner (context->GetScanner()) -/* Line 390 of yacc.c */ -#line 311 "config_parser.cc" + +/* Line 343 of yacc.c */ +#line 296 "../../../lib/config/config_parser.cc" #ifdef short # undef short @@ -360,33 +345,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if (! defined __GNUC__ || __GNUC__ < 2 \ - || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) -# define __attribute__(Spec) /* empty */ +# define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YYUSE(e) ((void) (e)) #else -# define YYUSE(E) /* empty */ +# define YYUSE(e) /* empty */ #endif - /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(N) (N) +# define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -422,7 +398,6 @@ YYID (yyi) # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif @@ -516,20 +491,20 @@ union yyalloc #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do +/* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ while (YYID (0)) # endif # endif @@ -653,7 +628,7 @@ static const yytype_uint16 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 1 +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -680,7 +655,7 @@ static const char *const yytname[] = "object_inherits_list", "object_inherits_specifier", "expressionlist", "expressions", "expressions_inner", "expression", "operator", "array", "array_items", "array_items_inner", "simplevalue", "constterm", - "constexpression", "value", YY_NULL + "constexpression", "value", 0 }; #endif @@ -811,10 +786,10 @@ static const yytype_int16 yytable[] = 0, 0, 13 }; -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-30))) +#define yypact_value_is_default(yystate) \ + ((yystate) == (-30)) -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -884,24 +859,23 @@ static const yytype_uint8 yystos[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ yyerror (&yylloc, context, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) -/* Error token number */ + #define YYTERROR 1 #define YYERRCODE 256 @@ -910,28 +884,27 @@ while (YYID (0)) If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ while (YYID (0)) #endif -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) - /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -939,46 +912,10 @@ while (YYID (0)) #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - -/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ - -__attribute__((__unused__)) -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static unsigned -yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) -#else -static unsigned -yy_location_print_ (yyo, yylocp) - FILE *yyo; - YYLTYPE const * const yylocp; -#endif -{ - unsigned res = 0; - int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; - if (0 <= yylocp->first_line) - { - res += fprintf (yyo, "%d", yylocp->first_line); - if (0 <= yylocp->first_column) - res += fprintf (yyo, ".%d", yylocp->first_column); - } - if (0 <= yylocp->last_line) - { - if (yylocp->first_line < yylocp->last_line) - { - res += fprintf (yyo, "-%d", yylocp->last_line); - if (0 <= end_col) - res += fprintf (yyo, ".%d", end_col); - } - else if (0 <= end_col && yylocp->first_column < end_col) - res += fprintf (yyo, "-%d", end_col); - } - return res; - } - -# define YY_LOCATION_PRINT(File, Loc) \ - yy_location_print_ (File, &(Loc)) - +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -986,6 +923,7 @@ yy_location_print_ (yyo, yylocp) /* YYLEX -- calling `yylex' with the right arguments. */ + #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -1037,8 +975,6 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) ConfigCompiler *context; #endif { - FILE *yyo = yyoutput; - YYUSE (yyo); if (!yyvaluep) return; YYUSE (yylocationp); @@ -1049,7 +985,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context) # else YYUSE (yyoutput); # endif - YYUSE (yytype); + switch (yytype) + { + default: + break; + } } @@ -1294,11 +1234,12 @@ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = YY_NULL; + const char *yyformat = 0; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1358,13 +1299,11 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, break; } yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; } } } @@ -1384,12 +1323,10 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, # undef YYCASE_ } - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; if (*yymsg_alloc < yysize) { @@ -1449,10 +1386,29 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - YYUSE (yytype); + switch (yytype) + { + + default: + break; + } } +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (ConfigCompiler *context); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ /*----------. @@ -1484,40 +1440,11 @@ yyparse (context) /* The lookahead symbol. */ int yychar; - -#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 -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -static YYSTYPE yyval_default; -# define YY_INITIAL_VALUE(Value) = Value -#endif -static YYLTYPE yyloc_default -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - = { 1, 1, 1, 1 } -# 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 - /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); +YYSTYPE yylval; /* Location data for the lookahead symbol. */ -YYLTYPE yylloc = yyloc_default; - +YYLTYPE yylloc; /* Number of syntax errors so far. */ int yynerrs; @@ -1531,7 +1458,7 @@ YYLTYPE yylloc = yyloc_default; `yyvs': related to semantic values. `yyls': related to locations. - Refer to the stacks through separate pointers, to allow yyoverflow + Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1557,7 +1484,7 @@ YYLTYPE yylloc = yyloc_default; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1576,9 +1503,10 @@ YYLTYPE yylloc = yyloc_default; Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yylsp = yyls = yylsa; + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1587,7 +1515,21 @@ YYLTYPE yylloc = yyloc_default; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - yylsp[0] = yylloc; + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + goto yysetstate; /*------------------------------------------------------------. @@ -1733,9 +1675,7 @@ yybackup: yychar = YYEMPTY; yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1773,7 +1713,8 @@ yyreduce: switch (yyn) { case 9: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 160 "config_parser.yy" { context->HandleInclude(*(yyvsp[(2) - (2)].variant), false, yylloc); @@ -1782,7 +1723,8 @@ yyreduce: break; case 10: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 165 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc); @@ -1791,7 +1733,8 @@ yyreduce: break; case 11: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 171 "config_parser.yy" { context->HandleLibrary((yyvsp[(2) - (2)].text)); @@ -1800,7 +1743,8 @@ yyreduce: break; case 12: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 177 "config_parser.yy" { Value *value = (yyvsp[(4) - (4)].variant); @@ -1819,7 +1763,8 @@ yyreduce: break; case 14: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 194 "config_parser.yy" { (yyval.text) = (yyvsp[(1) - (1)].text); @@ -1827,7 +1772,8 @@ yyreduce: break; case 15: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 200 "config_parser.yy" { String name = String((yyvsp[(3) - (3)].text)); @@ -1846,7 +1792,8 @@ yyreduce: break; case 16: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 215 "config_parser.yy" { TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant); @@ -1862,7 +1809,8 @@ yyreduce: break; case 17: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 229 "config_parser.yy" { (yyval.num) = 0; @@ -1870,7 +1818,8 @@ yyreduce: break; case 18: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 233 "config_parser.yy" { (yyval.num) = 1; @@ -1878,7 +1827,8 @@ yyreduce: break; case 19: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 239 "config_parser.yy" { m_RuleLists.push(boost::make_shared()); @@ -1886,7 +1836,8 @@ yyreduce: break; case 20: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 244 "config_parser.yy" { (yyval.variant) = new Value(m_RuleLists.top()); @@ -1895,7 +1846,8 @@ yyreduce: break; case 26: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 259 "config_parser.yy" { m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text)); @@ -1904,7 +1856,8 @@ yyreduce: break; case 27: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 264 "config_parser.yy" { m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text)); @@ -1913,7 +1866,8 @@ yyreduce: break; case 28: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 269 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (3)].type), String(), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc); @@ -1924,7 +1878,8 @@ yyreduce: break; case 29: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 276 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (6)].type), (yyvsp[(4) - (6)].text), (yyvsp[(6) - (6)].text), TypeRuleList::Ptr(), yylloc); @@ -1936,7 +1891,8 @@ yyreduce: break; case 30: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 284 "config_parser.yy" { TypeRule rule((yyvsp[(2) - (4)].type), String(), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc); @@ -1947,7 +1903,8 @@ yyreduce: break; case 32: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 294 "config_parser.yy" { m_Type->SetParent((yyvsp[(2) - (2)].text)); @@ -1956,7 +1913,8 @@ yyreduce: break; case 39: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 307 "config_parser.yy" { (yyval.type) = (yyvsp[(1) - (1)].type); @@ -1964,7 +1922,8 @@ yyreduce: break; case 40: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 313 "config_parser.yy" { m_Abstract = false; @@ -1972,7 +1931,8 @@ yyreduce: break; case 41: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 317 "config_parser.yy" { ConfigItemBuilder::Ptr item = boost::make_shared(yylloc); @@ -2012,7 +1972,8 @@ yyreduce: break; case 43: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 356 "config_parser.yy" { m_Abstract = true; @@ -2020,7 +1981,8 @@ yyreduce: break; case 46: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 365 "config_parser.yy" { m_Abstract = true; @@ -2028,7 +1990,8 @@ yyreduce: break; case 47: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 371 "config_parser.yy" { (yyval.slist) = NULL; @@ -2036,7 +1999,8 @@ yyreduce: break; case 48: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 375 "config_parser.yy" { (yyval.slist) = new std::vector(); @@ -2046,7 +2010,8 @@ yyreduce: break; case 49: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 381 "config_parser.yy" { if ((yyvsp[(1) - (3)].slist)) @@ -2060,7 +2025,8 @@ yyreduce: break; case 50: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 393 "config_parser.yy" { (yyval.slist) = NULL; @@ -2068,7 +2034,8 @@ yyreduce: break; case 51: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 397 "config_parser.yy" { (yyval.slist) = (yyvsp[(2) - (2)].slist); @@ -2076,7 +2043,8 @@ yyreduce: break; case 52: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 403 "config_parser.yy" { if ((yyvsp[(2) - (3)].exprl)) @@ -2087,7 +2055,8 @@ yyreduce: break; case 53: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 412 "config_parser.yy" { (yyval.exprl) = (yyvsp[(1) - (1)].exprl); @@ -2095,7 +2064,8 @@ yyreduce: break; case 54: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 416 "config_parser.yy" { (yyval.exprl) = (yyvsp[(1) - (2)].exprl); @@ -2103,7 +2073,8 @@ yyreduce: break; case 55: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 421 "config_parser.yy" { (yyval.exprl) = NULL; @@ -2111,7 +2082,8 @@ yyreduce: break; case 56: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 425 "config_parser.yy" { (yyval.exprl) = new ExpressionList(); @@ -2121,7 +2093,8 @@ yyreduce: break; case 57: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 431 "config_parser.yy" { if ((yyvsp[(1) - (3)].exprl)) @@ -2135,7 +2108,8 @@ yyreduce: break; case 58: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 443 "config_parser.yy" { (yyval.expr) = new Expression((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); @@ -2145,7 +2119,8 @@ yyreduce: break; case 59: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 449 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); @@ -2161,7 +2136,8 @@ yyreduce: break; case 64: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 467 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); @@ -2169,7 +2145,8 @@ yyreduce: break; case 65: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 473 "config_parser.yy" { (yyval.array) = (yyvsp[(2) - (3)].array); @@ -2177,7 +2154,8 @@ yyreduce: break; case 66: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 479 "config_parser.yy" { (yyval.array) = (yyvsp[(1) - (1)].array); @@ -2185,7 +2163,8 @@ yyreduce: break; case 67: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 483 "config_parser.yy" { (yyval.array) = (yyvsp[(1) - (2)].array); @@ -2193,7 +2172,8 @@ yyreduce: break; case 68: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 488 "config_parser.yy" { (yyval.array) = NULL; @@ -2201,7 +2181,8 @@ yyreduce: break; case 69: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 492 "config_parser.yy" { (yyval.array) = new Array(); @@ -2220,7 +2201,8 @@ yyreduce: break; case 70: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 507 "config_parser.yy" { if ((yyvsp[(1) - (3)].array)) @@ -2242,7 +2224,8 @@ yyreduce: break; case 71: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 527 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); @@ -2251,7 +2234,8 @@ yyreduce: break; case 72: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 532 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); @@ -2259,7 +2243,8 @@ yyreduce: break; case 73: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 536 "config_parser.yy" { (yyval.variant) = new Value(); @@ -2267,7 +2252,8 @@ yyreduce: break; case 74: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 540 "config_parser.yy" { if ((yyvsp[(1) - (1)].array) == NULL) @@ -2279,7 +2265,8 @@ yyreduce: break; case 75: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 550 "config_parser.yy" { (yyval.variant) = (yyvsp[(2) - (3)].variant); @@ -2287,7 +2274,8 @@ yyreduce: break; case 76: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 555 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); @@ -2296,7 +2284,8 @@ yyreduce: break; case 77: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 560 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); @@ -2304,7 +2293,8 @@ yyreduce: break; case 78: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 564 "config_parser.yy" { (yyval.variant) = new Value(ScriptVariable::Get((yyvsp[(1) - (1)].text))); @@ -2313,7 +2303,8 @@ yyreduce: break; case 79: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 569 "config_parser.yy" { if ((yyvsp[(1) - (3)].variant)->GetType() == ValueString || (yyvsp[(3) - (3)].variant)->GetType() == ValueString) @@ -2327,7 +2318,8 @@ yyreduce: break; case 80: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 579 "config_parser.yy" { (yyval.variant) = new Value((double)*(yyvsp[(1) - (3)].variant) - (double)*(yyvsp[(3) - (3)].variant)); @@ -2338,7 +2330,8 @@ yyreduce: break; case 81: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 586 "config_parser.yy" { (yyval.variant) = new Value((double)*(yyvsp[(1) - (3)].variant) * (double)*(yyvsp[(3) - (3)].variant)); @@ -2349,7 +2342,8 @@ yyreduce: break; case 82: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 593 "config_parser.yy" { (yyval.variant) = new Value((double)*(yyvsp[(1) - (3)].variant) / (double)*(yyvsp[(3) - (3)].variant)); @@ -2360,7 +2354,8 @@ yyreduce: break; case 83: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 600 "config_parser.yy" { (yyval.variant) = new Value((long)*(yyvsp[(1) - (3)].variant) & (long)*(yyvsp[(3) - (3)].variant)); @@ -2371,7 +2366,8 @@ yyreduce: break; case 84: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 607 "config_parser.yy" { (yyval.variant) = new Value((long)*(yyvsp[(1) - (3)].variant) | (long)*(yyvsp[(3) - (3)].variant)); @@ -2382,7 +2378,8 @@ yyreduce: break; case 85: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 614 "config_parser.yy" { (yyval.variant) = new Value((long)*(yyvsp[(1) - (3)].variant) << (long)*(yyvsp[(3) - (3)].variant)); @@ -2393,7 +2390,8 @@ yyreduce: break; case 86: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 621 "config_parser.yy" { (yyval.variant) = new Value((long)*(yyvsp[(1) - (3)].variant) >> (long)*(yyvsp[(3) - (3)].variant)); @@ -2404,7 +2402,8 @@ yyreduce: break; case 87: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 628 "config_parser.yy" { (yyval.variant) = (yyvsp[(2) - (3)].variant); @@ -2412,7 +2411,8 @@ yyreduce: break; case 89: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 635 "config_parser.yy" { ExpressionList::Ptr exprl = ExpressionList::Ptr((yyvsp[(1) - (1)].exprl)); @@ -2421,7 +2421,8 @@ yyreduce: break; case 90: -/* Line 1787 of yacc.c */ + +/* Line 1806 of yacc.c */ #line 640 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); @@ -2429,8 +2430,9 @@ yyreduce: break; -/* Line 1787 of yacc.c */ -#line 2434 "config_parser.cc" + +/* Line 1806 of yacc.c */ +#line 2436 "../../../lib/config/config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2595,9 +2597,7 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -2626,7 +2626,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE +#if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -2668,6 +2668,8 @@ yyreturn: } -/* Line 2050 of yacc.c */ + +/* Line 2067 of yacc.c */ #line 644 "config_parser.yy" + -- 2.40.0