Skip to content

Commit

Permalink
Merge pull request #53 from github/user-facing
Browse files Browse the repository at this point in the history
Add some user-facing AST classes
  • Loading branch information
hvitved authored Dec 1, 2020
2 parents f9c7ae7 + baf29ae commit 11927a9
Show file tree
Hide file tree
Showing 45 changed files with 2,637 additions and 2,036 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- uses: actions/upload-artifact@v2
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
name: ruby_ast.qll
path: ql/src/codeql_ruby/ast.qll
name: Generated.qll
path: ql/src/codeql_ruby/Generated.qll
- uses: actions/upload-artifact@v2
with:
name: extractor-${{ matrix.os }}
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ cargo build --release

## Generating the database schema and QL library

The generated `ql/src/ruby.dbscheme` and `ql/src/codeql_ruby/ast.qll` files are included in the repository, but they can be re-generated as follows:
The generated `ql/src/ruby.dbscheme` and `ql/src/codeql_ruby/Generated.qll` files are included in the repository, but they can be re-generated as follows:

```bash
# Run the generator
cargo run --release -p ruby-generator
# Then auto-format the QL library
codeql query format -i ql/src/codeql_ruby/ast.qll
codeql query format -i ql/src/codeql_ruby/Generated.qll
```

## Building a CodeQL database for a Ruby program
Expand Down
2 changes: 1 addition & 1 deletion create-extractor-pack.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cargo build --release

cargo run --release -p ruby-generator
codeql query format -i ql\src\codeql_ruby\ast.qll
codeql query format -i ql\src\codeql_ruby\Generated.qll

rm -Recurse -Force extractor-pack
mkdir extractor-pack | Out-Null
Expand Down
2 changes: 1 addition & 1 deletion create-extractor-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
cargo build --release

cargo run --release -p ruby-generator
codeql query format -i ql/src/codeql_ruby/ast.qll
codeql query format -i ql/src/codeql_ruby/Generated.qll

rm -rf extractor-pack
mkdir -p extractor-pack
Expand Down
2 changes: 1 addition & 1 deletion extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
flate2 = "1.0"
node-types = { path = "../node-types" }
tree-sitter = "0.17"
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "93632008c63e0577413bbedf120fb92a96397785" }
tree-sitter-ruby = { git = "https://github.com/nickrolfe/tree-sitter-ruby.git", branch = "refinements" }
clap = "2.33"
tracing = "0.1"
tracing-subscriber = { version = "0.2", features = ["env-filter"] }
2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ edition = "2018"
node-types = { path = "../node-types" }
tracing = "0.1"
tracing-subscriber = { version = "0.2", features = ["env-filter"] }
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "93632008c63e0577413bbedf120fb92a96397785" }
tree-sitter-ruby = { git = "https://github.com/nickrolfe/tree-sitter-ruby.git", branch = "refinements" }
2 changes: 1 addition & 1 deletion generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ fn main() {
name: "Ruby".to_owned(),
node_types: tree_sitter_ruby::NODE_TYPES,
dbscheme_path: PathBuf::from("ql/src/ruby.dbscheme"),
ql_library_path: PathBuf::from("ql/src/codeql_ruby/ast.qll"),
ql_library_path: PathBuf::from("ql/src/codeql_ruby/Generated.qll"),
};
match node_types::read_node_types_str(&ruby.node_types) {
Err(e) => {
Expand Down
2 changes: 2 additions & 0 deletions generator/src/ql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ pub fn write<'a>(
" * Automatically generated from the tree-sitter grammar; do not edit\n"
)?;
write!(file, " */\n\n")?;
write!(file, "module Generated {{\n")?;

for element in elements {
write!(file, "{}\n\n", &element)?;
}

write!(file, "}}")?;
Ok(())
}
2 changes: 1 addition & 1 deletion ql/consistency-queries/VariablesConsistency.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import codeql_ruby.Variables
import codeql_ruby.ast.Variable

query predicate ambiguousVariable(VariableAccess access, Variable variable) {
access.getVariable() = variable and
Expand Down
31 changes: 31 additions & 0 deletions ql/src/codeql_ruby/AST.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import codeql.Locations
import codeql_ruby.ast.Method
import codeql_ruby.ast.Parameter
import codeql_ruby.ast.Pattern
import codeql_ruby.ast.Variable
private import codeql_ruby.Generated

/**
* A node in the abstract syntax tree. This class is the base class for all Ruby
* program elements.
*/
class AstNode extends @ast_node {
Generated::AstNode generated;

AstNode() { generated = this }

/**
* Gets the name of a primary CodeQL class to which this node belongs.
*
* This predicate always has a result. If no primary class can be
* determined, the result is `"???"`. If multiple primary classes match,
* this predicate can have multiple results.
*/
string describeQlClass() { result = "???" }

/** Gets a textual representation of this node. */
string toString() { result = "AstNode" }

/** Gets the location if this node. */
Location getLocation() { result = generated.getLocation() }
}
Loading

0 comments on commit 11927a9

Please sign in to comment.