Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
e2896aa6
Commit
e2896aa6
authored
Nov 05, 2015
by
Tomek Mrugalski
🛰
Browse files
[4088] General smallish improvements in evaluation code
parent
06446ad1
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/lib/eval/eval_context.cc
View file @
e2896aa6
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <eval/eval_context.h>
#include <eval/parser.h>
#include <exceptions/exceptions.h>
#include <fstream>
EvalContext
::
EvalContext
()
:
trace_scanning
(
false
),
trace_parsing
(
false
)
:
trace_scanning
_
(
false
),
trace_parsing
_
(
false
)
{
}
...
...
@@ -16,11 +30,11 @@ int
EvalContext
::
parseFile
(
const
std
::
string
&
filename
)
{
file
=
filename
;
scan
_b
egin
();
scan
B
egin
();
isc
::
eval
::
EvalParser
parser
(
*
this
);
parser
.
set_debug_level
(
trace_parsing
);
parser
.
set_debug_level
(
trace_parsing
_
);
int
res
=
parser
.
parse
();
scan
_e
nd
();
scan
E
nd
();
return
res
;
}
...
...
src/lib/eval/eval_context.h
View file @
e2896aa6
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef EVAL_CONTEXT_H
#define EVAL_CONTEXT_H
#
include <string>
#
include <map>
#
include
"
parser.h
"
#include <string>
#include <map>
#include
<eval/
parser.h
>
// Tell Flex the lexer's prototype ...
# define YY_DECL \
isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
#define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
// ... and declare it for the parser's sake.
YY_DECL
;
//
Conducting the whole sc
an
n
in
g and parsing of Calc++
.
//
/ @brief Evaluation context,
an
in
terface to the expression evaluation
.
class
EvalContext
{
public:
EvalContext
();
virtual
~
EvalContext
();
/// @brief Default constructor.
EvalContext
();
/// @brief destructor
virtual
~
EvalContext
();
/// @brief Parsed expression (output tokens are stored here)
isc
::
dhcp
::
Expression
expression
;
isc
::
dhcp
::
Expression
expression
;
/// @brief Method called before scanning starts.
void
scanBegin
();
int
result
;
/// @brief Method called after the last tokens are scanned.
void
scanEnd
();
/// @brief Runs the parser on specified file.
///
/// @param filename
/// Return 0 on success.
int
parseFile
(
const
std
::
string
&
filename
);
// Handling the scanner
.
void
scan_begin
();
void
scan_end
();
bool
trace_scanning
;
/// @brief Run the parser on the string specified
.
///
/// @param str string to be written
int
parseString
(
const
std
::
string
&
str
)
;
// Run the parser on file F
.
// Return 0 on success
.
int
parseFile
(
const
std
::
string
&
file
name
)
;
/// @brief The name of the file being parsed
.
/// Used later to pass the file name to the location tracker
.
std
::
string
file
;
int
parseString
(
const
std
::
string
&
str
);
/// @brief Error handler
///
/// @param l location within the parsed file when experienced a problem.
/// @param what string explaining the nature of the error.
void
error
(
const
isc
::
eval
::
location
&
l
,
const
std
::
string
&
what
);
// The name of the file being parsed.
// Used later to pass the file name to the location tracker.
/// @brief Error handler
///
/// This is a simplified error reporting tool for possible future
/// cases when the EvalParser is not able to handle the packet.
void
error
(
const
std
::
string
&
what
);
std
::
string
file
;
// Wh
et
h
er
parser traces should be generated
.
bool
trace_
pars
ing
;
private:
/// @brief Flag d
eter
mining scanner debugging
.
bool
trace_
scann
ing
_
;
// Error handl
ing.
void
error
(
const
isc
::
eval
::
location
&
l
,
const
std
::
string
&
m
)
;
void
error
(
const
std
::
string
&
m
);
/// @brief Flag determing parser debugg
ing.
bool
trace_parsing_
;
};
#endif // ! EVALCONTEXT_HH
src/lib/eval/lexer.cc
View file @
e2896aa6
...
...
@@ -2220,21 +2220,21 @@ void yyfree (void * ptr )
void
EvalContext
::
scan
_b
egin
()
EvalContext
::
scan
B
egin
()
{
yy_flex_debug
=
trace_scanning
;
yy_flex_debug
=
trace_scanning
_
;
if
(
file
.
empty
()
||
file
==
"-"
)
{
yyin
=
stdin
;
}
else
if
(
!
(
yyin
=
fopen
(
file
.
c_str
(),
"r"
)))
{
error
(
"cannot open "
+
file
+
": "
+
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
error
(
"cannot open "
+
file
+
": "
+
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
}
void
EvalContext
::
scan
_e
nd
()
EvalContext
::
scan
E
nd
()
{
fclose
(
yyin
);
fclose
(
yyin
);
}
src/lib/eval/lexer.ll
View file @
e2896aa6
...
...
@@ -162,20 +162,20 @@ option\[{int}\] {
%%
void
EvalContext:
:scan
_b
egin
()
EvalContext:
:scan
B
egin
()
{
yy_flex_debug
=
trace_scanning
;
yy_flex_debug
=
trace_scanning
_
;
if
(
file
.
empty
()
||
file
==
"-"
)
{
yyin
=
stdin
;
}
else
if
(!(
yyin
=
fopen
(
file
.
c_str
(),
"r"
)))
{
error
(
"cannot open "
+
file
+
": "
+
strerror
(
errno
))
;
exit
(
EXIT_FAILURE
)
;
error
(
"cannot open "
+
file
+
": "
+
strerror
(
errno
))
;
exit
(
EXIT_FAILURE
)
;
}
}
void
EvalContext:
:scan
_e
nd
()
EvalContext:
:scan
E
nd
()
{
fclose
(
yyin
)
;
fclose
(
yyin
)
;
}
src/lib/eval/location.hh
View file @
e2896aa6
...
...
@@ -40,7 +40,7 @@
# include "position.hh"
#line
7
"parser.yy" // location.cc:337
#line
21
"parser.yy" // location.cc:337
namespace
isc
{
namespace
eval
{
#line 46 "location.hh" // location.cc:337
/// Abstract a location.
...
...
@@ -186,7 +186,7 @@ namespace isc { namespace eval {
return
ostr
;
}
#line
7
"parser.yy" // location.cc:337
#line
21
"parser.yy" // location.cc:337
}
}
// isc::eval
#line 192 "location.hh" // location.cc:337
#endif // !YY_YY_LOCATION_HH_INCLUDED
src/lib/eval/parser.cc
View file @
e2896aa6
...
...
@@ -49,7 +49,7 @@
#line 51 "parser.cc" // lalr1.cc:412
// Unqualified %code blocks.
#line 2
8
"parser.yy" // lalr1.cc:413
#line
4
2 "parser.yy" // lalr1.cc:413
# include "eval_context.h"
...
...
@@ -137,7 +137,7 @@
#define YYERROR goto yyerrorlab
#define YYRECOVERING() (!!yyerrstatus_)
#line
7
"parser.yy" // lalr1.cc:479
#line
21
"parser.yy" // lalr1.cc:479
namespace
isc
{
namespace
eval
{
#line 143 "parser.cc" // lalr1.cc:479
...
...
@@ -320,14 +320,14 @@ namespace isc { namespace eval {
{
case
8
:
// "constant string"
#line
42
"parser.yy" // lalr1.cc:636
#line
56
"parser.yy" // lalr1.cc:636
{
yyoutput
<<
yysym
.
value
.
template
as
<
std
::
string
>
();
}
#line 326 "parser.cc" // lalr1.cc:636
break
;
case
9
:
// "option code"
#line
42
"parser.yy" // lalr1.cc:636
#line
56
"parser.yy" // lalr1.cc:636
{
yyoutput
<<
yysym
.
value
.
template
as
<
int
>
();
}
#line 333 "parser.cc" // lalr1.cc:636
break
;
...
...
@@ -442,7 +442,7 @@ namespace isc { namespace eval {
// User initialization code.
#line
21
"parser.yy" // lalr1.cc:745
#line
35
"parser.yy" // lalr1.cc:745
{
// Initialize the initial location.
yyla
.
location
.
begin
.
filename
=
yyla
.
location
.
end
.
filename
=
&
ctx
.
file
;
...
...
@@ -564,7 +564,7 @@ namespace isc { namespace eval {
switch
(
yyn
)
{
case
2
:
#line
50
"parser.yy" // lalr1.cc:859
#line
64
"parser.yy" // lalr1.cc:859
{
TokenPtr
eq
(
new
TokenEqual
());
ctx
.
expression
.
push_back
(
eq
);
...
...
@@ -573,7 +573,7 @@ namespace isc { namespace eval {
break
;
case
4
:
#line
5
7 "parser.yy" // lalr1.cc:859
#line 7
1
"parser.yy" // lalr1.cc:859
{
TokenPtr
str
(
new
TokenString
(
yystack_
[
0
].
value
.
as
<
std
::
string
>
()));
ctx
.
expression
.
push_back
(
str
);
...
...
@@ -582,7 +582,7 @@ namespace isc { namespace eval {
break
;
case
5
:
#line
61
"parser.yy" // lalr1.cc:859
#line
75
"parser.yy" // lalr1.cc:859
{
TokenPtr
opt
(
new
TokenOption
(
yystack_
[
0
].
value
.
as
<
int
>
()));
ctx
.
expression
.
push_back
(
opt
);
...
...
@@ -591,7 +591,7 @@ namespace isc { namespace eval {
break
;
case
6
:
#line
65
"parser.yy" // lalr1.cc:859
#line
79
"parser.yy" // lalr1.cc:859
{
/* push back TokenSubstring */
}
...
...
@@ -933,7 +933,7 @@ namespace isc { namespace eval {
const
unsigned
char
EvalParser
::
yyrline_
[]
=
{
0
,
50
,
50
,
54
,
5
7
,
61
,
65
0
,
64
,
64
,
68
,
7
1
,
75
,
79
};
// Print the state stack on the debug stream.
...
...
@@ -966,10 +966,10 @@ namespace isc { namespace eval {
#endif // YYDEBUG
#line
7
"parser.yy" // lalr1.cc:1167
#line
21
"parser.yy" // lalr1.cc:1167
}
}
// isc::eval
#line 972 "parser.cc" // lalr1.cc:1167
#line
69
"parser.yy" // lalr1.cc:1168
#line
83
"parser.yy" // lalr1.cc:1168
void
isc
::
eval
::
EvalParser
::
error
(
const
location_type
&
l
,
...
...
src/lib/eval/parser.h
View file @
e2896aa6
...
...
@@ -40,7 +40,7 @@
#ifndef YY_YY_PARSER_H_INCLUDED
# define YY_YY_PARSER_H_INCLUDED
// // "%code requires" blocks.
#line
10
"parser.yy" // lalr1.cc:392
#line
24
"parser.yy" // lalr1.cc:392
#include <string>
#include <eval/token.h>
...
...
@@ -123,7 +123,7 @@ using namespace isc::dhcp;
# define YYDEBUG 1
#endif
#line
7
"parser.yy" // lalr1.cc:392
#line
21
"parser.yy" // lalr1.cc:392
namespace
isc
{
namespace
eval
{
#line 129 "parser.h" // lalr1.cc:392
...
...
@@ -991,7 +991,7 @@ namespace isc { namespace eval {
}
#line
7
"parser.yy" // lalr1.cc:392
#line
21
"parser.yy" // lalr1.cc:392
}
}
// isc::eval
#line 997 "parser.h" // lalr1.cc:392
...
...
src/lib/eval/parser.yy
View file @
e2896aa6
/* Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. */
%skeleton "lalr1.cc" /* -*- C++ -*- */
%require "3.0.0"
%defines
...
...
src/lib/eval/position.hh
View file @
e2896aa6
...
...
@@ -50,7 +50,7 @@
# endif
# endif
#line
7
"parser.yy" // location.cc:337
#line
21
"parser.yy" // location.cc:337
namespace
isc
{
namespace
eval
{
#line 56 "position.hh" // location.cc:337
/// Abstract a position.
...
...
@@ -174,7 +174,7 @@ namespace isc { namespace eval {
return
ostr
<<
pos
.
line
<<
'.'
<<
pos
.
column
;
}
#line
7
"parser.yy" // location.cc:337
#line
21
"parser.yy" // location.cc:337
}
}
// isc::eval
#line 180 "position.hh" // location.cc:337
#endif // !YY_YY_POSITION_HH_INCLUDED
src/lib/eval/stack.hh
View file @
e2896aa6
...
...
@@ -40,7 +40,7 @@
# include <vector>
#line
7
"parser.yy" // stack.hh:151
#line
21
"parser.yy" // stack.hh:151
namespace
isc
{
namespace
eval
{
#line 46 "stack.hh" // stack.hh:151
template
<
class
T
,
class
S
=
std
::
vector
<
T
>
>
...
...
@@ -150,7 +150,7 @@ namespace isc { namespace eval {
unsigned
int
range_
;
};
#line
7
"parser.yy" // stack.hh:151
#line
21
"parser.yy" // stack.hh:151
}
}
// isc::eval
#line 156 "stack.hh" // stack.hh:151
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment