mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Ruby/QL: unconditionally generate discard predicates
This commit is contained in:
@@ -36,5 +36,5 @@ pub fn run(options: Options) -> std::io::Result<()> {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
generate(languages, options.dbscheme, options.library, false)
|
generate(languages, options.dbscheme, options.library)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
import codeql.Locations as L
|
import codeql.Locations as L
|
||||||
|
|
||||||
|
/** Holds if the database is an overlay. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
|
||||||
|
|
||||||
module QL {
|
module QL {
|
||||||
/** The base class for all AST nodes */
|
/** The base class for all AST nodes */
|
||||||
class AstNode extends @ql_ast_node {
|
class AstNode extends @ql_ast_node {
|
||||||
@@ -48,6 +52,30 @@ module QL {
|
|||||||
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the file containing the given `node`. */
|
||||||
|
overlay[local]
|
||||||
|
private @file getNodeFile(@ql_ast_node node) {
|
||||||
|
exists(@location_default loc | ql_ast_node_location(node, loc) |
|
||||||
|
locations_default(loc, result, _, _, _, _)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `file` was extracted as part of the overlay database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardFile(@file file) { isOverlay() and file = getNodeFile(_) }
|
||||||
|
|
||||||
|
/** Holds if `node` is in the `file` and is part of the overlay base database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardableAstNode(@file file, @ql_ast_node node) {
|
||||||
|
not isOverlay() and file = getNodeFile(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `node` should be discarded, because it is part of the overlay base and is in a file that was also extracted as part of the overlay database. */
|
||||||
|
overlay[discard_entity]
|
||||||
|
private predicate discardAstNode(@ql_ast_node node) {
|
||||||
|
exists(@file file | discardableAstNode(file, node) and discardFile(file))
|
||||||
|
}
|
||||||
|
|
||||||
/** A class representing `add_expr` nodes. */
|
/** A class representing `add_expr` nodes. */
|
||||||
class AddExpr extends @ql_add_expr, AstNode {
|
class AddExpr extends @ql_add_expr, AstNode {
|
||||||
/** Gets the name of the primary QL class for this element. */
|
/** Gets the name of the primary QL class for this element. */
|
||||||
@@ -1318,6 +1346,30 @@ module Dbscheme {
|
|||||||
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the file containing the given `node`. */
|
||||||
|
overlay[local]
|
||||||
|
private @file getNodeFile(@dbscheme_ast_node node) {
|
||||||
|
exists(@location_default loc | dbscheme_ast_node_location(node, loc) |
|
||||||
|
locations_default(loc, result, _, _, _, _)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `file` was extracted as part of the overlay database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardFile(@file file) { isOverlay() and file = getNodeFile(_) }
|
||||||
|
|
||||||
|
/** Holds if `node` is in the `file` and is part of the overlay base database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardableAstNode(@file file, @dbscheme_ast_node node) {
|
||||||
|
not isOverlay() and file = getNodeFile(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `node` should be discarded, because it is part of the overlay base and is in a file that was also extracted as part of the overlay database. */
|
||||||
|
overlay[discard_entity]
|
||||||
|
private predicate discardAstNode(@dbscheme_ast_node node) {
|
||||||
|
exists(@file file | discardableAstNode(file, node) and discardFile(file))
|
||||||
|
}
|
||||||
|
|
||||||
/** A class representing `annotName` tokens. */
|
/** A class representing `annotName` tokens. */
|
||||||
class AnnotName extends @dbscheme_token_annot_name, Token {
|
class AnnotName extends @dbscheme_token_annot_name, Token {
|
||||||
/** Gets the name of the primary QL class for this element. */
|
/** Gets the name of the primary QL class for this element. */
|
||||||
@@ -1654,6 +1706,30 @@ module Blame {
|
|||||||
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the file containing the given `node`. */
|
||||||
|
overlay[local]
|
||||||
|
private @file getNodeFile(@blame_ast_node node) {
|
||||||
|
exists(@location_default loc | blame_ast_node_location(node, loc) |
|
||||||
|
locations_default(loc, result, _, _, _, _)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `file` was extracted as part of the overlay database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardFile(@file file) { isOverlay() and file = getNodeFile(_) }
|
||||||
|
|
||||||
|
/** Holds if `node` is in the `file` and is part of the overlay base database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardableAstNode(@file file, @blame_ast_node node) {
|
||||||
|
not isOverlay() and file = getNodeFile(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `node` should be discarded, because it is part of the overlay base and is in a file that was also extracted as part of the overlay database. */
|
||||||
|
overlay[discard_entity]
|
||||||
|
private predicate discardAstNode(@blame_ast_node node) {
|
||||||
|
exists(@file file | discardableAstNode(file, node) and discardFile(file))
|
||||||
|
}
|
||||||
|
|
||||||
/** A class representing `blame_entry` nodes. */
|
/** A class representing `blame_entry` nodes. */
|
||||||
class BlameEntry extends @blame_blame_entry, AstNode {
|
class BlameEntry extends @blame_blame_entry, AstNode {
|
||||||
/** Gets the name of the primary QL class for this element. */
|
/** Gets the name of the primary QL class for this element. */
|
||||||
@@ -1767,6 +1843,30 @@ module JSON {
|
|||||||
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
final override string getAPrimaryQlClass() { result = "ReservedWord" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the file containing the given `node`. */
|
||||||
|
overlay[local]
|
||||||
|
private @file getNodeFile(@json_ast_node node) {
|
||||||
|
exists(@location_default loc | json_ast_node_location(node, loc) |
|
||||||
|
locations_default(loc, result, _, _, _, _)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `file` was extracted as part of the overlay database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardFile(@file file) { isOverlay() and file = getNodeFile(_) }
|
||||||
|
|
||||||
|
/** Holds if `node` is in the `file` and is part of the overlay base database. */
|
||||||
|
overlay[local]
|
||||||
|
private predicate discardableAstNode(@file file, @json_ast_node node) {
|
||||||
|
not isOverlay() and file = getNodeFile(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Holds if `node` should be discarded, because it is part of the overlay base and is in a file that was also extracted as part of the overlay database. */
|
||||||
|
overlay[discard_entity]
|
||||||
|
private predicate discardAstNode(@json_ast_node node) {
|
||||||
|
exists(@file file | discardableAstNode(file, node) and discardFile(file))
|
||||||
|
}
|
||||||
|
|
||||||
class UnderscoreValue extends @json_underscore_value, AstNode { }
|
class UnderscoreValue extends @json_underscore_value, AstNode { }
|
||||||
|
|
||||||
/** A class representing `array` nodes. */
|
/** A class representing `array` nodes. */
|
||||||
|
|||||||
@@ -28,5 +28,5 @@ pub fn run(options: Options) -> std::io::Result<()> {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
generate(languages, options.dbscheme, options.library, true)
|
generate(languages, options.dbscheme, options.library)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ pub fn generate(
|
|||||||
languages: Vec<language::Language>,
|
languages: Vec<language::Language>,
|
||||||
dbscheme_path: PathBuf,
|
dbscheme_path: PathBuf,
|
||||||
ql_library_path: PathBuf,
|
ql_library_path: PathBuf,
|
||||||
overlay_support: bool,
|
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let dbscheme_file = File::create(dbscheme_path).map_err(|e| {
|
let dbscheme_file = File::create(dbscheme_path).map_err(|e| {
|
||||||
tracing::error!("Failed to create dbscheme file: {}", e);
|
tracing::error!("Failed to create dbscheme file: {}", e);
|
||||||
@@ -50,14 +49,12 @@ pub fn generate(
|
|||||||
})],
|
})],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if overlay_support {
|
|
||||||
ql::write(
|
ql::write(
|
||||||
&mut ql_writer,
|
&mut ql_writer,
|
||||||
&[ql::TopLevel::Predicate(
|
&[ql::TopLevel::Predicate(
|
||||||
ql_gen::create_is_overlay_predicate(),
|
ql_gen::create_is_overlay_predicate(),
|
||||||
)],
|
)],
|
||||||
)?;
|
)?;
|
||||||
}
|
|
||||||
|
|
||||||
for language in languages {
|
for language in languages {
|
||||||
let prefix = node_types::to_snake_case(&language.name);
|
let prefix = node_types::to_snake_case(&language.name);
|
||||||
@@ -103,7 +100,7 @@ pub fn generate(
|
|||||||
ql::TopLevel::Class(ql_gen::create_reserved_word_class(&reserved_word_name)),
|
ql::TopLevel::Class(ql_gen::create_reserved_word_class(&reserved_word_name)),
|
||||||
];
|
];
|
||||||
|
|
||||||
if overlay_support {
|
// Overlay discard predicates
|
||||||
body.push(ql::TopLevel::Predicate(
|
body.push(ql::TopLevel::Predicate(
|
||||||
ql_gen::create_get_node_file_predicate(&ast_node_name, &node_location_table_name),
|
ql_gen::create_get_node_file_predicate(&ast_node_name, &node_location_table_name),
|
||||||
));
|
));
|
||||||
@@ -116,7 +113,6 @@ pub fn generate(
|
|||||||
body.push(ql::TopLevel::Predicate(
|
body.push(ql::TopLevel::Predicate(
|
||||||
ql_gen::create_discard_ast_node_predicate(&ast_node_name),
|
ql_gen::create_discard_ast_node_predicate(&ast_node_name),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
body.append(&mut ql_gen::convert_nodes(&nodes));
|
body.append(&mut ql_gen::convert_nodes(&nodes));
|
||||||
ql::write(
|
ql::write(
|
||||||
|
|||||||
Reference in New Issue
Block a user