1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

Solved minor memory leaks when parser error occurs. Solved leaks in unit tests

This commit is contained in:
Ruben S. Montero 2010-08-08 13:20:24 +02:00
parent 190c324ca3
commit 62fd74e890
33 changed files with 1074 additions and 534 deletions

60
include/mem_collector.h Normal file
View File

@ -0,0 +1,60 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* 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 MEM_COLLECTOR_H_
#define MEM_COLLECTOR_H_
#define MEM_COLLECTOR_CHUNK 10
/**
* mem_collector. A simple struct to track strdup'ed strings in lex parsers.
* It prevents memory leaks in case of parse errors
*/
typedef struct mem_collector_
{
char** str_buffer;
int size;
} mem_collector;
/**
* Initialize mem_collector internal memory buffers. MUST be called before
* using any relared function
* @param mc pointer to the mem_collector
*/
void mem_collector_init(mem_collector * mc);
/**
* Frees mem_collector internal resources.
* @param mc pointer to the mem_collector
*/
void mem_collector_cleanup(mem_collector * mc);
/**
* Strdup's a string
* @param mc pointer to the mem_collector
* @param str string to be copied
* @return pointer to the new string
*/
char * mem_collector_strdup(mem_collector *mc, const char * str);
/**
* Frees a previously strdup'ed string with mem_collector_strdup
* @param mc pointer to the mem_collector
* @param str string to be freed
*/
void mem_collector_free(mem_collector *mc, const char * str);
#endif /*MEM_COLLECTOR_H_*/

View File

@ -31,6 +31,9 @@
#include <ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
using namespace std;
@ -54,7 +57,13 @@ class AuthManagerTest : public CppUnit::TestFixture
public:
AuthManagerTest(){};
~AuthManagerTest(){};
~AuthManagerTest(){
/*OpenSSL internal tables are allocated when an application starts up.
Since such tables do not grow in size over time they are harmless. */
EVP_cleanup() ;
CRYPTO_cleanup_all_ex_data();
};
/* ********************************************************************* */

View File

@ -23,7 +23,8 @@ lib_name='nebula_common'
# Sources to generate the library
source_files=[
'ActionManager.cc',
'Attribute.cc'
'Attribute.cc',
'mem_collector.c'
]
# Build library

111
src/common/mem_collector.c Normal file
View File

@ -0,0 +1,111 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* 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 <stdlib.h>
#include <string.h>
#include "mem_collector.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void mem_collector_init(mem_collector * mc)
{
int i;
mc->str_buffer = (char **) malloc (sizeof(char*) * MEM_COLLECTOR_CHUNK);
mc->size = MEM_COLLECTOR_CHUNK;
for (i=0; i< mc->size ; i++)
{
mc->str_buffer[i] = 0;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void mem_collector_cleanup(mem_collector * mc)
{
int i;
for (i=0; i< mc->size ; i++)
{
if ( mc->str_buffer[i] != 0 )
{
free(mc->str_buffer[i]);
}
}
free(mc->str_buffer);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
char * mem_collector_strdup(mem_collector *mc, const char * str)
{
int done = 0;
int i, old_size;
for (i=0; i< mc->size ; i++)
{
if ( mc->str_buffer[i] == 0 )
{
done = 1;
break;
}
}
if (done == 0)
{
old_size = mc->size;
mc->size = mc->size + MEM_COLLECTOR_CHUNK;
mc->str_buffer = (char **) realloc(mc->str_buffer,
sizeof(char*) * mc->size);
for ( i = old_size ; i < mc->size ; i++)
{
mc->str_buffer[i] = 0;
}
i = old_size;
}
mc->str_buffer[i] = strdup(str);
return mc->str_buffer[i];
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void mem_collector_free(mem_collector *mc, const char * str)
{
int i;
for (i=0; i< mc->size ; i++)
{
if ( mc->str_buffer[i] == str )
{
free(mc->str_buffer[i]);
mc->str_buffer[i] = 0;
break;
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -62,3 +62,4 @@ main_env.Append(LDFLAGS=["-g"])
main_env.Program('test_sa','single_attribute.cc')
main_env.Program('test_va','vector_attribute.cc')
main_env.Program('test_am','action_manager.cc')
main_env.Program('test_collector','mem_collector.cc')

View File

@ -0,0 +1,111 @@
extern "C"
{
#include "mem_collector.h"
}
#include <TestFixture.h>
#include <TestAssert.h>
#include <TestSuite.h>
#include <TestCaller.h>
#include <ui/text/TestRunner.h>
using namespace std;
class MemCollectorTest : public CppUnit::TestFixture
{
public:
void setUp()
{
}
void tearDown()
{
}
void test_all_free()
{
mem_collector mc;
mem_collector_init(&mc);
char * st1 = mem_collector_strdup(&mc,"HOLA");
char * st2 = mem_collector_strdup(&mc,"ADIOS");
char * st3 = mem_collector_strdup(&mc,"HELLO");
char * st4 = mem_collector_strdup(&mc,"BYE");
mem_collector_free(&mc,st1);
mem_collector_free(&mc,st2);
mem_collector_free(&mc,st3);
mem_collector_free(&mc,st4);
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK);
}
void test_not_free()
{
mem_collector mc;
mem_collector_init(&mc);
char * st1 = mem_collector_strdup(&mc,"HOLA");
char * st2 = mem_collector_strdup(&mc,"ADIOS");
char * st3 = mem_collector_strdup(&mc,"HELLO");
char * st4 = mem_collector_strdup(&mc,"BYE");
mem_collector_free(&mc,st2);
mem_collector_free(&mc,st4);
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK);
}
void test_realloc()
{
mem_collector mc;
int max_size;
max_size = (MEM_COLLECTOR_CHUNK * 3) + 1;
mem_collector_init(&mc);
for (int i=0; i < max_size ; i++)
{
mem_collector_strdup(&mc,"HOLA");
}
mem_collector_cleanup(&mc);
CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK * 4);
}
static CppUnit::TestSuite * suite()
{
CppUnit::TestSuite *ts=new CppUnit::TestSuite("mem_collector Tests");
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_all_free() Test",
&MemCollectorTest::test_all_free));
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_not_free() Test",
&MemCollectorTest::test_not_free));
ts->addTest(new CppUnit::TestCaller<MemCollectorTest>(
"test_realloc() Test",
&MemCollectorTest::test_realloc));
return ts;
}
};
int main(int argc, char ** argv)
{
CppUnit::TextUi::TestRunner tr;
tr.addTest(MemCollectorTest::suite());
tr.run();
return 0;
}

View File

@ -193,9 +193,9 @@ protected:
public:
HostPoolTest(){};
HostPoolTest(){xmlInitParser();};
~HostPoolTest(){};
~HostPoolTest(){xmlCleanupParser();};
/* ********************************************************************* */

View File

@ -95,6 +95,12 @@ public:
}
else
{
if (error_msg != 0 )
{
free(error_msg);
}
delete img_template;
return -2;
}
};
@ -198,9 +204,9 @@ protected:
public:
ImagePoolTest(){};
ImagePoolTest(){xmlInitParser();};
~ImagePoolTest(){};
~ImagePoolTest(){xmlCleanupParser();};
/* ********************************************************************* */

View File

