khushi-411 / lox.cpp

Lox programming language.
0 stars 0 forks source link

[fix] segfault & cpp codes #8

Closed khushi-411 closed 5 months ago

khushi-411 commented 5 months ago

Will create a new PR for the fix for the below error:

error

```cpp /home/khushi/Documents/lox.cpp/src/Lox.h:20:18: error: cannot declare field ‘lox::Lox::interpreter’ to be of abstract type ‘lox::Interpreter’ 20 | Interpreter interpreter; | ^~~~~~~~~~~ In file included from /home/khushi/Documents/lox.cpp/src/Lox.h:8: /home/khushi/Documents/lox.cpp/src/Interpreter.h:18:7: note: because the following virtual functions are pure within ‘lox::Interpreter’: 18 | class Interpreter : public lox::expr::Visitor, | ^~~~~~~~~~~ In file included from /home/khushi/Documents/lox.cpp/src/Interpreter.h:10: /home/khushi/Documents/lox.cpp/src/Stmt.h:154:13: note: ‘T lox::stmt::Visitor::visitBlockStmt(const lox::stmt::Block&) [with T = void]’ 154 | virtual T visitBlockStmt(const Block& stmt) = 0; | ^~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:155:13: note: ‘T lox::stmt::Visitor::visitClassStmt(const lox::stmt::Class&) [with T = void]’ 155 | virtual T visitClassStmt(const Class& stmt) = 0; | ^~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:156:13: note: ‘T lox::stmt::Visitor::visitExpressionStmt(const lox::stmt::Expression&) [with T = void]’ 156 | virtual T visitExpressionStmt(const Expression& stmt) = 0; | ^~~~~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:157:13: note: ‘T lox::stmt::Visitor::visitFunctionStmt(const lox::stmt::Function&) [with T = void]’ 157 | virtual T visitFunctionStmt(const Function& stmt) = 0; | ^~~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:158:13: note: ‘T lox::stmt::Visitor::visitIfStmt(const lox::stmt::If&) [with T = void]’ 158 | virtual T visitIfStmt(const If& stmt) = 0; | ^~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:159:13: note: ‘T lox::stmt::Visitor::visitPrintStmt(const lox::stmt::Print&) [with T = void]’ 159 | virtual T visitPrintStmt(const Print& stmt) = 0; | ^~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:160:13: note: ‘T lox::stmt::Visitor::visitReturnStmt(const lox::stmt::Return&) [with T = void]’ 160 | virtual T visitReturnStmt(const Return& stmt) = 0; | ^~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:161:13: note: ‘T lox::stmt::Visitor::visitVarStmt(const lox::stmt::Var&) [with T = void]’ 161 | virtual T visitVarStmt(const Var& stmt) = 0; | ^~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Stmt.h:162:13: note: ‘T lox::stmt::Visitor::visitWhileStmt(const lox::stmt::While&) [with T = void]’ 162 | virtual T visitWhileStmt(const While& stmt) = 0; | ^~~~~~~~~~~~~~ In file included from /home/khushi/Documents/lox.cpp/src/Interpreter.h:9: /home/khushi/Documents/lox.cpp/src/Expr.h:188:13: note: ‘T lox::expr::Visitor::visitAssignExpr(const lox::expr::Assign&) [with T = std::variant, std::allocator >, double, bool>]’ 188 | virtual T visitAssignExpr(const Assign& expr) = 0; // TODO | ^~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:189:13: note: ‘T lox::expr::Visitor::visitBinaryExpr(const lox::expr::Binary&) [with T = std::variant, std::allocator >, double, bool>]’ 189 | virtual T visitBinaryExpr(const Binary& expr) = 0; | ^~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:190:13: note: ‘T lox::expr::Visitor::visitCallExpr(const lox::expr::Call&) [with T = std::variant, std::allocator >, double, bool>]’ 190 | virtual T visitCallExpr(const Call& expr) = 0; | ^~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:191:13: note: ‘T lox::expr::Visitor::visitGetExpr(const lox::expr::Get&) [with T = std::variant, std::allocator >, double, bool>]’ 191 | virtual T visitGetExpr(const Get& expr) = 0; | ^~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:192:13: note: ‘T lox::expr::Visitor::visitGroupingExpr(const lox::expr::Grouping&) [with T = std::variant, std::allocator >, double, bool>]’ 192 | virtual T visitGroupingExpr(const Grouping& expr) = 0; | ^~~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:193:13: note: ‘T lox::expr::Visitor::visitLiteralExpr(const lox::expr::Literal&) [with T = std::variant, std::allocator >, double, bool>]’ 193 | virtual T visitLiteralExpr(const Literal& expr) = 0; | ^~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:194:13: note: ‘T lox::expr::Visitor::visitLogicalExpr(const lox::expr::Logical&) [with T = std::variant, std::allocator >, double, bool>]’ 194 | virtual T visitLogicalExpr(const Logical& expr) = 0; | ^~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:195:13: note: ‘T lox::expr::Visitor::visitSetExpr(const lox::expr::Set&) [with T = std::variant, std::allocator >, double, bool>]’ 195 | virtual T visitSetExpr(const Set& expr) = 0; | ^~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:196:13: note: ‘T lox::expr::Visitor::visitSuperExpr(const lox::expr::Super&) [with T = std::variant, std::allocator >, double, bool>]’ 196 | virtual T visitSuperExpr(const Super& expr) = 0; | ^~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:197:13: note: ‘T lox::expr::Visitor::visitThisExpr(const lox::expr::This&) [with T = std::variant, std::allocator >, double, bool>]’ 197 | virtual T visitThisExpr(const This& expr) = 0; | ^~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:198:13: note: ‘T lox::expr::Visitor::visitUnaryExpr(const lox::expr::Unary&) [with T = std::variant, std::allocator >, double, bool>]’ 198 | virtual T visitUnaryExpr(const Unary& expr) = 0; | ^~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Expr.h:199:13: note: ‘T lox::expr::Visitor::visitVariableExpr(const lox::expr::Variable&) [with T = std::variant, std::allocator >, double, bool>]’ 199 | virtual T visitVariableExpr(const Variable& expr) = 0; | ^~~~~~~~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/main.cpp: In function ‘int main(int, char**)’: /home/khushi/Documents/lox.cpp/src/main.cpp:14:15: error: use of deleted function ‘lox::Lox::Lox()’ 14 | lox::Lox _lox; | ^~~~ /home/khushi/Documents/lox.cpp/src/Lox.h:16:7: note: ‘lox::Lox::Lox()’ is implicitly deleted because the default definition would be ill-formed: 16 | class Lox { | ^~~ /home/khushi/Documents/lox.cpp/src/Lox.h:16:7: error: use of deleted function ‘lox::Interpreter::Interpreter()’ /home/khushi/Documents/lox.cpp/src/Interpreter.h:18:7: note: ‘lox::Interpreter::Interpreter()’ is implicitly deleted because the default definition would be ill-formed: 18 | class Interpreter : public lox::expr::Visitor, | ^~~~~~~~~~~ /home/khushi/Documents/lox.cpp/src/Interpreter.h:18:7: error: use of deleted function ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = lox::expr::Expr; _Tp = int; _Hash = std::hash >; _Pred = std::equal_to >; _Alloc = std::allocator, int> >]’ In file included from /usr/include/c++/13/unordered_map:41, from /usr/include/c++/13/functional:63, from /home/khushi/Documents/lox.cpp/src/Lox.h:4: /usr/include/c++/13/bits/unordered_map.h:148:7: note: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = lox::expr::Expr; _Tp = int; _Hash = std::hash >; _Pred = std::equal_to >; _Alloc = std::allocator, int> >]’ is implicitly deleted because the default definition would be ill-formed: 148 | unordered_map() = default; | ^~~~~~~~~~~~~ /usr/include/c++/13/bits/unordered_map.h:148:7: error: use of deleted function ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _Alloc = std::allocator, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to >; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits]’ In file included from /usr/include/c++/13/bits/unordered_map.h:33: /usr/include/c++/13/bits/hashtable.h:530:7: note: ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _Alloc = std::allocator, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to >; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits]’ is implicitly deleted because the default definition would be ill-formed: 530 | _Hashtable() = default; | ^~~~~~~~~~ /usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to >; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits]’ In file included from /usr/include/c++/13/bits/hashtable.h:35: /usr/include/c++/13/bits/hashtable_policy.h:1710:7: note: ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to >; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits]’ is implicitly deleted because the default definition would be ill-formed: 1710 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1710:7: error: use of deleted function ‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]’ /usr/include/c++/13/bits/hashtable_policy.h: In instantiation of ‘std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash >]’: /usr/include/c++/13/bits/hashtable_policy.h:1297:7: required from here /usr/include/c++/13/bits/hashtable_policy.h:1214:49: error: use of deleted function ‘std::hash >::hash()’ 1214 | _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { } | ^~~~~ In file included from /usr/include/c++/13/string_view:42, from /usr/include/c++/13/bits/basic_string.h:47, from /usr/include/c++/13/string:54, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/istream:40, from /usr/include/c++/13/fstream:40, from /home/khushi/Documents/lox.cpp/src/main.cpp:4: /usr/include/c++/13/bits/functional_hash.h:102:12: note: ‘std::hash >::hash()’ is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/13/bits/functional_hash.h:102:12: error: no matching function for call to ‘std::__hash_enum, false>::__hash_enum()’ /usr/include/c++/13/bits/functional_hash.h:83:7: note: candidate: ‘std::__hash_enum<_Tp, >::__hash_enum(std::__hash_enum<_Tp, >&&) [with _Tp = lox::expr::Expr; bool = false]’ 83 | __hash_enum(__hash_enum&&); | ^~~~~~~~~~~ /usr/include/c++/13/bits/functional_hash.h:83:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/13/bits/functional_hash.h:102:12: error: ‘std::__hash_enum<_Tp, >::~__hash_enum() [with _Tp = lox::expr::Expr; bool = false]’ is private within this context 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/13/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/13/bits/hashtable_policy.h:1297:7: note: ‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]’ is implicitly deleted because the default definition would be ill-formed: 1297 | _Hash_code_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1297:7: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper<1, std::hash >, true>::~_Hashtable_ebo_helper()’ /usr/include/c++/13/bits/hashtable_policy.h:1211:12: note: ‘std::__detail::_Hashtable_ebo_helper<1, std::hash >, true>::~_Hashtable_ebo_helper()’ is implicitly deleted because the default definition would be ill-formed: 1211 | struct _Hashtable_ebo_helper<_Nm, _Tp, true> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1211:12: error: use of deleted function ‘std::hash >::~hash()’ /usr/include/c++/13/bits/functional_hash.h:102:12: note: ‘std::hash >::~hash()’ is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/13/bits/functional_hash.h:102:12: error: ‘std::__hash_enum<_Tp, >::~__hash_enum() [with _Tp = lox::expr::Expr; bool = false]’ is private within this context /usr/include/c++/13/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/13/bits/hashtable_policy.h:1710:7: error: use of deleted function ‘std::__detail::_Hash_code_base, std::pair, int>, std::__detail::_Select1st, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()’ 1710 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1275:12: note: ‘std::__detail::_Hash_code_base, std::pair, int>, std::__detail::_Select1st, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()’ is implicitly deleted because the default definition would be ill-formed: 1275 | struct _Hash_code_base | ^~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1275:12: error: use of deleted function ‘std::__detail::_Hashtable_ebo_helper<1, std::hash >, true>::~_Hashtable_ebo_helper()’ /usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function ‘std::__detail::_Hashtable_base, std::pair, int>, std::__detail::_Select1st, std::equal_to >, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits >::~_Hashtable_base()’ 530 | _Hashtable() = default; | ^~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1667:12: note: ‘std::__detail::_Hashtable_base, std::pair, int>, std::__detail::_Select1st, std::equal_to >, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits >::~_Hashtable_base()’ is implicitly deleted because the default definition would be ill-formed: 1667 | struct _Hashtable_base | ^~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable_policy.h:1667:12: error: use of deleted function ‘std::__detail::_Hash_code_base, std::pair, int>, std::__detail::_Select1st, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()’ /usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function ‘constexpr std::_Enable_default_constructor::_Enable_default_constructor() [with _Tag = std::__detail::_Hash_node_base]’ 530 | _Hashtable() = default; | ^~~~~~~~~~ In file included from /usr/include/c++/13/bits/hashtable.h:36: /usr/include/c++/13/bits/enable_special_members.h:113:15: note: declared here 113 | constexpr _Enable_default_constructor() noexcept = delete; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable.h: In instantiation of ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::~_Hashtable() [with _Key = lox::expr::Expr; _Value = std::pair, int>; _Alloc = std::allocator, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to >; _Hash = std::hash >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits]’: /usr/include/c++/13/bits/unordered_map.h:109:11: required from here /usr/include/c++/13/bits/hashtable.h:1595:5: error: use of deleted function ‘std::__detail::_Hashtable_base, std::pair, int>, std::__detail::_Select1st, std::equal_to >, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits >::~_Hashtable_base()’ 1595 | } | ^ /usr/include/c++/13/bits/hashtable.h:1587:21: error: static assertion failed: Cache the hash code or qualify your functors involved in hash code and bucket index computation with noexcept 1587 | static_assert(noexcept(declval() | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1588 | ._M_bucket_index(declval(), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1589 | (std::size_t)0)), | ~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/hashtable.h:1587:21: note: ‘false’ evaluates to false make[2]: *** [CMakeFiles/main.dir/build.make:90: CMakeFiles/main.dir/src/main.cpp.o] Error 1 make[2]: Leaving directory '/home/khushi/Documents/lox.cpp/build' make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/main.dir/all] Error 2 make[1]: Leaving directory '/home/khushi/Documents/lox.cpp/build' make: *** [Makefile:91: all] Error 2 ```