Merge remote-tracking branch 'upstream/main' into aibaars/rust-doc-tests

This commit is contained in:
Arthur Baars
2024-09-13 17:31:38 +02:00
74 changed files with 666 additions and 1382 deletions

View File

@@ -23,7 +23,7 @@ permissions:
contents: read
jobs:
rust-check:
rust-code:
runs-on: ubuntu-latest
steps:
- name: Checkout
@@ -43,6 +43,13 @@ jobs:
run: |
cargo clippy --fix
git diff --exit-code
rust-codegen:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install CodeQL
uses: ./.github/actions/fetch-codeql
- name: Code generation
shell: bash
run: |

View File

@@ -767,7 +767,10 @@ newtype TTranslatedElement =
} or
// A statement
TTranslatedStmt(Stmt stmt) { translateStmt(stmt) } or
// The `__except` block of a `__try __except` statement
TTranslatedMicrosoftTryExceptHandler(MicrosoftTryExceptStmt stmt) or
// The `__finally` block of a `__try __finally` statement
TTranslatedMicrosoftTryFinallyHandler(MicrosoftTryFinallyStmt stmt) or
// A function
TTranslatedFunction(Function func) { translateFunction(func) } or
// A constructor init list

View File

@@ -233,6 +233,62 @@ class TranslatedMicrosoftTryExceptHandler extends TranslatedElement,
}
}
TranslatedMicrosoftTryFinallyHandler getTranslatedMicrosoftTryFinallyHandler(
MicrosoftTryFinallyStmt tryFinally
) {
result.getAst() = tryFinally.getFinally()
}
class TranslatedMicrosoftTryFinallyHandler extends TranslatedElement,
TTranslatedMicrosoftTryFinallyHandler
{
MicrosoftTryFinallyStmt tryFinally;
TranslatedMicrosoftTryFinallyHandler() {
this = TTranslatedMicrosoftTryFinallyHandler(tryFinally)
}
final override string toString() { result = tryFinally.toString() }
final override Locatable getAst() { result = tryFinally.getFinally() }
override Instruction getFirstInstruction(EdgeKind kind) {
result = this.getTranslatedFinally().getFirstInstruction(kind)
}
override Instruction getALastInstructionInternal() {
result = this.getTranslatedFinally().getALastInstruction()
}
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
child = this.getTranslatedFinally() and
result = this.getParent().getChildSuccessor(this, kind)
}
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) { none() }
override TranslatedElement getChild(int id) {
id = 0 and
result = this.getTranslatedFinally()
}
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
none()
}
final override Function getFunction() { result = tryFinally.getEnclosingFunction() }
private TranslatedStmt getTranslatedFinally() {
result = getTranslatedStmt(tryFinally.getFinally())
}
override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
// A throw from within a `__finally` block flows to the handler for the parent of
// the `__try`.
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind)
}
}
abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
Stmt stmt;
@@ -611,7 +667,9 @@ class TryOrMicrosoftTryStmt extends Stmt {
}
/** Gets the `finally` statement (usually a BlockStmt), if any. */
Stmt getFinally() { result = this.(MicrosoftTryFinallyStmt).getFinally() }
TranslatedElement getTranslatedFinally() {
result = getTranslatedMicrosoftTryFinallyHandler(this)
}
}
/**
@@ -681,11 +739,14 @@ class TranslatedTryStmt extends TranslatedStmt {
final override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
result = this.getHandler(0).getFirstInstruction(kind)
or
not exists(this.getHandler(_)) and
result = this.getFinally().getFirstInstruction(kind)
}
private TranslatedElement getHandler(int index) { result = stmt.getTranslatedHandler(index) }
private TranslatedStmt getFinally() { result = getTranslatedStmt(stmt.getFinally()) }
private TranslatedElement getFinally() { result = stmt.getTranslatedFinally() }
private TranslatedStmt getBody() { result = getTranslatedStmt(stmt.getStmt()) }
}

View File

@@ -3241,6 +3241,16 @@ ir.c:
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
# 62| m62_4(unknown) = ^CallSideEffect : ~m57_4
# 62| m62_5(unknown) = Chi : total:m57_4, partial:m62_4
#-----| Exception -> Block 1
# 66| Block 1
# 66| r66_1(int) = Constant[1] :
# 66| r66_2(glval<int>) = VariableAddress[x] :
# 66| m66_3(int) = Store[x] : &:r66_2, r66_1
# 68| v68_1(void) = NoOp :
# 57| v57_5(void) = ReturnVoid :
# 57| v57_6(void) = AliasedUse : ~m62_5
# 57| v57_7(void) = ExitFunction :
# 70| void throw_in_try_with_throw_in_finally()
# 70| Block 0
@@ -3253,6 +3263,20 @@ ir.c:
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
# 73| m73_4(unknown) = ^CallSideEffect : ~m70_4
# 73| m73_5(unknown) = Chi : total:m70_4, partial:m73_4
#-----| Exception -> Block 2
# 70| Block 1
# 70| v70_5(void) = Unwind :
# 70| v70_6(void) = AliasedUse : ~m76_5
# 70| v70_7(void) = ExitFunction :
# 76| Block 2
# 76| r76_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
# 76| r76_2(int) = Constant[0] :
# 76| v76_3(void) = Call[ExRaiseAccessViolation] : func:r76_1, 0:r76_2
# 76| m76_4(unknown) = ^CallSideEffect : ~m73_5
# 76| m76_5(unknown) = Chi : total:m73_5, partial:m76_4
#-----| Exception -> Block 1
# 80| void raise_access_violation()
# 80| Block 0

View File

@@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -6,9 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
| ir.c:76:5:76:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -3022,6 +3022,7 @@ ir.c:
# 62| r62_2(int) = Constant[0] :
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
# 62| mu62_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 3
# 57| Block 1
# 57| v57_4(void) = AliasedUse : ~m?
@@ -3048,6 +3049,7 @@ ir.c:
# 73| r73_2(int) = Constant[0] :
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
# 73| mu73_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 3
# 70| Block 1
# 70| v70_4(void) = AliasedUse : ~m?
@@ -3062,6 +3064,7 @@ ir.c:
# 76| r76_2(int) = Constant[0] :
# 76| v76_3(void) = Call[ExRaiseAccessViolation] : func:r76_1, 0:r76_2
# 76| mu76_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 2
# 78| Block 4
# 78| v78_1(void) = NoOp :

View File

@@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -7,8 +7,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | Chi: c106 | Instruction 'Chi: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
ambiguousSuccessors
unexplainedLoop

View File

@@ -8,8 +8,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | IndirectMayWriteSideEffect: c106 | Instruction 'IndirectMayWriteSideEffect: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
| stmt_expr.cpp:29:11:32:11 | CopyValue: (statement expression) | Instruction 'CopyValue: (statement expression)' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
| stmt_in_type.cpp:5:53:5:53 | Constant: 1 | Instruction 'Constant: 1' has no successors in function '$@'. | stmt_in_type.cpp:2:6:2:12 | void cpp_fun() | void cpp_fun() |

View File

@@ -7,8 +7,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | IndirectMayWriteSideEffect: c106 | Instruction 'IndirectMayWriteSideEffect: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
ambiguousSuccessors
unexplainedLoop

View File

@@ -118,7 +118,7 @@ class Class:
@dataclass
class Schema:
classes: Dict[str, Class] = field(default_factory=dict)
includes: Set[str] = field(default_factory=set)
includes: List[str] = field(default_factory=list)
null: Optional[str] = None
@property

View File

@@ -135,7 +135,7 @@ def load(m: types.ModuleType) -> schema.Schema:
if hasattr(defs, name):
continue
if name == "__includes":
includes = set(data)
includes = data
continue
if name.startswith("__"):
continue

View File

@@ -1,2 +1,2 @@
mod.rs 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e
top.rs c5be6a0f58f3699e51761681ea97677abfc827d264d634d8069d283dd9172353 c5be6a0f58f3699e51761681ea97677abfc827d264d634d8069d283dd9172353
top.rs 812d576622151c716ea439746dbdcd8d742badbe2c47cfb2e17750fba1cc256e 812d576622151c716ea439746dbdcd8d742badbe2c47cfb2e17750fba1cc256e

File diff suppressed because it is too large Load Diff

View File

@@ -59,11 +59,7 @@ impl CrateTranslator<'_> {
if !self.file_labels.contains_key(&canonical) {
self.archiver.archive(&canonical);
canonical = fs::canonicalize(&canonical).unwrap_or(canonical);
let name = canonical.to_string_lossy();
let label = self.trap.emit(generated::DbFile {
id: trap_key!["file;", name.as_ref()],
name: String::from(name),
});
let label = self.trap.emit_file(&canonical);
let line_index = <dyn LineIndexDatabase>::line_index(self.db, file_id);
self.file_labels
.insert(canonical.clone(), FileData { label, line_index });
@@ -74,56 +70,55 @@ impl CrateTranslator<'_> {
fn emit_location_for_ast_ptr<T>(
&mut self,
label: trap::Label,
source: ra_ap_hir::InFile<ra_ap_syntax::AstPtr<T>>,
) -> Option<trap::Label>
where
) where
T: AstNode,
{
source
.file_id
.file_id()
.map(|f| (f.file_id(), source))
.and_then(|(file_id, source)| self.emit_file(file_id).map(|data| (data, source)))
.map(|(data, source)| {
.map(|f| f.file_id())
.and_then(|file_id| self.emit_file(file_id))
.map(|data| {
let range = source.value.text_range();
self.emit_location_for_textrange(data, range)
})
self.emit_location_for_textrange(label, data, range)
});
}
fn emit_location_for_expr(
&mut self,
label: trap::Label,
expr: ra_ap_hir_def::hir::ExprId,
source_map: &BodySourceMap,
) -> Option<trap::Label> {
let source = source_map.expr_syntax(expr).ok()?;
self.emit_location_for_ast_ptr(source)
) {
if let Ok(source) = source_map.expr_syntax(expr) {
self.emit_location_for_ast_ptr(label, source);
}
}
fn emit_location_for_pat(
&mut self,
label: trap::Label,
pat_id: ra_ap_hir_def::hir::PatId,
source_map: &BodySourceMap,
) -> Option<trap::Label> {
let source = source_map.pat_syntax(pat_id).ok()?;
self.emit_location_for_ast_ptr(source)
) {
if let Ok(source) = source_map.pat_syntax(pat_id) {
self.emit_location_for_ast_ptr(label, source);
}
}
fn emit_literal_or_const_pat(
&mut self,
pat: &ra_ap_hir_def::hir::LiteralOrConst,
location: Option<trap::Label>,
body: &Body,
source_map: &BodySourceMap,
) -> trap::Label {
match pat {
ra_ap_hir_def::hir::LiteralOrConst::Literal(_literal) => {
let expr = self.trap.emit(generated::Literal {
id: TrapId::Star,
location: None,
});
let expr = self.trap.emit(generated::Literal { id: TrapId::Star });
self.trap.emit(generated::LiteralPat {
id: TrapId::Star,
location,
expr,
})
}
@@ -135,14 +130,17 @@ impl CrateTranslator<'_> {
fn emit_location_for_label(
&mut self,
label: trap::Label,
label_id: ra_ap_hir_def::hir::LabelId,
source_map: &BodySourceMap,
) -> Option<trap::Label> {
) {
// 'catch' a panic if the source map is incomplete
let source = std::panic::catch_unwind(|| source_map.label_syntax(label_id)).ok();
source.and_then(|source| self.emit_location_for_ast_ptr(source))
if let Some(source) = source {
self.emit_location_for_ast_ptr(label, source)
}
}
fn emit_location<T: HasSource>(&mut self, entity: T) -> Option<trap::Label>
fn emit_location<T: HasSource>(&mut self, label: trap::Label, entity: T)
where
T::Ast: AstNode,
{
@@ -152,10 +150,15 @@ impl CrateTranslator<'_> {
.and_then(|(file_id, source)| self.emit_file(file_id).map(|data| (data, source)))
.map(|(data, source)| {
let range = source.value.syntax().text_range();
self.emit_location_for_textrange(data, range)
})
self.emit_location_for_textrange(label, data, range);
});
}
fn emit_location_for_textrange(&mut self, data: FileData, range: TextRange) -> trap::Label {
fn emit_location_for_textrange(
&mut self,
label: trap::Label,
data: FileData,
range: TextRange,
) {
let start = data.line_index.line_col(range.start());
let end = data.line_index.line_col(
range
@@ -163,7 +166,7 @@ impl CrateTranslator<'_> {
.checked_sub(TextSize::new(1))
.unwrap_or(range.end()),
);
self.trap.emit_location(data.label, start, end)
self.trap.emit_location(data.label, label, start, end)
}
fn emit_label(
&mut self,
@@ -171,20 +174,17 @@ impl CrateTranslator<'_> {
body: &Body,
source_map: &BodySourceMap,
) -> trap::Label {
let location: Option<trap::Label> = self.emit_location_for_label(label_id, source_map);
let label = &body.labels[label_id];
self.trap.emit(generated::Label {
let ret = self.trap.emit(generated::Label {
id: TrapId::Star,
location,
name: label.name.as_str().into(),
})
});
self.emit_location_for_label(ret, label_id, source_map);
ret
}
fn emit_path(&mut self, _path: &Path, location: Option<trap::Label>) -> trap::Label {
self.trap.emit(generated::Path {
id: TrapId::Star,
location,
})
fn emit_path(&mut self, _path: &Path) -> trap::Label {
self.trap.emit(generated::Path { id: TrapId::Star })
}
fn emit_record_field_pat(
@@ -194,14 +194,14 @@ impl CrateTranslator<'_> {
source_map: &BodySourceMap,
) -> trap::Label {
let RecordFieldPat { name, pat } = field_pat;
let location = self.emit_location_for_pat(*pat, source_map);
let pat = self.emit_pat(*pat, body, source_map);
self.trap.emit(generated::RecordPatField {
let pat_label = self.emit_pat(*pat, body, source_map);
let ret = self.trap.emit(generated::RecordPatField {
id: TrapId::Star,
location,
name: name.as_str().into(),
pat,
})
pat: pat_label,
});
self.emit_location_for_pat(ret, *pat, source_map);
ret
}
fn emit_record_lit_field(
@@ -211,27 +211,24 @@ impl CrateTranslator<'_> {
source_map: &BodySourceMap,
) -> trap::Label {
let RecordLitField { name, expr } = field_expr;
let location = self.emit_location_for_expr(*expr, source_map);
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::RecordExprField {
let expr_label = self.emit_expr(*expr, body, source_map);
let ret = self.trap.emit(generated::RecordExprField {
id: TrapId::Star,
location,
name: name.as_str().into(),
expr,
})
expr: expr_label,
});
self.emit_location_for_expr(ret, *expr, source_map);
ret
}
fn emit_pat(&mut self, pat_id: PatId, body: &Body, source_map: &BodySourceMap) -> trap::Label {
let location: Option<trap::Label> = self.emit_location_for_pat(pat_id, source_map);
let pat = &body.pats[pat_id];
match pat {
ra_ap_hir_def::hir::Pat::Missing => self.trap.emit(generated::MissingPat {
id: TrapId::Star,
location,
}),
ra_ap_hir_def::hir::Pat::Wild => self.trap.emit(generated::WildcardPat {
id: TrapId::Star,
location,
}),
let ret = match pat {
ra_ap_hir_def::hir::Pat::Missing => {
self.trap.emit(generated::MissingPat { id: TrapId::Star })
}
ra_ap_hir_def::hir::Pat::Wild => {
self.trap.emit(generated::WildcardPat { id: TrapId::Star })
}
ra_ap_hir_def::hir::Pat::Tuple { args, ellipsis } => {
let args = args
.into_iter()
@@ -240,7 +237,6 @@ impl CrateTranslator<'_> {
let ellipsis_index = ellipsis.and_then(|x| x.try_into().ok());
self.trap.emit(generated::TuplePat {
id: TrapId::Star,
location,
args,
ellipsis_index,
})
@@ -252,7 +248,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::OrPat {
id: TrapId::Star,
location,
args,
})
}
@@ -261,14 +256,13 @@ impl CrateTranslator<'_> {
args,
ellipsis,
} => {
let path = path.as_ref().map(|path| self.emit_path(path, location));
let path = path.as_ref().map(|path| self.emit_path(path));
let flds = args
.into_iter()
.map(|arg| self.emit_record_field_pat(arg, body, source_map))
.collect();
self.trap.emit(generated::RecordPat {
id: TrapId::Star,
location,
path,
flds,
has_ellipsis: *ellipsis,
@@ -277,13 +271,12 @@ impl CrateTranslator<'_> {
ra_ap_hir_def::hir::Pat::Range { start, end } => {
let start = start
.as_ref()
.map(|x| self.emit_literal_or_const_pat(x, location, body, source_map));
.map(|x| self.emit_literal_or_const_pat(x, body, source_map));
let end = end
.as_ref()
.map(|x| self.emit_literal_or_const_pat(x, location, body, source_map));
.map(|x| self.emit_literal_or_const_pat(x, body, source_map));
self.trap.emit(generated::RangePat {
id: TrapId::Star,
location,
start,
end,
})
@@ -304,17 +297,15 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::SlicePat {
id: TrapId::Star,
location,
prefix,
slice,
suffix,
})
}
ra_ap_hir_def::hir::Pat::Path(path) => {
let path = self.emit_path(path, location);
let path = self.emit_path(path);
self.trap.emit(generated::PathPat {
id: TrapId::Star,
location,
path,
})
}
@@ -322,7 +313,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::LiteralPat {
id: TrapId::Star,
location,
expr,
})
}
@@ -330,7 +320,6 @@ impl CrateTranslator<'_> {
let subpat = subpat.map(|pat| self.emit_pat(pat, body, source_map));
self.trap.emit(generated::IdentPat {
id: TrapId::Star,
location,
subpat,
binding_id: body.bindings[*id].name.as_str().into(),
})
@@ -340,14 +329,13 @@ impl CrateTranslator<'_> {
args,
ellipsis,
} => {
let path = path.as_ref().map(|path| self.emit_path(path, location));
let path = path.as_ref().map(|path| self.emit_path(path));
let args = args
.into_iter()
.map(|arg| self.emit_pat(*arg, body, source_map))
.collect();
self.trap.emit(generated::TupleStructPat {
id: TrapId::Star,
location,
path,
args,
ellipsis_index: ellipsis.map(|x| x as usize),
@@ -357,7 +345,6 @@ impl CrateTranslator<'_> {
let pat = self.emit_pat(*pat, body, source_map);
self.trap.emit(generated::RefPat {
id: TrapId::Star,
location,
pat,
is_mut: mutability.is_mut(),
})
@@ -366,7 +353,6 @@ impl CrateTranslator<'_> {
let inner = self.emit_pat(*inner, body, source_map);
self.trap.emit(generated::BoxPat {
id: TrapId::Star,
location,
inner,
})
}
@@ -374,17 +360,15 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::ConstBlockPat {
id: TrapId::Star,
location,
expr,
})
}
}
};
self.emit_location_for_pat(ret, pat_id, source_map);
ret
}
fn emit_type_ref(&mut self, _type_ref: &TypeRef) -> trap::Label {
self.trap.emit(generated::Type {
id: TrapId::Star,
location: None,
})
self.trap.emit(generated::Type { id: TrapId::Star })
}
fn emit_match_arm(
&mut self,
@@ -392,17 +376,17 @@ impl CrateTranslator<'_> {
body: &Body,
source_map: &BodySourceMap,
) -> trap::Label {
let location: Option<trap::Label> = self.emit_location_for_pat(arm.pat, source_map);
let pat = self.emit_pat(arm.pat, body, source_map);
let guard = arm.guard.map(|g| self.emit_expr(g, body, source_map));
let expr = self.emit_expr(arm.expr, body, source_map);
self.trap.emit(generated::MatchArm {
let ret = self.trap.emit(generated::MatchArm {
id: TrapId::Star,
location,
pat,
guard,
expr,
})
});
self.emit_location_for_pat(ret, arm.pat, source_map);
ret
}
fn emit_stmt(
&mut self,
@@ -417,9 +401,7 @@ impl CrateTranslator<'_> {
initializer,
else_branch,
} => {
// TODO: find a way to get the location of the entire statement
let location = self.emit_location_for_pat(*pat, source_map);
let pat = self.emit_pat(*pat, body, source_map);
let pat_label = self.emit_pat(*pat, body, source_map);
let type_ = type_ref
.as_ref()
.map(|type_ref| self.emit_type_ref(type_ref));
@@ -427,29 +409,29 @@ impl CrateTranslator<'_> {
initializer.map(|initializer| self.emit_expr(initializer, body, source_map));
let else_ = else_branch.map(|else_| self.emit_expr(else_, body, source_map));
self.trap.emit(generated::LetStmt {
let ret = self.trap.emit(generated::LetStmt {
id: TrapId::Star,
location,
pat,
pat: pat_label,
type_,
initializer,
else_,
})
});
// TODO: find a way to get the location of the entire statement
self.emit_location_for_pat(ret, *pat, source_map);
ret
}
Statement::Expr { expr, has_semi } => {
let location = self.emit_location_for_expr(*expr, source_map);
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::ExprStmt {
let expr_label = self.emit_expr(*expr, body, source_map);
let ret = self.trap.emit(generated::ExprStmt {
id: TrapId::Star,
location,
expr,
expr: expr_label,
has_semicolon: *has_semi,
})
});
// TODO: find a way to get the location of the entire statement
self.emit_location_for_expr(ret, *expr, source_map);
ret
}
Statement::Item => self.trap.emit(generated::ItemStmt {
id: TrapId::Star,
location: None,
}),
Statement::Item => self.trap.emit(generated::ItemStmt { id: TrapId::Star }),
}
}
fn emit_expr(
@@ -458,18 +440,15 @@ impl CrateTranslator<'_> {
body: &Body,
source_map: &BodySourceMap,
) -> trap::Label {
let location: Option<trap::Label> = self.emit_location_for_expr(expr_id, source_map);
let expr = &body[expr_id];
match expr {
ra_ap_hir_def::hir::Expr::Missing => self.trap.emit(generated::MissingExpr {
id: TrapId::Star,
location,
}),
let ret = match expr {
ra_ap_hir_def::hir::Expr::Missing => {
self.trap.emit(generated::MissingExpr { id: TrapId::Star })
}
ra_ap_hir_def::hir::Expr::Path(path) => {
let path = self.emit_path(path, location);
let path = self.emit_path(path);
self.trap.emit(generated::PathExpr {
id: TrapId::Star,
location,
path,
})
}
@@ -483,7 +462,6 @@ impl CrateTranslator<'_> {
let else_ = else_branch.map(|x| self.emit_expr(x, body, source_map));
self.trap.emit(generated::IfExpr {
id: TrapId::Star,
location,
condition,
then,
else_,
@@ -494,7 +472,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::LetExpr {
id: TrapId::Star,
location,
pat,
expr,
})
@@ -513,7 +490,6 @@ impl CrateTranslator<'_> {
let label = label.map(|l| self.emit_label(l, body, source_map));
self.trap.emit(generated::BlockExpr {
id: TrapId::Star,
location,
statements,
tail,
label,
@@ -531,7 +507,6 @@ impl CrateTranslator<'_> {
let tail = tail.map(|expr_id| self.emit_expr(expr_id, body, source_map));
self.trap.emit(generated::AsyncBlockExpr {
id: TrapId::Star,
location,
statements,
tail,
})
@@ -541,7 +516,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(expr_id, body, source_map);
self.trap.emit(generated::ConstExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -557,7 +531,6 @@ impl CrateTranslator<'_> {
let tail = tail.map(|expr_id| self.emit_expr(expr_id, body, source_map));
self.trap.emit(generated::UnsafeBlockExpr {
id: TrapId::Star,
location,
statements,
tail,
})
@@ -570,7 +543,6 @@ impl CrateTranslator<'_> {
let label = label.map(|l| self.emit_label(l, body, source_map));
self.trap.emit(generated::LoopExpr {
id: TrapId::Star,
location,
body: loop_body,
label,
})
@@ -587,7 +559,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::CallExpr {
id: TrapId::Star,
location,
callee,
args,
is_assignee_expr: *is_assignee_expr,
@@ -605,14 +576,11 @@ impl CrateTranslator<'_> {
.map(|e| self.emit_expr(*e, body, source_map))
.collect();
let generic_args = generic_args.as_ref().map(|_args| {
self.trap.emit(generated::GenericArgList {
id: TrapId::Star,
location: None,
})
self.trap
.emit(generated::GenericArgList { id: TrapId::Star })
});
self.trap.emit(generated::MethodCallExpr {
id: TrapId::Star,
location,
receiver,
method_name: method_name.as_str().into(),
args,
@@ -628,7 +596,6 @@ impl CrateTranslator<'_> {
self.trap.emit(generated::MatchExpr {
id: TrapId::Star,
location,
expr,
branches,
})
@@ -637,7 +604,6 @@ impl CrateTranslator<'_> {
let label = label.map(|l| self.emit_label(l, body, source_map));
self.trap.emit(generated::ContinueExpr {
id: TrapId::Star,
location,
label,
})
}
@@ -646,7 +612,6 @@ impl CrateTranslator<'_> {
let label = label.map(|l| self.emit_label(l, body, source_map));
self.trap.emit(generated::BreakExpr {
id: TrapId::Star,
location,
expr,
label,
})
@@ -655,7 +620,6 @@ impl CrateTranslator<'_> {
let expr = expr.map(|e| self.emit_expr(e, body, source_map));
self.trap.emit(generated::ReturnExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -663,7 +627,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::BecomeExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -671,7 +634,6 @@ impl CrateTranslator<'_> {
let expr = expr.map(|e| self.emit_expr(e, body, source_map));
self.trap.emit(generated::YieldExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -679,7 +641,6 @@ impl CrateTranslator<'_> {
let expr = expr.map(|e| self.emit_expr(e, body, source_map));
self.trap.emit(generated::YeetExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -690,7 +651,7 @@ impl CrateTranslator<'_> {
ellipsis,
is_assignee_expr,
} => {
let path = path.as_ref().map(|path| self.emit_path(path, location));
let path = path.as_ref().map(|path| self.emit_path(path));
let flds = fields
.into_iter()
.map(|field| self.emit_record_lit_field(field, body, source_map))
@@ -698,7 +659,6 @@ impl CrateTranslator<'_> {
let spread = spread.map(|expr_id| self.emit_expr(expr_id, body, source_map));
self.trap.emit(generated::RecordExpr {
id: TrapId::Star,
location,
path,
flds,
spread,
@@ -710,7 +670,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::FieldExpr {
id: TrapId::Star,
location,
expr,
name: name.as_str().into(),
})
@@ -719,7 +678,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::AwaitExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -728,7 +686,6 @@ impl CrateTranslator<'_> {
let type_: trap::Label = self.emit_type_ref(type_ref.as_ref());
self.trap.emit(generated::CastExpr {
id: TrapId::Star,
location,
expr,
type_,
})
@@ -741,7 +698,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::RefExpr {
id: TrapId::Star,
location,
expr,
is_mut: mutability.is_mut(),
is_raw: rawness.is_raw(),
@@ -751,7 +707,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::BoxExpr {
id: TrapId::Star,
location,
expr,
})
}
@@ -764,7 +719,6 @@ impl CrateTranslator<'_> {
};
self.trap.emit(generated::PrefixExpr {
id: TrapId::Star,
location,
expr,
op: op.into(),
})
@@ -775,7 +729,6 @@ impl CrateTranslator<'_> {
let op = op.map(|op| format!("{op}"));
self.trap.emit(generated::BinExpr {
id: TrapId::Star,
location,
lhs,
rhs,
op,
@@ -790,7 +743,6 @@ impl CrateTranslator<'_> {
let rhs = rhs.map(|rhs| self.emit_expr(rhs, body, source_map));
self.trap.emit(generated::RangeExpr {
id: TrapId::Star,
location,
lhs,
rhs,
is_inclusive: *range_type == RangeOp::Inclusive,
@@ -805,7 +757,6 @@ impl CrateTranslator<'_> {
let index = self.emit_expr(*index, body, source_map);
self.trap.emit(generated::IndexExpr {
id: TrapId::Star,
location,
base,
index,
is_assignee_expr: *is_assignee_expr,
@@ -837,7 +788,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::ClosureExpr {
id: TrapId::Star,
location,
args,
arg_types,
body: expr,
@@ -856,7 +806,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::TupleExpr {
id: TrapId::Star,
location,
exprs,
is_assignee_expr: *is_assignee_expr,
})
@@ -871,7 +820,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::ElementListExpr {
id: TrapId::Star,
location,
elements,
is_assignee_expr: *is_assignee_expr,
})
@@ -885,25 +833,21 @@ impl CrateTranslator<'_> {
self.trap.emit(generated::RepeatExpr {
id: TrapId::Star,
location,
initializer,
repeat,
})
}
ra_ap_hir_def::hir::Expr::Literal(_literal) => self.trap.emit(generated::Literal {
id: TrapId::Star,
location,
}),
ra_ap_hir_def::hir::Expr::Underscore => self.trap.emit(generated::UnderscoreExpr {
id: TrapId::Star,
location,
}),
ra_ap_hir_def::hir::Expr::Literal(_literal) => {
self.trap.emit(generated::Literal { id: TrapId::Star })
}
ra_ap_hir_def::hir::Expr::Underscore => self
.trap
.emit(generated::UnderscoreExpr { id: TrapId::Star }),
ra_ap_hir_def::hir::Expr::OffsetOf(offset) => {
let container = self.emit_type_ref(&offset.container);
let fields = offset.fields.iter().map(|x| x.as_str().into()).collect();
self.trap.emit(generated::OffsetOfExpr {
id: TrapId::Star,
location,
container,
fields,
})
@@ -912,11 +856,12 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(asm.e, body, source_map);
self.trap.emit(generated::AsmExpr {
id: TrapId::Star,
location,
expr,
})
}
}
};
self.emit_location_for_expr(ret, expr_id, source_map);
ret
}
fn emit_definition(
@@ -925,96 +870,89 @@ impl CrateTranslator<'_> {
id: ModuleDef,
labels: &mut Vec<trap::Label>,
) {
match id {
ModuleDef::Module(_module) => {
let location = None;
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
}
let label = match id {
ModuleDef::Module(_) => self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star }),
ModuleDef::Function(function) => {
let def: ra_ap_hir::DefWithBody = function.into();
let name = function.name(self.db);
let location = self.emit_location(function);
let (body, source_map) = self.db.body_with_source_map(def.into());
let txt = body.pretty_print(self.db, def.into(), Edition::Edition2021);
log::trace!("{}", &txt);
let body = self.emit_expr(body.body_expr, &body, &source_map);
labels.push(self.trap.emit(generated::Function {
let label = self.trap.emit(generated::Function {
id: trap_key![module_label, name.as_str()],
location,
name: name.as_str().into(),
body,
}))
});
self.emit_location(label, function);
label
}
ModuleDef::Adt(adt) => {
let location = self.emit_location(adt);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, adt);
label
}
ModuleDef::Variant(variant) => {
let location = self.emit_location(variant);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, variant);
label
}
ModuleDef::Const(const_) => {
let location = self.emit_location(const_);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, const_);
label
}
ModuleDef::Static(static_) => {
let location = self.emit_location(static_);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, static_);
label
}
ModuleDef::Trait(trait_) => {
let location = self.emit_location(trait_);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, trait_);
label
}
ModuleDef::TraitAlias(alias) => {
let location = self.emit_location(alias);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, alias);
label
}
ModuleDef::TypeAlias(type_alias) => {
let location = self.emit_location(type_alias);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
}
ModuleDef::BuiltinType(_builtin_type) => {
let location = None;
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, type_alias);
label
}
ModuleDef::BuiltinType(_builtin_type) => self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star }),
ModuleDef::Macro(macro_) => {
let location = self.emit_location(macro_);
self.trap.emit(generated::UnimplementedDeclaration {
id: TrapId::Star,
location,
});
let label = self
.trap
.emit(generated::UnimplementedDeclaration { id: TrapId::Star });
self.emit_location(label, macro_);
label
}
}
};
labels.push(label);
}
fn emit_module(&mut self, label: trap::Label, module: Module) {
@@ -1024,7 +962,6 @@ impl CrateTranslator<'_> {
}
self.trap.emit(generated::Module {
id: label.into(),
location: None,
declarations: children,
});
}

View File

@@ -1,7 +1,6 @@
use crate::config::Compression;
use crate::generated;
use crate::{config, path};
use codeql_extractor::trap;
use codeql_extractor::{extractor, trap};
use log::debug;
use ra_ap_ide_db::line_index::LineCol;
use std::ffi::OsString;
@@ -82,29 +81,35 @@ impl TrapFile {
pub fn emit_location(
&mut self,
file_label: trap::Label,
entity_label: trap::Label,
start: LineCol,
end: LineCol,
) -> trap::Label {
) {
let start_line = 1 + start.line as usize;
let start_column = 1 + start.col as usize;
let end_line = 1 + end.line as usize;
let end_column = 1 + end.col as usize;
let (ret, _) = self.writer.location_label(trap::Location {
file_label,
start_line,
start_column,
end_line,
end_column,
});
self.emit(generated::DbLocation {
id: ret.into(),
file: file_label,
start_line,
start_column,
end_line,
end_column,
});
ret
let location_label = extractor::location_label(
&mut self.writer,
trap::Location {
file_label,
start_line,
start_column,
end_line,
end_column,
},
);
self.writer.add_tuple(
"locatable_locations",
vec![
trap::Arg::Label(entity_label),
trap::Arg::Label(location_label),
],
);
}
pub fn emit_file(&mut self, absolute_path: &Path) -> trap::Label {
extractor::populate_file(&mut self.writer, absolute_path)
}
pub fn label(&mut self, id: TrapId) -> trap::Label {
@@ -157,9 +162,11 @@ impl TrapFileProvider {
);
debug!("creating trap file {}", path.display());
path = self.trap_dir.join(path);
let mut writer = trap::Writer::new();
extractor::populate_empty_location(&mut writer);
TrapFile {
path,
writer: trap::Writer::new(),
writer,
compression: self.compression,
}
}

View File

@@ -1,6 +1,5 @@
/**
* The source location of the snapshot.
*/
sourceLocationPrefix(
string prefix: string ref
#keyset[id]
locatable_locations(
int id: @locatable ref,
int location: @location_default ref
);

View File

@@ -31,10 +31,6 @@ lib/codeql/rust/elements/ConstExpr.qll 70a7c9db14efaf290a77401eb04c439b24ed77c21
lib/codeql/rust/elements/ConstExprConstructor.qll b4c96adc2878047c36d7ceaba2346ef66a2269b5260a56c3d7ff6e3a332bad75 ce15bbfd1448e47d3039e912363efa607cc2c29d44b8248ac91c307af7b57016
lib/codeql/rust/elements/ContinueExpr.qll 6d123e17b40c8512e8abb63657ea6ab4cf3fa2485f503b6d750ec00dd5bb170e 5778fd7bd6ad44b6276b36a85f438c303b11bc6e995ed1cc92b9d51536725710
lib/codeql/rust/elements/ContinueExprConstructor.qll adc5c5b4fda5dc5102cdace41c32a6c94fe07a2e2555ced6ee62a2d2551b90a2 9dc5045b0d91a3a28cc1c0d59c6fd40620257a6c18ea8480792183c4d802fd8a
lib/codeql/rust/elements/DbFile.qll 056d363e1ba5ec08cacb2e90b8a7a3b47f52ded5dc2289edd4e85921fc50f37e 18e6926f77265a3a6319ca2f3bf3d529d17d46cebdd2ef6753357fdc53c22c70
lib/codeql/rust/elements/DbFileConstructor.qll ea93dc49b23b1c6d800ab9d0b9cacfa9dc661bfdb04b9e6efcad2bdb050fb0ab f7a891b1786604eee57a784733555b677e2580770d51d18073b59e7ca65df1d4
lib/codeql/rust/elements/DbLocation.qll 1f694594e8e4ab65a8781cd443ad4f864447ca88e2cb65504aee5a779393c84d 003ec72275406eb8f5ddd6ccc2b258fb7c906d4bb2c0ef1ba235f291624321ca
lib/codeql/rust/elements/DbLocationConstructor.qll 8848abace985818a5d3a6eddfc4cb200795970146d282b037b4f22ae6230b894 44dba880e17bb1072fa12451ccaae4830fd04dcc61f7403d35510309fde6906e
lib/codeql/rust/elements/Declaration.qll a902e494e43c13dafb0527a259c7244fca32cf38464d6892143d3a6856683df2 764d0db5928d4243f6c98bbc2cb9268dfad3f489a3e5382d533ddfee153b8685
lib/codeql/rust/elements/ElementListExpr.qll 64356a9bf66f0f316da659fe8046828445804dcf5ae6b19e52232aaea8744885 0822b1430e5c811e74e092cd19001dca783e8d26df140c5366cce61692eaeb2c
lib/codeql/rust/elements/ElementListExprConstructor.qll 12b06597e0700cd0eac70e42cbdc1a2d410e0ffcd05c21a213812a488b5b236b 7adb2e442f1bc362c44824aaba0ab4a7fb4a4bc550a3c96f963dc03bed582d39
@@ -135,7 +131,7 @@ lib/codeql/rust/elements/YeetExpr.qll 95a15d0ae79b9cad126700c07d5cb7e4e9699e2e5d
lib/codeql/rust/elements/YeetExprConstructor.qll f1871c6e0c966c52806e370dbe2956585bbfa1dcf0bd7ebfdb2bd39b7cfd0d7b a2333e80a325a921a66c34151401da12c250951952ccb0c81e5102dc62299503
lib/codeql/rust/elements/YieldExpr.qll 72682ae19d37abd6ec26569ae8f575979ebba1e0d373898211a9af4fad4979a1 ef0193011ee5f94cebbac5c007d652568f560685a213bf8be96cd0c0983a3880
lib/codeql/rust/elements/YieldExprConstructor.qll ff46ba17cc24abfcb0e310c7458d0539b704e7a771ad00853bd3a1844e4e6f82 1c13662ef01c88f1cf057d099eb46524036133e51a0e36ddf947f727ac6046bb
lib/codeql/rust/elements.qll 6bccd637e50ab9e7dd59ac18553d5c4a523e7883bf5261fd388715332cc7e500 6bccd637e50ab9e7dd59ac18553d5c4a523e7883bf5261fd388715332cc7e500
lib/codeql/rust/elements.qll e84f037bfcf04c0c38710f5c52b8d4aa842179f024cf19e29e54af775682980c e84f037bfcf04c0c38710f5c52b8d4aa842179f024cf19e29e54af775682980c
lib/codeql/rust/generated/ArrayExpr.qll 3fd7465da22e1eb810ae28ffab7b14e9ccceaab0082aa665f14b73d4221128b8 6e9edb5846656aad90283406a496aaae485d38854075a4443817b5098b72b427
lib/codeql/rust/generated/AsmExpr.qll 66f1a4bfb4d32d99b4dab1918a1aac75e0903c499d65a18105e3c837c1aa314d cd5c8ed300b5f5d19e404cd2e5f9dcbcee1081c5538f1840359eb491eb6ecaa2
lib/codeql/rust/generated/AstNode.qll 0598fac7859906f4103124270dfb2fbdb838387b1c45000bf50a4b62c797ec41 f47c84878c7c9676109e358073bddab92a1dbeb4d977d236ecc1eae44d81c894
@@ -154,15 +150,12 @@ lib/codeql/rust/generated/ClosureExpr.qll 326e2de4da089a078861f5b67fe1c4f4afb7dc
lib/codeql/rust/generated/ConstBlockPat.qll 05141706ad963e1d9c41b004c73c9569fd0ba2f353da8c19629a153bfb17b769 786fa7db63ea7a8106162fd05e01b52c8338d22b9502d3638880bc6f6d678344
lib/codeql/rust/generated/ConstExpr.qll 7bd3d75822259d2ac61bf3bab6a233948617fa09a7a3d48991b643f0c842925d 06785e5b723006a8c51cafda5b8ce3901e0ddd3aeafc0d3c80e61b9389830e85
lib/codeql/rust/generated/ContinueExpr.qll 452fc59b28ae46d00c6b42dc4b51bd5e65bc92859e769626a6f5b29ff2ec795d 4d7042814fb8f214bf982ad9771ca1a19bbb2a966ec20771478d50927cf1993f
lib/codeql/rust/generated/DbFile.qll 4dbf1931124291e0d6a958ae882f8aeef006642f72adc7ff86cffd3a4e9a970a 4dbf1931124291e0d6a958ae882f8aeef006642f72adc7ff86cffd3a4e9a970a
lib/codeql/rust/generated/DbLocation.qll 735d9351b5eb46a3231b528600dddec3a4122c18c210d4d632a8d4ceaf7f02e9 735d9351b5eb46a3231b528600dddec3a4122c18c210d4d632a8d4ceaf7f02e9
lib/codeql/rust/generated/Declaration.qll fd2401b9683a587cf1361039468c9e74666dce6c98443da63b1defea8e4e14de f1e72b51d4a411c5a74e0a78a34727dff8d20035e7d87bb1ef8657a18c9b262f
lib/codeql/rust/generated/Element.qll 21567fa7348dccdf69dd34e73cb6de7cc9c7e0f3f7bb419a1abd787f7dc851a1 21567fa7348dccdf69dd34e73cb6de7cc9c7e0f3f7bb419a1abd787f7dc851a1
lib/codeql/rust/generated/ElementListExpr.qll fd3a6fb638a38382a356b807acbbcb0bffb70fe75b827e7b46195b060a4b53d0 24da1239e70a7d95531784260af6867c62dca271246ae2c740d03231c329371d
lib/codeql/rust/generated/Expr.qll 91b1744d6b07e8549b94d19832dac9e18b70f54990b328b1872b8c73be202417 ed71e6d24ab3f0dc687bfb8a665552c05f848ce52d8e338899c1cb48783a778a
lib/codeql/rust/generated/ExprStmt.qll 40fd3659761005fe0de2a09e58d35b3b28203f8f354ef5f687e6064862eb73d2 c4bcefa928d8a82f6b9d26a6e4f42912114bd24a90ee5dcc24e7ec1a4c11dbcb
lib/codeql/rust/generated/FieldExpr.qll 5050cabcc1109f0c404a64a80cf8e595088b1dfd9c24364281176400436922ef c7562bc91fd7c3f7305100d146ebc84378e73aa76fd1b36c06e69070105c0401
lib/codeql/rust/generated/File.qll 2eff5c882d044d2e360fe6382fb55e5a45f6ccb9df323cfa1fae41eae9d2a47f 87e7a906b3a1b4de056952e288ddd7f69fa7cb1bd9dc7dd3972868a9002ac1e4
lib/codeql/rust/generated/Function.qll 133693679cd69f0c011d6aa779b067924e8d58ea15bc3f6b749cc3aa5d5e962d 5a18e3be5c7c681cebec762b2c2d3b1cb08c5fcc11ef422bf65c9b15fc82c893
lib/codeql/rust/generated/GenericArgList.qll abc549b0a763d2f5a162794676ab8f9a2fef8a02c77dbd14467dbafccf261c29 abc549b0a763d2f5a162794676ab8f9a2fef8a02c77dbd14467dbafccf261c29
lib/codeql/rust/generated/IdentPat.qll 1acf5c9a4f20930f33339904be534c3b64dc16b06ad6c6189c3561f3f0acd244 c5f03e20dd26a21a492766dbeda8896ceb00369cff91df566b99238c3d627a26
@@ -174,8 +167,7 @@ lib/codeql/rust/generated/LetExpr.qll 377099647451717af698677ca7119436982354d4e0
lib/codeql/rust/generated/LetStmt.qll 5d347ca3dbc1b6801de1b339a7694cf6fb4e4b30731356321ccab865d5ab6599 506c4a9745d0e014c600d23a2eb7862a069902b1ebe79dc5bd346147e3a08bdb
lib/codeql/rust/generated/Literal.qll 66f362fb7e464f1d1350ce13465b029ae14673c84dd8ba7db1bc66083c3da4e7 66f362fb7e464f1d1350ce13465b029ae14673c84dd8ba7db1bc66083c3da4e7
lib/codeql/rust/generated/LiteralPat.qll 6cb250e374f6c3d2c86aaea6ad7baeaa40ee438b42ac6987d823edb91b757d4c f8cf9ef6bb6cd39d65c6eb905f11f79c65daf3d493e1240c0781be29c3fe9202
lib/codeql/rust/generated/Locatable.qll 9e9685bba50ad2220701f3465e63af9331f7f9dc548ad906ff954fc2ce0a4400 78c89b2cc78a357d682ab65310dd474603071f07c1eaaab07711714ce17549f2
lib/codeql/rust/generated/Location.qll bce4c72988ec6fedd1439c60a37c45aa6147c962904709ef9f12206937174be4 d57000571771a2d997c50d9a43ef1c2f075960f847effa0e80ea91fd4c6b4d6c
lib/codeql/rust/generated/Locatable.qll 2d2b9a7cf26d6134b1e4a2047dfe99f09deb9231a05047d37b697c11ea91d0d2 dae7e0c66024d7f03a58d71ffef93cf23aeb629d7a21d36901c443fb29ff4d3d
lib/codeql/rust/generated/LoopExpr.qll ddc646e715dced161b60638ac36a7671b45ddd6245a6876d647916d41495faf1 864be7033c093a8513be05691f772f19f99b606abe510f810af5f004596c0c7c
lib/codeql/rust/generated/MatchArm.qll e4e129ac42537138a3f5d288113ee805b49a5c914cf44564e59be389e07d6eda 5e5ae462925501265237f06a68549d5a26e01864386d16d0e28a12305127cb71
lib/codeql/rust/generated/MatchExpr.qll 74966bd8286aa8cd4238c5f6964b5668d3f95fd47a56fcece47fbd0abe3a8376 9afcc11f0af8e5daee2746226b2c39bec0f9cbc74d0cb1bf567a8ea122409331
@@ -185,7 +177,7 @@ lib/codeql/rust/generated/MissingPat.qll 40fa87d446056c7263ef5843fb13fe60b644e16
lib/codeql/rust/generated/Module.qll c6007444c796654fb48fbe4a4596580f08feec2aac13932043062a170dd73f0b 0560c738dbee3937baf0f2ab661c8e4dacd69eb886635241b1ff90f2c0f4bd67
lib/codeql/rust/generated/OffsetOfExpr.qll 5f2c1d2b5d63d2a86c02c8a20fede528403f8dd267f3026ddc420e128f53c73c d4a7eb9e533a943913aa3bdc6f57d89023a0a2075681b6aaa53d5c4dd7ad764b
lib/codeql/rust/generated/OrPat.qll 52e637c652f8caf64d2388a1829159d187d3799384cc3318e07785f518ff0c4b 598a11d067519bb7bb279d8f8a3ea85a48ae99c2974182636c157ba111b9605e
lib/codeql/rust/generated/ParentChild.qll 1988b870c14148c2b23136dd00456d898a73d52a8cfb10039a0db414f5c01dbd bda2c0e7a5333206a6f7ab3a2c438be376c8b75f4d5810d91439cd10b88214a2
lib/codeql/rust/generated/ParentChild.qll 8ab9e1929ef96817cee929c9c66b6d71bbfb3e5c5f9e44152850e0e9a1ebf29a bca5dd83c47ae5fb7b24e49cabec4d01a59213344b9578bad5d35880ba60a2ff
lib/codeql/rust/generated/Pat.qll b035e7866ea500232421ef9f79e7e60b90b9c27dbe47d25758548e94750d2965 adf701ad35559ea7d0284d6718ad507518778dc78100f48063e6a6bf3705c91f
lib/codeql/rust/generated/Path.qll ffd26e9e5e3878f374bc1163d6ccb47072cc1d3abd937d0206bf1a7c62c843ff ffd26e9e5e3878f374bc1163d6ccb47072cc1d3abd937d0206bf1a7c62c843ff
lib/codeql/rust/generated/PathExpr.qll 5a82e07a0c641fec4e8ce29656fa4e33f420b19b2556b418769f4d899a3dfae3 21920262735114d8304c3569f884828a390b95ca039afcc3e81c75d3f23df9ca
@@ -194,7 +186,7 @@ lib/codeql/rust/generated/PrefixExpr.qll a3f6cc62e5a12acd253ea59cb6957fb7157aa70
lib/codeql/rust/generated/PureSynthConstructors.qll 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573
lib/codeql/rust/generated/RangeExpr.qll 1678fa524166552a36d73cad9d34213309b1989c1e427bc990b5c11a12588ce5 beb90978cea26a2ec9d3e8cc7b0b6a728ae952212ada5d6ad19319120f3218a8
lib/codeql/rust/generated/RangePat.qll 2e96aece5ff2300659c2729c7037f7334790456d86160dc1e16ae99545c6ed0d eae4f95f9eaacbc2319ee67556dcc164527d82a6eaa5af59f6efce9caf3cba3b
lib/codeql/rust/generated/Raw.qll 965c8d9172ca1e887e7ab7e9c0177919febc40312e6a2ef720fddb054356a96c ee71ddc24f2694502d9d7649441fd5b605ca8d7360bd688da7f499994a154670
lib/codeql/rust/generated/Raw.qll 4b2faf8b23ff72bb606378893aa9235861e5f35cd69f4f49893e5832ac9fd454 b9144c583f9bd0cb6110d52e3ccc6d5559de735e5d0a0075e8a4ad8ca8f48848
lib/codeql/rust/generated/RecordExpr.qll bdafc10cde139617b67cb46bb205f99bc3fc0b9fd8634d304b81b524b9592aa8 2826c453c72416237467b08cf9ad9421b03203a8593420146dad8e1e71711b8a
lib/codeql/rust/generated/RecordExprField.qll eb06236fbdb856169dfe50ae1ebf59384222de6670ca91c34eed647823dda4ce 750bc7ab1e156db3927d6dd206e9d2c9388519425c0e8665afd322a6594aa5e2
lib/codeql/rust/generated/RecordPat.qll 20b62cfd4ee4e911ad4a2b8e5762da2abb7ff0c1d7f21cc6f72b1ebcbebbcd42 c0502e6bfc637058524cf7369c63396ca5440c58e5e91600fecd35ca5299d86c
@@ -205,8 +197,8 @@ lib/codeql/rust/generated/RepeatExpr.qll 5a33101a5e2ba973beafe0d933ad5ca238050eb
lib/codeql/rust/generated/ReturnExpr.qll 3d8fffeb6420a35d78f4f2e2e3e4ccf1c8454022c50395be2e8446f29740ddfa cc9dd916dc18114469d2eed9b82f83518af0de78797ad98777b29a5055bc77df
lib/codeql/rust/generated/SlicePat.qll 73dce5e310068357eb41e8c51923ff5c4054548db27987cde85735ddf071fc44 67fa0c285c110f18446689d1eaad9e82896df79d62999ad3f788fc295fa1d2c3
lib/codeql/rust/generated/Stmt.qll 58b010f32956f2736a7b9ebb43467ecd03308a1f27c99e2b09bb925c349ac859 9859da4a4aa29b4f7ab47313b2dfe8baf9717a162fcd8bd62a7cbab4afd1886e
lib/codeql/rust/generated/Synth.qll e0f3f080170ea9906c3969c0ace3b4852e9c99369bc8aba7b90f378e9aae0b4e 63b2dc0096f382743898d4958d7947bafa44318f192c251ba6b2d0cb4db0e44c
lib/codeql/rust/generated/SynthConstructors.qll 59c6e7ff37e6b8a2eb9ef8cd4546adfa4caeba76fa0c13d36e9509c3cb0d689e 59c6e7ff37e6b8a2eb9ef8cd4546adfa4caeba76fa0c13d36e9509c3cb0d689e
lib/codeql/rust/generated/Synth.qll c47c641625abd6c964dd75d35e4906292ec015458dc6294018f7db75b2891987 1e54a00ef3e83299e36c9ff6cefcae8258c3ca9b5e7440f576f837920ce69c09
lib/codeql/rust/generated/SynthConstructors.qll 38a59a0baffdf538c363f80680e6647e0096a78dda515054a031959856975752 38a59a0baffdf538c363f80680e6647e0096a78dda515054a031959856975752
lib/codeql/rust/generated/TupleExpr.qll 0828181e2f1f1f233598eab367688615356f6b91451a40f8d812d247d93467fc 2473c52d3dfbec6c8cd66bd439c85959e854f617edf5afe545252a24304f2f2e
lib/codeql/rust/generated/TuplePat.qll a1b22c20ca02497e9be8c6edaeaff214a669ecb0d2493890e79c28c485f512a1 5cc082ea99de61662b2d4c8b59f7a833236e7e448943e8ee894ab6066cc761c4
lib/codeql/rust/generated/TupleStructPat.qll 089563349c9866f5703e9d306ba2a475d7d4002e7236dbbf2feeb89290b4d24c a77842d7262a7d19b175f239d1ee6550b3b66a4efe903c5112bb82c0abd7b05d
@@ -214,8 +206,6 @@ lib/codeql/rust/generated/Type.qll abe5ef4f20ca98dfc300fdae2ecbf37faf70381feab4e
lib/codeql/rust/generated/UnderscoreExpr.qll 964b77ddae265ad51fd03fcb7ef008fcb34eb5ea1a7ac0cd06ed84c1922fc07f 964b77ddae265ad51fd03fcb7ef008fcb34eb5ea1a7ac0cd06ed84c1922fc07f
lib/codeql/rust/generated/Unimplemented.qll bcf63c2be3e0f7b88704a76ed182616101cd4b317f539ef5a65e5a4b87fb6b39 0e3e0ba85e03f327334b752c1dd1aa82b71bf1601725fcc071d93a29e40e1188
lib/codeql/rust/generated/UnimplementedDeclaration.qll a6eb4e61be018288304be010e063b68039a97f2cfe19e7049d3d54c65c88e9ab 662da5c38f5907d1f0f9990caca2114bf5e3b179591104dde777ae67262815df
lib/codeql/rust/generated/UnknownFile.qll ec9d1a3f15ecbf1743d4e39cb3b2f217aa9b54951c93302c2c4c238c3f0ce595 ec9d1a3f15ecbf1743d4e39cb3b2f217aa9b54951c93302c2c4c238c3f0ce595
lib/codeql/rust/generated/UnknownLocation.qll a19e2838c52d702d268ae530f3dbd6fcd8bb28a237a52636a960f225454103cf a19e2838c52d702d268ae530f3dbd6fcd8bb28a237a52636a960f225454103cf
lib/codeql/rust/generated/UnsafeBlockExpr.qll 52edde0daa57fea065f06537db05b5d442c63b3fa8777bf55ef2b2106c228ee9 52edde0daa57fea065f06537db05b5d442c63b3fa8777bf55ef2b2106c228ee9
lib/codeql/rust/generated/WildcardPat.qll 84da49dc571151b0c5e0661426546a53d499ce37fe927ca07f67c4977dd70e16 84da49dc571151b0c5e0661426546a53d499ce37fe927ca07f67c4977dd70e16
lib/codeql/rust/generated/YeetExpr.qll 0e673204c592b6025570098b14e0378a0e0c68d13be9217ce1543f2781667d42 6546ce98d42717d4e6932e1add628591e488d063ef2a79bf093b831645342e21
@@ -252,7 +242,6 @@ test/extractor-tests/generated/ElementListExpr/ElementListExpr.ql 22ba315472cfc2
test/extractor-tests/generated/ElementListExpr/ElementListExpr_getElement.ql 0a327e668c653a31d98f64290db768f68383d103cce4354076a226df708fe982 50231f088f3d81abd66be0ab1bf7159f47f8705cec977677b15738897dba5342
test/extractor-tests/generated/ExprStmt/ExprStmt.ql 037695af057183ef9e35569c9255625cb17b10590632aad4f9a917ab036a9b9e 8ded0651563b0447b3040303ad9e0b1bc9e2873ad5485ae4c6447f5893c77402
test/extractor-tests/generated/FieldExpr/FieldExpr.ql 6d85c8b85905baf66ae1f6ed716e42530d814f86261d98eddceab861939227e5 5765fb0376978a9006e2dc175bb224c5c944f19ddf628a2b933b1bebf81015a2
test/extractor-tests/generated/File/File.ql dec43be882fad904fab0c6447ca93633d801cb08ff8bec309befde7d2b9e5dda 74e1f1d698558c35fa03935cc34f4c8145d376b56d7657b18aeb338f5ca752cf
test/extractor-tests/generated/Function/Function.ql c49434420dbb6fc3d9e6294161dcd3d3b306fae5ba5c85b610e534b8b15ef74c fe02208b673b74eebed92b5cbb3a8a06c31c0681eb28f3e596515663f14fa9e2
test/extractor-tests/generated/GenericArgList/GenericArgList.ql f03097d3a9840ba08efa367d9da32011da8474e078eb13e14dd8a17955689887 57b9934868d324e7e99e9e79b8c3e2a5f760ba9ed6bed98b537dc3f5580253bd
test/extractor-tests/generated/IdentPat/IdentPat.ql dee6892ebf23f374f8e0403e7f6c4006f958159ecffc96dde8e4244e689ed7b4 0b48b337bc9ddc184ca240e3aafd9f5fdcfb1348f0a4e80106d4ce6541567f84

11
rust/ql/.gitattributes generated vendored
View File

@@ -33,10 +33,6 @@
/lib/codeql/rust/elements/ConstExprConstructor.qll linguist-generated
/lib/codeql/rust/elements/ContinueExpr.qll linguist-generated
/lib/codeql/rust/elements/ContinueExprConstructor.qll linguist-generated
/lib/codeql/rust/elements/DbFile.qll linguist-generated
/lib/codeql/rust/elements/DbFileConstructor.qll linguist-generated
/lib/codeql/rust/elements/DbLocation.qll linguist-generated
/lib/codeql/rust/elements/DbLocationConstructor.qll linguist-generated
/lib/codeql/rust/elements/Declaration.qll linguist-generated
/lib/codeql/rust/elements/ElementListExpr.qll linguist-generated
/lib/codeql/rust/elements/ElementListExprConstructor.qll linguist-generated
@@ -156,15 +152,12 @@
/lib/codeql/rust/generated/ConstBlockPat.qll linguist-generated
/lib/codeql/rust/generated/ConstExpr.qll linguist-generated
/lib/codeql/rust/generated/ContinueExpr.qll linguist-generated
/lib/codeql/rust/generated/DbFile.qll linguist-generated
/lib/codeql/rust/generated/DbLocation.qll linguist-generated
/lib/codeql/rust/generated/Declaration.qll linguist-generated
/lib/codeql/rust/generated/Element.qll linguist-generated
/lib/codeql/rust/generated/ElementListExpr.qll linguist-generated
/lib/codeql/rust/generated/Expr.qll linguist-generated
/lib/codeql/rust/generated/ExprStmt.qll linguist-generated
/lib/codeql/rust/generated/FieldExpr.qll linguist-generated
/lib/codeql/rust/generated/File.qll linguist-generated
/lib/codeql/rust/generated/Function.qll linguist-generated
/lib/codeql/rust/generated/GenericArgList.qll linguist-generated
/lib/codeql/rust/generated/IdentPat.qll linguist-generated
@@ -177,7 +170,6 @@
/lib/codeql/rust/generated/Literal.qll linguist-generated
/lib/codeql/rust/generated/LiteralPat.qll linguist-generated
/lib/codeql/rust/generated/Locatable.qll linguist-generated
/lib/codeql/rust/generated/Location.qll linguist-generated
/lib/codeql/rust/generated/LoopExpr.qll linguist-generated
/lib/codeql/rust/generated/MatchArm.qll linguist-generated
/lib/codeql/rust/generated/MatchExpr.qll linguist-generated
@@ -216,8 +208,6 @@
/lib/codeql/rust/generated/UnderscoreExpr.qll linguist-generated
/lib/codeql/rust/generated/Unimplemented.qll linguist-generated
/lib/codeql/rust/generated/UnimplementedDeclaration.qll linguist-generated
/lib/codeql/rust/generated/UnknownFile.qll linguist-generated
/lib/codeql/rust/generated/UnknownLocation.qll linguist-generated
/lib/codeql/rust/generated/UnsafeBlockExpr.qll linguist-generated
/lib/codeql/rust/generated/WildcardPat.qll linguist-generated
/lib/codeql/rust/generated/YeetExpr.qll linguist-generated
@@ -254,7 +244,6 @@
/test/extractor-tests/generated/ElementListExpr/ElementListExpr_getElement.ql linguist-generated
/test/extractor-tests/generated/ExprStmt/ExprStmt.ql linguist-generated
/test/extractor-tests/generated/FieldExpr/FieldExpr.ql linguist-generated
/test/extractor-tests/generated/File/File.ql linguist-generated
/test/extractor-tests/generated/Function/Function.ql linguist-generated
/test/extractor-tests/generated/GenericArgList/GenericArgList.ql linguist-generated
/test/extractor-tests/generated/IdentPat/IdentPat.ql linguist-generated

View File

@@ -2,7 +2,7 @@
* Provides shared predicates related to contextual queries in the code viewer.
*/
private import codeql.rust.elements.File
import codeql.files.FileSystem
private import codeql.util.FileSystem
/**

View File

@@ -0,0 +1,68 @@
/** Provides classes for working with locations. */
import files.FileSystem
/**
* A location as given by a file, a start line, a start column,
* an end line, and an end column.
*
* For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
class Location extends @location_default {
/** Gets the file for this location. */
File getFile() { locations_default(this, result, _, _, _, _) }
/** Gets the 1-based line number (inclusive) where this location starts. */
int getStartLine() { locations_default(this, _, result, _, _, _) }
/** Gets the 1-based column number (inclusive) where this location starts. */
int getStartColumn() { locations_default(this, _, _, result, _, _) }
/** Gets the 1-based line number (inclusive) where this location ends. */
int getEndLine() { locations_default(this, _, _, _, result, _) }
/** Gets the 1-based column number (inclusive) where this location ends. */
int getEndColumn() { locations_default(this, _, _, _, _, result) }
/** Gets the number of lines covered by this location. */
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
/** Gets a textual representation of this element. */
bindingset[this]
pragma[inline_late]
string toString() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(File f |
locations_default(this, f, startline, startcolumn, endline, endcolumn) and
filepath = f.getAbsolutePath()
)
}
/** Holds if this location starts strictly before the specified location. */
pragma[inline]
predicate strictlyBefore(Location other) {
this.getStartLine() < other.getStartLine()
or
this.getStartLine() = other.getStartLine() and this.getStartColumn() < other.getStartColumn()
}
}
/** An entity representing an empty location. */
class EmptyLocation extends Location {
EmptyLocation() { empty_location(this) }
}