@ -37,7 +37,8 @@ main_env.Append(CPPPATH=[
main_env.Append(LIBPATH=[
cwd+'/..',
cwd+'/../../xml',
cwd+'/../../../../log'
cwd+'/../../../../log',
cwd+'/../../../../common'
])
# Compile flags
@ -54,7 +55,8 @@ main_env.Append(LIBS=[
'cppunit',
'scheduler_xml',
'scheduler_pool',
'nebula_log'
'nebula_log',
'nebula_common'
])
main_env.Program('test_vm','VirtualMachineXMLTest.cc')

View File

@ -28,11 +28,11 @@ env.StaticLibrary(lib_name, source_files)
# Build daemon
env.Append(LIBS=[
'nebula_common',
'scheduler_sched',
'scheduler_pool',
'nebula_log',
'scheduler_xml',
'nebula_common',
'crypto',
'pthread'
])

View File

@ -63,14 +63,14 @@
#define YYLSP_NEEDED 1
/* Substitute the variable and function names. */
#define yyparse expr_arith_parse
#define yylex expr_arith_lex
#define yyerror expr_arith_error
#define yylval expr_arith_lval
#define yychar expr_arith_char
#define yydebug expr_arith_debug
#define yynerrs expr_arith_nerrs
#define yylloc expr_arith_lloc
#define yyparse expr_arith__parse
#define yylex expr_arith__lex
#define yyerror expr_arith__error
#define yylval expr_arith__lval
#define yychar expr_arith__char
#define yydebug expr_arith__debug
#define yynerrs expr_arith__nerrs
#define yylloc expr_arith__lloc
/* Copy the first part of user declarations. */
@ -82,6 +82,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <ctype.h>
#include <string.h>
@ -91,26 +92,46 @@
#include "ObjectXML.h"
#define YYERROR_VERBOSE
#define expr_arith_lex expr_lex
#define expr_arith__lex expr_lex
extern "C"
{
void expr_arith_error(
YYLTYPE * llocp,
ObjectXML * oxml,
int& result,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int expr_arith_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void expr_arith__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** error_msg,
const char * str);
int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg);
int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int expr_arith__parse(mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** errmsg);
int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = expr_arith__parse(&mc,oxml,result,errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
/* Line 189 of yacc.c */
#line 114 "expr_arith.cc"
#line 135 "expr_arith.cc"
/* Enabling traces. */
#ifndef YYDEBUG
@ -150,16 +171,16 @@ typedef union YYSTYPE
{
/* Line 214 of yacc.c */
#line 54 "expr_arith.y"
#line 78 "expr_arith.y"
char * val_str;
int val_int;
char * val_str;
int val_int;
float val_float;
/* Line 214 of yacc.c */
#line 163 "expr_arith.cc"
#line 184 "expr_arith.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -184,7 +205,7 @@ typedef struct YYLTYPE
/* Line 264 of yacc.c */
#line 188 "expr_arith.cc"
#line 209 "expr_arith.cc"
#ifdef short
# undef short
@ -472,8 +493,8 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 76, 76, 77, 80, 107, 108, 109, 110, 111,
112, 113, 114
0, 100, 100, 101, 104, 131, 132, 133, 134, 135,
136, 137, 138
};
#endif
@ -607,7 +628,7 @@ do \
} \
else \
{ \
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
@ -664,7 +685,7 @@ while (YYID (0))
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval, &yylloc)
# define YYLEX yylex (&yylval, &yylloc, mc)
#endif
/* Enable debugging if requested. */
@ -687,7 +708,7 @@ do { \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, Location, oxml, result, error_msg); \
Type, Value, Location, mc, oxml, result, error_msg); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
@ -701,14 +722,15 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, int& result, char ** error_msg)
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
mem_collector * mc;
ObjectXML * oxml;
int& result;
char ** error_msg;
@ -717,6 +739,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er
if (!yyvaluep)
return;
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (oxml);
YYUSE (result);
YYUSE (error_msg);
@ -741,14 +764,15 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, int& result, char ** error_msg)
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
mem_collector * mc;
ObjectXML * oxml;
int& result;
char ** error_msg;
@ -761,7 +785,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_ms
YY_LOCATION_PRINT (yyoutput, *yylocationp);
YYFPRINTF (yyoutput, ": ");
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg);
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg);
YYFPRINTF (yyoutput, ")");
}
@ -804,13 +828,14 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, ObjectXML * oxml, int& result, char ** error_msg)
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg)
#else
static void
yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
yy_reduce_print (yyvsp, yylsp, yyrule, mc, oxml, result, error_msg)
YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyrule;
mem_collector * mc;
ObjectXML * oxml;
int& result;
char ** error_msg;
@ -827,7 +852,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, &(yylsp[(yyi + 1) - (yynrhs)]) , oxml, result, error_msg);
, &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg);
YYFPRINTF (stderr, "\n");
}
}
@ -835,7 +860,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyvsp, yylsp, Rule, oxml, result, error_msg); \
yy_reduce_print (yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
@ -1086,14 +1111,15 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, ObjectXML * oxml, int& result, char ** error_msg)
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
YYLTYPE *yylocationp;
mem_collector * mc;
ObjectXML * oxml;
int& result;
char ** error_msg;
@ -1101,6 +1127,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
{
YYUSE (yyvaluep);
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (oxml);
YYUSE (result);
YYUSE (error_msg);
@ -1126,7 +1153,7 @@ int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (ObjectXML * oxml, int& result, char ** error_msg);
int yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg);
#else
int yyparse ();
#endif
@ -1154,10 +1181,11 @@ yyparse (YYPARSE_PARAM)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (ObjectXML * oxml, int& result, char ** error_msg)
yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg)
#else
int
yyparse (oxml, result, error_msg)
yyparse (mc, oxml, result, error_msg)
mem_collector * mc;
ObjectXML * oxml;
int& result;
char ** error_msg;
@ -1442,21 +1470,21 @@ yyreduce:
case 2:
/* Line 1464 of yacc.c */
#line 76 "expr_arith.y"
#line 100 "expr_arith.y"
{ result = static_cast<int>((yyvsp[(1) - (1)].val_float));;}
break;
case 3:
/* Line 1464 of yacc.c */
#line 77 "expr_arith.y"
#line 101 "expr_arith.y"
{ result = 0; ;}
break;
case 4:
/* Line 1464 of yacc.c */
#line 80 "expr_arith.y"
#line 104 "expr_arith.y"
{ float val = 0.0;
ostringstream xpath_t;
@ -1482,70 +1510,70 @@ yyreduce:
(yyval.val_float) = val;
free((yyvsp[(1) - (1)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (1)].val_str));
;}
break;
case 5:
/* Line 1464 of yacc.c */
#line 107 "expr_arith.y"
#line 131 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(1) - (1)].val_float); ;}
break;
case 6:
/* Line 1464 of yacc.c */
#line 108 "expr_arith.y"
#line 132 "expr_arith.y"
{ (yyval.val_float) = static_cast<float>((yyvsp[(1) - (1)].val_int)); ;}
break;
case 7:
/* Line 1464 of yacc.c */
#line 109 "expr_arith.y"
#line 133 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(1) - (3)].val_float) + (yyvsp[(3) - (3)].val_float);;}
break;
case 8:
/* Line 1464 of yacc.c */
#line 110 "expr_arith.y"
#line 134 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(1) - (3)].val_float) - (yyvsp[(3) - (3)].val_float);;}
break;
case 9:
/* Line 1464 of yacc.c */
#line 111 "expr_arith.y"
#line 135 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(1) - (3)].val_float) * (yyvsp[(3) - (3)].val_float);;}
break;
case 10:
/* Line 1464 of yacc.c */
#line 112 "expr_arith.y"
#line 136 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(1) - (3)].val_float) / (yyvsp[(3) - (3)].val_float);;}
break;
case 11:
/* Line 1464 of yacc.c */
#line 113 "expr_arith.y"
#line 137 "expr_arith.y"
{ (yyval.val_float) = - (yyvsp[(2) - (2)].val_float);;}
break;
case 12:
/* Line 1464 of yacc.c */
#line 114 "expr_arith.y"
#line 138 "expr_arith.y"
{ (yyval.val_float) = (yyvsp[(2) - (3)].val_float);;}
break;
/* Line 1464 of yacc.c */
#line 1549 "expr_arith.cc"
#line 1577 "expr_arith.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1581,7 +1609,7 @@ yyerrlab:
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
@ -1605,11 +1633,11 @@ yyerrlab:
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (&yylloc, oxml, result, error_msg, yymsg);
yyerror (&yylloc, mc, oxml, result, error_msg, yymsg);
}
else
{
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
@ -1633,7 +1661,7 @@ yyerrlab:
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc, oxml, result, error_msg);
yytoken, &yylval, &yylloc, mc, oxml, result, error_msg);
yychar = YYEMPTY;
}
}
@ -1690,7 +1718,7 @@ yyerrlab1:
yyerror_range[0] = *yylsp;
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp, oxml, result, error_msg);
yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@ -1730,7 +1758,7 @@ yyabortlab:
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (&yylloc, oxml, result, error_msg, YY_("memory exhausted"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
@ -1738,7 +1766,7 @@ yyexhaustedlab:
yyreturn:
if (yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc, oxml, result, error_msg);
yytoken, &yylval, &yylloc, mc, oxml, result, error_msg);
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
@ -1746,7 +1774,7 @@ yyreturn:
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp, oxml, result, error_msg);
yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg);
YYPOPSTACK (1);
}
#ifndef yyoverflow
@ -1764,11 +1792,12 @@ yyreturn:
/* Line 1684 of yacc.c */
#line 117 "expr_arith.y"
#line 141 "expr_arith.y"
extern "C" void expr_arith_error(
extern "C" void expr_arith__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** error_msg,

View File

@ -51,10 +51,10 @@ typedef union YYSTYPE
{
/* Line 1685 of yacc.c */
#line 54 "expr_arith.y"
#line 78 "expr_arith.y"
char * val_str;
int val_int;
char * val_str;
int val_int;
float val_float;

View File

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <ctype.h>
#include <string.h>
@ -29,38 +30,61 @@
#include "ObjectXML.h"
#define YYERROR_VERBOSE
#define expr_arith_lex expr_lex
#define expr_arith__lex expr_lex
extern "C"
{
void expr_arith_error(
YYLTYPE * llocp,
ObjectXML * oxml,
int& result,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int expr_arith_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void expr_arith__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** error_msg,
const char * str);
int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg);
int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int expr_arith__parse(mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** errmsg);
int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = expr_arith__parse(&mc,oxml,result,errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
%}
%parse-param {mem_collector * mc}
%parse-param {ObjectXML * oxml}
%parse-param {int& result}
%parse-param {char ** error_msg}
%lex-param {mem_collector * mc}
%union {
char * val_str;
int val_int;
char * val_str;
int val_int;
float val_float;
};
%defines
%locations
%pure_parser
%name-prefix = "expr_arith_"
%name-prefix = "expr_arith__"
%output = "expr_arith.cc"
%left '+' '-'
@ -102,7 +126,7 @@ expr: STRING { float val = 0.0;
$$ = val;
free($1);
mem_collector_free(mc,$1);
}
| FLOAT { $$ = $1; }
| INTEGER { $$ = static_cast<float>($1); }
@ -116,8 +140,9 @@ expr: STRING { float val = 0.0;
%%
extern "C" void expr_arith_error(
extern "C" void expr_arith__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
int& result,
char ** error_msg,

View File

@ -63,14 +63,14 @@
#define YYLSP_NEEDED 1
/* Substitute the variable and function names. */
#define yyparse expr_bool_parse
#define yylex expr_bool_lex
#define yyerror expr_bool_error
#define yylval expr_bool_lval
#define yychar expr_bool_char
#define yydebug expr_bool_debug
#define yynerrs expr_bool_nerrs
#define yylloc expr_bool_lloc
#define yyparse expr_bool__parse
#define yylex expr_bool__lex
#define yyerror expr_bool__error
#define yylval expr_bool__lval
#define yychar expr_bool__char
#define yydebug expr_bool__debug
#define yynerrs expr_bool__nerrs
#define yylloc expr_bool__lloc
/* Copy the first part of user declarations. */
@ -91,20 +91,40 @@
#include "ObjectXML.h"
#define YYERROR_VERBOSE
#define expr_bool_lex expr_lex
#define expr_bool__lex expr_lex
extern "C"
{
void expr_bool_error(
YYLTYPE * llocp,
ObjectXML * oxml,
bool& result,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void expr_bool__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** error_msg,
const char * str);
int expr_bool_parse(ObjectXML * oxml, bool& result, char ** errmsg);
int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int expr_bool__parse(mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** errmsg);
int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = expr_bool__parse(&mc,oxml,result,errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val);
@ -116,7 +136,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val);
/* Line 189 of yacc.c */
#line 120 "expr_bool.cc"
#line 140 "expr_bool.cc"
/* Enabling traces. */
#ifndef YYDEBUG
@ -156,7 +176,7 @@ typedef union YYSTYPE
{
/* Line 214 of yacc.c */
#line 60 "expr_bool.y"
#line 83 "expr_bool.y"
char * val_str;
int val_int;
@ -165,7 +185,7 @@ typedef union YYSTYPE
/* Line 214 of yacc.c */
#line 169 "expr_bool.cc"
#line 189 "expr_bool.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -190,7 +210,7 @@ typedef struct YYLTYPE
/* Line 264 of yacc.c */
#line 194 "expr_bool.cc"
#line 214 "expr_bool.cc"
#ifdef short
# undef short
@ -481,8 +501,8 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 80, 80, 81, 84, 91, 98, 105, 112, 119,
126, 133, 140, 148, 156, 157, 158, 159
0, 103, 103, 104, 107, 114, 121, 128, 135, 142,
149, 156, 163, 171, 179, 180, 181, 182
};
#endif
@ -619,7 +639,7 @@ do \
} \
else \
{ \
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
@ -676,7 +696,7 @@ while (YYID (0))
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval, &yylloc)
# define YYLEX yylex (&yylval, &yylloc, mc)
#endif
/* Enable debugging if requested. */
@ -699,7 +719,7 @@ do { \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, Location, oxml, result, error_msg); \
Type, Value, Location, mc, oxml, result, error_msg); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
@ -713,22 +733,24 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, bool& result, char ** error_msg)
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
ObjectXML * oxml;
bool& result;
char ** error_msg;
mem_collector * mc;
ObjectXML * oxml;
bool& result;
char ** error_msg;
#endif
{
if (!yyvaluep)
return;
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (oxml);
YYUSE (result);
YYUSE (error_msg);
@ -753,17 +775,18 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, bool& result, char ** error_msg)
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
ObjectXML * oxml;
bool& result;
char ** error_msg;
mem_collector * mc;
ObjectXML * oxml;
bool& result;
char ** error_msg;
#endif
{
if (yytype < YYNTOKENS)
@ -773,7 +796,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_ms
YY_LOCATION_PRINT (yyoutput, *yylocationp);
YYFPRINTF (yyoutput, ": ");
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg);
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg);
YYFPRINTF (yyoutput, ")");
}
@ -816,16 +839,17 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, ObjectXML * oxml, bool& result, char ** error_msg)
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg)
#else
static void
yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
yy_reduce_print (yyvsp, yylsp, yyrule, mc, oxml, result, error_msg)
YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyrule;
ObjectXML * oxml;
bool& result;
char ** error_msg;
mem_collector * mc;
ObjectXML * oxml;
bool& result;
char ** error_msg;
#endif
{
int yynrhs = yyr2[yyrule];
@ -839,7 +863,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, &(yylsp[(yyi + 1) - (yynrhs)]) , oxml, result, error_msg);
, &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg);
YYFPRINTF (stderr, "\n");
}
}
@ -847,7 +871,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg)
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyvsp, yylsp, Rule, oxml, result, error_msg); \
yy_reduce_print (yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
@ -1098,21 +1122,23 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, ObjectXML * oxml, bool& result, char ** error_msg)
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg)
yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
YYLTYPE *yylocationp;
ObjectXML * oxml;
bool& result;
char ** error_msg;
mem_collector * mc;
ObjectXML * oxml;
bool& result;
char ** error_msg;
#endif
{
YYUSE (yyvaluep);
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (oxml);
YYUSE (result);
YYUSE (error_msg);
@ -1138,7 +1164,7 @@ int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (ObjectXML * oxml, bool& result, char ** error_msg);
int yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg);
#else
int yyparse ();
#endif
@ -1166,13 +1192,14 @@ yyparse (YYPARSE_PARAM)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (ObjectXML * oxml, bool& result, char ** error_msg)
yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg)
#else
int
yyparse (oxml, result, error_msg)
ObjectXML * oxml;
bool& result;
char ** error_msg;
yyparse (mc, oxml, result, error_msg)
mem_collector * mc;
ObjectXML * oxml;
bool& result;
char ** error_msg;
#endif
#endif
{
@ -1454,171 +1481,171 @@ yyreduce:
case 2:
/* Line 1464 of yacc.c */
#line 80 "expr_bool.y"
#line 103 "expr_bool.y"
{ result=(yyvsp[(1) - (1)].val_int); ;}
break;
case 3:
/* Line 1464 of yacc.c */
#line 81 "expr_bool.y"
#line 104 "expr_bool.y"
{ result=true; ;}
break;
case 4:
/* Line 1464 of yacc.c */
#line 84 "expr_bool.y"
#line 107 "expr_bool.y"
{ int val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val == (yyvsp[(3) - (3)].val_int);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 5:
/* Line 1464 of yacc.c */
#line 91 "expr_bool.y"
#line 114 "expr_bool.y"
{ int val;
get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val);
(yyval.val_int) = val != (yyvsp[(4) - (4)].val_int);
free((yyvsp[(1) - (4)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (4)].val_str));;}
break;
case 6:
/* Line 1464 of yacc.c */
#line 98 "expr_bool.y"
#line 121 "expr_bool.y"
{ int val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val > (yyvsp[(3) - (3)].val_int);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 7:
/* Line 1464 of yacc.c */
#line 105 "expr_bool.y"
#line 128 "expr_bool.y"
{ int val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val < (yyvsp[(3) - (3)].val_int);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 8:
/* Line 1464 of yacc.c */
#line 112 "expr_bool.y"
#line 135 "expr_bool.y"
{ float val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val == (yyvsp[(3) - (3)].val_float);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 9:
/* Line 1464 of yacc.c */
#line 119 "expr_bool.y"
#line 142 "expr_bool.y"
{ float val;
get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val);
(yyval.val_int) = val != (yyvsp[(4) - (4)].val_float);
free((yyvsp[(1) - (4)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (4)].val_str));;}
break;
case 10:
/* Line 1464 of yacc.c */
#line 126 "expr_bool.y"
#line 149 "expr_bool.y"
{float val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val > (yyvsp[(3) - (3)].val_float);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 11:
/* Line 1464 of yacc.c */
#line 133 "expr_bool.y"
#line 156 "expr_bool.y"
{float val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val < (yyvsp[(3) - (3)].val_float);
free((yyvsp[(1) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));;}
break;
case 12:
/* Line 1464 of yacc.c */
#line 140 "expr_bool.y"
#line 163 "expr_bool.y"
{ string val;
get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val);
(yyval.val_int) = val.empty() ? false :fnmatch((yyvsp[(3) - (3)].val_str), val.c_str(), 0) == 0;
free((yyvsp[(1) - (3)].val_str));
free((yyvsp[(3) - (3)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (3)].val_str));;}
break;
case 13:
/* Line 1464 of yacc.c */
#line 148 "expr_bool.y"
#line 171 "expr_bool.y"
{ string val;
get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val);
(yyval.val_int) = val.empty() ? false : fnmatch((yyvsp[(4) - (4)].val_str), val.c_str(), 0) != 0;
free((yyvsp[(1) - (4)].val_str));
free((yyvsp[(4) - (4)].val_str));;}
mem_collector_free(mc,(yyvsp[(1) - (4)].val_str));
mem_collector_free(mc,(yyvsp[(4) - (4)].val_str));;}
break;
case 14:
/* Line 1464 of yacc.c */
#line 156 "expr_bool.y"
#line 179 "expr_bool.y"
{ (yyval.val_int) = (yyvsp[(1) - (3)].val_int) && (yyvsp[(3) - (3)].val_int); ;}
break;
case 15:
/* Line 1464 of yacc.c */
#line 157 "expr_bool.y"
#line 180 "expr_bool.y"
{ (yyval.val_int) = (yyvsp[(1) - (3)].val_int) || (yyvsp[(3) - (3)].val_int); ;}
break;
case 16:
/* Line 1464 of yacc.c */
#line 158 "expr_bool.y"
#line 181 "expr_bool.y"
{ (yyval.val_int) = ! (yyvsp[(2) - (2)].val_int); ;}
break;
case 17:
/* Line 1464 of yacc.c */
#line 159 "expr_bool.y"
#line 182 "expr_bool.y"
{ (yyval.val_int) = (yyvsp[(2) - (3)].val_int); ;}
break;
/* Line 1464 of yacc.c */
#line 1622 "expr_bool.cc"
#line 1649 "expr_bool.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1654,7 +1681,7 @@ yyerrlab:
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
@ -1678,11 +1705,11 @@ yyerrlab:
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (&yylloc, oxml, result, error_msg, yymsg);
yyerror (&yylloc, mc, oxml, result, error_msg, yymsg);
}
else
{
yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
@ -1706,7 +1733,7 @@ yyerrlab:
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc, oxml, result, error_msg);
yytoken, &yylval, &yylloc, mc, oxml, result, error_msg);
yychar = YYEMPTY;
}
}
@ -1763,7 +1790,7 @@ yyerrlab1:
yyerror_range[0] = *yylsp;
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp, oxml, result, error_msg);
yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@ -1803,7 +1830,7 @@ yyabortlab:
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (&yylloc, oxml, result, error_msg, YY_("memory exhausted"));
yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
@ -1811,7 +1838,7 @@ yyexhaustedlab:
yyreturn:
if (yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc, oxml, result, error_msg);
yytoken, &yylval, &yylloc, mc, oxml, result, error_msg);
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
@ -1819,7 +1846,7 @@ yyreturn:
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp, oxml, result, error_msg);
yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg);
YYPOPSTACK (1);
}
#ifndef yyoverflow
@ -1837,11 +1864,12 @@ yyreturn:
/* Line 1684 of yacc.c */
#line 162 "expr_bool.y"
#line 185 "expr_bool.y"
extern "C" void expr_bool_error(
extern "C" void expr_bool__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** error_msg,
@ -1863,6 +1891,8 @@ extern "C" void expr_bool_error(
llocp->first_column,
llocp->last_column);
}
result = false;
}
void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val)

View File

@ -51,7 +51,7 @@ typedef union YYSTYPE
{
/* Line 1685 of yacc.c */
#line 60 "expr_bool.y"
#line 83 "expr_bool.y"
char * val_str;
int val_int;

View File

@ -29,20 +29,40 @@
#include "ObjectXML.h"
#define YYERROR_VERBOSE
#define expr_bool_lex expr_lex
#define expr_bool__lex expr_lex
extern "C"
{
void expr_bool_error(
YYLTYPE * llocp,
ObjectXML * oxml,
bool& result,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void expr_bool__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** error_msg,
const char * str);
int expr_bool_parse(ObjectXML * oxml, bool& result, char ** errmsg);
int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int expr_bool__parse(mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** errmsg);
int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = expr_bool__parse(&mc,oxml,result,errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val);
@ -53,9 +73,12 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val);
%}
%parse-param {ObjectXML * oxml}
%parse-param {bool& result}
%parse-param {char ** error_msg}
%parse-param {mem_collector * mc}
%parse-param {ObjectXML * oxml}
%parse-param {bool& result}
%parse-param {char ** error_msg}
%lex-param {mem_collector * mc}
%union {
char * val_str;
@ -66,7 +89,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val);
%defines
%locations
%pure_parser
%name-prefix = "expr_bool_"
%name-prefix = "expr_bool__"
%output = "expr_bool.cc"
%left '!' '&' '|'
@ -86,72 +109,72 @@ expr: STRING '=' INTEGER { int val;
get_xml_attribute(oxml,$1,val);
$$ = val == $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '!' '=' INTEGER { int val;
get_xml_attribute(oxml,$1,val);
$$ = val != $4;
free($1);}
mem_collector_free(mc,$1);}
| STRING '>' INTEGER { int val;
get_xml_attribute(oxml,$1,val);
$$ = val > $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '<' INTEGER { int val;
get_xml_attribute(oxml,$1,val);
$$ = val < $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '=' FLOAT { float val;
get_xml_attribute(oxml,$1,val);
$$ = val == $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '!' '=' FLOAT { float val;
get_xml_attribute(oxml,$1,val);
$$ = val != $4;
free($1);}
mem_collector_free(mc,$1);}
| STRING '>' FLOAT {float val;
get_xml_attribute(oxml,$1,val);
$$ = val > $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '<' FLOAT {float val;
get_xml_attribute(oxml,$1,val);
$$ = val < $3;
free($1);}
mem_collector_free(mc,$1);}
| STRING '=' STRING { string val;
get_xml_attribute(oxml,$1,val);
$$ = val.empty() ? false :fnmatch($3, val.c_str(), 0) == 0;
free($1);
free($3);}
mem_collector_free(mc,$1);
mem_collector_free(mc,$3);}
| STRING '!''=' STRING { string val;
get_xml_attribute(oxml,$1,val);
$$ = val.empty() ? false : fnmatch($4, val.c_str(), 0) != 0;
free($1);
free($4);}
mem_collector_free(mc,$1);
mem_collector_free(mc,$4);}
| expr '&' expr { $$ = $1 && $3; }
| expr '|' expr { $$ = $1 || $3; }
@ -161,8 +184,9 @@ expr: STRING '=' INTEGER { int val;
%%
extern "C" void expr_bool_error(
extern "C" void expr_bool__error(
YYLTYPE * llocp,
mem_collector * mc,
ObjectXML * oxml,
bool& result,
char ** error_msg,
@ -184,6 +208,8 @@ extern "C" void expr_bool_error(
llocp->first_column,
llocp->last_column);
}
result = false;
}
void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val)

