Skip to content

Commit 7c2841f

Browse files
committed
Ruby: QL generator: use qualified imports
1 parent 474c808 commit 7c2841f

File tree

4 files changed

+120
-106
lines changed

4 files changed

+120
-106
lines changed

ruby/generator/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,10 @@ fn main() -> std::io::Result<()> {
611611
)?;
612612
ql::write(
613613
&mut ql_writer,
614-
&[
615-
ql::TopLevel::Import("codeql.files.FileSystem"),
616-
ql::TopLevel::Import("codeql.Locations"),
617-
],
614+
&[ql::TopLevel::Import(ql::Import {
615+
module: "codeql.Locations",
616+
alias: Some("L"),
617+
})],
618618
)?;
619619

620620
for language in languages {

ruby/generator/src/ql.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@ use std::fmt;
44
#[derive(Clone, Eq, PartialEq, Hash)]
55
pub enum TopLevel<'a> {
66
Class(Class<'a>),
7-
Import(&'a str),
7+
Import(Import<'a>),
88
Module(Module<'a>),
99
}
1010

1111
impl<'a> fmt::Display for TopLevel<'a> {
1212
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1313
match self {
14-
TopLevel::Import(x) => write!(f, "private import {}", x),
14+
TopLevel::Import(imp) => write!(f, "{}", imp),
1515
TopLevel::Class(cls) => write!(f, "{}", cls),
1616
TopLevel::Module(m) => write!(f, "{}", m),
1717
}
1818
}
1919
}
2020

21+
#[derive(Clone, Eq, PartialEq, Hash)]
22+
pub struct Import<'a> {
23+
pub module: &'a str,
24+
pub alias: Option<&'a str>,
25+
}
26+
27+
impl<'a> fmt::Display for Import<'a> {
28+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29+
write!(f, "import {}", &self.module)?;
30+
if let Some(name) = &self.alias {
31+
write!(f, " as {}", name)?;
32+
}
33+
Ok(())
34+
}
35+
}
2136
#[derive(Clone, Eq, PartialEq, Hash)]
2237
pub struct Class<'a> {
2338
pub qldoc: Option<String>,

ruby/generator/src/ql_gen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn create_ast_node_class<'a>(ast_node: &'a str, ast_node_parent: &'a str) ->
2626
Some(String::from("Gets the location of this element.")),
2727
"getLocation",
2828
false,
29-
Some(ql::Type::Normal("Location")),
29+
Some(ql::Type::Normal("L::Location")),
3030
);
3131
let get_a_field_or_child = create_none_predicate(
3232
Some(String::from("Gets a field or child node of this node.")),
@@ -136,7 +136,7 @@ pub fn create_token_class<'a>(token_type: &'a str, tokeninfo: &'a str) -> ql::Cl
136136
qldoc: Some(String::from("Gets the location of this token.")),
137137
name: "getLocation",
138138
overridden: true,
139-
return_type: Some(ql::Type::Normal("Location")),
139+
return_type: Some(ql::Type::Normal("L::Location")),
140140
formal_parameters: vec![],
141141
body: create_get_field_expr_for_column_storage("result", tokeninfo, 2, tokeninfo_arity),
142142
};
@@ -236,7 +236,7 @@ fn create_get_location_predicate(def_table: &str, arity: usize) -> ql::Predicate
236236
qldoc: Some(String::from("Gets the location of this element.")),
237237
name: "getLocation",
238238
overridden: true,
239-
return_type: Some(ql::Type::Normal("Location")),
239+
return_type: Some(ql::Type::Normal("L::Location")),
240240
formal_parameters: vec![],
241241
// body of the form: foo_bar_def(_, _, ..., result)
242242
body: ql::Expression::Pred(

0 commit comments

Comments
 (0)