Rust: integrate into standard files+location library

This commit is contained in:
Paolo Tranquilli 2024-09-12 13:15:46 +02:00
Родитель a4c1ec75db
Коммит b4b680775c
43 изменённых файлов: 445 добавлений и 1221 удалений

2
rust/extractor/src/generated/.generated.list сгенерированный
Просмотреть файл

@ -1,2 +1,2 @@
mod.rs 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e
top.rs 569909061b9a993481764765a014327d143939778f2dbc79836e7496cdb83e1f 569909061b9a993481764765a014327d143939778f2dbc79836e7496cdb83e1f
top.rs 7150acaeab0b57039ca9f2ed20311229aab5fd48b533f13410ecc34fd8e3bda0 7150acaeab0b57039ca9f2ed20311229aab5fd48b533f13410ecc34fd8e3bda0

282
rust/extractor/src/generated/top.rs сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -62,11 +62,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 });
@ -77,56 +73,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::LiteralExpr {
id: TrapId::Star,
location: None,
});
let expr = self.trap.emit(generated::LiteralExpr { id: TrapId::Star });
self.trap.emit(generated::LitPat {
id: TrapId::Star,
location,
expr,
})
}
@ -138,14 +133,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,
{
@ -155,10 +153,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
@ -166,7 +169,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,
@ -174,23 +177,21 @@ 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_unimplemented(&mut self, location: Option<trap::Label>) -> trap::Label {
self.trap.emit(generated::Unimplemented {
id: TrapId::Star,
location,
})
fn emit_unimplemented(&mut self) -> trap::Label {
self.trap
.emit(generated::Unimplemented { id: TrapId::Star })
}
fn emit_path(&mut self, _path: &Path, location: Option<trap::Label>) -> trap::Label {
self.emit_unimplemented(location)
fn emit_path(&mut self, _path: &Path) -> trap::Label {
self.emit_unimplemented()
}
fn emit_record_field_pat(
@ -200,14 +201,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::RecordFieldPat {
let pat_label = self.emit_pat(*pat, body, source_map);
let ret = self.trap.emit(generated::RecordFieldPat {
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(
@ -217,27 +218,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::RecordLitField {
let expr_label = self.emit_expr(*expr, body, source_map);
let ret = self.trap.emit(generated::RecordLitField {
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::WildPat {
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::WildPat { id: TrapId::Star })
}
ra_ap_hir_def::hir::Pat::Tuple { args, ellipsis } => {
let args = args
.into_iter()
@ -246,7 +244,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,
})
@ -258,7 +255,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::OrPat {
id: TrapId::Star,
location,
args,
})
}
@ -267,14 +263,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_record_field_pat(arg, body, source_map))
.collect();
self.trap.emit(generated::RecordPat {
id: TrapId::Star,
location,
path,
args,
has_ellipsis: *ellipsis,
@ -283,13 +278,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,
})
@ -310,17 +304,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,
})
}
@ -328,7 +320,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::LitPat {
id: TrapId::Star,
location,
expr,
})
}
@ -336,7 +327,6 @@ impl CrateTranslator<'_> {
let subpat = subpat.map(|pat| self.emit_pat(pat, body, source_map));
self.trap.emit(generated::BindPat {
id: TrapId::Star,
location,
subpat,
binding_id: body.bindings[*id].name.as_str().into(),
})
@ -346,14 +336,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),
@ -363,7 +352,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(),
})
@ -372,7 +360,6 @@ impl CrateTranslator<'_> {
let inner = self.emit_pat(*inner, body, source_map);
self.trap.emit(generated::BoxPat {
id: TrapId::Star,
location,
inner,
})
}
@ -380,14 +367,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.emit_unimplemented(None)
self.emit_unimplemented()
}
fn emit_match_arm(
&mut self,
@ -395,17 +383,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,
@ -420,9 +408,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_ref = type_ref
.as_ref()
.map(|type_ref| self.emit_type_ref(type_ref));
@ -430,29 +416,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_ref,
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(
@ -461,18 +447,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,
})
}
@ -486,7 +469,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_,
@ -497,7 +479,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::LetExpr {
id: TrapId::Star,
location,
pat,
expr,
})
@ -516,7 +497,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,
@ -534,7 +514,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,
})
@ -544,7 +523,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(expr_id, body, source_map);
self.trap.emit(generated::ConstExpr {
id: TrapId::Star,
location,
expr,
})
}
@ -560,7 +538,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,
})
@ -573,7 +550,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,
})
@ -590,7 +566,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::CallExpr {
id: TrapId::Star,
location,
callee,
args,
is_assignee_expr: *is_assignee_expr,
@ -607,12 +582,9 @@ impl CrateTranslator<'_> {
.into_iter()
.map(|e| self.emit_expr(*e, body, source_map))
.collect();
let generic_args = generic_args
.as_ref()
.map(|_args| self.emit_unimplemented(None));
let generic_args = generic_args.as_ref().map(|_args| self.emit_unimplemented());
self.trap.emit(generated::MethodCallExpr {
id: TrapId::Star,
location,
receiver,
method_name: method_name.as_str().into(),
args,
@ -628,7 +600,6 @@ impl CrateTranslator<'_> {
self.trap.emit(generated::MatchExpr {
id: TrapId::Star,
location,
expr,
branches,
})
@ -637,7 +608,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 +616,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 +624,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 +631,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::BecomeExpr {
id: TrapId::Star,
location,
expr,
})
}
@ -671,7 +638,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 +645,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 +655,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 fields = fields
.into_iter()
.map(|field| self.emit_record_lit_field(field, body, source_map))
@ -698,7 +663,6 @@ impl CrateTranslator<'_> {
let spread = spread.map(|expr_id| self.emit_expr(expr_id, body, source_map));
self.trap.emit(generated::RecordLitExpr {
id: TrapId::Star,
location,
path,
fields,
spread,
@ -710,7 +674,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 +682,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::AwaitExpr {
id: TrapId::Star,
location,
expr,
})
}
@ -728,7 +690,6 @@ impl CrateTranslator<'_> {
let type_ref: trap::Label = self.emit_type_ref(type_ref.as_ref());
self.trap.emit(generated::CastExpr {
id: TrapId::Star,
location,
expr,
type_ref,
})
@ -741,7 +702,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 +711,6 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(*expr, body, source_map);
self.trap.emit(generated::BoxExpr {
id: TrapId::Star,
location,
expr,
})
}
@ -764,7 +723,6 @@ impl CrateTranslator<'_> {
};
self.trap.emit(generated::UnaryOpExpr {
id: TrapId::Star,
location,
expr,
op: op.into(),
})
@ -775,7 +733,6 @@ impl CrateTranslator<'_> {
let op = op.map(|op| format!("{op}"));
self.trap.emit(generated::BinaryOpExpr {
id: TrapId::Star,
location,
lhs,
rhs,
op,
@ -790,7 +747,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 +761,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 +792,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::ClosureExpr {
id: TrapId::Star,
location,
args,
arg_types,
body: expr,
@ -856,7 +810,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::TupleExpr {
id: TrapId::Star,
location,
exprs,
is_assignee_expr: *is_assignee_expr,
})
@ -871,7 +824,6 @@ impl CrateTranslator<'_> {
.collect();
self.trap.emit(generated::ElementListExpr {
id: TrapId::Star,
location,
elements,
is_assignee_expr: *is_assignee_expr,
})
@ -885,25 +837,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::LiteralExpr {
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::LiteralExpr { 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 +860,12 @@ impl CrateTranslator<'_> {
let expr = self.emit_expr(asm.e, body, source_map);
self.trap.emit(generated::InlineAsmExpr {
id: TrapId::Star,
location,
expr,
})
}
}
};
self.emit_location_for_expr(ret, expr_id, source_map);
ret
}
fn emit_definition(
@ -925,15 +874,12 @@ impl CrateTranslator<'_> {
id: ModuleDef,
labels: &mut Vec<trap::Label>,
) {
match id {
ModuleDef::Module(_) => {
self.emit_unimplemented(None);
}
let _label = match id {
ModuleDef::Module(_) => self.emit_unimplemented(),
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 = if self.extract_dependencies || self.krate.origin(self.db).is_local() {
let (body, source_map) = self.db.body_with_source_map(def.into());
@ -941,54 +887,62 @@ impl CrateTranslator<'_> {
log::trace!("{}", &txt);
self.emit_expr(body.body_expr, &body, &source_map)
} else {
self.trap.emit(generated::MissingExpr {
id: TrapId::Star,
location: None,
})
self.trap.emit(generated::MissingExpr { id: TrapId::Star })
};
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);
// TODO: move this below to add all to module children. For now this causes a
// DB inconsistency
labels.push(label);
label
}
ModuleDef::Adt(adt) => {
let location = self.emit_location(adt);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, adt);
label
}
ModuleDef::Variant(variant) => {
let location = self.emit_location(variant);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, variant);
label
}
ModuleDef::Const(const_) => {
let location = self.emit_location(const_);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, const_);
label
}
ModuleDef::Static(static_) => {
let location = self.emit_location(static_);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, static_);
label
}
ModuleDef::Trait(trait_) => {
let location = self.emit_location(trait_);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, trait_);
label
}
ModuleDef::TraitAlias(alias) => {
let location = self.emit_location(alias);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, alias);
label
}
ModuleDef::TypeAlias(type_alias) => {
let location = self.emit_location(type_alias);
self.emit_unimplemented(location);
}
ModuleDef::BuiltinType(_builtin_type) => {
self.emit_unimplemented(None);
let label = self.emit_unimplemented();
self.emit_location(label, type_alias);
label
}
ModuleDef::BuiltinType(_builtin_type) => self.emit_unimplemented(),
ModuleDef::Macro(macro_) => {
let location = self.emit_location(macro_);
self.emit_unimplemented(location);
let label = self.emit_unimplemented();
self.emit_location(label, macro_);
label
}
}
};
//TODO: labels.push(label) for all, not just functions
}
fn emit_module(&mut self, label: trap::Label, module: Module) {
@ -998,7 +952,6 @@ impl CrateTranslator<'_> {
}
self.trap.emit(generated::Module {
id: label.into(),
location: None,
declarations: children,
});
}

Просмотреть файл

@ -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,
}
}

Просмотреть файл

@ -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
);

23
rust/ql/.generated.list сгенерированный
Просмотреть файл

@ -31,10 +31,6 @@ lib/codeql/rust/elements/ConstExpr.qll df129a4a1f65c07076e15097571ffd12b91a63d3d
lib/codeql/rust/elements/ConstExprConstructor.qll b4c96adc2878047c36d7ceaba2346ef66a2269b5260a56c3d7ff6e3a332bad75 ce15bbfd1448e47d3039e912363efa607cc2c29d44b8248ac91c307af7b57016
lib/codeql/rust/elements/ContinueExpr.qll 46635ab257d8cc8ab3ba4b6786df7a2ff4d2e6360578bebde8bec1d6ae90b8c7 a0c60fb018ced67e1d6eed1c493b2c6d729636f1325b556ed5bcbcff072cd8d7
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 d4ec5c83728f1837243caf2f27d06fd05ecdd2ca440112accff99bfd37b45e5f c1cd9b297be8b69207e75d24b29949b9f71c78406ee0ffd38d0b0810288d6140
lib/codeql/rust/elements/ElementListExpr.qll ec535846c4f449a3e58bb3b8dc583960ef3b42a10836ad13a6c3091f625ab463 3797f92086ecab90406b7493953d78af27b0b5c68199e2f37abc15f3d1cf88ed
lib/codeql/rust/elements/ElementListExprConstructor.qll 12b06597e0700cd0eac70e42cbdc1a2d410e0ffcd05c21a213812a488b5b236b 7adb2e442f1bc362c44824aaba0ab4a7fb4a4bc550a3c96f963dc03bed582d39
@ -130,7 +126,7 @@ lib/codeql/rust/elements/YeetExpr.qll 04a1f4f7b2bb697e30ab284720ed30c0c8e1377cac
lib/codeql/rust/elements/YeetExprConstructor.qll f1871c6e0c966c52806e370dbe2956585bbfa1dcf0bd7ebfdb2bd39b7cfd0d7b a2333e80a325a921a66c34151401da12c250951952ccb0c81e5102dc62299503
lib/codeql/rust/elements/YieldExpr.qll b0f238ba2e4b83b449b44224d766b6cf6b15523a413467f608f4a711d34edc01 355fcafe43915d69a07725ec3707e66abfefc6157bd7dc1c1fd846a965c6580d
lib/codeql/rust/elements/YieldExprConstructor.qll ff46ba17cc24abfcb0e310c7458d0539b704e7a771ad00853bd3a1844e4e6f82 1c13662ef01c88f1cf057d099eb46524036133e51a0e36ddf947f727ac6046bb
lib/codeql/rust/elements.qll c0e6bff934b1925ec03e55afc2b5b9127f51dc4a613e047e687bc83cdab4f196 c0e6bff934b1925ec03e55afc2b5b9127f51dc4a613e047e687bc83cdab4f196
lib/codeql/rust/elements.qll 54bf00efa3d1846ed2ec874cbdcf5bf5789bf5df240cb90ea6c68d4b469abdd2 54bf00efa3d1846ed2ec874cbdcf5bf5789bf5df240cb90ea6c68d4b469abdd2
lib/codeql/rust/generated/ArrayExpr.qll b9778720acf4080c065897ba1471be185c0c35f3ea01c15594c0a3ee4029b231 cbc8c9dbcb805063c4b893e21ed0bf00312490a0c92ee126d49dbfff6978fa99
lib/codeql/rust/generated/AstNode.qll 0598fac7859906f4103124270dfb2fbdb838387b1c45000bf50a4b62c797ec41 f47c84878c7c9676109e358073bddab92a1dbeb4d977d236ecc1eae44d81c894
lib/codeql/rust/generated/AsyncBlockExpr.qll 1e9d3bcd5d5703bf61748f2746d3f9a4e2a12080268b29a2685b762d13c30555 1e9d3bcd5d5703bf61748f2746d3f9a4e2a12080268b29a2685b762d13c30555
@ -149,15 +145,12 @@ lib/codeql/rust/generated/ClosureExpr.qll f0c7ce7aecc9da9663cbda3e285be73b23464f
lib/codeql/rust/generated/ConstBlockPat.qll d0818fe4cee066f1e6d3439c82122942ae62941e69da686b7d5c399e820c395c 2fae5a2f0457bb7106d52ac7457afb597d7ac9658b8dcff8e76294f5fe34019a
lib/codeql/rust/generated/ConstExpr.qll dd851fb049429fe965569beb75957a6a596137b333a6cd7cd588d1c4d40412c4 824825bc46a393827d5df5ae30f622ef2a053ea1f5e338c3b957625a8542cfa5
lib/codeql/rust/generated/ContinueExpr.qll 436847767d2f68f95d011df0eb8a175924c029ac747daf620a203596479b20b3 e362f28dde0bf3e6ff3b234e81a44bc5026b4c9ed38b8b7872954cca9565eece
lib/codeql/rust/generated/DbFile.qll 4dbf1931124291e0d6a958ae882f8aeef006642f72adc7ff86cffd3a4e9a970a 4dbf1931124291e0d6a958ae882f8aeef006642f72adc7ff86cffd3a4e9a970a
lib/codeql/rust/generated/DbLocation.qll 735d9351b5eb46a3231b528600dddec3a4122c18c210d4d632a8d4ceaf7f02e9 735d9351b5eb46a3231b528600dddec3a4122c18c210d4d632a8d4ceaf7f02e9
lib/codeql/rust/generated/Declaration.qll bbf5ba3792797a829b0032c41fa99d22c26e4277d655099912cdbafb80f0c8cd c4666a71099b21ad5cd83ef6f991ba18f9bef03b3ffbcedfa10aec081d6501d5
lib/codeql/rust/generated/Element.qll 21567fa7348dccdf69dd34e73cb6de7cc9c7e0f3f7bb419a1abd787f7dc851a1 21567fa7348dccdf69dd34e73cb6de7cc9c7e0f3f7bb419a1abd787f7dc851a1
lib/codeql/rust/generated/ElementListExpr.qll 3f7e9c1f7249f7283406d2e59b00af750b6dea93b284d7f25af66fe4b3345fea d340242d6072e274fbafd6ff2a5455bf53b3b77ed91539e91563d67cf2ed48f0
lib/codeql/rust/generated/Expr.qll 32cdd43d17e8b2fb7c73ec723eba89704d1e853e29d304db5eea3979fcdd2e0b 0b8382b0659afa1bd1d13d0cd492d7fbdc0fd7a5162fa658ca2973bc15ee6534
lib/codeql/rust/generated/ExprStmt.qll f35543fe1481f768eb8abe3fd0d36e2dedf00f0d1adbc31562e6280ef291d0b6 0663097b4b539c5f35dab9b26ab55baee879c7ef543810581347a8951aee46d9
lib/codeql/rust/generated/FieldExpr.qll 25dd7f15ee3fe1b0de4371cab9df83d3713c1612501e5496c9a15df8d093a755 3c75b0136d1849f6de1bbd14bda4285c52d51c8a6427984c7e5302c05d706e99
lib/codeql/rust/generated/File.qll 2eff5c882d044d2e360fe6382fb55e5a45f6ccb9df323cfa1fae41eae9d2a47f 87e7a906b3a1b4de056952e288ddd7f69fa7cb1bd9dc7dd3972868a9002ac1e4
lib/codeql/rust/generated/Function.qll 84a00eb88479efdfe70fe51c3b5cb27ae64a54b48dcca1f2e02f68691b7d907a cde5b965ab27e811f0d24eb4f12bca90c3e8aec3a4c1d9b8bd0023745dfab105
lib/codeql/rust/generated/IfExpr.qll 7d8e5bd93bb8eda6d5d6551431b0389a2ec5893bd8c13276205d6677856c8341 935bf1be8f790a52e71a6a28456f2f1a5c5cbe6e64bf20fa8602980560899835
lib/codeql/rust/generated/IndexExpr.qll d44004268aa2e7d79e29133eb593d748beef1d4612318ef469220b3c2252a057 86892c04c59936d33f0cfd5272a04a6ef726f477c2e8f4ef27dae7240af9c804
@ -168,8 +161,7 @@ lib/codeql/rust/generated/LetExpr.qll 896efc732db1ddc8be7281408dfeaf6f04f29d25ee
lib/codeql/rust/generated/LetStmt.qll 1f8fda11b71689fb1a1b9b25a2ce046c56f36f26cddb354805bd395a03e4db3d 80ad6ea6afb1891a02db434cfefdb95b0fb7d766af6246ff27129dc15cb48ace
lib/codeql/rust/generated/LitPat.qll 92c3c0f32ab9d5b08e246231e5465fe18536dee99351f73e158048bb007baf8a 6736a7824e5bdb0cc16de1231bdb5169d2f48251d5917bf2c31a36422b0bf2fd
lib/codeql/rust/generated/LiteralExpr.qll 9202e11f56a2c5e99fb98ed784c7ca043c1f5d80680b48ba4ea340dd689ebe55 9202e11f56a2c5e99fb98ed784c7ca043c1f5d80680b48ba4ea340dd689ebe55
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 e9304e282a97984e147b92ec7061c98fde238a8691e945e4cb775ccf34c27b0c 65b859e44e83bddb710d4ce9e5ab1346b98eaaa46509671776b75c9e8f1c1667
lib/codeql/rust/generated/MatchArm.qll 5ad0dc254b6d58ccd856e4235b68ca0226a898c33f1f6b6fe7b48266a01ca627 f519af39f45e820eb3a70cefb0e4dfb541c3cf17952c00c6dd7e59f854a629bd
lib/codeql/rust/generated/MatchExpr.qll f8b422699337324c91ec9c55024630efe114ca617f4f088a18d180df132d5754 13169bde872f533f55aa196d7150761857c593a4657ab34051346dde14e736c7
@ -179,14 +171,14 @@ lib/codeql/rust/generated/MissingPat.qll 0d8034cee20bacf07ebb9337c797f53a25686a1
lib/codeql/rust/generated/Module.qll 2a931a4f2cdb2fee00ed83af045ea63d36b7dbd708e58c30445b5610feaae333 cd62add5c31a509f965aa294f44a1607ec7c62e3a9e3fe9ee063b3c814f4eb62
lib/codeql/rust/generated/OffsetOfExpr.qll 58dfd632efcb48de7fe6ffbcb2192fcf95bfabdb407a751133f63a0e32ae7489 21ebb1b3d66849fc21c04083cfa751eb56c55809cd52664020bd61ccfbe5ea68
lib/codeql/rust/generated/OrPat.qll f8fe5c7b83a08dabcc530484a696274930040ea13501ae20f1426faeec67bcf0 f3adb3148890531b698570a48740335983a5e81977ba4ac651778f940f184398
lib/codeql/rust/generated/ParentChild.qll 956f55ac17d66926c59f76d391b75c30767d236b145d6ae402f4308fa22a7d01 dd3cabb5b4a9ba42be60345f445cde18b0d7be934aeb94d7312eeef122e148d2
lib/codeql/rust/generated/ParentChild.qll e1658ad4b3406b882726ed623e3668b99d1353c92c22f2939e2b7fc2b4053711 739da3c782d40cbd83c2b1d752376a0363802b64b950bea61e79cfb63bdd4f6d
lib/codeql/rust/generated/Pat.qll fe1c72856442dbab5655eff93f86c2cbce8d69d9fa1f99a0f9203061ea1112a4 d85d86e8b6c48df733589d186f610b1cd9086629180701e017774bddc62402c7
lib/codeql/rust/generated/PathExpr.qll 3664ed2ad08097e4446b0fdad148118c754f8203541ae588d967ba9d79b6bf21 0d987d2358fe9b42e57585e7ae906de80e9f4ccf7c20e1d9bb7624ffbad96941
lib/codeql/rust/generated/PathPat.qll acc4dda795bae97626a8d0041538f3ba1f0b591c743fed381cf198a8b04653cb c3deee1b3bb9bd37ae3ed4761d8ee2f498384fe5e1f5e31c0f9b99dfd864a0d5
lib/codeql/rust/generated/PureSynthConstructors.qll 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573 5eb1fc4f6a04172c34ae31e4931e4bf1f8b72fbe414c5f644731a45372d13573
lib/codeql/rust/generated/RangeExpr.qll f499d8c1f260d6262a55c1f3640aaee832ed8c9aac922cb2e05fefbca4509053 a01563640bc23fbce9d33da756bc209fd16155dc76a7fed4ba325979723f48a5
lib/codeql/rust/generated/RangePat.qll 6ec95f6cb9c4bd93b38990bb1e3b89b526624305ac6ee7b94e6fb0a2f3db28fc 0e193f3816a7587d5103dba421bc2bf22b869522353d4e3f43d49a792eac6cf4
lib/codeql/rust/generated/Raw.qll 48d1e7d642bd2a7605dbafe3929c558560054a4e4e3e4b36925a8bfafb7536b9 3b881e64127e9b41fee7e091de725f5cd1cb1263e4a52c02adb1fb339fe36c3d
lib/codeql/rust/generated/Raw.qll fcc1c9f3b06f7c1ae5ad6f7e7ab508c5fbbe9f13a5888db7e1a1e878d53b0f7e 45b6ee33b3ebe83d7f297eb0a9700da42648dc6228caed1e6649e940ea304907
lib/codeql/rust/generated/RecordFieldPat.qll 26bed2285d849b9b7ac52d86131eacb40df912db350e423e81fb98c393c08a69 05ed735aecee90901a1bdfae05d9f85d7f6581616eca3a9262fdef6673222f9b
lib/codeql/rust/generated/RecordLitExpr.qll 1d3264446ff57e8b169f1ad6da150b2d457d6b60eda0ff63e2353eb8ef9e9113 f523dd5ce7f4bac0aafab7b27c6cfe766c72a9ee0c92d7a263347e67edf096df
lib/codeql/rust/generated/RecordLitField.qll bc704b56a986f3a399dc9c3dc2b61cca0d40cd389c694b9fe13374780835ffcc ab6b05a87f240a97cc2a8c15bb84a1338ad33ce367619125a8514e8815fd050e
@ -197,8 +189,8 @@ lib/codeql/rust/generated/RepeatExpr.qll 43aff00e966e4550179d756489e4cbc30618d66
lib/codeql/rust/generated/ReturnExpr.qll 6160f3a14ff1cbd6a297edae015769f90e8e31201639828d8a9d0d6e38c1ef99 b8c8a12f78281e558d230c6959236780758e9645fe22aca697b948535c20f9be
lib/codeql/rust/generated/SlicePat.qll b4de6692eebf1205940e04da963adc20a07b15923c3c3a7a512a24e3bd8342c9 ee9b919983807f39d97cfe8ca66b76bdbfde76db02db5c93268ce22cbddf4213
lib/codeql/rust/generated/Stmt.qll 55688c8f42f6e7fd1b871e572d75fac60d0543e38c4be4638abbb00187651d3d f978006a8453137f989249e849a7c935a090da3a9b0116145da80068760e12fd
lib/codeql/rust/generated/Synth.qll 03ecd0d7e89aca555d2393bbea8de1cde0476e28fb9f198ed3355a74f1b5c1c8 11855cc446c2d8a77503795a7c395e86ff149ea10d773a6e50e54b08dd438642
lib/codeql/rust/generated/SynthConstructors.qll 07106a119dcfc7a839454d1fa66c0e65d6ab17eeace40cd5bc857a65dc7c859b 07106a119dcfc7a839454d1fa66c0e65d6ab17eeace40cd5bc857a65dc7c859b
lib/codeql/rust/generated/Synth.qll 6d1c4648a7f705bf5d7e8f8081f835c03feb6eee99bbf5fcca825902cb0cac20 620582c3743f8e0172288660bf5b2f344d8696620675ad0a04df20da55ba9c45
lib/codeql/rust/generated/SynthConstructors.qll 15f62ecc76505a326df6a6d61896892ecbacdd1edc8bb4fede39f1a84e36431e 15f62ecc76505a326df6a6d61896892ecbacdd1edc8bb4fede39f1a84e36431e
lib/codeql/rust/generated/TupleExpr.qll 13e4dbc1afcabf388c793145cd399789f4014662f2eed1d49cbe96eeb8355413 bfa0708885c120bad24e29deb29641c69a5e5361654f3a144ead9543bfbd7197
lib/codeql/rust/generated/TuplePat.qll 23911b2ac7ee2279df8ef40a6e447437ef0ed62518504b17874a7652bf5e3f4b fc4f6f7ea40754290de194ac55939f08549bd637104baf8dc84ca3938bcbd1f1
lib/codeql/rust/generated/TupleStructPat.qll fff004cce780501eac94fe4b146619a84e02c85cae12ffeba5a4058e8c9738ea 738659f8208aa65d1d8cf601e0d92a90a890d6cbaec51cf04c81fc75a827e30b
@ -206,14 +198,11 @@ lib/codeql/rust/generated/TypeRef.qll 7cc468c2f473ee13c11a97c4360100376560e8fc42
lib/codeql/rust/generated/UnaryOpExpr.qll fd55d4bc9cd1a49d1f38f02fef16771f29bb5fb2512abd18341d56665859d18c f271ef5036410c018f48d6f15b17cb9beaf4111a42fc638ac4ed3db974a5f870
lib/codeql/rust/generated/UnderscoreExpr.qll cd7f615e41562b80d89e413c1c808048da7746fd445f0eb6ad8c5d9996b44d5d cd7f615e41562b80d89e413c1c808048da7746fd445f0eb6ad8c5d9996b44d5d
lib/codeql/rust/generated/Unimplemented.qll 375b7935b7f4103728ece3042282ae82d19e471d7a9fa58c8cbdea31ea0cb113 375b7935b7f4103728ece3042282ae82d19e471d7a9fa58c8cbdea31ea0cb113
lib/codeql/rust/generated/UnknownFile.qll ec9d1a3f15ecbf1743d4e39cb3b2f217aa9b54951c93302c2c4c238c3f0ce595 ec9d1a3f15ecbf1743d4e39cb3b2f217aa9b54951c93302c2c4c238c3f0ce595
lib/codeql/rust/generated/UnknownLocation.qll a19e2838c52d702d268ae530f3dbd6fcd8bb28a237a52636a960f225454103cf a19e2838c52d702d268ae530f3dbd6fcd8bb28a237a52636a960f225454103cf
lib/codeql/rust/generated/UnsafeBlockExpr.qll 8464597373ea46f6391394f02c4ceb93ffe8441b434e6e71907b0a3369f72d8e 8464597373ea46f6391394f02c4ceb93ffe8441b434e6e71907b0a3369f72d8e
lib/codeql/rust/generated/WildPat.qll 8a2cede00ac2941cb94e294ffa81ada9ae6e61d8d8a720ce4f288740345802f8 8a2cede00ac2941cb94e294ffa81ada9ae6e61d8d8a720ce4f288740345802f8
lib/codeql/rust/generated/YeetExpr.qll 2b37cf55ec26958cf226885e99d81c8bbc6ece69fbe92d9fcc8884ee0bc4aad4 e371531507311ea8a9fbaac74442fe9994ae85f0acdb79cc870e5318af52aba9
lib/codeql/rust/generated/YieldExpr.qll 70ca98e14b24f12a3cbfe690417543fdce45b162f241834e2f7f58543aa11bda 40fe1281107317a7d80c7141229eed9c6904805dff615dfd0141ede2457e2c57
test/extractor-tests/generated/Expr/MISSING_SOURCE.txt cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e
test/extractor-tests/generated/File/File.ql dec43be882fad904fab0c6447ca93633d801cb08ff8bec309befde7d2b9e5dda 74e1f1d698558c35fa03935cc34f4c8145d376b56d7657b18aeb338f5ca752cf
test/extractor-tests/generated/Function/Function.ql c49434420dbb6fc3d9e6294161dcd3d3b306fae5ba5c85b610e534b8b15ef74c fe02208b673b74eebed92b5cbb3a8a06c31c0681eb28f3e596515663f14fa9e2
test/extractor-tests/generated/Module/MISSING_SOURCE.txt cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e
test/extractor-tests/generated/Pat/MISSING_SOURCE.txt cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e cc7c395e7c651d62596826b1a0bedf10f35d01b8afeef47600b4ddaf804f406e

11
rust/ql/.gitattributes сгенерированный поставляемый
Просмотреть файл

@ -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
@ -151,15 +147,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/IfExpr.qll linguist-generated
/lib/codeql/rust/generated/IndexExpr.qll linguist-generated
@ -171,7 +164,6 @@
/lib/codeql/rust/generated/LitPat.qll linguist-generated
/lib/codeql/rust/generated/LiteralExpr.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
@ -208,14 +200,11 @@
/lib/codeql/rust/generated/UnaryOpExpr.qll linguist-generated
/lib/codeql/rust/generated/UnderscoreExpr.qll linguist-generated
/lib/codeql/rust/generated/Unimplemented.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/WildPat.qll linguist-generated
/lib/codeql/rust/generated/YeetExpr.qll linguist-generated
/lib/codeql/rust/generated/YieldExpr.qll linguist-generated
/test/extractor-tests/generated/Expr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/File/File.ql linguist-generated
/test/extractor-tests/generated/Function/Function.ql linguist-generated
/test/extractor-tests/generated/Module/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/Pat/MISSING_SOURCE.txt linguist-generated

Просмотреть файл

@ -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) }
}

Просмотреть файл

@ -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() }
}

6
rust/ql/lib/codeql/rust/elements.qll сгенерированный
Просмотреть файл