View File

@ -512,12 +512,12 @@ char *expr_text;
#line 18 "expr_parser.l"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "expr_bool.h"
#include "expr_arith.h"
#include "mem_collector.h"
#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = expr_lineno; \
llocp->first_column = llocp->last_column; \
@ -808,7 +808,7 @@ YY_RULE_SETUP
case 2:
YY_RULE_SETUP
#line 44 "expr_parser.l"
{ lvalp->val_str = strdup(expr_text);
{ lvalp->val_str = mem_collector_strdup(mc,expr_text);
return STRING;}
YY_BREAK
case 3:
@ -821,7 +821,7 @@ case 4:
/* rule 4 can match eol */
YY_RULE_SETUP
#line 50 "expr_parser.l"
{ lvalp->val_str = strdup(expr_text+1);
{ lvalp->val_str = mem_collector_strdup(mc,expr_text+1);
lvalp->val_str[expr_leng-2] = '\0';
return STRING;}
YY_BREAK

View File

@ -17,12 +17,12 @@
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "expr_bool.h"
#include "expr_arith.h"
#include "mem_collector.h"
#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = yylineno; \
llocp->first_column = llocp->last_column; \
@ -41,13 +41,13 @@
/* --- Strings, also quoted form --- */
[A-Za-z][0-9A-Za-z_]* { lvalp->val_str = strdup(yytext);
[A-Za-z][0-9A-Za-z_]* { lvalp->val_str = mem_collector_strdup(mc,yytext);
return STRING;}
\"\" { lvalp->val_str = NULL;
return STRING;}
\"[^\"]*\" { lvalp->val_str = strdup(yytext+1);
\"[^\"]*\" { lvalp->val_str = mem_collector_strdup(mc,yytext+1);
lvalp->val_str[yyleng-2] = '\0';
return STRING;}

View File

@ -240,7 +240,7 @@ public:
// is not set to false.
rc = obj.eval_bool( "TOTALCPU ^ * - = abc", res, &err );
CPPUNIT_ASSERT( rc != 0 );
// CPPUNIT_ASSERT( res == false );
CPPUNIT_ASSERT( res == false );
if (err != 0)
{

View File

@ -34,6 +34,7 @@ main_env.Append(CPPPATH=[
# Library dirs
main_env.Append(LIBPATH=[
cwd+'/../../../../common',
'../'
])
@ -49,7 +50,8 @@ main_env.Append(LDFLAGS=["-g"])
# Libraries
main_env.Append(LIBS=[
'cppunit',
'scheduler_xml'
'scheduler_xml',
'nebula_common'
])
main_env.Program('test_xml','ObjectXMLTest.cc')

View File

@ -542,14 +542,16 @@ char *template_text;
#include <pthread.h>
#include "template_syntax.h"
#include "mem_collector.h"
#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \
mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = template_lineno; \
llocp->first_column = llocp->last_column; \
#define YY_USER_ACTION llocp->first_line = template_lineno; \
llocp->first_column = llocp->last_column; \
llocp->last_column += template_leng;
#line 553 "template_parser.c"
#line 555 "template_parser.c"
#define INITIAL 0
#define VALUE 1
@ -730,13 +732,13 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 40 "template_parser.l"
#line 42 "template_parser.l"
/* ------------------------------------------------------------------------- */
/* Comments (lines with an starting #), and empty lines */
/* ------------------------------------------------------------------------- */
#line 740 "template_parser.c"
#line 742 "template_parser.c"
if ( !(yy_init) )
{
@ -832,13 +834,13 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
#line 45 "template_parser.l"
#line 47 "template_parser.l"
;
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 46 "template_parser.l"
#line 48 "template_parser.l"
;
YY_BREAK
/* ------------------------------------------------------------------------- */
@ -846,8 +848,9 @@ YY_RULE_SETUP
/* ------------------------------------------------------------------------- */
case 3:
YY_RULE_SETUP
#line 51 "template_parser.l"
{ lvalp->val_str = strdup(template_text); return VARIABLE;}
#line 53 "template_parser.l"
{ lvalp->val_str = mem_collector_strdup(mc,template_text);
return VARIABLE; }
YY_BREAK
/* ------------------------------------------------------------------------ */
/* TOKENS */
@ -856,31 +859,31 @@ YY_RULE_SETUP
/* ------------------------------------------------------------------------ */
case 4:
YY_RULE_SETUP
#line 58 "template_parser.l"
#line 61 "template_parser.l"
{ BEGIN VALUE; return EQUAL;}
YY_BREAK
case 5:
/* rule 5 can match eol */
YY_RULE_SETUP
#line 60 "template_parser.l"
#line 63 "template_parser.l"
{ return EQUAL_EMPTY;}
YY_BREAK
case 6:
/* rule 6 can match eol */
YY_RULE_SETUP
#line 62 "template_parser.l"
#line 65 "template_parser.l"
{ return COMMA;}
YY_BREAK
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
#line 64 "template_parser.l"
#line 67 "template_parser.l"
{ return CBRACKET;}
YY_BREAK
case 8:
/* rule 8 can match eol */
YY_RULE_SETUP
#line 66 "template_parser.l"
#line 69 "template_parser.l"
{ BEGIN(INITIAL); return OBRACKET;}
YY_BREAK
/* ------------------------------------------------------------------------ */
@ -891,8 +894,8 @@ YY_RULE_SETUP
case 9:
/* rule 9 can match eol */
YY_RULE_SETUP
#line 73 "template_parser.l"
{ lvalp->val_str = strdup(template_text+1);
#line 76 "template_parser.l"
{ lvalp->val_str = mem_collector_strdup(mc,template_text+1);
lvalp->val_str[template_leng-2] = '\0';
BEGIN(INITIAL); return STRING; }
YY_BREAK
@ -903,16 +906,16 @@ YY_RULE_SETUP
*/
case 10:
YY_RULE_SETUP
#line 82 "template_parser.l"
{ lvalp->val_str = strdup(template_text);
#line 85 "template_parser.l"
{ lvalp->val_str = mem_collector_strdup(mc,template_text);
BEGIN(INITIAL); return STRING;}
YY_BREAK
case 11:
YY_RULE_SETUP
#line 84 "template_parser.l"
#line 87 "template_parser.l"
ECHO;
YY_BREAK
#line 916 "template_parser.c"
#line 919 "template_parser.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(VALUE):
yyterminate();
@ -1882,7 +1885,7 @@ void template_free (void * ptr )
#define YYTABLES_NAME "yytables"
#line 84 "template_parser.l"
#line 87 "template_parser.l"

View File

@ -21,11 +21,13 @@
#include <pthread.h>
#include "template_syntax.h"
#include "mem_collector.h"
#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \
mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = yylineno; \
llocp->first_column = llocp->last_column; \
#define YY_USER_ACTION llocp->first_line = yylineno; \
llocp->first_column = llocp->last_column; \
llocp->last_column += yyleng;
%}
@ -48,7 +50,8 @@ STRING [^=#[:blank:]\n,\[\]]+
/* ------------------------------------------------------------------------- */
/* Variable: Alpha numeric charatcers and '_' */
/* ------------------------------------------------------------------------- */
[[:alnum:]_]+ { lvalp->val_str = strdup(yytext); return VARIABLE;}
[[:alnum:]_]+ { lvalp->val_str = mem_collector_strdup(mc,yytext);
return VARIABLE; }
/* ------------------------------------------------------------------------ */
/* TOKENS */
@ -70,7 +73,7 @@ STRING [^=#[:blank:]\n,\[\]]+
/* - String in double quoted form */
/* - Anything but =,][# and blanks */
/* ------------------------------------------------------------------------ */
<VALUE>\"([^\"]|"\\\"")+\" { lvalp->val_str = strdup(yytext+1);
<VALUE>\"([^\"]|"\\\"")+\" { lvalp->val_str = mem_collector_strdup(mc,yytext+1);
lvalp->val_str[yyleng-2] = '\0';
BEGIN(INITIAL); return STRING; }
@ -79,7 +82,7 @@ STRING [^=#[:blank:]\n,\[\]]+
lvalp->val_str[yyleng-2] = '\0';
BEGIN(INITIAL); return STRING; }
*/
<VALUE>{STRING} { lvalp->val_str = strdup(yytext);
<VALUE>{STRING} { lvalp->val_str = mem_collector_strdup(mc,yytext);
BEGIN(INITIAL); return STRING;}
%%

View File

@ -63,14 +63,14 @@
#define YYLSP_NEEDED 1
/* Substitute the variable and function names. */
#define yyparse template_parse
#define yylex template_lex
#define yyerror template_error
#define yylval template_lval
#define yychar template_char
#define yydebug template_debug
#define yynerrs template_nerrs
#define yylloc template_lloc
#define yyparse template__parse
#define yylex template__lex
#define yyerror template__error
#define yylval template__lval
#define yychar template__char
#define yydebug template__debug
#define yynerrs template__nerrs
#define yylloc template__lloc
/* Copy the first part of user declarations. */
@ -88,27 +88,47 @@
#include "template_syntax.h"
#include "Template.h"
#define template__lex template_lex
#define YYERROR_VERBOSE
#define TEMPLATE_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \
(int(*)(int))toupper)
extern "C"
{
void template_error(
YYLTYPE * llocp,
Template * tmpl,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void template__error(
YYLTYPE * llocp,
mem_collector * mc,
Template * tmpl,
char ** error_msg,
const char * str);
int template_parse(Template * tmpl, char ** errmsg);
int template__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int template__parse(mem_collector * mc, Template * tmpl, char ** errmsg);
int template_parse(Template * tmpl, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = template__parse(&mc, tmpl, errmsg);
mem_collector_cleanup(&mc);
return rc;
}
static string& unescape (string &str);
}
static string& unescape (string &str);
/* Line 189 of yacc.c */
#line 112 "template_syntax.cc"
#line 132 "template_syntax.cc"
/* Enabling traces. */
#ifndef YYDEBUG
@ -152,7 +172,7 @@ typedef union YYSTYPE
{
/* Line 214 of yacc.c */
#line 51 "template_syntax.y"
#line 74 "template_syntax.y"
char * val_str;
void * val_attr;
@ -160,7 +180,7 @@ typedef union YYSTYPE
/* Line 214 of yacc.c */
#line 164 "template_syntax.cc"
#line 184 "template_syntax.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -185,7 +205,7 @@ typedef struct YYLTYPE
/* Line 264 of yacc.c */
#line 189 "template_syntax.cc"
#line 209 "template_syntax.cc"
#ifdef short
# undef short
@ -472,7 +492,7 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 71, 71, 72, 75, 88, 102, 116, 132
0, 94, 94, 95, 98, 111, 125, 139, 155
};
#endif
@ -602,7 +622,7 @@ do \
} \
else \
{ \
yyerror (&yylloc, tmpl, error_msg, YY_("syntax error: cannot back up")); \
yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
@ -659,7 +679,7 @@ while (YYID (0))
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval, &yylloc)
# define YYLEX yylex (&yylval, &yylloc, mc)
#endif
/* Enable debugging if requested. */
@ -682,7 +702,7 @@ do { \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, Location, tmpl, error_msg); \
Type, Value, Location, mc, tmpl, error_msg); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
@ -696,21 +716,23 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, Template * tmpl, char ** error_msg)
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, tmpl, error_msg)
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
Template * tmpl;
char ** error_msg;
mem_collector * mc;
Template * tmpl;
char ** error_msg;
#endif
{
if (!yyvaluep)
return;
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (tmpl);
YYUSE (error_msg);
# ifdef YYPRINT
@ -734,16 +756,17 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, tmpl, error_msg)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, Template * tmpl, char ** error_msg)
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, tmpl, error_msg)
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
Template * tmpl;
char ** error_msg;
mem_collector * mc;
Template * tmpl;
char ** error_msg;
#endif
{
if (yytype < YYNTOKENS)
@ -753,7 +776,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, tmpl, error_msg)
YY_LOCATION_PRINT (yyoutput, *yylocationp);
YYFPRINTF (yyoutput, ": ");
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, tmpl, error_msg);
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg);
YYFPRINTF (yyoutput, ")");
}
@ -796,15 +819,16 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, Template * tmpl, char ** error_msg)
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, Template * tmpl, char ** error_msg)
#else
static void
yy_reduce_print (yyvsp, yylsp, yyrule, tmpl, error_msg)
yy_reduce_print (yyvsp, yylsp, yyrule, mc, tmpl, error_msg)
YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyrule;
Template * tmpl;
char ** error_msg;
mem_collector * mc;
Template * tmpl;
char ** error_msg;
#endif
{
int yynrhs = yyr2[yyrule];
@ -818,7 +842,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, tmpl, error_msg)
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, &(yylsp[(yyi + 1) - (yynrhs)]) , tmpl, error_msg);
, &(yylsp[(yyi + 1) - (yynrhs)]) , mc, tmpl, error_msg);
YYFPRINTF (stderr, "\n");
}
}
@ -826,7 +850,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, tmpl, error_msg)
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyvsp, yylsp, Rule, tmpl, error_msg); \
yy_reduce_print (yyvsp, yylsp, Rule, mc, tmpl, error_msg); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
@ -1077,20 +1101,22 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, Template * tmpl, char ** error_msg)
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, yylocationp, tmpl, error_msg)
yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
YYLTYPE *yylocationp;
Template * tmpl;
char ** error_msg;
mem_collector * mc;
Template * tmpl;
char ** error_msg;
#endif
{
YYUSE (yyvaluep);
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (tmpl);
YYUSE (error_msg);
@ -1115,7 +1141,7 @@ int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (Template * tmpl, char ** error_msg);
int yyparse (mem_collector * mc, Template * tmpl, char ** error_msg);
#else
int yyparse ();
#endif
@ -1143,12 +1169,13 @@ yyparse (YYPARSE_PARAM)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (Template * tmpl, char ** error_msg)
yyparse (mem_collector * mc, Template * tmpl, char ** error_msg)
#else
int
yyparse (tmpl, error_msg)
Template * tmpl;
char ** error_msg;
yyparse (mc, tmpl, error_msg)
mem_collector * mc;
Template * tmpl;
char ** error_msg;
#endif
#endif
{
@ -1430,7 +1457,7 @@ yyreduce:
case 4:
/* Line 1464 of yacc.c */
#line 76 "template_syntax.y"
#line 99 "template_syntax.y"
{
Attribute * pattr;
string name((yyvsp[(1) - (3)].val_str));
@ -1440,15 +1467,15 @@ yyreduce:
tmpl->set(pattr);
free((yyvsp[(1) - (3)].val_str));
free((yyvsp[(3) - (3)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (3)].val_str));
;}
break;
case 5:
/* Line 1464 of yacc.c */
#line 89 "template_syntax.y"
#line 112 "template_syntax.y"
{
Attribute * pattr;
string name((yyvsp[(1) - (5)].val_str));
@ -1460,14 +1487,14 @@ yyreduce:
tmpl->set(pattr);
delete amap;
free((yyvsp[(1) - (5)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (5)].val_str));
;}
break;
case 6:
/* Line 1464 of yacc.c */
#line 103 "template_syntax.y"
#line 126 "template_syntax.y"
{
Attribute * pattr;
string name((yyvsp[(1) - (2)].val_str));
@ -1477,14 +1504,14 @@ yyreduce:
tmpl->set(pattr);
free((yyvsp[(1) - (2)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (2)].val_str));
;}
break;
case 7:
/* Line 1464 of yacc.c */
#line 117 "template_syntax.y"
#line 140 "template_syntax.y"
{
map<string,string>* vattr;
string name((yyvsp[(1) - (3)].val_str));
@ -1497,15 +1524,15 @@ yyreduce:
(yyval.val_attr) = static_cast<void *>(vattr);
free((yyvsp[(1) - (3)].val_str));
free((yyvsp[(3) - (3)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (3)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (3)].val_str));
;}
break;
case 8:
/* Line 1464 of yacc.c */
#line 133 "template_syntax.y"
#line 156 "template_syntax.y"
{
string name((yyvsp[(3) - (5)].val_str));
string value((yyvsp[(5) - (5)].val_str));
@ -1518,15 +1545,15 @@ yyreduce:
attrmap->insert(make_pair(name,unescape(value)));
(yyval.val_attr) = (yyvsp[(1) - (5)].val_attr);
free((yyvsp[(3) - (5)].val_str));
free((yyvsp[(5) - (5)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (5)].val_str));
mem_collector_free(mc,(yyvsp[(5) - (5)].val_str));
;}
break;
/* Line 1464 of yacc.c */
#line 1530 "template_syntax.cc"
#line 1557 "template_syntax.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1562,7 +1589,7 @@ yyerrlab:
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (&yylloc, tmpl, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
@ -1586,11 +1613,11 @@ yyerrlab:
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (&yylloc, tmpl, error_msg, yymsg);
yyerror (&yylloc, mc, tmpl, error_msg, yymsg);
}
else
{
yyerror (&yylloc, tmpl, error_msg, YY_("syntax error"));
yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
@ -1614,7 +1641,7 @@ yyerrlab:
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc, tmpl, error_msg);
yytoken, &yylval, &yylloc, mc, tmpl, error_msg);
yychar = YYEMPTY;
}
}
@ -1671,7 +1698,7 @@ yyerrlab1:
yyerror_range[0] = *yylsp;
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp, tmpl, error_msg);
yystos[yystate], yyvsp, yylsp, mc, tmpl, error_msg);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@ -1711,7 +1738,7 @@ yyabortlab:
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (&yylloc, tmpl, error_msg, YY_("memory exhausted"));
yyerror (&yylloc, mc, tmpl, error_msg, YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
@ -1719,7 +1746,7 @@ yyexhaustedlab:
yyreturn:
if (yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc, tmpl, error_msg);
yytoken, &yylval, &yylloc, mc, tmpl, error_msg);
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
@ -1727,7 +1754,7 @@ yyreturn:
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp, tmpl, error_msg);
yystos[*yyssp], yyvsp, yylsp, mc, tmpl, error_msg);
YYPOPSTACK (1);
}
#ifndef yyoverflow
@ -1745,42 +1772,43 @@ yyreturn:
/* Line 1684 of yacc.c */
#line 149 "template_syntax.y"
#line 172 "template_syntax.y"
string& unescape (string &str)
{
size_t pos;
while ((pos = str.find("\\\"")) != string::npos)
{
str.replace(pos,2,"\"");
}
return str;
}
extern "C" void template_error(
YYLTYPE * llocp,
Template * tmpl,
char ** error_msg,
const char * str)
extern "C" void template__error(
YYLTYPE * llocp,
mem_collector * mc,
Template * tmpl,
char ** error_msg,
const char * str)
{
int length;
int length;
length = strlen(str)+ 64;
length = strlen(str)+ 64;
*error_msg = (char *) malloc(sizeof(char)*length);
*error_msg = (char *) malloc(sizeof(char)*length);
if (*error_msg != 0)
{
snprintf(*error_msg,
length,
"%s at line %i, columns %i:%i",
str,
llocp->first_line,
llocp->first_column,
llocp->last_column);
}
if (*error_msg != 0)
{
snprintf(*error_msg,
length,
"%s at line %i, columns %i:%i",
str,
llocp->first_line,
llocp->first_column,
llocp->last_column);
}
}

