mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: extract declarations of builtin types
This commit is contained in:
@@ -36,6 +36,7 @@ pkg_filegroup(
|
|||||||
srcs = [
|
srcs = [
|
||||||
":tools-arch",
|
":tools-arch",
|
||||||
"//rust/tools",
|
"//rust/tools",
|
||||||
|
"//rust/tools/builtins",
|
||||||
],
|
],
|
||||||
prefix = "tools",
|
prefix = "tools",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
use std::{env, fs};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
@@ -77,17 +78,19 @@ impl<'a> Extractor<'a> {
|
|||||||
}
|
}
|
||||||
let no_location = (LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 });
|
let no_location = (LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 });
|
||||||
if let Err(reason) = semantics_info {
|
if let Err(reason) = semantics_info {
|
||||||
let message = format!("semantic analyzer unavailable ({reason})");
|
if !reason.is_empty() {
|
||||||
let full_message = format!(
|
let message = format!("semantic analyzer unavailable ({reason})");
|
||||||
"{message}: macro expansion, call graph, and type inference will be skipped."
|
let full_message = format!(
|
||||||
);
|
"{message}: macro expansion, call graph, and type inference will be skipped."
|
||||||
translator.emit_diagnostic(
|
);
|
||||||
trap::DiagnosticSeverity::Warning,
|
translator.emit_diagnostic(
|
||||||
"semantics".to_owned(),
|
trap::DiagnosticSeverity::Warning,
|
||||||
message,
|
"semantics".to_owned(),
|
||||||
full_message,
|
message,
|
||||||
no_location,
|
full_message,
|
||||||
);
|
no_location,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
translator.emit_source_file(ast);
|
translator.emit_source_file(ast);
|
||||||
translator.trap.commit().unwrap_or_else(|err| {
|
translator.trap.commit().unwrap_or_else(|err| {
|
||||||
@@ -276,5 +279,16 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let builtins_dir = env::var("CODEQL_EXTRACTOR_RUST_ROOT")
|
||||||
|
.map(|path| Path::new(&path).join("tools").join("builtins"))?;
|
||||||
|
let builtins = fs::read_dir(builtins_dir).context("failed to read builtins directory")?;
|
||||||
|
for entry in builtins {
|
||||||
|
let entry = entry.context("failed to read builtins directory")?;
|
||||||
|
let path = entry.path();
|
||||||
|
if path.extension().is_some_and(|ext| ext == "rs") {
|
||||||
|
extractor.extract_without_semantics(&path, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extractor.emit_extraction_diagnostics(start, &cfg)
|
extractor.emit_extraction_diagnostics(start, &cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
8
rust/tools/builtins/BUILD.bazel
Normal file
8
rust/tools/builtins/BUILD.bazel
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
load("//misc/bazel:pkg.bzl", "codeql_pkg_files")
|
||||||
|
|
||||||
|
codeql_pkg_files(
|
||||||
|
name = "builtins",
|
||||||
|
srcs = glob(["*.rs"]),
|
||||||
|
prefix = "builtins",
|
||||||
|
visibility = ["//rust:__subpackages__"],
|
||||||
|
)
|
||||||
25
rust/tools/builtins/types.rs
Normal file
25
rust/tools/builtins/types.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// The Language Prelude: https://doc.rust-lang.org/reference/names/preludes.html#language-prelude
|
||||||
|
|
||||||
|
// Type namespace
|
||||||
|
// Boolean type
|
||||||
|
pub struct bool;
|
||||||
|
// Textual types
|
||||||
|
pub struct char;
|
||||||
|
pub struct str;
|
||||||
|
// Integer types
|
||||||
|
pub struct i8;
|
||||||
|
pub struct i16;
|
||||||
|
pub struct i32;
|
||||||
|
pub struct i64;
|
||||||
|
pub struct i128;
|
||||||
|
pub struct u8;
|
||||||
|
pub struct u16;
|
||||||
|
pub struct u32;
|
||||||
|
pub struct u64;
|
||||||
|
pub struct u128;
|
||||||
|
// Machine-dependent integer types
|
||||||
|
pub struct usize;
|
||||||
|
pub struct isize;
|
||||||
|
// floating-point types
|
||||||
|
pub struct f32;
|
||||||
|
pub struct f64;
|
||||||
Reference in New Issue
Block a user