@ -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.IfExpr
import codeql.rust.elements.IndexExpr
@ -41,7 +38,6 @@ import codeql.rust.elements.LetStmt
import codeql.rust.elements.LitPat
import codeql.rust.elements.LiteralExpr
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
@ -73,8 +69,6 @@ import codeql.rust.elements.TypeRef
import codeql.rust.elements.UnaryOpExpr
import codeql.rust.elements.UnderscoreExpr
import codeql.rust.elements.Unimplemented
import codeql.rust.elements.UnknownFile
import codeql.rust.elements.UnknownLocation
import codeql.rust.elements.UnsafeBlockExpr
import codeql.rust.elements.WildPat
import codeql.rust.elements.YeetExpr

Просмотреть файл

@ -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 { }

Просмотреть файл

@ -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() }

Просмотреть файл

@ -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 { }

Просмотреть файл

@ -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() }

Просмотреть файл

@ -3,16 +3,23 @@
*/
private import codeql.rust.generated.Locatable
private import codeql.rust.elements.File
private import codeql.rust.elements.UnknownLocation
import codeql.files.FileSystem
import codeql.Locations
private import codeql.rust.generated.Synth
private import codeql.rust.generated.Raw
class Locatable extends Generated::Locatable {
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
)
)
}
/**

Просмотреть файл

@ -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)
)
}
}

Просмотреть файл

@ -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 = "" }
}

Просмотреть файл

@ -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" }
}

Просмотреть файл

@ -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" }
}
}

Просмотреть файл

@ -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" }
}
}

Просмотреть файл

@ -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() }
}
}

18
rust/ql/lib/codeql/rust/generated/Locatable.qll сгенерированный
Просмотреть файл

@ -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 { }
}

Просмотреть файл

@ -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() }
}
}

90
rust/ql/lib/codeql/rust/generated/ParentChild.qll сгенерированный
Просмотреть файл

@ -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 getImmediateChildOfAstNode(AstNode e, int index, string partialPredicateCall) {
exists(int b, int bLocatable, int n |
b = 0 and
@ -62,62 +36,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
) {
@ -1301,14 +1219,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 = getImmediateChildOfLabel(e, index, partialAccessor)
or
result = getImmediateChildOfMatchArm(e, index, partialAccessor)

61
rust/ql/lib/codeql/rust/generated/Raw.qll сгенерированный
Просмотреть файл

@ -13,72 +13,13 @@ 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.
*/
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.
*/