View File

@ -55,7 +55,7 @@ typedef union YYSTYPE
{
/* Line 1685 of yacc.c */
#line 51 "template_syntax.y"
#line 74 "template_syntax.y"
char * val_str;
void * val_attr;

View File

@ -26,27 +26,50 @@
#include "template_syntax.h"
#include "Template.h"
#define template__lex template_lex
#define YYERROR_VERBOSE
#define TEMPLATE_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \
(int(*)(int))toupper)
extern "C"
{
void template_error(
YYLTYPE * llocp,
Template * tmpl,
char ** error_msg,
const char * str);
#include "mem_collector.h"
int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void template__error(
YYLTYPE * llocp,
mem_collector * mc,
Template * tmpl,
char ** error_msg,
const char * str);
int template_parse(Template * tmpl, char ** errmsg);
int template__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int template__parse(mem_collector * mc, Template * tmpl, char ** errmsg);
int template_parse(Template * tmpl, char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = template__parse(&mc, tmpl, errmsg);
mem_collector_cleanup(&mc);
return rc;
}
static string& unescape (string &str);
}
static string& unescape (string &str);
%}
%parse-param {Template * tmpl}
%parse-param {char ** error_msg}
%parse-param {mem_collector * mc}
%parse-param {Template * tmpl}
%parse-param {char ** error_msg}
%lex-param {mem_collector * mc}
%union {
char * val_str;
@ -56,7 +79,7 @@ static string& unescape (string &str);
%defines
%locations
%pure_parser
%name-prefix = "template_"
%name-prefix = "template__"
%output = "template_syntax.cc"
%token EQUAL COMMA OBRACKET CBRACKET EQUAL_EMPTY
@ -82,8 +105,8 @@ attribute: VARIABLE EQUAL STRING
tmpl->set(pattr);
free($1);
free($3);
mem_collector_free(mc,$1);
mem_collector_free(mc,$3);
}
| VARIABLE EQUAL OBRACKET array_val CBRACKET
{
@ -97,7 +120,7 @@ attribute: VARIABLE EQUAL STRING
tmpl->set(pattr);
delete amap;
free($1);
mem_collector_free(mc,$1);
}
| VARIABLE EQUAL_EMPTY
{
@ -109,7 +132,7 @@ attribute: VARIABLE EQUAL STRING
tmpl->set(pattr);
free($1);
mem_collector_free(mc,$1);
}
;
@ -126,8 +149,8 @@ array_val: VARIABLE EQUAL STRING
$$ = static_cast<void *>(vattr);
free($1);
free($3);
mem_collector_free(mc,$1);
mem_collector_free(mc,$3);
}
| array_val COMMA VARIABLE EQUAL STRING
{
@ -142,8 +165,8 @@ array_val: VARIABLE EQUAL STRING
attrmap->insert(make_pair(name,unescape(value)));
$$ = $1;
free($3);
free($5);
mem_collector_free(mc,$3);
mem_collector_free(mc,$5);
}
;
%%
@ -151,35 +174,36 @@ array_val: VARIABLE EQUAL STRING
string& unescape (string &str)
{
size_t pos;
while ((pos = str.find("\\\"")) != string::npos)
{
str.replace(pos,2,"\"");
}
return str;
}
extern "C" void template_error(
YYLTYPE * llocp,
Template * tmpl,
char ** error_msg,
const char * str)
extern "C" void template__error(
YYLTYPE * llocp,
mem_collector * mc,
Template * tmpl,
char ** error_msg,
const char * str)
{
int length;
int length;
length = strlen(str)+ 64;
length = strlen(str)+ 64;
*error_msg = (char *) malloc(sizeof(char)*length);
*error_msg = (char *) malloc(sizeof(char)*length);
if (*error_msg != 0)
{
snprintf(*error_msg,
length,
"%s at line %i, columns %i:%i",
str,
llocp->first_line,
llocp->first_column,
llocp->last_column);
}
if (*error_msg != 0)
{
snprintf(*error_msg,
length,
"%s at line %i, columns %i:%i",
str,
llocp->first_line,
llocp->first_column,
llocp->last_column);
}
}