View File

@@ -0,0 +1,36 @@
/** Provides classes for working with files and folders. */
private import codeql.Locations
private import codeql.util.FileSystem
private module Input implements InputSig {
abstract class ContainerBase extends @container {
abstract string getAbsolutePath();
ContainerBase getParentContainer() { containerparent(result, this) }
string toString() { result = this.getAbsolutePath() }
}
class FolderBase extends ContainerBase, @folder {
override string getAbsolutePath() { folders(this, result) }
}
class FileBase extends ContainerBase, @file {
override string getAbsolutePath() { files(this, result) }
}
predicate hasSourceLocationPrefix = sourceLocationPrefix/1;
}
private module Impl = Make<Input>;
class Container = Impl::Container;
class Folder = Impl::Folder;
/** A file. */
class File extends Container, Impl::File {
/** Holds if this file was extracted from ordinary source code. */
predicate fromSource() { any() }
}

View File

@@ -7,7 +7,7 @@
* @tags ide-contextual-queries/print-cfg
*/
private import codeql.rust.elements.File
private import codeql.files.FileSystem
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl
private import codeql.rust.controlflow.ControlFlowGraph

View File

@@ -21,15 +21,12 @@ import codeql.rust.elements.ClosureExpr
import codeql.rust.elements.ConstBlockPat
import codeql.rust.elements.ConstExpr
import codeql.rust.elements.ContinueExpr
import codeql.rust.elements.DbFile
import codeql.rust.elements.DbLocation
import codeql.rust.elements.Declaration
import codeql.rust.elements.Element
import codeql.rust.elements.ElementListExpr
import codeql.rust.elements.Expr
import codeql.rust.elements.ExprStmt
import codeql.rust.elements.FieldExpr
import codeql.rust.elements.File
import codeql.rust.elements.Function
import codeql.rust.elements.GenericArgList
import codeql.rust.elements.IdentPat
@@ -42,7 +39,6 @@ import codeql.rust.elements.LetStmt
import codeql.rust.elements.Literal
import codeql.rust.elements.LiteralPat
import codeql.rust.elements.Locatable
import codeql.rust.elements.Location
import codeql.rust.elements.LoopExpr
import codeql.rust.elements.MatchArm
import codeql.rust.elements.MatchExpr
@@ -76,8 +72,6 @@ import codeql.rust.elements.Type
import codeql.rust.elements.UnderscoreExpr
import codeql.rust.elements.Unimplemented
import codeql.rust.elements.UnimplementedDeclaration
import codeql.rust.elements.UnknownFile
import codeql.rust.elements.UnknownLocation
import codeql.rust.elements.UnsafeBlockExpr
import codeql.rust.elements.WildcardPat
import codeql.rust.elements.YeetExpr