142
rust/ql/lib/codeql/rust/generated/Synth.qll сгенерированный
Просмотреть файл

@ -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.
*/
@ -251,14 +243,6 @@ module Synth {
* INTERNAL: Do not use.
*/
TUnimplemented(Raw::Unimplemented id) { constructUnimplemented(id) } or
/**
* INTERNAL: Do not use.
*/
TUnknownFile() or
/**
* INTERNAL: Do not use.
*/
TUnknownLocation() or
/**
* INTERNAL: Do not use.
*/
@ -309,21 +293,11 @@ module Synth {
TRangeExpr or TRecordLitExpr or TRefExpr or TReturnExpr or TTupleExpr or TUnaryOpExpr 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.
*/
@ -441,20 +415,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.
@ -749,20 +709,6 @@ module Synth {
cached
TUnimplemented convertUnimplementedFromRaw(Raw::Element e) { result = TUnimplemented(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.
@ -858,13 +804,7 @@ module Synth {
* Converts a raw DB element to a synthesized `TElement`, if possible.
*/
cached
TElement convertElementFromRaw(Raw::Element e) {
result = convertFileFromRaw(e)
or
result = convertLocatableFromRaw(e)
or
result = convertLocationFromRaw(e)
}
TElement convertElementFromRaw(Raw::Element e) { result = convertLocatableFromRaw(e) }
/**
* INTERNAL: Do not use.
@ -939,17 +879,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.
@ -957,17 +886,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.
@ -1121,20 +1039,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.
@ -1429,20 +1333,6 @@ module Synth {
cached
Raw::Element convertUnimplementedToRaw(TUnimplemented e) { e = TUnimplemented(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.
@ -1538,13 +1428,7 @@ module Synth {
* Converts a synthesized `TElement` to a raw DB element, if possible.
*/
cached
Raw::Element convertElementToRaw(TElement e) {
result = convertFileToRaw(e)
or
result = convertLocatableToRaw(e)
or
result = convertLocationToRaw(e)
}
Raw::Element convertElementToRaw(TElement e) { result = convertLocatableToRaw(e) }
/**
* INTERNAL: Do not use.
@ -1619,17 +1503,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.
@ -1637,17 +1510,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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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" }
}
}

Просмотреть файл

@ -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" }
}
}

Просмотреть файл

@ -1,56 +1,132 @@
// 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
;
@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
);
@ast_node =
@declaration
| @expr
@ -64,14 +140,6 @@ locations(
| @unimplemented
;
db_files(
unique int id: @db_file
);
db_locations(
unique int id: @db_location
);
@declaration =
@function
| @module

Просмотреть файл

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

Просмотреть файл

@ -1,13 +1,10 @@
private import codeql.rust.elements
private import rust
cached
predicate toBeTested(Element e) {
exists(File f |
f.getName().matches("%rust/ql/test%") and
(
e = f
or
e.(Locatable).getLocation().getFile() = f
)
)
not e instanceof Locatable or
fileIsInTest(e.(Locatable).getFile())
}
cached
predicate fileIsInTest(File f) { f.getAbsolutePath().matches("%rust/ql/test%") }

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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 |

Просмотреть файл

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

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

@ -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):

Просмотреть файл

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

Просмотреть файл

@ -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(