Skip to content

Add clang-format and yapf checks #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint

on: pull_request

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: jidicula/[email protected]

yapf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: AlexanderMelde/[email protected]
42 changes: 26 additions & 16 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ def main():
os.chdir(config_dir)
progname = sys.argv[0]
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-m", "--mode", metavar="MODE",
type=str, choices="dbg dev opt".split(), default="opt",
parser.add_argument("-m",
"--mode",
metavar="MODE",
type=str,
choices="dbg dev opt".split(),
default="opt",
help="set build configuration:\n"
" - opt: compile for fast binaries (default)\n"
" - dev: compile for fast builds\n"
" - dbg: add debugging symbols")
parser.add_argument("-o", "--target-os", metavar="OS",
parser.add_argument("-o",
"--target-os",
metavar="OS",
type=str,
help="target os (default: host os)")
parser.add_argument("--prefix", type=str, default="/usr/local",
parser.add_argument("--prefix",
type=str,
default="/usr/local",
help="installation prefix (default: /usr/local)")
parser.add_argument("--sanitizer", choices="memory address undefined".split(), default="",
parser.add_argument("--sanitizer",
choices="memory address undefined".split(),
default="",
help="run sanitizer (memory, address, or undefined)")
args = parser.parse_args()

Expand Down Expand Up @@ -127,18 +137,19 @@ def check_mac(args):

missing = collections.OrderedDict()
if not (cfg.check_clang() and cfg.check_libcxx()):
missing["xcode"] = (
"* Xcode can be installed via the App Store:\n"
" https://itunes.apple.com/en/app/xcode/id497799835\n"
" After installing, open it and accept the license agreement\n")
missing["xcode"] = ("* Xcode can be installed via the App Store:\n"
" https://itunes.apple.com/en/app/xcode/id497799835\n"
" After installing, open it and accept the license agreement\n")

if missing:
print("\nmissing dependencies: %s\n" % " ".join(missing.keys()))
for step in missing.values():
sys.stdout.write(step)
if any("Homebrew" in v for v in missing.values()):
print("* Homebrew can be installed like so:")
print(' $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
print(
' $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
)
sys.exit(1)


Expand Down Expand Up @@ -184,12 +195,11 @@ def check_linux_native(args):

def check_mac_on_linux(args):
missing = collections.OrderedDict()
if not (cfg.check_clang("x86_64-apple-darwin15-clang++") and
cfg.check_libcxx("x86_64-apple-darwin15-clang++")):
missing["osxcross"] = (
"* OSXCross can be found here:\n"
" https://github.com/tpoechtrager/osxcross\n"
" Download and build it, and ensure target/bin is in your $PATH\n")
if not (cfg.check_clang("x86_64-apple-darwin15-clang++")
and cfg.check_libcxx("x86_64-apple-darwin15-clang++")):
missing["osxcross"] = ("* OSXCross can be found here:\n"
" https://github.com/tpoechtrager/osxcross\n"
" Download and build it, and ensure target/bin is in your $PATH\n")

if missing:
print("\nmissing dependencies: %s\n" % " ".join(missing.keys()))
Expand Down
8 changes: 4 additions & 4 deletions misc/pygments/procyonlexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class ProcyonLexer(RegexLexer):
(r"\*", Punctuation),
(r"([>|])([ \t])?(.+)?$", bygroups(Punctuation, Text, String.Other)),
(r"(!)([ \t])?(.+)?$", bygroups(Punctuation, Text, Error)),
(r"([A-Za-z0-9_./+-]*)(:)([ \t]+)?(.+)?$", bygroups(Name.Tag, Punctuation, Text,
using(this, state="value"))),
(r'("(?:[^"\\]|\\.)*")(:)([ \t]+)?(.+)?$', bygroups(Name.Tag, Punctuation, Text,
using(this, state="value"))),
(r"([A-Za-z0-9_./+-]*)(:)([ \t]+)?(.+)?$",
bygroups(Name.Tag, Punctuation, Text, using(this, state="value"))),
(r'("(?:[^"\\]|\\.)*")(:)([ \t]+)?(.+)?$',
bygroups(Name.Tag, Punctuation, Text, using(this, state="value"))),
(r"#.*$", Comment),
include("value"),
(r".+$", Error),
Expand Down
3 changes: 2 additions & 1 deletion misc/pygments/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
"Topic :: Text Processing :: Filters",
"Topic :: Text Processing :: Markup",
"Topic :: Utilities",
], )
],
)
13 changes: 8 additions & 5 deletions src/bin/src/pnfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,19 @@ static void usage(pn::output_view out, int status) {

static pn::value repr(const token& t) {
pn::map m{
{"type", t.type}, {"column", t.column}, {"content", t.content.copy()},
{"type", t.type},
{"column", t.column},
{"content", t.content.copy()},
};
return std::move(m);
}

static pn::value repr(const line& l) {
pn::map m{{"indent", l.indent},
{"lineno", l.lineno},
{"width", l.width},
{"extra_nl_before", l.extra_nl_before}};
pn::map m{
{"indent", l.indent},
{"lineno", l.lineno},
{"width", l.width},
{"extra_nl_before", l.extra_nl_before}};
if (!l.tokens.empty()) {
pn::array_ref a = m["tokens"].to_array();
for (const token& token : l.tokens) {
Expand Down
4 changes: 4 additions & 0 deletions src/c/scripts/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def output_c(lex, parser):
yield "#include \"gen_table.h\""

yield
yield "// clang-format off"
yield "const uint8_t lex_classes[256] = {"
for i in range(0, 256, 16):
line = " "
Expand Down Expand Up @@ -137,6 +138,7 @@ def output_python(lex, parser):
yield "from .error import Error"
yield "from .parse_enums import Acc, Emit, Key"
yield
yield "# yapf: disable"

lines = []
for i in range(0, 256, 16):
Expand Down Expand Up @@ -198,6 +200,7 @@ def lex_transition_value(kind, value):


class Lexer:

def __init__(self, spec):
lex = OrderedDict()
for s, t in spec["lex"].items():
Expand Down Expand Up @@ -296,6 +299,7 @@ def list_chars(char_set):


class Parser:

def __init__(self, spec):
parse_states = OrderedDict((state, i) for i, state in enumerate(spec["parse"]))
self.defs = OrderedDict()
Expand Down
59 changes: 29 additions & 30 deletions src/c/src/dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,33 +582,34 @@ static int16_t Lhint[2098] = {
642, 642, 642, 643, 643, 643, 644, 644, 644, 644, 645, 645, 645, 646, 646, 646, 647, 647,
647, 647, 648, 648, 648, 649, 649, 649, 650, 650};

static uint64_t pfive[27] = {5ll,
25ll,
125ll,
625ll,
3125ll,
15625ll,
78125ll,
390625ll,
1953125ll,
9765625ll,
48828125ll,
244140625ll,
1220703125ll,
6103515625ll,
30517578125ll,
152587890625ll,
762939453125ll,
3814697265625ll,
19073486328125ll,
95367431640625ll,
476837158203125ll,
2384185791015625ll,
11920928955078125ll,
59604644775390625ll,
298023223876953125ll,
1490116119384765625ll,
7450580596923828125ll};
static uint64_t pfive[27] = {
5ll,
25ll,
125ll,
625ll,
3125ll,
15625ll,
78125ll,
390625ll,
1953125ll,
9765625ll,
48828125ll,
244140625ll,
1220703125ll,
6103515625ll,
30517578125ll,
152587890625ll,
762939453125ll,
3814697265625ll,
19073486328125ll,
95367431640625ll,
476837158203125ll,
2384185791015625ll,
11920928955078125ll,
59604644775390625ll,
298023223876953125ll,
1490116119384765625ll,
7450580596923828125ll};

static int pfivebits[25] = {3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31,
33, 35, 38, 40, 42, 45, 47, 49, 52, 54, 56, 59};
Expand Down Expand Up @@ -682,9 +683,7 @@ typedef struct ThInfo {

#ifdef _MSC_VER
static __declspec(thread) ThInfo ti_instance;
static ThInfo* get_TI(void) {
return &ti_instance;
}
static ThInfo* get_TI(void) { return &ti_instance; }
#else
static pthread_key_t ti_key;
static pthread_once_t ti_once;
Expand Down
2 changes: 1 addition & 1 deletion src/c/src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static bool dump_bool(pn_bool_t b, pn_output_t* out) {
}

static bool dump_int(pn_int_t i, pn_output_t* out) {
char buf[32];
char buf[32];
ptrdiff_t len;
return ((len = sprintf(buf, "%" PRId64, i)) > 0) && pn_raw_write(out, buf, len);
}
Expand Down
2 changes: 1 addition & 1 deletion src/c/src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void set_arg(char format, struct format_arg* dst, va_list* vl) {
}

static bool print_u(pn_output_t* out, uint64_t u) {
char buf[32];
char buf[32];
ptrdiff_t len;
return ((len = sprintf(buf, "%" PRIu64, u)) > 0) && pn_write(out, "S", buf, (size_t)len);
}
Expand Down
1 change: 1 addition & 0 deletions src/c/src/gen_table.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gen_table.h"

// clang-format off
const uint8_t lex_classes[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
36 changes: 18 additions & 18 deletions src/c/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
#include "./io.h"

union pn_primitive {
int i;
unsigned I;
int16_t h;
uint16_t H;
int32_t l;
uint32_t L;
int64_t q;
uint64_t Q;
intptr_t p;
uintptr_t P;
size_t z;
ptrdiff_t Z;
int i;
unsigned I;
int16_t h;
uint16_t H;
int32_t l;
uint32_t L;
int64_t q;
uint64_t Q;
intptr_t p;
uintptr_t P;
size_t z;
ptrdiff_t Z;

float f;
double d;
Expand Down Expand Up @@ -118,13 +118,13 @@ bool pn_read_arg(pn_input_t* in, char format, va_list* vl) {

case 's': return read_bytes_strlen(in, va_arg(*vl, char*));
case 'S': {
char* data_ptr = va_arg(*vl, char*);
char* data_ptr = va_arg(*vl, char*);
size_t data_size = va_arg(*vl, size_t);
return pn_raw_read(in, data_ptr, data_size);
}
case '$': {
uint8_t* data_ptr = va_arg(*vl, uint8_t*);
size_t data_size = va_arg(*vl, size_t);
size_t data_size = va_arg(*vl, size_t);
return pn_raw_read(in, data_ptr, data_size);
}
case 'c': return PN_READ_BYTE(char);
Expand Down Expand Up @@ -201,13 +201,13 @@ static bool pn_write_arg(pn_output_t* out, char format, va_list* vl) {

case 's': return write_bytes_strlen(out, va_arg(*vl, const char*));
case 'S': {
const char* data_ptr = va_arg(*vl, const char*);
const char* data_ptr = va_arg(*vl, const char*);
const size_t data_size = va_arg(*vl, size_t);
return pn_raw_write(out, data_ptr, data_size);
}
case '$': {
const uint8_t* data_ptr = va_arg(*vl, const uint8_t*);
const size_t data_size = va_arg(*vl, size_t);
const uint8_t* data_ptr = va_arg(*vl, const uint8_t*);
const size_t data_size = va_arg(*vl, size_t);
return pn_raw_write(out, data_ptr, data_size);
}
case 'c': return write_byte(out, va_arg(*vl, int));
Expand Down Expand Up @@ -359,7 +359,7 @@ ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size) {
}
memmove(*data, in->view->data, out_size);
(*data)[out_size] = '\0';
in->view->data = (char*)in->view->data + out_size;
in->view->data = (char*)in->view->data + out_size;
in->view->size -= out_size;
return out_size;
}
Expand Down
10 changes: 5 additions & 5 deletions src/c/src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ struct pn_input_view {
size_t size;
};

int pn_getc(pn_input_t* in);
int pn_putc(int ch, pn_output_t* out);
bool pn_raw_read(pn_input_t* in, void* data, size_t size);
bool pn_raw_write(pn_output_t* out, const void* data, size_t size);
ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size);
int pn_getc(pn_input_t* in);
int pn_putc(int ch, pn_output_t* out);
bool pn_raw_read(pn_input_t* in, void* data, size_t size);
bool pn_raw_write(pn_output_t* out, const void* data, size_t size);
ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size);

#ifdef __cplusplus
} // extern "C"
Expand Down
10 changes: 5 additions & 5 deletions src/c/src/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ typedef struct {
char* begin;
char* end;
} token;
size_t lineno;
size_t lineno;
ptrdiff_t indent;
size_t prev_width;
bool eq;
size_t prev_width;
bool eq;

struct {
char* begin; // data in current line (not NUL-terminated)
Expand All @@ -91,8 +91,8 @@ typedef struct {
} buffer;

struct {
size_t count;
size_t size;
size_t count;
size_t size;
ptrdiff_t values[];
} * levels;
} pn_lexer_t;
Expand Down
5 changes: 3 additions & 2 deletions src/c/src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ static void parse_short_string_value(pn_string_t** s, const char* begin, const c
char utf[] = {0340 | ((u >> 12) & 0017), 0200 | ((u >> 6) & 0077), 0200 | (u & 0077)};
pn_strncat(s, utf, 3);
} else {
char utf[] = {0360 | ((u >> 18) & 0x007), 0200 | ((u >> 12) & 0077),
0200 | ((u >> 6) & 0077), 0200 | (u & 0077)};
char utf[] = {
0360 | ((u >> 18) & 0x007), 0200 | ((u >> 12) & 0077),
0200 | ((u >> 6) & 0077), 0200 | (u & 0077)};
pn_strncat(s, utf, 4);
}
}
Expand Down
Loading