View File

@@ -1,8 +0,0 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `DbFile`.
*/
private import codeql.rust.generated.DbFile
class DbFile extends Generated::DbFile { }

View File

@@ -1,14 +0,0 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module defines the hook used internally to tweak the characteristic predicate of
* `DbFile` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.rust.generated.Raw
/**
* The characteristic predicate of `DbFile` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructDbFile(Raw::DbFile id) { any() }

View File

@@ -1,8 +0,0 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `DbLocation`.
*/
private import codeql.rust.generated.DbLocation
class DbLocation extends Generated::DbLocation { }

View File

@@ -1,14 +0,0 @@
// generated by codegen, remove this comment if you wish to edit this file
/**
* This module defines the hook used internally to tweak the characteristic predicate of
* `DbLocation` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.rust.generated.Raw
/**
* The characteristic predicate of `DbLocation` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructDbLocation(Raw::DbLocation id) { any() }

View File

@@ -1,111 +0,0 @@
/**
* This module provides a hand-modifiable wrapper around the generated class `File`.
*/
private import codeql.rust.generated.File
private import codeql.rust.elements.Location
private import codeql.rust.elements.UnknownLocation
class File extends Generated::File {
/** toString */
override string toString() { result = this.getAbsolutePath() }
/** Gets the absolute path of this file. */
string getAbsolutePath() { result = this.getName() }
/** Gets the full name of this file. */
string getFullName() { result = this.getAbsolutePath() }
/** Gets the URL of this file. */
string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
/**
* Holds if either,
* - `part` is the base name of this container and `i = 1`, or
* - `part` is the stem of this container and `i = 2`, or
* - `part` is the extension of this container and `i = 3`.
*/
cached
private predicate splitAbsolutePath(string part, int i) {
part = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", i)
}
/** Gets the base name of this file. */
string getBaseName() { this.splitAbsolutePath(result, 1) }
/**
* Gets the extension of this container, that is, the suffix of its base name
* after the last dot character, if any.
*
* In particular,
*
* - if the name does not include a dot, there is no extension, so this
* predicate has no result;
* - if the name ends in a dot, the extension is the empty string;
* - if the name contains multiple dots, the extension follows the last dot.
*
* Here are some examples of absolute paths and the corresponding extensions
* (surrounded with quotes to avoid ambiguity):
*
* <table border="1">
* <tr><th>Absolute path</th><th>Extension</th></tr>
* <tr><td>"/tmp/tst.txt"</td><td>"txt"</td></tr>
* <tr><td>"/tmp/.classpath"</td><td>"classpath"</td></tr>
* <tr><td>"/bin/bash"</td><td>not defined</td></tr>
* <tr><td>"/tmp/tst2."</td><td>""</td></tr>
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
* </table>
*/
string getExtension() { this.splitAbsolutePath(result, 3) }
/**
* Gets the stem of this container, that is, the prefix of its base name up to
* (but not including) the last dot character if there is one, or the entire
* base name if there is not.
*
* Here are some examples of absolute paths and the corresponding stems
* (surrounded with quotes to avoid ambiguity):
*
* <table border="1">
* <tr><th>Absolute path</th><th>Stem</th></tr>
* <tr><td>"/tmp/tst.txt"</td><td>"tst"</td></tr>
* <tr><td>"/tmp/.classpath"</td><td>""</td></tr>
* <tr><td>"/bin/bash"</td><td>"bash"</td></tr>
* <tr><td>"/tmp/tst2."</td><td>"tst2"</td></tr>
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
* </table>
*/
string getStem() { this.splitAbsolutePath(result, 2) }
/**
* Gets the number of lines containing code in this file. This value
* is approximate.
*/
int getNumberOfLinesOfCode() {
result =
count(int line |
exists(Location loc |
not loc instanceof UnknownLocation and loc.getFile() = this and loc.getStartLine() = line
)
)
}
/**
* Gets the relative path of this file from the root folder of the
* analyzed source location. The relative path of the root folder itself
* would be the empty string.
*
* This has no result if the file is outside the source root, that is,
* if the root folder is not a reflexive, transitive parent of this file.
*/
string getRelativePath() {
exists(string absPath, string pref |
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
|
absPath = pref and result = ""
or
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
not result.matches("/%")
)
}
}

