mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Add ast_node_parent relation
This commit is contained in:
@@ -178,30 +178,14 @@ fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<dbscheme::Entry<
|
||||
// It's a product type, defined by a table.
|
||||
let mut main_table = dbscheme::Table {
|
||||
name: &name,
|
||||
columns: vec![
|
||||
dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "id",
|
||||
unique: true,
|
||||
ql_type: ql::Type::AtType(&node.dbscheme_name),
|
||||
ql_type_is_ref: false,
|
||||
},
|
||||
dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "parent",
|
||||
unique: false,
|
||||
ql_type: ql::Type::AtType("ast_node_parent"),
|
||||
ql_type_is_ref: true,
|
||||
},
|
||||
dbscheme::Column {
|
||||
unique: false,
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "parent_index",
|
||||
ql_type: ql::Type::Int,
|
||||
ql_type_is_ref: true,
|
||||
},
|
||||
],
|
||||
keysets: Some(vec!["parent", "parent_index"]),
|
||||
columns: vec![dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "id",
|
||||
unique: true,
|
||||
ql_type: ql::Type::AtType(&node.dbscheme_name),
|
||||
ql_type_is_ref: false,
|
||||
}],
|
||||
keysets: None,
|
||||
};
|
||||
ast_node_members.insert(&node.dbscheme_name);
|
||||
|
||||
@@ -275,22 +259,21 @@ fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<dbscheme::Entry<
|
||||
name: "ast_node_parent",
|
||||
members: ["ast_node", "file"].iter().cloned().collect(),
|
||||
}));
|
||||
|
||||
entries.push(dbscheme::Entry::Table(create_ast_node_parent_table()));
|
||||
|
||||
entries
|
||||
}
|
||||
|
||||
fn create_tokeninfo<'a>(
|
||||
token_kinds: Map<&'a str, usize>,
|
||||
) -> (dbscheme::Case<'a>, dbscheme::Table<'a>) {
|
||||
let table = dbscheme::Table {
|
||||
name: "tokeninfo",
|
||||
keysets: Some(vec!["parent", "parent_index"]),
|
||||
fn create_ast_node_parent_table<'a>() -> dbscheme::Table<'a> {
|
||||
dbscheme::Table {
|
||||
name: "ast_node_parent",
|
||||
columns: vec![
|
||||
dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "id",
|
||||
unique: true,
|
||||
ql_type: ql::Type::AtType("token"),
|
||||
ql_type_is_ref: false,
|
||||
name: "child",
|
||||
unique: false,
|
||||
ql_type: ql::Type::AtType("ast_node"),
|
||||
ql_type_is_ref: true,
|
||||
},
|
||||
dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
@@ -306,6 +289,25 @@ fn create_tokeninfo<'a>(
|
||||
ql_type: ql::Type::Int,
|
||||
ql_type_is_ref: true,
|
||||
},
|
||||
],
|
||||
keysets: Some(vec!["parent", "parent_index"]),
|
||||
}
|
||||
}
|
||||
|
||||
fn create_tokeninfo<'a>(
|
||||
token_kinds: Map<&'a str, usize>,
|
||||
) -> (dbscheme::Case<'a>, dbscheme::Table<'a>) {
|
||||
let table = dbscheme::Table {
|
||||
name: "tokeninfo",
|
||||
keysets: None,
|
||||
columns: vec![
|
||||
dbscheme::Column {
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
name: "id",
|
||||
unique: true,
|
||||
ql_type: ql::Type::AtType("token"),
|
||||
ql_type_is_ref: false,
|
||||
},
|
||||
dbscheme::Column {
|
||||
unique: false,
|
||||
db_type: dbscheme::DbColumnType::Int,
|
||||
|
||||
@@ -75,33 +75,48 @@ fn create_ast_node_class<'a>() -> ql::Class<'a> {
|
||||
}
|
||||
|
||||
fn create_token_class<'a>() -> ql::Class<'a> {
|
||||
let tokeninfo_arity = 6;
|
||||
let get_parent = ql::Predicate {
|
||||
name: "getParent",
|
||||
overridden: true,
|
||||
return_type: Some(ql::Type::Normal("AstNode")),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 0, 8),
|
||||
body: ql::Expression::Pred(
|
||||
"ast_node_parent",
|
||||
vec![
|
||||
ql::Expression::Var("this"),
|
||||
ql::Expression::Var("result"),
|
||||
ql::Expression::Var("_"),
|
||||
],
|
||||
),
|
||||
};
|
||||
let get_parent_index = ql::Predicate {
|
||||
name: "getParentIndex",
|
||||
overridden: true,
|
||||
return_type: Some(ql::Type::Int),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 1, 8),
|
||||
body: ql::Expression::Pred(
|
||||
"ast_node_parent",
|
||||
vec![
|
||||
ql::Expression::Var("this"),
|
||||
ql::Expression::Var("_"),
|
||||
ql::Expression::Var("result"),
|
||||
],
|
||||
),
|
||||
};
|
||||
let get_value = ql::Predicate {
|
||||
name: "getValue",
|
||||
overridden: false,
|
||||
return_type: Some(ql::Type::String),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 5, 8),
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 3, tokeninfo_arity),
|
||||
};
|
||||
let get_location = ql::Predicate {
|
||||
name: "getLocation",
|
||||
overridden: true,
|
||||
return_type: Some(ql::Type::Normal("Location")),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 6, 8),
|
||||
body: create_get_field_expr_for_column_storage("result", "tokeninfo", 4, tokeninfo_arity),
|
||||
};
|
||||
let to_string = ql::Predicate {
|
||||
name: "toString",
|
||||
@@ -476,12 +491,10 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
|
||||
// Count how many columns there will be in the main table.
|
||||
// There will be:
|
||||
// - one for the id
|
||||
// - one for the parent
|
||||
// - one for the parent index
|
||||
// - one for the location
|
||||
// - one for each field that's stored as a column
|
||||
// - if there are no fields, one for the text column.
|
||||
let main_table_arity = 4 + if fields.is_empty() {
|
||||
let main_table_arity = 2 + if fields.is_empty() {
|
||||
1
|
||||
} else {
|
||||
fields
|
||||
@@ -512,7 +525,7 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
|
||||
.predicates
|
||||
.push(create_get_text_predicate(&main_table_name));
|
||||
} else {
|
||||
let mut main_table_column_index: usize = 2;
|
||||
let mut main_table_column_index: usize = 0;
|
||||
let mut get_child_exprs: Vec<ql::Expression> = Vec::new();
|
||||
|
||||
// Iterate through the fields, creating:
|
||||
@@ -538,11 +551,13 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
|
||||
overridden: true,
|
||||
return_type: Some(ql::Type::Normal("AstNode")),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage(
|
||||
"result",
|
||||
&main_table_name,
|
||||
0,
|
||||
main_table_arity,
|
||||
body: ql::Expression::Pred(
|
||||
"ast_node_parent",
|
||||
vec![
|
||||
ql::Expression::Var("this"),
|
||||
ql::Expression::Var("result"),
|
||||
ql::Expression::Var("_"),
|
||||
],
|
||||
),
|
||||
});
|
||||
|
||||
@@ -551,11 +566,13 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
|
||||
overridden: true,
|
||||
return_type: Some(ql::Type::Int),
|
||||
formal_parameters: vec![],
|
||||
body: create_get_field_expr_for_column_storage(
|
||||
"result",
|
||||
&main_table_name,
|
||||
1,
|
||||
main_table_arity,
|
||||
body: ql::Expression::Pred(
|
||||
"ast_node_parent",
|
||||
vec![
|
||||
ql::Expression::Var("this"),
|
||||
ql::Expression::Var("_"),
|
||||
ql::Expression::Var("result"),
|
||||
],
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user