Skip to content

Commit

Permalink
Fix for issue #785; readme formatting (#786)
Browse files Browse the repository at this point in the history
* Fix for issue #785; readme formatting

* cpplint fix; removed more autotools files; gtest warning fix

* Fewer ignored files

* Fix incorrect README.md merge

* Added cstring utility method
  • Loading branch information
Mihai Budiu authored and Calin Cascaval committed Jul 26, 2017
1 parent 611c1f7 commit 30df762
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 34 deletions.
26 changes: 0 additions & 26 deletions .gitignore
@@ -1,29 +1,3 @@
# Autotools generated files

Makefile.in
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
test-driver
ylwrap
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
frontends/p4/p4-lex.c
frontends/p4/p4-parse.cpp
py-compile
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Expand Up @@ -12,8 +12,7 @@ ARG MAKEFLAGS=-j2
# removed from the image.
ARG IMAGE_TYPE=build

ENV P4C_DEPS automake \
bison \
ENV P4C_DEPS bison \
build-essential \
cmake \
flex \
Expand All @@ -23,7 +22,6 @@ ENV P4C_DEPS automake \
libfl-dev \
libgc-dev \
libgmp-dev \
libtool \
pkg-config \
python-ipaddr \
python-pip \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -102,7 +102,7 @@ included with `p4c` are documented here:

Most dependencies can be installed using `apt-get install`:

`sudo apt-get install g++ git automake libtool libgc-dev bison flex libfl-dev libgmp-dev libboost-dev libboost-iostreams-dev pkg-config python python-scapy python-ipaddr tcpdump`
`sudo apt-get install g++ git automake libtool libgc-dev bison flex libfl-dev libgmp-dev libboost-dev libboost-iostreams-dev pkg-config python python-scapy python-ipaddr tcpdump cmake`

For documentation building:
`sudo apt-get install -y doxygen graphviz texlive-full`
Expand Down
3 changes: 2 additions & 1 deletion ir/node.cpp
Expand Up @@ -117,7 +117,8 @@ void IR::Node::sourceInfoToJSON(JSONGenerator &json) const {
json << json.indent << "\"filename\" : " << fName << "," << std::endl;
json << json.indent << "\"line\" : " << lineNumber << "," << std::endl;
json << json.indent << "\"column\" : " << columnNumber << "," << std::endl;
json << json.indent << "\"source_fragment\" : " << si.toBriefSourceFragment() << std::endl;
json << json.indent << "\"source_fragment\" : " <<
si.toBriefSourceFragment().escapeJson() << std::endl;

json << --json.indent << "}";
}
Expand Down
13 changes: 12 additions & 1 deletion lib/cstring.cpp
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,3 +77,14 @@ cstring cstring::replace(char c, char with) const {
*p = with;
return cstring(dup);
}

cstring cstring::escapeJson() const {
std::string out;
for (size_t i = 0; i < size(); i++) {
char c = get(i);
if (c == '\\' || c == '"')
out += "\\";
out += c;
}
return cstring(out);
}
4 changes: 4 additions & 0 deletions lib/cstring.h
Expand Up @@ -88,6 +88,10 @@ class cstring {
cstring(const std::string &a) { *this = a; } // NOLINT(runtime/explicit)
cstring &operator=(const char *);
cstring &operator=(const std::string&);
/// @return a version of the string where all necessary characters
/// are properly escaped to make this into a json string (without
/// the enclosing quotes).
cstring escapeJson() const;

template <typename Iter> cstring(Iter begin, Iter end) {
*this = std::string(begin, end);
Expand Down
4 changes: 2 additions & 2 deletions test/gtest/bmv2_isvalid.cpp
Expand Up @@ -313,9 +313,9 @@ TEST(BMV2_SynthesizeValidField, ConstTableEntries) {
ASSERT_TRUE(falses[1]->is<IR::Constant>());
EXPECT_EQ(0, falses[1]->to<IR::Constant>()->asInt());
ASSERT_TRUE(falses[2]->is<IR::BoolLiteral>());
EXPECT_EQ(false, falses[2]->to<IR::BoolLiteral>()->value);
ASSERT_FALSE(falses[2]->to<IR::BoolLiteral>()->value);
ASSERT_TRUE(falses[3]->is<IR::BoolLiteral>());
EXPECT_EQ(false, falses[3]->to<IR::BoolLiteral>()->value);
ASSERT_FALSE(falses[3]->to<IR::BoolLiteral>()->value);
});

program = program->apply(P4::TypeChecking(&refMap, &typeMap));
Expand Down

0 comments on commit 30df762

Please sign in to comment.