View File

@@ -3,16 +3,23 @@
*/
private import codeql.rust.generated.Locatable
private import codeql.rust.elements.File
private import codeql.rust.elements.UnknownLocation
import codeql.Locations
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
class Locatable extends Generated::Locatable {
/** Gets the primary location of this element. */
pragma[nomagic]
override Location getLocation() {
result = Generated::Locatable.super.getLocation()
or
not exists(Generated::Locatable.super.getLocation()) and
result instanceof UnknownLocation
final Location getLocation() {
exists(Raw::Locatable raw |
raw = Synth::convertLocatableToRaw(this) and
(
locatable_locations(raw, result)
or
not exists(Location loc | locatable_locations(raw, loc)) and
result instanceof EmptyLocation
)
)
}
/**

View File

@@ -1,29 +0,0 @@
/**
* This module provides a hand-modifiable wrapper around the generated class `Location`.
*/
private import codeql.rust.generated.Location
class Location extends Generated::Location {
/**
* Holds if this location is described by `path`, `startLine`, `startColumn`, `endLine` and `endColumn`.
*/
predicate hasLocationInfo(string path, int startLine, int startColumn, int endLine, int endColumn) {
path = this.getFile().getFullName() and
startLine = this.getStartLine() and
startColumn = this.getStartColumn() and
endLine = this.getEndLine() and
endColumn = this.getEndColumn()
}
/**
* Gets a textual representation of this location.
*/
override string toString() {
exists(string filePath, int startLine, int startColumn, int endLine, int endColumn |
this.hasLocationInfo(filePath, startLine, startColumn, endLine, endColumn)
|
toUrl(filePath, startLine, startColumn, endLine, endColumn, result)
)
}
}

View File

@@ -1,9 +0,0 @@
/**
* This module provides a hand-modifiable wrapper around the generated class `UnknownFile`.
*/
private import codeql.rust.generated.UnknownFile
class UnknownFile extends Generated::UnknownFile {
override string getName() { result = "" }
}

View File

@@ -1,21 +0,0 @@
/**
* This module provides a hand-modifiable wrapper around the generated class `UnknownLocation`.
*/
private import codeql.rust.generated.UnknownLocation
private import codeql.rust.elements.File
private import codeql.rust.elements.UnknownFile
class UnknownLocation extends Generated::UnknownLocation {
override File getFile() { result instanceof UnknownFile }
override int getStartLine() { result = 0 }
override int getStartColumn() { result = 0 }
override int getEndLine() { result = 0 }
override int getEndColumn() { result = 0 }
override string toString() { result = "UnknownLocation" }
}

View File

@@ -1,23 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `DbFile`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.File
/**
* INTERNAL: This module contains the fully generated definition of `DbFile` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::DbFile` class directly.
* Use the subclass `DbFile`, where the following predicates are available.
*/
class DbFile extends Synth::TDbFile, File {
override string getAPrimaryQlClass() { result = "DbFile" }
}
}

View File

@@ -1,23 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `DbLocation`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.Location
/**
* INTERNAL: This module contains the fully generated definition of `DbLocation` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::DbLocation` class directly.
* Use the subclass `DbLocation`, where the following predicates are available.
*/
class DbLocation extends Synth::TDbLocation, Location {
override string getAPrimaryQlClass() { result = "DbLocation" }
}
}

