Skip to content

Commit a04e1a5

Browse files
authored
[Feature:Autograding] tree-sitter c-api (#2)
* Initial C-API * Update readme * Initial class implementation * Add function call counting * Refactor header * Add c counting * Fix function counting * Fix requested changes * Update source sh scripts * Add cpp shell static checks * Add function counting * File glob handling and format * Update cmakelists * Fix function changes * Update actions * Remove test.yml * Initial diagnostics * Refactor diagnostics * Add nlohmann json * Fix shell-check * Format json output * Add fixes * Add identifier counting * Add c++ * Update counting * Add tests for executable * Update test.yml * check * Fix file name * Switch user * Change to sudo * FIx format * Spaces for tabs
1 parent 046c660 commit a04e1a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+667
-10891
lines changed

.eslintrc.json

Lines changed: 0 additions & 59 deletions
This file was deleted.

.gitattributes

100644100755
File mode changed.

.github/PULL_REQUEST_TEMPLATE.md

100644100755
File mode changed.

.github/workflows/pr_title.yml

100644100755
File mode changed.

.github/workflows/static_analysis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Static analysis
2+
on: [push]
3+
4+
jobs:
5+
cppcheck:
6+
name: Cppcheck
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: install cpp-check
11+
run: sudo apt-get install -y cppcheck
12+
- name: run cpp-check
13+
run: cppcheck src/
14+
15+
shellcheck:
16+
name: Shellcheck
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: install shellcheck
21+
run: sudo apt-get install -y shellcheck
22+
- name: run shell-check
23+
run: shellcheck *.sh -e SC1090
24+

.github/workflows/test.yml

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
name: Test
2-
3-
on: ['push', 'pull_request']
2+
on: [push]
43

54
jobs:
6-
build:
5+
test:
6+
name: Test
77
runs-on: ubuntu-latest
8-
9-
strategy:
10-
matrix:
11-
# Disable 17.x for now, see https://github.com/tree-sitter/node-tree-sitter/issues/102
12-
node-version: [16.x]
13-
148
steps:
15-
- uses: actions/checkout@v2
16-
17-
- uses: actions/setup-node@v2
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
cache: npm
21-
22-
- run: npm install
23-
24-
- run: npm run lint
25-
26-
- run: npm run build
27-
28-
- run: npm run test
29-
30-
- uses: codecov/codecov-action@v2
9+
- uses: actions/checkout@v2
10+
- name: Change permission
11+
run: chmod +x install_analysistoolsts.sh
12+
- name: Build executable
13+
run: sudo ./install_analysistoolsts.sh local
14+
- name: run tests
15+
run: python testRunner.py

.gitignore

100644100755
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
node_modules/
2-
.DS_Store
3-
4-
# build artifacts
5-
dist/
6-
7-
# test artifacts
8-
.nyc_output/
9-
coverage/
1+
include/
2+
build/

.husky/pre-commit

Lines changed: 0 additions & 5 deletions
This file was deleted.

.prettierrc.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.16.3)
2+
3+
project(analysis_tools_ts)
4+
5+
set(JSONCODE include/json/include/)
6+
7+
if(JSONDIR)
8+
set(JSONCODE ${JSONDIR})
9+
endif()
10+
11+
add_library(tree-sitter-python include/tree-sitter-python/src/parser.c
12+
include/tree-sitter-python/src/scanner.cc)
13+
14+
add_library(tree-sitter-cpp include/tree-sitter-cpp/src/parser.c
15+
include/tree-sitter-cpp/src/scanner.cc)
16+
17+
add_library(tree-sitter-c include/tree-sitter-c/src/parser.c)
18+
19+
link_libraries(tree-sitter-python tree-sitter-c tree-sitter-cpp
20+
${PROJECT_SOURCE_DIR}/include/tree-sitter/libtree-sitter.a)
21+
22+
add_executable(submitty_count_ts src/count.cpp src/parser.cpp src/utils.cpp)
23+
24+
add_executable(submitty_diagnostics_ts src/diagnostics.cpp src/parser.cpp
25+
src/utils.cpp)
26+
27+
include_directories(include/tree-sitter/lib/include)
28+
29+
target_include_directories(submitty_diagnostics_ts PUBLIC ${JSONCODE})

LICENSE.md

