Skip to content

Commit

Permalink
A few gtest cases for PSA (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanw authored Apr 9, 2017
1 parent bbf177c commit 1297646
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 86 deletions.
5 changes: 3 additions & 2 deletions frontends/p4/p4-parse.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,14 @@ const IR::P4Program *parse_P4_16_file(const char *name, FILE *in) {

const IR::P4Program *parse_string(const std::string &pgm) {
int errors = 0;
Util::InputSources::reset();
clearErrorReporter();
structure.clear();
allErrors = nullptr;
declarations = new IR::IndexedVector<IR::Node>();
YY_BUFFER_STATE state = yy_scan_string(pgm.c_str());
errors |= yyparse();
yy_delete_buffer(state);
structure.clear();
allErrors = nullptr;
if (errors) {
return nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions frontends/p4/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,7 @@ cstring ProgramStructure::toString() const {

void ProgramStructure::clear() {
rootNamespace->clear();
currentNamespace = rootNamespace;
debugStream = stderr;
}
} // namespace Util
5 changes: 5 additions & 0 deletions lib/source_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ InputSources::InputSources() :
this->contents.push_back("");
}

/* static */
void InputSources::reset() {
instance = new InputSources;
}

// prevent further changes
void InputSources::seal() {
if (this->sealed)
Expand Down
3 changes: 3 additions & 0 deletions lib/source_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ class InputSources final {

cstring toDebugString() const;

// Reset all source information, so that a new file can be parsed.
static void reset();

static InputSources* instance;

private:
Expand Down
5 changes: 3 additions & 2 deletions test/gtest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# General GTest unit tests. Add tests here if they don't have a logical home
# elsewhere in the codebase.
gtest_unittest_UNIFIED = \
test/gtest/helpers.cpp \
test/gtest/opeq_test.cpp \
test/gtest/typecheck_test.cpp \
test/gtest/midend_test.cpp
test/gtest/midend_test.cpp \
test/gtest/arch_test.cpp

cpplint_FILES += $(gtest_unittest_UNIFIED)
gtest_SOURCES += $(gtest_unittest_SOURCES)
Loading

0 comments on commit 1297646

Please sign in to comment.