Closed yesint closed 4 years ago
@yesint, thank you for the report. I tried to reproduce it, but I couldn't. I built the following code with g++ --std=c++11 a.cpp
, and the build succeeded with no error.
a.cpp
#include "peglib.h"
using namespace peg;
struct MyAst_annotation {
bool is_coord_dependent;
std::vector<int> precomputed;
};
typedef peg::AstBase<MyAst_annotation> MyAst;
int main(void) {
parser parser("START <- 'hello' ' '+ 'world'");
parser.enable_ast();
/// AST tree
std::shared_ptr<MyAst> tree;
if (parser.parse("hello world", tree)) {
tree = AstOptimizer(true).optimize(tree);
return 0;
}
return -1;
}
Could you give me more information, and the smallest possible example which reproduces the problem? Thanks for your help!
@yhirose, thank you for prompt reaction! Unfortunately I was unable to reproduced outside of our project, which is very weird and most likely points to our mistake, but in any case it was compiling nicely before and doesn't compile with the latest peglib. I would be grateful if you'll help us to understand why.
This is how to reproduce:
git clone -b new-peglib https://github.com/yesint/pteros.git pteros
mkdir build
cd build
cmake ../pteros -DWITH_GROMACS=OFF -DWITH_OPENBABEL=OFF -DWITH_PYTHON=OFF -DCMAKE_BUILD_TYPE=Release
make
This builds our pteros library in the bare minimal configuration and fails with this compilation error. If I substitute peglib.h with older version in compiles nicely without any other changes.
The project is large but peglib is only used in one place: src/core/selection_parser
.
@yesint, I tried to build it, but cmake stops working with the following message:
-- Generating examples
-- Generating tests
-- Checking for module 'libsystemd'
-- No package 'libsystemd' found
-- Generating install
-- =======================
CMake Error at /usr/local/Cellar/cmake/3.13.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.13.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.13.1/share/cmake/Modules/FindOpenMP.cmake:473 (find_package_handle_standard_args)
CMakeLists.txt:134 (find_package)
Do I miss something? (I am running on Mac OS 10.15 Catalina.)
Apparently it can't find OpenMP, could you try with -DWITH_OPENMP=OFF ?
@yesint, thanks for the info. I am now able to generate Makefile. But when I run make, I encountered another compile error in dssp.cpp before reaching selection_parser.cpp... Is there any easy way to compile just the selection_parser.cpp? Thanks for your help!
[ 33%] Building CXX object thirdparty/dssp/CMakeFiles/dssp.dir/dssp.cpp.o
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/dssp.cpp:6:
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/mas.h:8:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:504:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:175:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2147:9: error:
cannot initialize a member subobject of type 'int *' with an rvalue of type 'long'
: __value_(_VSTD::forward<_Up>(__u))
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2240:9: note:
in instantiation of function template specialization 'std::__1::__compressed_pair_elem<int *, 0,
false>::__compressed_pair_elem<long, void>' requested here
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:436:7: note:
in instantiation of function template specialization 'std::__1::__compressed_pair<int *,
std::__1::allocator<int> >::__compressed_pair<long, true>' requested here
__end_cap_(nullptr)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:517:5: note:
in instantiation of member function 'std::__1::__vector_base<int, std::__1::allocator<int>
>::__vector_base' requested here
vector(size_type __n, const value_type& __x);
^
/usr/local/include/boost/token_functions.hpp:360:9: note: in instantiation of member function
'std::__1::vector<int, std::__1::allocator<int> >::vector' requested here
: offsets_(1,1), current_offset_(),
^
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/dssp.cpp:6:
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/mas.h:8:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:504:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:175:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2250:9: error:
no matching constructor for initialization of '__compressed_pair_elem<int *, 0>'
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
^ ~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:455:7: note:
in instantiation of function template specialization 'std::__1::__compressed_pair<int *,
std::__1::allocator<int> >::__compressed_pair<long, std::__1::allocator<int> >' requested here
__end_cap_(nullptr, std::move(__a)) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1281:7: note:
in instantiation of member function 'std::__1::__vector_base<int, std::__1::allocator<int>
>::__vector_base' requested here
: __base(_VSTD::move(__x.__alloc()))
^
/usr/local/include/boost/token_functions.hpp:343:9: note: in instantiation of member function
'std::__1::vector<int, std::__1::allocator<int> >::vector' requested here
class offset_separator {
^
/usr/local/include/boost/date_time/gregorian/parsers.hpp:50:23: note: in instantiation of function template
specialization 'boost::date_time::parse_undelimited_date<boost::gregorian::date>' requested here
return date_time::parse_undelimited_date<date>(s);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2133:8: note:
candidate constructor (the implicit copy constructor) not viable: no known conversion from 'long' to
'const std::__1::__compressed_pair_elem<int *, 0, false>' for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2133:8: note:
candidate constructor (the implicit move constructor) not viable: no known conversion from 'long' to
'std::__1::__compressed_pair_elem<int *, 0, false>' for 1st argument
struct __compressed_pair_elem {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2146:3: note:
candidate template ignored: substitution failure [with _Up = long, $1 = void]
__compressed_pair_elem(_Up&& __u)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2153:3: note:
candidate constructor template not viable: requires 3 arguments, but 1 was provided
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2139:39: note:
candidate constructor not viable: requires 0 arguments, but 1 was provided
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2147:9: error:
cannot initialize a member subobject of type 'short *' with an rvalue of type 'long'
: __value_(_VSTD::forward<_Up>(__u))
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2250:9: note:
in instantiation of function template specialization 'std::__1::__compressed_pair_elem<short *, 0,
false>::__compressed_pair_elem<long, void>' requested here
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:455:7: note:
in instantiation of function template specialization 'std::__1::__compressed_pair<short *,
std::__1::allocator<short> >::__compressed_pair<long, std::__1::allocator<short> >' requested here
__end_cap_(nullptr, std::move(__a)) {}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:1243:7: note:
in instantiation of member function 'std::__1::__vector_base<short, std::__1::allocator<short>
>::__vector_base' requested here
: __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
^
/Users/yhirose/Projects/pteros/thirdparty/dssp/align-2d.h:24:9: note: in instantiation of member function
'std::__1::vector<short, std::__1::allocator<short> >::vector' requested here
, m_positions(e.m_positions)
^
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/dssp.cpp:6:
In file included from /Users/yhirose/Projects/pteros/thirdparty/dssp/mas.h:
Ups, I'm sorry for these troubles. Unfortunately pteros was never tested on Mac and apparently it doesn't compile there without some changes. I'll try to disable all third-party components and will commit the bare-bone version tomorrow.
@yhirose, please try the latest git. I've removed all offending code and I hope it should now compile on Mac up to the point where peglib is used.
@yesint, I am now able to see the compile errors!
They are caused by the enhancement of AstBase
constructors. (https://github.com/yhirose/cpp-peglib/commit/b76e4fe305d07b50dad80e25bc711ed843ff0cbe, https://github.com/yhirose/cpp-peglib/commit/b330799cd683f2884fe92cacd46cccc60c1f681c).
std::make_shared<MyAst>(...)
calls with the latest peglib now require more parameters. The new parameters are useful information for debugging.
I am thinking to move these additional parameters to the end of the parameter list and make them with default values, so that your code doesn't need to make any change.
I'll let you know when it becomes ready.
@yesint, I think I fixed it. Could you try with the latest peglib.h?
@yhirose, it works perfectly now! Thanks a lot!
@yesint, glad to hear the problem is gone!
By the way, when I was looking in the section_parser.cpp, I found that name
property in AstBase is used a number of times to check Ast node type. That's totally fine. But there is another way to check the type with tag
property.
Here is the original code of is_node_coordinate_dependent
:
bool is_node_coordinate_dependent(const std::shared_ptr<MyAst>& node){
if(node->name == "X" || node->name == "Y" || node->name == "Z" || node->name == "WITHIN"
|| node->name == "POINT" || node->name == "PLANE" || node->name == "VECTOR" || node->name == "COM"
){
return true;
} else {
return false;
}
}
Here is a revised code with tag
property.
bool is_node_coordinate_dependent(const std::shared_ptr<MyAst>& node){
using namespace peg::udl;
switch (node->tag){
case "X"_:
case "Y"_:
case "WITHIN"_:
case "POINT"_:
case "PLANE"_:
case "VECTOR"_:
case "COM"_:
return true;
default:
return false;
}
}
tag
is a 32-bits hash value for name
property. "???"_
generates a 32-bits hash value for "???"
string on compile time. So we can check Ast node type with integer comparison instead of slower string comparison. It also allows us to use switch
statement which could make code a bit more readable.
Anyway, thank you for your interest in this library!
@yhirose, thanks a lot for suggestion! This was one of my questions of how to avoid rather costly string comparisons. This is a very clever way indeed! Thank you for your fantastic library!
Hello! I've recently update peglib to latest version and my AST with custom annotation suddenly stopped working, while it was perfectly fine with older version:
This is no more compiling (see below). What should I change to make it work again?