Skip to content

Commit 08cf249

Browse files
author
Varun Gandhi
committed
Replace using/decltype with typedefs.
1 parent 45b1485 commit 08cf249

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ matrix:
1111
osx_image: xcode9.2
1212
compiler: clang
1313
- os: linux
14-
env: CXX=clang-5.0 CXXFLAGS="-std=c++11 $CXXFLAGS"
14+
env: CXX=clang-5.0
1515
compiler: clang-5.0
1616
addons:
1717
apt:
@@ -27,7 +27,8 @@ branches:
2727
# - "/^v.*$/"
2828
deploy:
2929
provider: script
30-
script: npm run prebuild && npm run prebuild:upload -u ${PREBUILD_UPLOAD}
30+
script: |
31+
npm run prebuild && npm run prebuild:upload -u ${PREBUILD_UPLOAD}
3132
skip_cleanup: true
3233
on:
3334
all_branches: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"rebuild": "npx tree-sitter generate && npx node-gyp rebuild",
8-
"install": "prebuild-install || npx node-gyp rebuild",
8+
"install": "CXXFLAGS=\"-std=c++11\" prebuild-install || npx node-gyp rebuild",
99
"prebuild": "prebuild --all --strip --verbose",
1010
"prebuild:upload": "prebuild --upload-all",
1111
"test": "npx tree-sitter test",

src/scanner.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
#include <cwctype>
44
#include <cassert>
55
#include <cstring>
6+
#include <cstdint>
67

78
namespace {
89

10+
// If we could somehow force the CI to use C++11, we could use decltype
11+
// instead of using this work-around of declaring aliases up-front.
12+
typedef uint32_t queued_dedent_count_type;
13+
typedef uint16_t indent_length_stack_element_type;
14+
915
using std::vector;
1016

1117
enum TokenType {
@@ -21,18 +27,17 @@ namespace {
2127

2228
unsigned serialize(char *buffer) {
2329
size_t n_copied_so_far = 0;
24-
size_t n_to_copy = sizeof(decltype(queued_dedent_count));
30+
size_t n_to_copy = sizeof(queued_dedent_count_type);
2531

2632
std::memcpy((void *) &(buffer[n_copied_so_far]),
2733
(void *) &queued_dedent_count,
2834
n_to_copy);
2935
n_copied_so_far += n_to_copy;
3036

31-
using element_type = decltype(indent_length_stack)::value_type;
32-
n_to_copy = indent_length_stack.size() * sizeof(element_type);
37+
n_to_copy = indent_length_stack.size() * sizeof(indent_length_stack_element_type);
3338
if (n_copied_so_far + n_to_copy > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
3439
n_to_copy = TREE_SITTER_SERIALIZATION_BUFFER_SIZE - n_copied_so_far;
35-
n_to_copy -= n_to_copy % sizeof(element_type);
40+
n_to_copy -= n_to_copy % sizeof(indent_length_stack_element_type);
3641
}
3742
std::memcpy((void *) &(buffer[n_copied_so_far]),
3843
(void *) indent_length_stack.data(),
@@ -60,14 +65,13 @@ namespace {
6065
n_to_copy);
6166
n_copied_so_far += n_to_copy;
6267

63-
using element_type = decltype(indent_length_stack)::value_type;
6468
n_to_copy = length - n_copied_so_far;
65-
n_to_copy -= n_to_copy % sizeof(element_type);
69+
n_to_copy -= n_to_copy % sizeof(indent_length_stack_element_type);
6670
if (n_to_copy == 0) {
6771
indent_length_stack.push_back(0);
6872
return;
6973
}
70-
indent_length_stack.resize(n_to_copy / sizeof(element_type));
74+
indent_length_stack.resize(n_to_copy / sizeof(indent_length_stack_element_type));
7175
std::memcpy((void *) indent_length_stack.data(),
7276
(void *) &(buffer[n_copied_so_far]),
7377
n_to_copy);
@@ -225,8 +229,8 @@ namespace {
225229
return false;
226230
}
227231

228-
vector<uint16_t> indent_length_stack;
229-
uint32_t queued_dedent_count;
232+
vector<indent_length_stack_element_type> indent_length_stack;
233+
queued_dedent_count_type queued_dedent_count;
230234

231235
// column_number : Maybe Int
232236
// -1 as Nothing,

0 commit comments

Comments
 (0)