diff --git a/config/dbscheme-fragments.json b/config/dbscheme-fragments.json index 8e66d2df008..c97213e3162 100644 --- a/config/dbscheme-fragments.json +++ b/config/dbscheme-fragments.json @@ -1,15 +1,26 @@ { "files": [ "javascript/ql/lib/semmlecode.javascript.dbscheme", + "ruby/ql/lib/ruby.dbscheme", + "ql/ql/src/ql.dbscheme" ], "fragments": [ "/*- External data -*/", "/*- Files and folders -*/", + "/*- Diagnostic messages -*/", + "/*- Diagnostic messages: severity -*/", "/*- Source location prefix -*/", "/*- Lines of code -*/", "/*- Configuration files with key value pairs -*/", "/*- YAML -*/", "/*- XML Files -*/", - "/*- JavaScript-specific part -*/" + "/*- JavaScript-specific part -*/", + "/*- Ruby dbscheme -*/", + "/*- Erb dbscheme -*/", + "/*- QL dbscheme -*/", + "/*- Dbscheme dbscheme -*/", + "/*- Yaml dbscheme -*/", + "/*- Blame dbscheme -*/", + "/*- JSON dbscheme -*/" ] } diff --git a/ql/ql/src/codeql/Locations.qll b/ql/ql/src/codeql/Locations.qll index 1cfb8a8d41a..ae8058c916d 100644 --- a/ql/ql/src/codeql/Locations.qll +++ b/ql/ql/src/codeql/Locations.qll @@ -8,7 +8,7 @@ import files.FileSystem * * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). */ -class Location extends @location { +class Location extends @location_default { /** Gets the file for this location. */ File getFile() { locations_default(this, result, _, _, _, _) } diff --git a/ql/ql/src/ql.dbscheme b/ql/ql/src/ql.dbscheme index 2f4f6f7d26f..2f98ed2d92d 100644 --- a/ql/ql/src/ql.dbscheme +++ b/ql/ql/src/ql.dbscheme @@ -1,15 +1,22 @@ // CodeQL database schema for QL // Automatically generated from the tree-sitter grammar; do not edit -@location = @location_default +/*- 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 start_line: int ref, - int start_column: int ref, - int end_line: int ref, - int end_column: int ref + int beginLine: int ref, + int beginColumn: int ref, + int endLine: int ref, + int endColumn: int ref ); files( @@ -29,9 +36,14 @@ containerparent( unique int child: @container ref ); -sourceLocationPrefix( - string prefix: string ref -); +/*- Source location prefix -*/ + +/** + * The source location of the snapshot. + */ +sourceLocationPrefix(string prefix : string ref); + +/*- Diagnostic messages -*/ diagnostics( unique int id: @diagnostic, @@ -42,14 +54,15 @@ diagnostics( int location: @location_default ref ); +/*- Diagnostic messages: severity -*/ + case @diagnostic.severity of 10 = @diagnostic_debug | 20 = @diagnostic_info | 30 = @diagnostic_warning | 40 = @diagnostic_error ; - - +/*- QL dbscheme -*/ @ql_add_expr_left_type = @ql_add_expr | @ql_aggregate | @ql_call_or_unqual_agg_expr | @ql_comp_term | @ql_conjunction | @ql_disjunction | @ql_expr_annotation | @ql_if_term | @ql_implication | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_mul_expr | @ql_negation | @ql_par_expr | @ql_prefix_cast | @ql_qualified_expr | @ql_quantified | @ql_range | @ql_set_literal | @ql_special_call | @ql_super_ref | @ql_unary_expr | @ql_variable @ql_add_expr_right_type = @ql_add_expr | @ql_aggregate | @ql_call_or_unqual_agg_expr | @ql_comp_term | @ql_conjunction | @ql_disjunction | @ql_expr_annotation | @ql_if_term | @ql_implication | @ql_in_expr | @ql_instance_of | @ql_literal | @ql_mul_expr | @ql_negation | @ql_par_expr | @ql_prefix_cast | @ql_qualified_expr | @ql_quantified | @ql_range | @ql_set_literal | @ql_special_call | @ql_super_ref | @ql_unary_expr | @ql_variable @@ -926,9 +939,10 @@ ql_ast_node_info( unique int node: @ql_ast_node ref, int parent: @ql_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); +/*- Dbscheme dbscheme -*/ dbscheme_annotation_args_annotation( unique int dbscheme_annotation: @dbscheme_annotation ref, unique int args_annotation: @dbscheme_args_annotation ref @@ -1112,9 +1126,10 @@ dbscheme_ast_node_info( unique int node: @dbscheme_ast_node ref, int parent: @dbscheme_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); +/*- Yaml dbscheme -*/ yaml_comment_def( unique int id: @yaml_comment, int child: @yaml_token_value ref @@ -1184,9 +1199,10 @@ yaml_ast_node_info( unique int node: @yaml_ast_node ref, int parent: @yaml_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); +/*- Blame dbscheme -*/ #keyset[blame_blame_entry, index] blame_blame_entry_line( int blame_blame_entry: @blame_blame_entry ref, @@ -1246,9 +1262,10 @@ blame_ast_node_info( unique int node: @blame_ast_node ref, int parent: @blame_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); +/*- JSON dbscheme -*/ #keyset[json_array, index] json_array_child( int json_array: @json_array ref, @@ -1327,6 +1344,6 @@ json_ast_node_info( unique int node: @json_ast_node ref, int parent: @json_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); diff --git a/ql/ql/src/ql.dbscheme.stats b/ql/ql/src/ql.dbscheme.stats index d6e8abb350c..85072c39df5 100644 --- a/ql/ql/src/ql.dbscheme.stats +++ b/ql/ql/src/ql.dbscheme.stats @@ -1060,19 +1060,19 @@ 8553 - start_line + startLine 74697 - start_column + startColumn 2236 - end_line + endLine 74730 - end_column + endColumn 2415 @@ -1095,7 +1095,7 @@ id - start_line + startLine 12 @@ -1111,7 +1111,7 @@ id - start_column + startColumn 12 @@ -1127,7 +1127,7 @@ id - end_line + endLine 12 @@ -1143,7 +1143,7 @@ id - end_column + endColumn 12 @@ -1235,7 +1235,7 @@ file - start_line + startLine 12 @@ -1316,7 +1316,7 @@ file - start_column + startColumn 12 @@ -1392,7 +1392,7 @@ file - end_line + endLine 12 @@ -1473,7 +1473,7 @@ file - end_column + endColumn 12 @@ -1548,7 +1548,7 @@ - start_line + startLine id @@ -1624,7 +1624,7 @@ - start_line + startLine file @@ -1675,8 +1675,8 @@ - start_line - start_column + startLine + startColumn 12 @@ -1751,8 +1751,8 @@ - start_line - end_line + startLine + endLine 12 @@ -1797,8 +1797,8 @@ - start_line - end_column + startLine + endColumn 12 @@ -1873,7 +1873,7 @@ - start_column + startColumn id @@ -1949,7 +1949,7 @@ - start_column + startColumn file @@ -2025,8 +2025,8 @@ - start_column - start_line + startColumn + startLine 12 @@ -2101,8 +2101,8 @@ - start_column - end_line + startColumn + endLine 12 @@ -2177,8 +2177,8 @@ - start_column - end_column + startColumn + endColumn 12 @@ -2248,7 +2248,7 @@ - end_line + endLine id @@ -2324,7 +2324,7 @@ - end_line + endLine file @@ -2375,8 +2375,8 @@ - end_line - start_line + endLine + startLine 12 @@ -2421,8 +2421,8 @@ - end_line - start_column + endLine + startColumn 12 @@ -2497,8 +2497,8 @@ - end_line - end_column + endLine + endColumn 12 @@ -2573,7 +2573,7 @@ - end_column + endColumn id @@ -2649,7 +2649,7 @@ - end_column + endColumn file @@ -2725,8 +2725,8 @@ - end_column - start_line + endColumn + startLine 12 @@ -2801,8 +2801,8 @@ - end_column - start_column + endColumn + startColumn 12 @@ -2872,8 +2872,8 @@ - end_column - end_line + endColumn + endLine 12 diff --git a/ql/ql/test/queries/style/OmittableExists/Test.qll b/ql/ql/test/queries/style/OmittableExists/Test.qll index fc020742b85..517758a9dab 100644 --- a/ql/ql/test/queries/style/OmittableExists/Test.qll +++ b/ql/ql/test/queries/style/OmittableExists/Test.qll @@ -4,7 +4,7 @@ predicate anotherPredicate(int i) { none() } predicate yetAnotherPredicate(int i, int y) { none() } -predicate dbTypePredicate(@location l) { none() } +predicate dbTypePredicate(@location_default l) { none() } string predicateWithResult(int i) { none() } @@ -12,7 +12,7 @@ class SmallInt extends int { SmallInt() { this = [0 .. 10] } } -class Location extends @location { +class Location extends @location_default { string toString() { result = "" } } diff --git a/ruby/ql/lib/codeql/Locations.qll b/ruby/ql/lib/codeql/Locations.qll index 94536357003..3a16bdec40d 100644 --- a/ruby/ql/lib/codeql/Locations.qll +++ b/ruby/ql/lib/codeql/Locations.qll @@ -17,7 +17,7 @@ private string locationToString(Location loc) { * * For more information about locations see [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). */ -class Location extends @location { +class Location extends @location_default { /** Gets the file for this location. */ File getFile() { locations_default(this, result, _, _, _, _) } diff --git a/ruby/ql/lib/ruby.dbscheme b/ruby/ql/lib/ruby.dbscheme index ff289788b15..a9b02f60315 100644 --- a/ruby/ql/lib/ruby.dbscheme +++ b/ruby/ql/lib/ruby.dbscheme @@ -1,15 +1,22 @@ // CodeQL database schema for Ruby // Automatically generated from the tree-sitter grammar; do not edit -@location = @location_default +/*- 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 start_line: int ref, - int start_column: int ref, - int end_line: int ref, - int end_column: int ref + int beginLine: int ref, + int beginColumn: int ref, + int endLine: int ref, + int endColumn: int ref ); files( @@ -29,9 +36,14 @@ containerparent( unique int child: @container ref ); -sourceLocationPrefix( - string prefix: string ref -); +/*- Source location prefix -*/ + +/** + * The source location of the snapshot. + */ +sourceLocationPrefix(string prefix : string ref); + +/*- Diagnostic messages -*/ diagnostics( unique int id: @diagnostic, @@ -42,14 +54,15 @@ diagnostics( int location: @location_default ref ); +/*- Diagnostic messages: severity -*/ + case @diagnostic.severity of 10 = @diagnostic_debug | 20 = @diagnostic_info | 30 = @diagnostic_warning | 40 = @diagnostic_error ; - - +/*- Ruby dbscheme -*/ @ruby_underscore_arg = @ruby_assignment | @ruby_binary | @ruby_conditional | @ruby_operator_assignment | @ruby_range | @ruby_unary | @ruby_underscore_primary @ruby_underscore_call_operator = @ruby_reserved_word @@ -1375,9 +1388,10 @@ ruby_ast_node_info( unique int node: @ruby_ast_node ref, int parent: @ruby_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); +/*- Erb dbscheme -*/ erb_comment_directive_child( unique int erb_comment_directive: @erb_comment_directive ref, unique int child: @erb_token_comment ref @@ -1450,6 +1464,6 @@ erb_ast_node_info( unique int node: @erb_ast_node ref, int parent: @erb_ast_node_parent ref, int parent_index: int ref, - int loc: @location ref + int loc: @location_default ref ); diff --git a/ruby/ql/lib/ruby.dbscheme.stats b/ruby/ql/lib/ruby.dbscheme.stats index ef1eb901127..5bd381c4691 100644 --- a/ruby/ql/lib/ruby.dbscheme.stats +++ b/ruby/ql/lib/ruby.dbscheme.stats @@ -2636,19 +2636,19 @@ 17807 - start_line + startLine 30866 - start_column + startColumn 5140 - end_line + endLine 30866 - end_column + endColumn 5244 @@ -2671,7 +2671,7 @@ id - start_line + startLine 12 @@ -2687,7 +2687,7 @@ id - start_column + startColumn 12 @@ -2703,7 +2703,7 @@ id - end_line + endLine 12 @@ -2719,7 +2719,7 @@ id - end_column + endColumn 12 @@ -2811,7 +2811,7 @@ file - start_line + startLine 12 @@ -2887,7 +2887,7 @@ file - start_column + startColumn 12 @@ -2963,7 +2963,7 @@ file - end_line + endLine 12 @@ -3039,7 +3039,7 @@ file - end_column + endColumn 12 @@ -3114,7 +3114,7 @@ - start_line + startLine id @@ -3195,7 +3195,7 @@ - start_line + startLine file @@ -3251,8 +3251,8 @@ - start_line - start_column + startLine + startColumn 12 @@ -3332,8 +3332,8 @@ - start_line - end_line + startLine + endLine 12 @@ -3383,8 +3383,8 @@ - start_line - end_column + startLine + endColumn 12 @@ -3464,7 +3464,7 @@ - start_column + startColumn id @@ -3545,7 +3545,7 @@ - start_column + startColumn file @@ -3606,8 +3606,8 @@ - start_column - start_line + startColumn + startLine 12 @@ -3677,8 +3677,8 @@ - start_column - end_line + startColumn + endLine 12 @@ -3748,8 +3748,8 @@ - start_column - end_column + startColumn + endColumn 12 @@ -3809,7 +3809,7 @@ - end_line + endLine id @@ -3890,7 +3890,7 @@ - end_line + endLine file @@ -3946,8 +3946,8 @@ - end_line - start_line + endLine + startLine 12 @@ -3997,8 +3997,8 @@ - end_line - start_column + endLine + startColumn 12 @@ -4073,8 +4073,8 @@ - end_line - end_column + endLine + endColumn 12 @@ -4154,7 +4154,7 @@ - end_column + endColumn id @@ -4235,7 +4235,7 @@ - end_column + endColumn file @@ -4296,8 +4296,8 @@ - end_column - start_line + endColumn + startLine 12 @@ -4367,8 +4367,8 @@ - end_column - start_column + endColumn + startColumn 12 @@ -4438,8 +4438,8 @@ - end_column - end_line + endColumn + endLine 12 diff --git a/shared/tree-sitter-extractor/src/generator/mod.rs b/shared/tree-sitter-extractor/src/generator/mod.rs index 9b1b972d0d2..d8737f789cc 100644 --- a/shared/tree-sitter-extractor/src/generator/mod.rs +++ b/shared/tree-sitter-extractor/src/generator/mod.rs @@ -30,21 +30,7 @@ pub fn generate( languages[0].name )?; - let (diagnostics_case, diagnostics_table) = create_diagnostics(); - dbscheme::write( - &mut dbscheme_writer, - &[ - create_location_union(), - create_locations_default_table(), - create_files_table(), - create_folders_table(), - create_container_union(), - create_containerparent_table(), - create_source_location_prefix_table(), - dbscheme::Entry::Table(diagnostics_table), - dbscheme::Entry::Case(diagnostics_case), - ], - )?; + write!(dbscheme_writer, include_str!("prefix.dbscheme"))?; let mut ql_writer = LineWriter::new(File::create(ql_library_path)?); write!( @@ -74,6 +60,7 @@ pub fn generate( let nodes = node_types::read_node_types_str(&prefix, language.node_types)?; let (dbscheme_entries, mut ast_node_members, token_kinds) = convert_nodes(&nodes); ast_node_members.insert(&token_name); + write!(&mut dbscheme_writer, "/*- {} dbscheme -*/\n", language.name)?; dbscheme::write(&mut dbscheme_writer, &dbscheme_entries)?; let token_case = create_token_case(&token_name, token_kinds); dbscheme::write( @@ -388,7 +375,7 @@ fn create_ast_node_info_table<'a>( unique: false, db_type: dbscheme::DbColumnType::Int, name: "loc", - ql_type: ql::Type::At("location"), + ql_type: ql::Type::At("location_default"), ql_type_is_ref: true, }, ], @@ -437,213 +424,3 @@ fn create_token_case<'a>(name: &'a str, token_kinds: Map<&'a str, usize>) -> dbs branches, } } - -fn create_location_union<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Union(dbscheme::Union { - name: "location", - members: vec!["location_default"].into_iter().collect(), - }) -} - -fn create_files_table<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Table(dbscheme::Table { - name: "files", - keysets: None, - columns: vec![ - dbscheme::Column { - unique: true, - db_type: dbscheme::DbColumnType::Int, - name: "id", - ql_type: ql::Type::At("file"), - ql_type_is_ref: false, - }, - dbscheme::Column { - db_type: dbscheme::DbColumnType::String, - name: "name", - unique: false, - ql_type: ql::Type::String, - ql_type_is_ref: true, - }, - ], - }) -} -fn create_folders_table<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Table(dbscheme::Table { - name: "folders", - keysets: None, - columns: vec![ - dbscheme::Column { - unique: true, - db_type: dbscheme::DbColumnType::Int, - name: "id", - ql_type: ql::Type::At("folder"), - ql_type_is_ref: false, - }, - dbscheme::Column { - db_type: dbscheme::DbColumnType::String, - name: "name", - unique: false, - ql_type: ql::Type::String, - ql_type_is_ref: true, - }, - ], - }) -} - -fn create_locations_default_table<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Table(dbscheme::Table { - name: "locations_default", - keysets: None, - columns: vec![ - dbscheme::Column { - unique: true, - db_type: dbscheme::DbColumnType::Int, - name: "id", - ql_type: ql::Type::At("location_default"), - ql_type_is_ref: false, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "file", - ql_type: ql::Type::At("file"), - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "start_line", - ql_type: ql::Type::Int, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "start_column", - ql_type: ql::Type::Int, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "end_line", - ql_type: ql::Type::Int, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "end_column", - ql_type: ql::Type::Int, - ql_type_is_ref: true, - }, - ], - }) -} - -fn create_container_union<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Union(dbscheme::Union { - name: "container", - members: vec!["folder", "file"].into_iter().collect(), - }) -} - -fn create_containerparent_table<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Table(dbscheme::Table { - name: "containerparent", - columns: vec![ - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "parent", - ql_type: ql::Type::At("container"), - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: true, - db_type: dbscheme::DbColumnType::Int, - name: "child", - ql_type: ql::Type::At("container"), - ql_type_is_ref: true, - }, - ], - keysets: None, - }) -} - -fn create_source_location_prefix_table<'a>() -> dbscheme::Entry<'a> { - dbscheme::Entry::Table(dbscheme::Table { - name: "sourceLocationPrefix", - keysets: None, - columns: vec![dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::String, - name: "prefix", - ql_type: ql::Type::String, - ql_type_is_ref: true, - }], - }) -} - -fn create_diagnostics<'a>() -> (dbscheme::Case<'a>, dbscheme::Table<'a>) { - let table = dbscheme::Table { - name: "diagnostics", - keysets: None, - columns: vec![ - dbscheme::Column { - unique: true, - db_type: dbscheme::DbColumnType::Int, - name: "id", - ql_type: ql::Type::At("diagnostic"), - ql_type_is_ref: false, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "severity", - ql_type: ql::Type::Int, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::String, - name: "error_tag", - ql_type: ql::Type::String, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::String, - name: "error_message", - ql_type: ql::Type::String, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::String, - name: "full_error_message", - ql_type: ql::Type::String, - ql_type_is_ref: true, - }, - dbscheme::Column { - unique: false, - db_type: dbscheme::DbColumnType::Int, - name: "location", - ql_type: ql::Type::At("location_default"), - ql_type_is_ref: true, - }, - ], - }; - let severities: Vec<(usize, &str)> = vec![ - (10, "diagnostic_debug"), - (20, "diagnostic_info"), - (30, "diagnostic_warning"), - (40, "diagnostic_error"), - ]; - let case = dbscheme::Case { - name: "diagnostic", - column: "severity", - branches: severities, - }; - (case, table) -} diff --git a/shared/tree-sitter-extractor/src/generator/prefix.dbscheme b/shared/tree-sitter-extractor/src/generator/prefix.dbscheme new file mode 100644 index 00000000000..f371901ca6f --- /dev/null +++ b/shared/tree-sitter-extractor/src/generator/prefix.dbscheme @@ -0,0 +1,61 @@ +/*- 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 +); + +/*- Source location prefix -*/ + +/** + * The source location of the snapshot. + */ +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 +;