Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ else()
endif()

list(REMOVE_ITEM sources
# Don't build
${CMAKE_CURRENT_SOURCE_DIR}/elf_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/smt2_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/json.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/osx_fat_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp_scanner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ieee_float.cpp

# Will be built into a separate library and linked
${testing_utils}

Expand Down
6 changes: 6 additions & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ SRC += analyses/ai/ai.cpp \
ansi-c/type2name.cpp \
ansi-c/c_typecheck_base.cpp \
big-int/big-int.cpp \
cpp/cpp_parser.cpp \
cpp/cpp_scanner.cpp \
compound_block_locations.cpp \
get_goto_model_from_c_test.cpp \
goto-cc/armcc_cmdline.cpp \
Expand All @@ -61,6 +63,7 @@ SRC += analyses/ai/ai.cpp \
goto-instrument/cover_instrument.cpp \
goto-instrument/cover/cover_only.cpp \
goto-synthesizer/expr_enumerator/expr_enumerator.cpp \
goto-programs/elf_reader.cpp \
goto-programs/goto_program_assume.cpp \
goto-programs/goto_program_dead.cpp \
goto-programs/goto_program_declaration.cpp \
Expand All @@ -77,6 +80,7 @@ SRC += analyses/ai/ai.cpp \
goto-programs/restrict_function_pointers.cpp \
goto-programs/structured_trace_util.cpp \
goto-programs/remove_returns.cpp \
goto-programs/wp.cpp \
goto-programs/xml_expr.cpp \
goto-symex/apply_condition.cpp \
goto-symex/complexity_limiter.cpp \
Expand Down Expand Up @@ -110,6 +114,7 @@ SRC += analyses/ai/ai.cpp \
solvers/sat/satcheck_cadical.cpp \
solvers/sat/satcheck_minisat2.cpp \
solvers/smt2/smt2_conv.cpp \
solvers/smt2/smt2_parser.cpp \
solvers/smt2/smt2irep.cpp \
solvers/smt2_incremental/ast/smt_commands.cpp \
solvers/smt2_incremental/ast/smt_index.cpp \
Expand Down Expand Up @@ -173,6 +178,7 @@ SRC += analyses/ai/ai.cpp \
util/irep.cpp \
util/irep_sharing.cpp \
util/invariant.cpp \
util/json.cpp \
util/json_array.cpp \
util/json_object.cpp \
util/lazy.cpp \
Expand Down
67 changes: 67 additions & 0 deletions unit/cpp/cpp_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************\

Module: Unit tests for cpp_parser

Author: Daniel Kroening

\*******************************************************************/

#include <util/config.h>
#include <util/tempfile.h>

#include <cpp/cpp_parser.h>
#include <testing-utils/message.h>
#include <testing-utils/use_catch.h>

#include <fstream>

TEST_CASE("Parse empty C++ file", "[core][cpp][cpp_parser]")
{
temporary_filet temp_file("empty_cpp_", ".cpp");
std::ofstream out(temp_file().c_str());
out << "";
out.close();

config.ansi_c.set_ILP32();

std::ifstream in(temp_file().c_str());

cpp_parsert parser(null_message_handler);
parser.in = &in;

REQUIRE(parser.parse() == false);
}

TEST_CASE("Parse simple C++ code", "[core][cpp][cpp_parser]")
{
temporary_filet temp_file("simple_cpp_", ".cpp");
std::ofstream out(temp_file().c_str());
out << "int main() { return 0; }\n";
out.close();

config.ansi_c.set_ILP32();

std::ifstream in(temp_file().c_str());

cpp_parsert parser(null_message_handler);
parser.in = &in;

REQUIRE(parser.parse() == false);
}

TEST_CASE("Parse C++ with class", "[core][cpp][cpp_parser]")
{
temporary_filet temp_file("class_cpp_", ".cpp");
std::ofstream out(temp_file().c_str());
out << "class MyClass { public: int x; };\n";
out.close();

config.ansi_c.set_ILP32();

std::ifstream in(temp_file().c_str());

cpp_parsert parser(null_message_handler);
parser.in = &in;

REQUIRE(parser.parse() == false);
}
93 changes: 93 additions & 0 deletions unit/cpp/cpp_scanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************\

Module: Unit tests for CPP lexer/scanner

Author: Daniel Kroening, 2015

\*******************************************************************/

#include <util/config.h>
#include <util/tempfile.h>

#include <ansi-c/ansi_c_parser.h>
#include <cpp/cpp_parser.h>
#include <cpp/cpp_token_buffer.h>
#include <testing-utils/message.h>
#include <testing-utils/use_catch.h>

#include <fstream>
#include <sstream>
#include <vector>

TEST_CASE("Scan simple C++ tokens", "[core][cpp][cpp_scanner]")
{
temporary_filet temp_file("tokens_cpp_", ".cpp");
std::ofstream out(temp_file().c_str());
out << "int x = 42;\n";
out.close();

std::ifstream in(temp_file().c_str());

config.ansi_c.set_ILP32();

ansi_c_scanner_init();
ansi_c_parser.clear();
ansi_c_parser.mode = ansi_c_parsert::GCC;
ansi_c_parser.cpp98 = true;
ansi_c_parser.cpp11 = false;
ansi_c_parser.ts_18661_3_Floatn_types = false;
ansi_c_parser.__float128_is_keyword = false;
ansi_c_parser.float16_type = false;
ansi_c_parser.bf16_type = false;
ansi_c_parser.fp16_type = false;
ansi_c_parser.in = &in;

cpp_parsert parser(null_message_handler);
parser.in = &in;

cpp_tokent tk;
std::vector<std::string> tokens;

while(parser.token_buffer.get_token(tk))
tokens.push_back(tk.text);

REQUIRE(tokens.size() > 0);
REQUIRE(tokens[0] == "int");
}

TEST_CASE("Scan C++ keywords", "[core][cpp][cpp_scanner]")
{
temporary_filet temp_file("keywords_cpp_", ".cpp");
std::ofstream out(temp_file().c_str());
out << "class namespace public private\n";
out.close();

std::ifstream in(temp_file().c_str());

config.ansi_c.set_ILP32();

ansi_c_scanner_init();
ansi_c_parser.clear();
ansi_c_parser.mode = ansi_c_parsert::GCC;
ansi_c_parser.cpp98 = true;
ansi_c_parser.cpp11 = false;
ansi_c_parser.ts_18661_3_Floatn_types = false;
ansi_c_parser.__float128_is_keyword = false;
ansi_c_parser.float16_type = false;
ansi_c_parser.bf16_type = false;
ansi_c_parser.fp16_type = false;
ansi_c_parser.in = &in;

cpp_parsert parser(null_message_handler);
parser.in = &in;

cpp_tokent tk;
std::vector<std::string> tokens;

while(parser.token_buffer.get_token(tk))
tokens.push_back(tk.text);

REQUIRE(tokens.size() == 4);
REQUIRE(tokens[0] == "class");
REQUIRE(tokens[1] == "namespace");
}
3 changes: 3 additions & 0 deletions unit/cpp/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing-utils
cpp
util
31 changes: 0 additions & 31 deletions unit/cpp_parser.cpp

This file was deleted.

57 changes: 0 additions & 57 deletions unit/cpp_scanner.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions unit/elf_reader.cpp

This file was deleted.

Loading
Loading