Skip to content

Commit fe8dbbe

Browse files
committed
Library doesn't die with warnings enabled anymore
Great success
1 parent e132d68 commit fe8dbbe

5 files changed

Lines changed: 16 additions & 12 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
A light weight single header alternative to DBMS
44

5-
This library was developed during my honors project at the University of Victoria under the supervision of [Bill Bird](https://github.com/billbird). The original development occurred in this [Metaprogramming Optimization](https://github.com/mkitzan/metaprogramming-optimization) repository, but was moved into a new, dedicated, home repository. The project was inspired and influenced by [Hana Dusíková](https://github.com/hanickadot)'s great [Compile Time Regular Expression](https://github.com/hanickadot/compile-time-regular-expressions) library (CTRE).
5+
This library was developed during my honors project at the [University of Victoria](https://www.uvic.ca/engineering/computerscience/index.php) under the supervision of [Bill Bird](https://github.com/billbird). The original development occurred in this [Metaprogramming Optimization](https://github.com/mkitzan/metaprogramming-optimization) repository, but was moved into a new, dedicated, home repository. The project was inspired and influenced by [Hana Dusíková](https://github.com/hanickadot)'s great [Compile Time Regular Expression](https://github.com/hanickadot/compile-time-regular-expressions) library (CTRE).
6+
7+
Maintenance may slow in the near future due to my employer's open source software policy. I will be looking into getting approval to continue maintaining this project.
68

79
## Library Features and Compiler Support
810

@@ -88,7 +90,7 @@ int main()
8890
The example is from [`example.cpp`](https://github.com/mkitzan/constexpr-sql/blob/master/example.cpp) in the root of the repository, and can be compiled and executed with the following command:
8991

9092
```shell
91-
g++ -std=c++2a -O3 -Isingle-header/ -o example example.cpp && ./example
93+
g++ -std=c++2a -pedantic -Wall -Wextra -Werror -O3 -Isingle-header/ -o example example.cpp && ./example
9294
```
9395

9496
It is strongly recommended to compile with optimizations enabled, otherwise expect template bloat. Use of multiple objects of the same `sql::query` type is considered **undefined behavior** (due to issues involving static members). Instantiating `sql::query` objects should be performed within a guarded scope, like in the example. However, there are no use restrictions to `sql::schema` types. `sql::schema` types may be used multiple times within a single query or in many queries at once. There are more examples and information in [`presentation.pdf`](https://github.com/mkitzan/constexpr-sql/blob/master/presentation.pdf) at the root of the repository.
@@ -131,6 +133,8 @@ At the moment, [`ra::projection`](https://github.com/mkitzan/constexpr-sql/blob/
131133

132134
As a proof of concept for `constexpr` parsing, two math expression parsers were implemented in old repository: [`cexpr::prefix`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp) and [`cexpr::infix`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/infix.hpp). `cexpr::prefix` demonstrates the fundamental method of `constexpr` parsing an expression tree into a class template. `cexpr::infix` extends this to perform `constepxr` recursive descent parsing. `cexpr::infix` and the SQL query parser are a whole order of magnitude more complex, because there's recursive function template instantiations to many different function templates. The explanation of `constexpr` parsing is illustrated through `cexpr::prefix` for simplicity.
133135

134-
The expression tree created while parsing is a template recursive tree which shares similar properties to the template linked-list (discussed [earlier](https://github.com/mkitzan/constexpr-sql#class-template-sqlrow)). A notable benefit to this data structure is that because the tree is composed of types rather than data values, the tree can be used to express computation models (expression trees) rather than just a tree based container. Fundamentally, the parsing is accomplished by calling a template recursive `static constexpr` parsing function member parameterized on the token position which the parser's "cursor" is standing on ([`Pos`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L39) template parameter). At each "cursor" position, the function uses the token to decide the how to proceed. If the token indicates the start of an operation, the parser recurses the immediate left subexpression ("cursor" + 1). On return, the left subexpression will report the depth in the token stream it recursed at which point the right subexpression will pick up at this position. This control flow is expressed in [this line](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L47) of [`cexpr::prefix::parse`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L40). Once both left and right subexpressions are parsed, the new node's type is formed ([`decltype`](https://en.cppreference.com/w/cpp/language/decltype) left and right subexpressions) which is then propagated to the caller. Otherwise, if the token indicates a terminal, then an appropriate terminal node is constructed. It is necessary that the "cursor" position is unique across template instantiations, otherwise template memoization will lead to "infinite" recursion.
136+
The expression tree created while parsing is a template recursive tree which shares similar properties to the template linked-list (discussed [earlier](https://github.com/mkitzan/constexpr-sql#class-template-sqlrow)). A notable benefit to this data structure is that because the tree is composed of types rather than data values, the tree can be used to express computation models (expression trees) rather than just a tree based container.
137+
138+
Fundamentally, the parsing is accomplished by calling a template recursive `static constexpr` parsing function member parameterized on the token position which the parser's "cursor" is standing on ([`Pos`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L39) template parameter). At each "cursor" position, the function uses the token to decide the how to proceed. If the token indicates the start of an operation, the parser recurses the immediate left subexpression ("cursor" + 1). On return, the left subexpression will report the depth in the token stream it recursed at which point the right subexpression will pick up at this position. This control flow is expressed in [this line](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L47) of [`cexpr::prefix::parse`](https://github.com/mkitzan/metaprogramming-optimization/blob/master/include/cexpr/prefix.hpp#L40). Once both left and right subexpressions are parsed, the new node's type is formed ([`decltype`](https://en.cppreference.com/w/cpp/language/decltype) left and right subexpressions) which is then propagated to the caller. Otherwise, if the token indicates a terminal, then an appropriate terminal node is constructed. It is necessary that the "cursor" position is unique across template instantiations, otherwise template memoization will lead to "infinite" recursion.
135139

136-
The few ancillary class templates used to support this parsing and the math node struct templates can be found in the [`templ` namespace](https://github.com/mkitzan/metaprogramming-optimization/tree/master/include/templ) of the old repository. There is also a [driver program](https://github.com/mkitzan/metaprogramming-optimization/blob/master/resources/parser/equation.cpp) using the parsers in the old repository. In the Constexpr SQL parser, all of the entities in the `templ` namespace were replaced for more template metaprogramming idiomatic structures.
140+
The few ancillary class templates used to support this parsing and the math node `struct` templates can be found in the [`templ` namespace](https://github.com/mkitzan/metaprogramming-optimization/tree/master/include/templ) of the old repository. There is also a [driver program](https://github.com/mkitzan/metaprogramming-optimization/blob/master/resources/parser/equation.cpp) using the parsers in the old repository. In the Constexpr SQL parser, all of the entities in the `templ` namespace were replaced for more template metaprogramming idiomatic structures.

include/cexpr/string.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ namespace cexpr
134134
}
135135

136136
private:
137-
Char string_[N];
138137
std::size_t size_;
138+
Char string_[N];
139139
};
140140

141141
template <typename Char, std::size_t N>

include/sql/predicate.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace sql
7979
template <auto Const, typename Row>
8080
struct constant
8181
{
82-
static constexpr auto eval(Row const& row)
82+
static constexpr auto eval(__attribute__((unused)) Row const& row)
8383
{
8484
return Const.val;
8585
}

include/sql/query.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace sql
6464
constexpr value<ValT> convert(cexpr::string<CharT, N> const& str)
6565
{
6666
auto curr{ str.cbegin() }, end{ str.cend() };
67-
constexpr CharT nul{ '\0' }, dot{ '.' }, zro{ '0' }, min{ '-' };
67+
constexpr CharT dot{ '.' }, zro{ '0' }, min{ '-' };
6868
ValT acc{}, sign{ 1 }, scalar{ 10 };
6969

7070
if (*curr == min)
@@ -600,7 +600,7 @@ namespace sql
600600
{
601601
return has_rename<Pos + 1>();
602602
}
603-
};
603+
}
604604

605605
// decide RA node to root the expression tree
606606
template <std::size_t Pos>

single-header/sql.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ namespace cexpr
143143
}
144144

145145
private:
146-
Char string_[N];
147146
std::size_t size_;
147+
Char string_[N];
148148
};
149149

150150
template <typename Char, std::size_t N>
@@ -1133,7 +1133,7 @@ namespace sql
11331133
template <auto Const, typename Row>
11341134
struct constant
11351135
{
1136-
static constexpr auto eval(Row const& row)
1136+
static constexpr auto eval(__attribute__((unused)) Row const& row)
11371137
{
11381138
return Const.val;
11391139
}
@@ -1187,7 +1187,7 @@ namespace sql
11871187
constexpr value<ValT> convert(cexpr::string<CharT, N> const& str)
11881188
{
11891189
auto curr{ str.cbegin() }, end{ str.cend() };
1190-
constexpr CharT nul{ '\0' }, dot{ '.' }, zro{ '0' }, min{ '-' };
1190+
constexpr CharT dot{ '.' }, zro{ '0' }, min{ '-' };
11911191
ValT acc{}, sign{ 1 }, scalar{ 10 };
11921192

11931193
if (*curr == min)
@@ -1723,7 +1723,7 @@ namespace sql
17231723
{
17241724
return has_rename<Pos + 1>();
17251725
}
1726-
};
1726+
}
17271727

17281728
// decide RA node to root the expression tree
17291729
template <std::size_t Pos>

0 commit comments

Comments
 (0)