View File

@@ -1,26 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `File`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.Element
/**
* INTERNAL: This module contains the fully generated definition of `File` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::File` class directly.
* Use the subclass `File`, where the following predicates are available.
*/
class File extends Synth::TFile, Element {
/**
* Gets the name of this file.
*/
string getName() { result = Synth::convertFileToRaw(this).(Raw::File).getName() }
}
}

View File

@@ -7,7 +7,6 @@
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.Element
import codeql.rust.elements.Location
/**
* INTERNAL: This module contains the fully generated definition of `Locatable` and should not
@@ -18,20 +17,5 @@ module Generated {
* INTERNAL: Do not reference the `Generated::Locatable` class directly.
* Use the subclass `Locatable`, where the following predicates are available.
*/
class Locatable extends Synth::TLocatable, Element {
/**
* Gets the location of this locatable, if it exists.
*/
Location getLocation() {
result =
Synth::convertLocationFromRaw(Synth::convertLocatableToRaw(this)
.(Raw::Locatable)
.getLocation())
}
/**
* Holds if `getLocation()` exists.
*/
final predicate hasLocation() { exists(this.getLocation()) }
}
class Locatable extends Synth::TLocatable, Element { }
}

View File

@@ -1,52 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `Location`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.Element
import codeql.rust.elements.File
/**
* INTERNAL: This module contains the fully generated definition of `Location` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::Location` class directly.
* Use the subclass `Location`, where the following predicates are available.
*/
class Location extends Synth::TLocation, Element {
/**
* Gets the file of this location.
*/
File getFile() {
result =
Synth::convertFileFromRaw(Synth::convertLocationToRaw(this).(Raw::Location).getFile())
}
/**
* Gets the start line of this location.
*/
int getStartLine() { result = Synth::convertLocationToRaw(this).(Raw::Location).getStartLine() }
/**
* Gets the start column of this location.
*/
int getStartColumn() {
result = Synth::convertLocationToRaw(this).(Raw::Location).getStartColumn()
}
/**
* Gets the end line of this location.
*/
int getEndLine() { result = Synth::convertLocationToRaw(this).(Raw::Location).getEndLine() }
/**
* Gets the end column of this location.
*/
int getEndColumn() { result = Synth::convertLocationToRaw(this).(Raw::Location).getEndColumn() }
}
}