View File

@ -206,9 +206,9 @@ protected:
};
public:
VirtualMachinePoolTest(){};
VirtualMachinePoolTest(){xmlInitParser();};
~VirtualMachinePoolTest(){};
~VirtualMachinePoolTest(){xmlCleanupParser();};
/* ********************************************************************* */

View File

@ -521,14 +521,16 @@ char *vm_var_text;
#include <pthread.h>
#include "vm_var_syntax.h"
#include "mem_collector.h"
#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \
mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = vm_var_lineno; \
llocp->first_column = llocp->last_column; \
#define YY_USER_ACTION llocp->first_line = vm_var_lineno; \
llocp->first_column = llocp->last_column; \
llocp->last_column += vm_var_leng;
#line 532 "vm_var_parser.c"
#line 534 "vm_var_parser.c"
#define INITIAL 0
#define VAR 1
@ -709,7 +711,7 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 38 "vm_var_parser.l"
#line 40 "vm_var_parser.l"
/* ------------------------------------------------------------------------- */
@ -720,7 +722,7 @@ YY_DECL
/* $NUM.CONTEXT_VARIABLE */
/* ------------------------------------------------------------------------- */
#line 724 "vm_var_parser.c"
#line 726 "vm_var_parser.c"
if ( !(yy_init) )
{
@ -815,58 +817,60 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 48 "vm_var_parser.l"
#line 50 "vm_var_parser.l"
{ BEGIN VAR;}
YY_BREAK
case 2:
YY_RULE_SETUP
#line 50 "vm_var_parser.l"
#line 52 "vm_var_parser.l"
{ return EQUAL;}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 51 "vm_var_parser.l"
#line 53 "vm_var_parser.l"
{ return COMMA;}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 52 "vm_var_parser.l"
#line 54 "vm_var_parser.l"
{ return OBRACKET;}
YY_BREAK
case 5:
YY_RULE_SETUP
#line 53 "vm_var_parser.l"
#line 55 "vm_var_parser.l"
{ return CBRACKET;}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 55 "vm_var_parser.l"
{ lvalp->val_str = strdup(vm_var_text);
#line 57 "vm_var_parser.l"
{ lvalp->val_str =
mem_collector_strdup(mc,vm_var_text);
return VARIABLE;}
YY_BREAK
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
#line 58 "vm_var_parser.l"
{ lvalp->val_str = strdup(vm_var_text+1);
#line 61 "vm_var_parser.l"
{ lvalp->val_str =
mem_collector_strdup(mc,vm_var_text+1);
lvalp->val_str[vm_var_leng-2] = '\0';
return STRING;}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 62 "vm_var_parser.l"
#line 66 "vm_var_parser.l"
{ lvalp->val_char = '\0';
return EOA;}
YY_BREAK
case 9:
YY_RULE_SETUP
#line 65 "vm_var_parser.l"
#line 69 "vm_var_parser.l"
{ lvalp->val_char = *vm_var_text;
BEGIN(INITIAL);
return EOA;}
YY_BREAK
case YY_STATE_EOF(VAR):
#line 69 "vm_var_parser.l"
#line 73 "vm_var_parser.l"
{ lvalp->val_char = '\0';
BEGIN(INITIAL);
return EOA;}
@ -877,15 +881,15 @@ case YY_STATE_EOF(VAR):
case 10:
/* rule 10 can match eol */
YY_RULE_SETUP
#line 77 "vm_var_parser.l"
{ lvalp->val_str = strdup(vm_var_text); return RSTRING;}
#line 81 "vm_var_parser.l"
{ lvalp->val_str = mem_collector_strdup(mc,vm_var_text); return RSTRING;}
YY_BREAK
case 11:
YY_RULE_SETUP
#line 79 "vm_var_parser.l"
#line 83 "vm_var_parser.l"
ECHO;
YY_BREAK
#line 889 "vm_var_parser.c"
#line 893 "vm_var_parser.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@ -1854,7 +1858,7 @@ void vm_var_free (void * ptr )
#define YYTABLES_NAME "yytables"
#line 79 "vm_var_parser.l"
#line 83 "vm_var_parser.l"

View File

@ -21,11 +21,13 @@
#include <pthread.h>
#include "vm_var_syntax.h"
#include "mem_collector.h"
#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp)
#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \
mem_collector *mc)
#define YY_USER_ACTION llocp->first_line = yylineno; \
llocp->first_column = llocp->last_column; \
#define YY_USER_ACTION llocp->first_line = yylineno; \
llocp->first_column = llocp->last_column; \
llocp->last_column += yyleng;
%}
@ -52,10 +54,12 @@
<VAR>\[[[:blank:]]* { return OBRACKET;}
<VAR>[[:blank:]]*\] { return CBRACKET;}
<VAR>[[:alnum:]_]+ { lvalp->val_str = strdup(yytext);
<VAR>[[:alnum:]_]+ { lvalp->val_str =
mem_collector_strdup(mc,yytext);
return VARIABLE;}
<VAR>\"[^\"]*\" { lvalp->val_str = strdup(yytext+1);
<VAR>\"[^\"]*\" { lvalp->val_str =
mem_collector_strdup(mc,yytext+1);
lvalp->val_str[yyleng-2] = '\0';
return STRING;}
@ -74,7 +78,7 @@
/* Just copy the string verbatim till we find a variable (starts with $) */
/* ------------------------------------------------------------------------- */
[^\$]+ { lvalp->val_str = strdup(yytext); return RSTRING;}
[^\$]+ { lvalp->val_str = mem_collector_strdup(mc,yytext); return RSTRING;}
%%

View File

@ -63,14 +63,14 @@
#define YYLSP_NEEDED 1
/* Substitute the variable and function names. */
#define yyparse vm_var_parse
#define yylex vm_var_lex
#define yyerror vm_var_error
#define yylval vm_var_lval
#define yychar vm_var_char
#define yydebug vm_var_debug
#define yynerrs vm_var_nerrs
#define yylloc vm_var_lloc
#define yyparse vm_var__parse
#define yylex vm_var__lex
#define yyerror vm_var__error
#define yylval vm_var__lval
#define yychar vm_var__char
#define yydebug vm_var__debug
#define yynerrs vm_var__nerrs
#define yylloc vm_var__lloc
/* Copy the first part of user declarations. */
@ -91,24 +91,46 @@
#include "VirtualMachine.h"
#include "Nebula.h"
#define vm_var__lex vm_var_lex
#define YYERROR_VERBOSE
#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \
(int(*)(int))toupper)
extern "C"
{
void vm_var_error(
YYLTYPE * llocp,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg,
const char * str);
#include "mem_collector.h"
int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void vm_var__error(
YYLTYPE * llocp,
mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg,
const char * str);
int vm_var_parse (VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg);
int vm_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int vm_var__parse (mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg);
int vm_var_parse (VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = vm_var__parse(&mc, vm, parsed, errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
/* -------------------------------------------------------------------------- */
@ -180,7 +202,7 @@ void insert_single(VirtualMachine * vm,
string value = "";
vm->get_template_attribute(name.c_str(),value);
parsed << value;
}
@ -193,17 +215,17 @@ void insert_vector(VirtualMachine * vm,
const string& vname,
const string& vvar,
const string& vval)
{
{
vector<const Attribute*> values;
const VectorAttribute * vattr = 0;
int num;
if ( name == "NETWORK")
{
string value;
get_network_attribute(vm,vname,vvar,vval,value);
if (!value.empty())
@ -218,19 +240,19 @@ void insert_vector(VirtualMachine * vm,
{
return;
}
if ( vvar.empty() )
{
vattr = dynamic_cast<const VectorAttribute *>(values[0]);
vattr = dynamic_cast<const VectorAttribute *>(values[0]);
}
else
{
const VectorAttribute * tmp = 0;
for (int i=0 ; i < num ; i++)
{
tmp = dynamic_cast<const VectorAttribute *>(values[i]);
if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval ))
{
vattr = tmp;
@ -244,14 +266,14 @@ void insert_vector(VirtualMachine * vm,
parsed << vattr->vector_value(vname.c_str());
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* Line 189 of yacc.c */
#line 255 "vm_var_syntax.cc"
#line 277 "vm_var_syntax.cc"
/* Enabling traces. */
#ifndef YYDEBUG
@ -297,7 +319,7 @@ typedef union YYSTYPE
{
/* Line 214 of yacc.c */
#line 195 "vm_var_syntax.y"
#line 220 "vm_var_syntax.y"
char * val_str;
int val_int;
@ -306,7 +328,7 @@ typedef union YYSTYPE
/* Line 214 of yacc.c */
#line 310 "vm_var_syntax.cc"
#line 332 "vm_var_syntax.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -331,7 +353,7 @@ typedef struct YYLTYPE
/* Line 264 of yacc.c */
#line 335 "vm_var_syntax.cc"
#line 357 "vm_var_syntax.cc"
#ifdef short
# undef short
@ -617,7 +639,7 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
0, 219, 219, 220, 223, 228, 243, 261
0, 244, 244, 245, 248, 253, 268, 286
};
#endif
@ -748,7 +770,7 @@ do \
} \
else \
{ \
yyerror (&yylloc, vm, parsed, errmsg, YY_("syntax error: cannot back up")); \
yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
@ -805,7 +827,7 @@ while (YYID (0))
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
# define YYLEX yylex (&yylval, &yylloc)
# define YYLEX yylex (&yylval, &yylloc, mc)
#endif
/* Enable debugging if requested. */
@ -828,7 +850,7 @@ do { \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value, Location, vm, parsed, errmsg); \
Type, Value, Location, mc, vm, parsed, errmsg); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
@ -842,14 +864,15 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
#else
static void
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errmsg)
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
mem_collector * mc;
VirtualMachine * vm;
ostringstream * parsed;
char ** errmsg;
@ -858,6 +881,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errm
if (!yyvaluep)
return;
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (vm);
YYUSE (parsed);
YYUSE (errmsg);
@ -882,14 +906,15 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errm
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
#else
static void
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errmsg)
yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
YYLTYPE const * const yylocationp;
mem_collector * mc;
VirtualMachine * vm;
ostringstream * parsed;
char ** errmsg;
@ -902,7 +927,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errmsg)
YY_LOCATION_PRINT (yyoutput, *yylocationp);
YYFPRINTF (yyoutput, ": ");
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, vm, parsed, errmsg);
yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg);
YYFPRINTF (yyoutput, ")");
}
@ -945,13 +970,14 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
#else
static void
yy_reduce_print (yyvsp, yylsp, yyrule, vm, parsed, errmsg)
yy_reduce_print (yyvsp, yylsp, yyrule, mc, vm, parsed, errmsg)
YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyrule;
mem_collector * mc;
VirtualMachine * vm;
ostringstream * parsed;
char ** errmsg;
@ -968,7 +994,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, vm, parsed, errmsg)
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, &(yylsp[(yyi + 1) - (yynrhs)]) , vm, parsed, errmsg);
, &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, parsed, errmsg);
YYFPRINTF (stderr, "\n");
}
}
@ -976,7 +1002,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, vm, parsed, errmsg)
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyvsp, yylsp, Rule, vm, parsed, errmsg); \
yy_reduce_print (yyvsp, yylsp, Rule, mc, vm, parsed, errmsg); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
@ -1227,14 +1253,15 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
#else
static void
yydestruct (yymsg, yytype, yyvaluep, yylocationp, vm, parsed, errmsg)
yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
YYLTYPE *yylocationp;
mem_collector * mc;
VirtualMachine * vm;
ostringstream * parsed;
char ** errmsg;
@ -1242,6 +1269,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, vm, parsed, errmsg)
{
YYUSE (yyvaluep);
YYUSE (yylocationp);
YYUSE (mc);
YYUSE (vm);
YYUSE (parsed);
YYUSE (errmsg);
@ -1267,7 +1295,7 @@ int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg);
int yyparse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg);
#else
int yyparse ();
#endif
@ -1295,10 +1323,11 @@ yyparse (YYPARSE_PARAM)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
yyparse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg)
#else
int
yyparse (vm, parsed, errmsg)
yyparse (mc, vm, parsed, errmsg)
mem_collector * mc;
VirtualMachine * vm;
ostringstream * parsed;
char ** errmsg;
@ -1583,41 +1612,41 @@ yyreduce:
case 4:
/* Line 1464 of yacc.c */
#line 224 "vm_var_syntax.y"
#line 249 "vm_var_syntax.y"
{
(*parsed) << (yyvsp[(1) - (1)].val_str);
free((yyvsp[(1) - (1)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (1)].val_str));
;}
break;
case 5:
/* Line 1464 of yacc.c */
#line 229 "vm_var_syntax.y"
#line 254 "vm_var_syntax.y"
{
string name((yyvsp[(1) - (2)].val_str));
VM_VAR_TO_UPPER(name);
insert_single(vm,*parsed,name);
if ( (yyvsp[(2) - (2)].val_char) != '\0' )
{
(*parsed) << (yyvsp[(2) - (2)].val_char);
}
free((yyvsp[(1) - (2)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (2)].val_str));
;}
break;
case 6:
/* Line 1464 of yacc.c */
#line 244 "vm_var_syntax.y"
#line 269 "vm_var_syntax.y"
{
string name((yyvsp[(1) - (5)].val_str));
string vname((yyvsp[(3) - (5)].val_str));
VM_VAR_TO_UPPER(name);
VM_VAR_TO_UPPER(vname);
@ -1628,15 +1657,15 @@ yyreduce:
(*parsed) << (yyvsp[(5) - (5)].val_char);
}
free((yyvsp[(1) - (5)].val_str));
free((yyvsp[(3) - (5)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (5)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (5)].val_str));
;}
break;
case 7:
/* Line 1464 of yacc.c */
#line 262 "vm_var_syntax.y"
#line 287 "vm_var_syntax.y"
{
string name((yyvsp[(1) - (9)].val_str));
string vname((yyvsp[(3) - (9)].val_str));
@ -1648,23 +1677,23 @@ yyreduce:
VM_VAR_TO_UPPER(vvar);
insert_vector(vm,*parsed,name,vname,vvar,vval);
if ( (yyvsp[(9) - (9)].val_char) != '\0' )
{
(*parsed) << (yyvsp[(9) - (9)].val_char);
}
free((yyvsp[(1) - (9)].val_str));
free((yyvsp[(3) - (9)].val_str));
free((yyvsp[(5) - (9)].val_str));
free((yyvsp[(7) - (9)].val_str));
mem_collector_free(mc,(yyvsp[(1) - (9)].val_str));
mem_collector_free(mc,(yyvsp[(3) - (9)].val_str));
mem_collector_free(mc,(yyvsp[(5) - (9)].val_str));
mem_collector_free(mc,(yyvsp[(7) - (9)].val_str));
;}
break;
/* Line 1464 of yacc.c */
#line 1668 "vm_var_syntax.cc"
#line 1697 "vm_var_syntax.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1700,7 +1729,7 @@ yyerrlab:
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (&yylloc, vm, parsed, errmsg, YY_("syntax error"));
yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
@ -1724,11 +1753,11 @@ yyerrlab:
if (0 < yysize && yysize <= yymsg_alloc)
{
(void) yysyntax_error (yymsg, yystate, yychar);
yyerror (&yylloc, vm, parsed, errmsg, yymsg);
yyerror (&yylloc, mc, vm, parsed, errmsg, yymsg);
}
else
{
yyerror (&yylloc, vm, parsed, errmsg, YY_("syntax error"));
yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
@ -1752,7 +1781,7 @@ yyerrlab:
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, &yylloc, vm, parsed, errmsg);
yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg);
yychar = YYEMPTY;
}
}
@ -1809,7 +1838,7 @@ yyerrlab1:
yyerror_range[0] = *yylsp;
yydestruct ("Error: popping",
yystos[yystate], yyvsp, yylsp, vm, parsed, errmsg);
yystos[yystate], yyvsp, yylsp, mc, vm, parsed, errmsg);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@ -1849,7 +1878,7 @@ yyabortlab:
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (&yylloc, vm, parsed, errmsg, YY_("memory exhausted"));
yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
@ -1857,7 +1886,7 @@ yyexhaustedlab:
yyreturn:
if (yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, &yylloc, vm, parsed, errmsg);
yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg);
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
@ -1865,7 +1894,7 @@ yyreturn:
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[*yyssp], yyvsp, yylsp, vm, parsed, errmsg);
yystos[*yyssp], yyvsp, yylsp, mc, vm, parsed, errmsg);
YYPOPSTACK (1);
}
#ifndef yyoverflow
@ -1883,11 +1912,12 @@ yyreturn:
/* Line 1684 of yacc.c */
#line 285 "vm_var_syntax.y"
#line 310 "vm_var_syntax.y"
extern "C" void vm_var_error(
extern "C" void vm_var__error(
YYLTYPE * llocp,
mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** error_msg,
@ -1898,7 +1928,7 @@ extern "C" void vm_var_error(
length = strlen(str)+ 64;
*error_msg = (char *) malloc(sizeof(char)*length);
if (*error_msg != 0)
{
snprintf(*error_msg,

View File

@ -57,7 +57,7 @@ typedef union YYSTYPE
{
/* Line 1685 of yacc.c */
#line 195 "vm_var_syntax.y"
#line 220 "vm_var_syntax.y"
char * val_str;
int val_int;

View File

@ -29,24 +29,46 @@
#include "VirtualMachine.h"
#include "Nebula.h"
#define vm_var__lex vm_var_lex
#define YYERROR_VERBOSE
#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \
(int(*)(int))toupper)
extern "C"
{
void vm_var_error(
YYLTYPE * llocp,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg,
const char * str);
#include "mem_collector.h"
int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
void vm_var__error(
YYLTYPE * llocp,
mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg,
const char * str);
int vm_var_parse (VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg);
int vm_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc);
int vm_var__parse (mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg);
int vm_var_parse (VirtualMachine * vm,
ostringstream * parsed,
char ** errmsg)
{
mem_collector mc;
int rc;
mem_collector_init(&mc);
rc = vm_var__parse(&mc, vm, parsed, errmsg);
mem_collector_cleanup(&mc);
return rc;
}
}
/* -------------------------------------------------------------------------- */
@ -118,7 +140,7 @@ void insert_single(VirtualMachine * vm,
string value = "";
vm->get_template_attribute(name.c_str(),value);
parsed << value;
}
@ -131,17 +153,17 @@ void insert_vector(VirtualMachine * vm,
const string& vname,
const string& vvar,
const string& vval)
{
{
vector<const Attribute*> values;
const VectorAttribute * vattr = 0;
int num;
if ( name == "NETWORK")
{
string value;
get_network_attribute(vm,vname,vvar,vval,value);
if (!value.empty())
@ -156,19 +178,19 @@ void insert_vector(VirtualMachine * vm,
{
return;
}
if ( vvar.empty() )
{
vattr = dynamic_cast<const VectorAttribute *>(values[0]);
vattr = dynamic_cast<const VectorAttribute *>(values[0]);
}
else
{
const VectorAttribute * tmp = 0;
for (int i=0 ; i < num ; i++)
{
tmp = dynamic_cast<const VectorAttribute *>(values[i]);
if ( tmp && ( tmp->vector_value(vvar.c_str()) == vval ))
{
vattr = tmp;
@ -182,16 +204,19 @@ void insert_vector(VirtualMachine * vm,
parsed << vattr->vector_value(vname.c_str());
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
%}
%parse-param {mem_collector * mc}
%parse-param {VirtualMachine * vm}
%parse-param {ostringstream * parsed}
%parse-param {char ** errmsg}
%lex-param {mem_collector * mc}
%union {
char * val_str;
int val_int;
@ -201,7 +226,7 @@ void insert_vector(VirtualMachine * vm,
%defines
%locations
%pure_parser
%name-prefix = "vm_var_"
%name-prefix = "vm_var__"
%output = "vm_var_syntax.cc"
%token EQUAL COMMA OBRACKET CBRACKET
@ -223,28 +248,28 @@ vm_string: vm_variable
vm_variable:RSTRING
{
(*parsed) << $1;
free($1);
mem_collector_free(mc,$1);
}
| VARIABLE EOA
{
string name($1);
VM_VAR_TO_UPPER(name);
insert_single(vm,*parsed,name);
if ( $2 != '\0' )
{
(*parsed) << $2;
}
free($1);
mem_collector_free(mc,$1);
}
| VARIABLE OBRACKET VARIABLE CBRACKET EOA
{
string name($1);
string vname($3);
VM_VAR_TO_UPPER(name);
VM_VAR_TO_UPPER(vname);
@ -255,8 +280,8 @@ vm_variable:RSTRING
(*parsed) << $5;
}
free($1);
free($3);
mem_collector_free(mc,$1);
mem_collector_free(mc,$3);
}
| VARIABLE OBRACKET VARIABLE COMMA VARIABLE EQUAL STRING CBRACKET EOA
{
@ -270,22 +295,23 @@ vm_variable:RSTRING
VM_VAR_TO_UPPER(vvar);
insert_vector(vm,*parsed,name,vname,vvar,vval);
if ( $9 != '\0' )
{
(*parsed) << $9;
}
free($1);
free($3);
free($5);
free($7);
mem_collector_free(mc,$1);
mem_collector_free(mc,$3);
mem_collector_free(mc,$5);
mem_collector_free(mc,$7);
}
;
%%
extern "C" void vm_var_error(
extern "C" void vm_var__error(
YYLTYPE * llocp,
mem_collector * mc,
VirtualMachine * vm,
ostringstream * parsed,
char ** error_msg,
@ -296,7 +322,7 @@ extern "C" void vm_var_error(
length = strlen(str)+ 64;
*error_msg = (char *) malloc(sizeof(char)*length);
if (*error_msg != 0)
{
snprintf(*error_msg,

View File

@ -59,9 +59,9 @@ main_env.Append(LIBS=[
'nebula_authm',
'nebula_template',
'nebula_pool',
'nebula_common',
'nebula_mad',
'nebula_core',
'nebula_common',
'nebula_sql',
'cppunit',
'dl',

View File

@ -113,6 +113,12 @@ public:
}
else
{
if (error_msg != 0 )
{
free(error_msg);
}
delete vn_template;
return -1;
}
};
@ -210,9 +216,9 @@ protected:
public:
VirtualNetworkPoolTest(){};
VirtualNetworkPoolTest(){xmlInitParser();};
~VirtualNetworkPoolTest(){};
~VirtualNetworkPoolTest(){xmlCleanupParser();};
/* ********************************************************************* */
/* ********************************************************************* */
@ -235,7 +241,6 @@ public:
CPPUNIT_ASSERT( rc == -1 );
// Parser error for Vnet template
//TODO: Check memory leak for allocating strings in template parser
rc = allocate(4);
CPPUNIT_ASSERT( rc == -1 );