100644100755
File mode changed.

README.md

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ This is intended to be a successor to the `count` and `diagnostics` applications
1212
To work with this repo, you will need [Node.js](https://nodejs.org/).
1313

1414
```bash
15-
git clone https://github.com/Submitty/tree-analyzer
16-
cd tree-analyzer
17-
npm install
15+
git clone https://github.com/Submitty/AnalysisToolsTS
16+
cd AnalysisToolsTS
17+
```
18+
19+
To run locally setup with command
20+
```
21+
./install_analysistoolsts.sh local
1822
```

install_analysistoolsts.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
3+
########################################################################################################################
4+
########################################################################################################################
5+
# this script must be run by root or sudo
6+
if [[ "$UID" -ne "0" ]] ; then
7+
echo "ERROR: This script must be run by root or sudo"
8+
exit 1
9+
fi
10+
11+
VARS="$(dirname "$0")"/submitty.sh
12+
13+
if [ $# -gt 0 ] && [ "$1" == "local" ]; then
14+
VARS="$(dirname "$0")"/local.sh
15+
fi
16+
17+
source "${VARS}"
18+
19+
echo -e "Installing AnalysisToolsTS... "
20+
21+
mkdir -p "${INSTALLATION_DIR}"
22+
23+
# Copy cloned files to AnalysisToolsTS directory
24+
rsync -rtz "${REPO_DIR}" "${INSTALLATION_DIR}"
25+
26+
mkdir -p "${INCLUDE_DIR}"
27+
28+
########################################################################
29+
30+
# Clone the tree-sitter repos
31+
repos=( tree-sitter tree-sitter-python tree-sitter-c tree-sitter-cpp)
32+
33+
for repo in "${repos[@]}"
34+
do
35+
dir="${INCLUDE_DIR}"/"${repo}"
36+
37+
echo "clone or update ${repo}... "
38+
39+
if [ -d "${dir}" ]; then
40+
echo "pulling changes ..."
41+
# IF THE REPO ALREADY EXISTS...
42+
pushd "${dir}" || exit
43+
44+
# PULL CHANGES
45+
git fetch
46+
git reset --hard HEAD
47+
git merge origin/"$CURRENT_BRANCH"
48+
popd || exit
49+
50+
else
51+
# THE REPO DID NOT EXIST
52+
echo "the repository did not previously exist cloning... "
53+
pushd "${INCLUDE_DIR}" || exit
54+
git clone --depth 1 "https://github.com/tree-sitter/${repo}" || exit
55+
popd || exit
56+
57+
fi
58+
done
59+
60+
# CHECKOUT & INSTALL THE NLOHMANN C++ JSON LIBRARY
61+
# If we don't already have a copy of this repository, check it out, only for local development
62+
if [ $# -gt 0 ] && [ ! -d "${NLOHMANN_DIR}" ]; then
63+
git clone --depth 1 "https://github.com/nlohmann/json.git" "${NLOHMANN_DIR}"
64+
fi
65+
66+
########################################################################
67+
68+
# build tree sitter library
69+
pushd "${INCLUDE_DIR}"/tree-sitter || exit
70+
71+
make
72+
73+
popd || exit
74+
75+
echo "building submitty_count_ts ..."
76+
77+
# Compile the project
78+
mkdir -p "${INSTALLATION_DIR}/build"
79+
80+
cmake -S "${INSTALLATION_DIR}" -B "${INSTALLATION_DIR}/build" -DJSONDIR="${NLOHMANN_INCLUDE_DIR}"
81+
82+
pushd "${INSTALLATION_DIR}/build" || exit
83+
84+
make
85+
86+
popd || exit
87+
88+
# # change permissions
89+
if [ $# -eq 0 ]; then
90+
chown -R root:root "${INSTALLATION_DIR}"
91+
chmod -R 755 "${INSTALLATION_DIR}"
92+
fi
93+
94+
echo "Done setting up AnalysisToolsTS"

local.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
REPO_DIR=$(pwd)
3+
export REPO_DIR=.
4+
export INSTALLATION_DIR=.
5+
export INCLUDE_DIR=include
6+
export NLOHMANN_DIR=include/json
7+
export NLOHMANN_INCLUDE_DIR=include/json/include/

0 commit comments

Comments
 (0)