View File

@@ -10,19 +10,6 @@ private module Impl {
none()
}
private Element getImmediateChildOfFile(File e, int index, string partialPredicateCall) {
exists(int b, int bElement, int n |
b = 0 and
bElement = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfElement(e, i, _)) | i) and
n = bElement and
(
none()
or
result = getImmediateChildOfElement(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfLocatable(Locatable e, int index, string partialPredicateCall) {
exists(int b, int bElement, int n |
b = 0 and
@@ -36,19 +23,6 @@ private module Impl {
)
}
private Element getImmediateChildOfLocation(Location e, int index, string partialPredicateCall) {
exists(int b, int bElement, int n |
b = 0 and
bElement = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfElement(e, i, _)) | i) and
n = bElement and
(
none()
or
result = getImmediateChildOfElement(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfUnimplemented(
Unimplemented e, int index, string partialPredicateCall
) {
@@ -77,62 +51,6 @@ private module Impl {
)
}
private Element getImmediateChildOfDbFile(DbFile e, int index, string partialPredicateCall) {
exists(int b, int bFile, int n |
b = 0 and
bFile = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfFile(e, i, _)) | i) and
n = bFile and
(
none()
or
result = getImmediateChildOfFile(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfDbLocation(DbLocation e, int index, string partialPredicateCall) {
exists(int b, int bLocation, int n |
b = 0 and
bLocation = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocation(e, i, _)) | i) and
n = bLocation and
(
none()
or
result = getImmediateChildOfLocation(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfUnknownFile(
UnknownFile e, int index, string partialPredicateCall
) {
exists(int b, int bFile, int n |
b = 0 and
bFile = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfFile(e, i, _)) | i) and
n = bFile and
(
none()
or
result = getImmediateChildOfFile(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfUnknownLocation(
UnknownLocation e, int index, string partialPredicateCall
) {
exists(int b, int bLocation, int n |
b = 0 and
bLocation = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocation(e, i, _)) | i) and
n = bLocation and
(
none()
or
result = getImmediateChildOfLocation(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfDeclaration(
Declaration e, int index, string partialPredicateCall
) {
@@ -1354,14 +1272,6 @@ private module Impl {
// * none() simplifies generation, as we can append `or ...` without a special case for the first item
none()
or
result = getImmediateChildOfDbFile(e, index, partialAccessor)
or
result = getImmediateChildOfDbLocation(e, index, partialAccessor)
or
result = getImmediateChildOfUnknownFile(e, index, partialAccessor)
or
result = getImmediateChildOfUnknownLocation(e, index, partialAccessor)
or
result = getImmediateChildOfGenericArgList(e, index, partialAccessor)
or
result = getImmediateChildOfLabel(e, index, partialAccessor)

View File

@@ -13,52 +13,7 @@ module Raw {
/**
* INTERNAL: Do not use.
*/
class File extends @file, Element {
/**
* Gets the name of this file.
*/
string getName() { files(this, result) }
}
/**
* INTERNAL: Do not use.
*/
class Locatable extends @locatable, Element {
/**
* Gets the location of this locatable, if it exists.
*/
Location getLocation() { locatable_locations(this, result) }
}
/**
* INTERNAL: Do not use.
*/
class Location extends @location, Element {
/**
* Gets the file of this location.
*/
File getFile() { locations(this, result, _, _, _, _) }
/**
* Gets the start line of this location.
*/
int getStartLine() { locations(this, _, result, _, _, _) }
/**
* Gets the start column of this location.
*/
int getStartColumn() { locations(this, _, _, result, _, _) }
/**
* Gets the end line of this location.
*/
int getEndLine() { locations(this, _, _, _, result, _) }
/**
* Gets the end column of this location.
*/
int getEndColumn() { locations(this, _, _, _, _, result) }
}
class Locatable extends @locatable, Element { }
/**
* INTERNAL: Do not use.
@@ -71,20 +26,6 @@ module Raw {
*/
class AstNode extends @ast_node, Locatable { }
/**
* INTERNAL: Do not use.
*/
class DbFile extends @db_file, File {
override string toString() { result = "DbFile" }
}
/**
* INTERNAL: Do not use.
*/
class DbLocation extends @db_location, Location {
override string toString() { result = "DbLocation" }
}
/**
* INTERNAL: Do not use.
* The base class for declarations.

View File

@@ -75,14 +75,6 @@ module Synth {
* INTERNAL: Do not use.
*/
TContinueExpr(Raw::ContinueExpr id) { constructContinueExpr(id) } or
/**
* INTERNAL: Do not use.
*/
TDbFile(Raw::DbFile id) { constructDbFile(id) } or
/**
* INTERNAL: Do not use.
*/
TDbLocation(Raw::DbLocation id) { constructDbLocation(id) } or
/**
* INTERNAL: Do not use.
*/
@@ -261,14 +253,6 @@ module Synth {
TUnimplementedDeclaration(Raw::UnimplementedDeclaration id) {
constructUnimplementedDeclaration(id)
} or
/**
* INTERNAL: Do not use.
*/
TUnknownFile() or
/**
* INTERNAL: Do not use.
*/
TUnknownLocation() or
/**
* INTERNAL: Do not use.
*/
@@ -319,21 +303,11 @@ module Synth {
TRangeExpr or TRecordExpr or TRefExpr or TReturnExpr or TTupleExpr or TUnderscoreExpr or
TYeetExpr or TYieldExpr;
/**
* INTERNAL: Do not use.
*/
class TFile = TDbFile or TUnknownFile;
/**
* INTERNAL: Do not use.
*/
class TLocatable = TAstNode;
/**
* INTERNAL: Do not use.
*/
class TLocation = TDbLocation or TUnknownLocation;
/**
* INTERNAL: Do not use.
*/
@@ -457,20 +431,6 @@ module Synth {
cached
TContinueExpr convertContinueExprFromRaw(Raw::Element e) { result = TContinueExpr(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TDbFile`, if possible.
*/
cached
TDbFile convertDbFileFromRaw(Raw::Element e) { result = TDbFile(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TDbLocation`, if possible.
*/
cached
TDbLocation convertDbLocationFromRaw(Raw::Element e) { result = TDbLocation(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TElementListExpr`, if possible.
@@ -781,20 +741,6 @@ module Synth {
result = TUnimplementedDeclaration(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TUnknownFile`, if possible.
*/
cached
TUnknownFile convertUnknownFileFromRaw(Raw::Element e) { none() }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TUnknownLocation`, if possible.
*/
cached
TUnknownLocation convertUnknownLocationFromRaw(Raw::Element e) { none() }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TUnsafeBlockExpr`, if possible.
@@ -895,12 +841,8 @@ module Synth {
*/
cached
TElement convertElementFromRaw(Raw::Element e) {
result = convertFileFromRaw(e)
or
result = convertLocatableFromRaw(e)
or
result = convertLocationFromRaw(e)
or
result = convertUnimplementedFromRaw(e)
}
@@ -977,17 +919,6 @@ module Synth {
result = convertYieldExprFromRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TFile`, if possible.
*/
cached
TFile convertFileFromRaw(Raw::Element e) {
result = convertDbFileFromRaw(e)
or
result = convertUnknownFileFromRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TLocatable`, if possible.
@@ -995,17 +926,6 @@ module Synth {
cached
TLocatable convertLocatableFromRaw(Raw::Element e) { result = convertAstNodeFromRaw(e) }
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TLocation`, if possible.
*/
cached
TLocation convertLocationFromRaw(Raw::Element e) {
result = convertDbLocationFromRaw(e)
or
result = convertUnknownLocationFromRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw DB element to a synthesized `TPat`, if possible.
@@ -1174,20 +1094,6 @@ module Synth {
cached
Raw::Element convertContinueExprToRaw(TContinueExpr e) { e = TContinueExpr(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TDbFile` to a raw DB element, if possible.
*/
cached
Raw::Element convertDbFileToRaw(TDbFile e) { e = TDbFile(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TDbLocation` to a raw DB element, if possible.
*/
cached
Raw::Element convertDbLocationToRaw(TDbLocation e) { e = TDbLocation(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TElementListExpr` to a raw DB element, if possible.
@@ -1498,20 +1404,6 @@ module Synth {
e = TUnimplementedDeclaration(result)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TUnknownFile` to a raw DB element, if possible.
*/
cached
Raw::Element convertUnknownFileToRaw(TUnknownFile e) { none() }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TUnknownLocation` to a raw DB element, if possible.
*/
cached
Raw::Element convertUnknownLocationToRaw(TUnknownLocation e) { none() }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TUnsafeBlockExpr` to a raw DB element, if possible.
@@ -1612,12 +1504,8 @@ module Synth {
*/
cached
Raw::Element convertElementToRaw(TElement e) {
result = convertFileToRaw(e)
or
result = convertLocatableToRaw(e)
or
result = convertLocationToRaw(e)
or
result = convertUnimplementedToRaw(e)
}
@@ -1694,17 +1582,6 @@ module Synth {
result = convertYieldExprToRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TFile` to a raw DB element, if possible.
*/
cached
Raw::Element convertFileToRaw(TFile e) {
result = convertDbFileToRaw(e)
or
result = convertUnknownFileToRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TLocatable` to a raw DB element, if possible.
@@ -1712,17 +1589,6 @@ module Synth {
cached
Raw::Element convertLocatableToRaw(TLocatable e) { result = convertAstNodeToRaw(e) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TLocation` to a raw DB element, if possible.
*/
cached
Raw::Element convertLocationToRaw(TLocation e) {
result = convertDbLocationToRaw(e)
or
result = convertUnknownLocationToRaw(e)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TPat` to a raw DB element, if possible.

View File

@@ -18,8 +18,6 @@ import codeql.rust.elements.ClosureExprConstructor
import codeql.rust.elements.ConstBlockPatConstructor
import codeql.rust.elements.ConstExprConstructor
import codeql.rust.elements.ContinueExprConstructor
import codeql.rust.elements.DbFileConstructor
import codeql.rust.elements.DbLocationConstructor
import codeql.rust.elements.ElementListExprConstructor
import codeql.rust.elements.ExprStmtConstructor
import codeql.rust.elements.FieldExprConstructor

View File

@@ -1,23 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `UnknownFile`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.File
/**
* INTERNAL: This module contains the fully generated definition of `UnknownFile` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::UnknownFile` class directly.
* Use the subclass `UnknownFile`, where the following predicates are available.
*/
class UnknownFile extends Synth::TUnknownFile, File {
override string getAPrimaryQlClass() { result = "UnknownFile" }
}
}

View File

@@ -1,23 +0,0 @@
// generated by codegen
/**
* This module provides the generated definition of `UnknownLocation`.
* INTERNAL: Do not import directly.
*/
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
import codeql.rust.elements.Location
/**
* INTERNAL: This module contains the fully generated definition of `UnknownLocation` and should not
* be referenced directly.
*/
module Generated {
/**
* INTERNAL: Do not reference the `Generated::UnknownLocation` class directly.
* Use the subclass `UnknownLocation`, where the following predicates are available.
*/
class UnknownLocation extends Synth::TUnknownLocation, Location {
override string getAPrimaryQlClass() { result = "UnknownLocation" }
}
}

View File

@@ -12,7 +12,7 @@ private int getOrder(PrintAstNode node) {
|
n
order by
loc.getFile().getName(), loc.getStartLine(), loc.getStartColumn(), loc.getEndLine(),
loc.getFile().getAbsolutePath(), loc.getStartLine(), loc.getStartColumn(), loc.getEndLine(),
loc.getEndColumn()
)
}

View File

@@ -1,57 +1,133 @@
// generated by codegen
// from prefix.dbscheme
// from ../shared/tree-sitter-extractor/src/generator/prefix.dbscheme
/*- Files and folders -*/
/**
* The location of an element.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `file`.
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
locations_default(
unique int id: @location_default,
int file: @file ref,
int beginLine: int ref,
int beginColumn: int ref,
int endLine: int ref,
int endColumn: int ref
);
files(
unique int id: @file,
string name: string ref
);
folders(
unique int id: @folder,
string name: string ref
);
@container = @file | @folder
containerparent(
int parent: @container ref,
unique int child: @container ref
);
/*- Empty location -*/
empty_location(
int location: @location_default ref
);
/*- Source location prefix -*/
/**
* The source location of the snapshot.
*/
sourceLocationPrefix(
string prefix: string ref
sourceLocationPrefix(string prefix : string ref);
/*- Diagnostic messages -*/
diagnostics(
unique int id: @diagnostic,
int severity: int ref,
string error_tag: string ref,
string error_message: string ref,
string full_error_message: string ref,
int location: @location_default ref
);
/*- Diagnostic messages: severity -*/
case @diagnostic.severity of
10 = @diagnostic_debug
| 20 = @diagnostic_info
| 30 = @diagnostic_warning
| 40 = @diagnostic_error
;
/*- YAML -*/
#keyset[parent, idx]
yaml (unique int id: @yaml_node,
int kind: int ref,
int parent: @yaml_node_parent ref,
int idx: int ref,
string tag: string ref,
string tostring: string ref);
case @yaml_node.kind of
0 = @yaml_scalar_node
| 1 = @yaml_mapping_node
| 2 = @yaml_sequence_node
| 3 = @yaml_alias_node
;
@yaml_collection_node = @yaml_mapping_node | @yaml_sequence_node;
@yaml_node_parent = @yaml_collection_node | @file;
yaml_anchors (unique int node: @yaml_node ref,
string anchor: string ref);
yaml_aliases (unique int alias: @yaml_alias_node ref,
string target: string ref);
yaml_scalars (unique int scalar: @yaml_scalar_node ref,
int style: int ref,
string value: string ref);
yaml_errors (unique int id: @yaml_error,
string message: string ref);
yaml_locations(unique int locatable: @yaml_locatable ref,
int location: @location_default ref);
@yaml_locatable = @yaml_node | @yaml_error;
// from prefix.dbscheme
#keyset[id]
locatable_locations(
int id: @locatable ref,
int location: @location_default ref
);
// from schema.py
@element =
@file
| @locatable
| @location
@locatable
| @unimplemented
;
@file =
@db_file
;
#keyset[id]
files(
int id: @file ref,
string name: string ref
);
@locatable =
@ast_node
;
#keyset[id]
locatable_locations(
int id: @locatable ref,
int location: @location ref
);
@location =
@db_location
;
#keyset[id]
locations(
int id: @location ref,
int file: @file ref,
int start_line: int ref,
int start_column: int ref,
int end_line: int ref,
int end_column: int ref
);
@unimplemented =
@generic_arg_list
| @path
@@ -73,14 +149,6 @@ locations(
| @type
;
db_files(
unique int id: @db_file
);
db_locations(
unique int id: @db_location
);
@declaration =
@function
| @module

View File

@@ -1,3 +1,5 @@
/** Top-level import for the Rust language pack */
import codeql.rust.elements
import codeql.Locations
import codeql.files.FileSystem

View File

@@ -0,0 +1,4 @@
- description: Standard Code Scanning queries for Rust
- queries: .
- apply: code-scanning-selectors.yml
from: codeql/suite-helpers

View File

@@ -0,0 +1,4 @@
- description: Security-and-quality queries for Rust
- queries: .
- apply: security-and-quality-selectors.yml
from: codeql/suite-helpers

View File

@@ -0,0 +1,4 @@
- description: Extended and experimental security queries for Rust
- queries: .
- apply: security-experimental-selectors.yml
from: codeql/suite-helpers

View File

@@ -0,0 +1,4 @@
- description: Security-extended queries for Rust
- queries: .
- apply: security-extended-selectors.yml
from: codeql/suite-helpers

View File

@@ -0,0 +1,13 @@
/**
* @name Extracted files
* @description Lists all files in the source code directory that were extracted.
* @kind diagnostic
* @id rust/diagnostics/successfully-extracted-files
* @tags successfully-extracted-files
*/
import rust
from File f
where exists(f.getRelativePath())
select f, "File successfully extracted."

View File

@@ -1,4 +1,3 @@
private import codeql.rust.elements
private import rust
cached
predicate toBeTested(Element e) { any() }

View File

@@ -0,0 +1 @@
| file://:0:0:0:0 | @0:0:0:0 | file://:0:0:0:0 | |

View File

@@ -0,0 +1,4 @@
import rust
from EmptyLocation loc
select loc, loc.getFile()

View File

@@ -0,0 +1,3 @@
| a_file.rs:0:0:0:0 | a_file.rs |
| another_file.rs:0:0:0:0 | another_file.rs |
| lib.rs:0:0:0:0 | lib.rs |

View File

@@ -0,0 +1,6 @@
import rust
import TestUtils
from File f
where fileIsInTest(f)
select f

View File

@@ -1,10 +0,0 @@
// generated by codegen
import codeql.rust.elements
import TestUtils
from File x, string getName
where
toBeTested(x) and
not x.isUnknown() and
getName = x.getName()
select x, x.getPrimaryQlClasses(), "getName:", getName

View File

@@ -1 +0,0 @@
fn main() {}

View File

@@ -0,0 +1,6 @@
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | File successfully extracted. |
| error.rs:0:0:0:0 | error.rs | File successfully extracted. |
| lib.rs:0:0:0:0 | lib.rs | File successfully extracted. |
| main.rs:0:0:0:0 | main.rs | File successfully extracted. |
| my_macro.rs:0:0:0:0 | my_macro.rs | File successfully extracted. |
| my_struct.rs:0:0:0:0 | my_struct.rs | File successfully extracted. |

View File

@@ -0,0 +1 @@
queries/diagnostics/ExtractedFiles.ql

View File

@@ -0,0 +1,3 @@
pub fn my_func() {
This is not correct Rust code.
}

View File

@@ -0,0 +1,3 @@
pub fn my_func() {
compile_error!("An error!");
}

View File

@@ -0,0 +1,18 @@
/**
* total lines in this file: 18
* of which code: 7
* of which only comments: 7
* of which blank: 4
*/
mod my_struct;
mod my_macro;
// another comment
fn main() {
println!("Hello, world!"); // another comment
my_struct::my_func();
my_macro::my_func();
}

View File

@@ -0,0 +1,18 @@
/**
* total lines in this file: 18
* of which code: 10
* of which only comments: 6
* of which blank: 2
*/
macro_rules! myMacro {
() => {
println!("Hello, world!");
};
}
pub fn my_func() {
if true {
myMacro!();
}
}

View File

@@ -0,0 +1,30 @@
#![allow(dead_code)]
/**
* total lines in this file: 30
* of which code: 20
* of which only comments: 6
* of which blank: 4
*/
#[derive(Debug)]
struct MyStruct {
name: String,
value: i32,
}
impl MyStruct {
fn my_method(&self) {
println!("Hello, world!");
}
}
pub fn my_func() {
let _a = 1;
let b =
MyStruct {
name: String::from("abc"),
value: 123,
};
b.my_method();
}

View File

@@ -11,6 +11,7 @@ For how documentation of generated QL code works, please read `misc/codegen/sche
from misc.codegen.lib.schemadefs import *
include("../shared/tree-sitter-extractor/src/generator/prefix.dbscheme")
include("prefix.dbscheme")
@@ -19,43 +20,9 @@ class Element:
pass
@qltest.collapse_hierarchy
class File(Element):
name: string
@qltest.skip
@qltest.collapse_hierarchy
class Location(Element):
file: File
start_line: int
start_column: int
end_line: int
end_column: int
class DbFile(File):
pass
class DbLocation(Location):
pass
@synth.on_arguments()
class UnknownFile(File):
pass
@synth.on_arguments()
class UnknownLocation(Location):
pass
@qltest.skip
class Locatable(Element):
location: optional[Location]
pass
@qltest.skip
class AstNode(Locatable):

View File

@@ -14,3 +14,8 @@ rust_library(
],
deps = all_crate_deps(),
)
filegroup(
name = "dbscheme-prefix",
srcs = ["src/generator/prefix.dbscheme"],
)

View File

@@ -154,7 +154,7 @@ fn global_location(writer: &mut trap::Writer, location: trap::Location) -> trap:
/** Get the label for the given location, creating it as a fresh ID if we haven't seen the location
* yet for this file. */
fn location_label(writer: &mut trap::Writer, location: trap::Location) -> trap::Label {
pub fn location_label(writer: &mut trap::Writer, location: trap::Location) -> trap::Label {
let (loc_label, fresh) = writer.location_label(location);
if fresh {
writer.add_tuple(