Merge pull request #13154 from aibaars/sync-dbscheme-py

JS/Ruby/QL/Python: sync dbscheme fragments
This commit is contained in:
Arthur Baars
2023-05-23 19:14:29 +02:00
committed by GitHub
51 changed files with 34663 additions and 16577 deletions

View File

@@ -32,7 +32,7 @@ jobs:
path: |
ql/extractor-pack/
ql/target/release/buramu
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('ql/**/*.rs') }}
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ql/**/*.rs') }}
- name: Cache cargo
if: steps.cache-extractor.outputs.cache-hit != 'true'
uses: actions/cache@v3

View File

@@ -61,7 +61,7 @@ jobs:
ruby/extractor/target/release/codeql-extractor-ruby
ruby/extractor/target/release/codeql-extractor-ruby.exe
ruby/extractor/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/Cargo.lock') }}--${{ hashFiles('ruby/extractor/**/*.rs') }}
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}
- uses: actions/cache@v3
if: steps.cache-extractor.outputs.cache-hit != 'true'
with:

View File

@@ -17,4 +17,6 @@ jobs:
- uses: actions/checkout@v3
- name: Check synchronized files
run: python config/sync-files.py
- name: Check dbscheme fragments
run: python config/sync-dbscheme-fragments.py

View File

@@ -0,0 +1,33 @@
{
"files": [
"javascript/ql/lib/semmlecode.javascript.dbscheme",
"python/ql/lib/semmlecode.python.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 -*/",
"/*- XML: sourceline -*/",
"/*- DEPRECATED: External defects and metrics -*/",
"/*- DEPRECATED: Snapshot date -*/",
"/*- DEPRECATED: Duplicate code -*/",
"/*- DEPRECATED: Version control data -*/",
"/*- JavaScript-specific part -*/",
"/*- Ruby dbscheme -*/",
"/*- Erb dbscheme -*/",
"/*- QL dbscheme -*/",
"/*- Dbscheme dbscheme -*/",
"/*- Yaml dbscheme -*/",
"/*- Blame dbscheme -*/",
"/*- JSON dbscheme -*/",
"/*- Python dbscheme -*/"
]
}

View File

@@ -0,0 +1,86 @@
#!/usr/bin/env python3
import argparse
import json
import os
import pathlib
import re
def make_groups(blocks):
groups = {}
for block in blocks:
groups.setdefault("".join(block["lines"]), []).append(block)
return list(groups.values())
def validate_fragments(fragments):
ok = True
for header, blocks in fragments.items():
groups = make_groups(blocks)
if len(groups) > 1:
ok = False
print("Warning: dbscheme fragments with header '{}' are different for {}".format(header, ["{}:{}:{}".format(
group[0]["file"], group[0]["start"], group[0]["end"]) for group in groups]))
return ok
def main():
script_path = os.path.realpath(__file__)
script_dir = os.path.dirname(script_path)
parser = argparse.ArgumentParser(
prog=os.path.basename(script_path),
description='Sync dbscheme fragments across files.'
)
parser.add_argument('files', metavar='dbscheme_file', type=pathlib.Path, nargs='*', default=[],
help='dbscheme files to check')
args = parser.parse_args()
with open(os.path.join(script_dir, "dbscheme-fragments.json"), "r") as f:
config = json.load(f)
fragment_headers = set(config["fragments"])
fragments = {}
ok = True
for file in args.files + config["files"]:
with open(os.path.join(os.path.dirname(script_dir), file), "r") as dbscheme:
header = None
line_number = 1
block = {"file": file, "start": line_number,
"end": None, "lines": []}
def end_block():
block["end"] = line_number - 1
if len(block["lines"]) > 0:
if header is None:
if re.match(r'(?m)\A(\s|//.*$|/\*(\**[^\*])*\*+/)*\Z', "".join(block["lines"])):
# Ignore comments at the beginning of the file
pass
else:
ok = False
print("Warning: dbscheme fragment without header: {}:{}:{}".format(
block["file"], block["start"], block["end"]))
else:
fragments.setdefault(header, []).append(block)
for line in dbscheme:
m = re.match(r"^\/\*-.*-\*\/$", line)
if m:
end_block()
header = line.strip()
if header not in fragment_headers:
ok = False
print("Warning: unknown header for dbscheme fragment: '{}': {}:{}".format(
header, file, line_number))
block = {"file": file, "start": line_number,
"end": None, "lines": []}
block["lines"].append(line)
line_number += 1
block["lines"].append('\n')
line_number += 1
end_block()
if not ok or not validate_fragments(fragments):
exit(1)
if __name__ == "__main__":
main()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Sync dbscheme fragments
compatibility: full

View File

@@ -1,103 +1,75 @@
/*** Standard fragments ***/
/** Files and folders **/
/*- Files and folders -*/
@location = @location_default;
/**
* 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
);
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
);
@sourceline = @locatable;
folders(
unique int id: @folder,
string name: string ref
);
numlines(int element_id: @sourceline ref,
int num_lines: int ref,
int num_code: int ref,
int num_comment: int ref
);
@container = @file | @folder
files(unique int id: @file,
varchar(900) name: string ref);
containerparent(
int parent: @container ref,
unique int child: @container ref
);
folders(unique int id: @folder,
varchar(900) name: string ref);
/*- Lines of code -*/
numlines(
int element_id: @sourceline ref,
int num_lines: int ref,
int num_code: int ref,
int num_comment: int ref
);
@container = @folder | @file ;
containerparent(int parent: @container ref,
unique int child: @container ref);
/** Duplicate code **/
duplicateCode(
unique int id : @duplication,
varchar(900) relativePath : string ref,
int equivClass : int ref);
similarCode(
unique int id : @similarity,
varchar(900) relativePath : string ref,
int equivClass : int ref);
@duplication_or_similarity = @duplication | @similarity;
tokens(
int id : @duplication_or_similarity ref,
int offset : int ref,
int beginLine : int ref,
int beginColumn : int ref,
int endLine : int ref,
int endColumn : int ref);
/** External data **/
/*- External data -*/
/**
* External data, loaded from CSV files during snapshot creation. See
* [Tutorial: Incorporating external data](https://help.semmle.com/wiki/display/SD/Tutorial%3A+Incorporating+external+data)
* for more information.
*/
externalData(
int id : @externalDataElement,
varchar(900) path : string ref,
string path : string ref,
int column: int ref,
varchar(900) value : string ref
string value : string ref
);
snapshotDate(unique date snapshotDate : date ref);
/*- Source location prefix -*/
sourceLocationPrefix(varchar(900) prefix : string ref);
/**
* The source location of the snapshot.
*/
sourceLocationPrefix(string prefix : string ref);
/** Version control data **/
/*- JavaScript-specific part -*/
svnentries(
int id : @svnentry,
varchar(500) revision : string ref,
varchar(500) author : string ref,
date revisionDate : date ref,
int changeSize : int ref
);
@location = @location_default
svnaffectedfiles(
int id : @svnentry ref,
int file : @file ref,
varchar(500) action : string ref
);
svnentrymsg(
int id : @svnentry ref,
varchar(500) message : string ref
);
svnchurn(
int commit : @svnentry ref,
int file : @file ref,
int addedLines : int ref,
int deletedLines : int ref
);
/*** JavaScript-specific part ***/
@sourceline = @locatable;
filetype(
int file: @file ref,
@@ -1046,14 +1018,50 @@ jsdoc_has_new_parameter (int fn: @jsdoc_function_type_expr ref);
jsdoc_errors (unique int id: @jsdoc_error, int tag: @jsdoc_tag ref, varchar(900) message: string ref, varchar(900) tostring: string ref);
// YAML
@dataflownode = @expr | @function_decl_stmt | @class_decl_stmt | @namespace_declaration | @enum_declaration | @property;
@optionalchainable = @call_expr | @propaccess;
isOptionalChaining(int id: @optionalchainable ref);
/**
* The time taken for the extraction of a file.
* This table contains non-deterministic content.
*
* The sum of the `time` column for each (`file`, `timerKind`) pair
* is the total time taken for extraction of `file`. The `extractionPhase`
* column provides a granular view of the extraction time of the file.
*/
extraction_time(
int file : @file ref,
// see `com.semmle.js.extractor.ExtractionMetrics.ExtractionPhase`.
int extractionPhase: int ref,
// 0 for the elapsed CPU time in nanoseconds, 1 for the elapsed wallclock time in nanoseconds
int timerKind: int ref,
float time: float ref
)
/**
* Non-timing related data for the extraction of a single file.
* This table contains non-deterministic content.
*/
extraction_data(
int file : @file ref,
// the absolute path to the cache file
varchar(900) cacheFile: string ref,
boolean fromCache: boolean ref,
int length: int ref
)
/*- YAML -*/
#keyset[parent, idx]
yaml (unique int id: @yaml_node,
int kind: int ref,
int parent: @yaml_node_parent ref,
int idx: int ref,
varchar(900) tag: string ref,
varchar(900) tostring: string ref);
string tag: string ref,
string tostring: string ref);
case @yaml_node.kind of
0 = @yaml_scalar_node
@@ -1067,41 +1075,41 @@ case @yaml_node.kind of
@yaml_node_parent = @yaml_collection_node | @file;
yaml_anchors (unique int node: @yaml_node ref,
varchar(900) anchor: string ref);
string anchor: string ref);
yaml_aliases (unique int alias: @yaml_alias_node ref,
varchar(900) target: string ref);
string target: string ref);
yaml_scalars (unique int scalar: @yaml_scalar_node ref,
int style: int ref,
varchar(900) value: string ref);
string value: string ref);
yaml_errors (unique int id: @yaml_error,
varchar(900) message: string ref);
string message: string ref);
yaml_locations(unique int locatable: @yaml_locatable ref,
int location: @location_default ref);
@yaml_locatable = @yaml_node | @yaml_error;
/* XML Files */
/*- XML Files -*/
xmlEncoding(
unique int id: @file ref,
varchar(900) encoding: string ref
string encoding: string ref
);
xmlDTDs(
unique int id: @xmldtd,
varchar(900) root: string ref,
varchar(900) publicId: string ref,
varchar(900) systemId: string ref,
string root: string ref,
string publicId: string ref,
string systemId: string ref,
int fileid: @file ref
);
xmlElements(
unique int id: @xmlelement,
varchar(900) name: string ref,
string name: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int fileid: @file ref
@@ -1110,16 +1118,16 @@ xmlElements(
xmlAttrs(
unique int id: @xmlattribute,
int elementid: @xmlelement ref,
varchar(900) name: string ref,
varchar(3600) value: string ref,
string name: string ref,
string value: string ref,
int idx: int ref,
int fileid: @file ref
);
xmlNs(
int id: @xmlnamespace,
varchar(900) prefixName: string ref,
varchar(900) URI: string ref,
string prefixName: string ref,
string URI: string ref,
int fileid: @file ref
);
@@ -1131,14 +1139,14 @@ xmlHasNs(
xmlComments(
unique int id: @xmlcomment,
varchar(3600) text: string ref,
string text: string ref,
int parentid: @xmlparent ref,
int fileid: @file ref
);
xmlChars(
unique int id: @xmlcharacters,
varchar(3600) text: string ref,
string text: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int isCDATA: int ref,
@@ -1155,15 +1163,7 @@ xmllocations(
@xmllocatable = @xmlcharacters | @xmlelement | @xmlcomment | @xmlattribute | @xmldtd | @file | @xmlnamespace;
@dataflownode = @expr | @function_decl_stmt | @class_decl_stmt | @namespace_declaration | @enum_declaration | @property;
@optionalchainable = @call_expr | @propaccess;
isOptionalChaining(int id: @optionalchainable ref);
/*
* configuration files with key value pairs
*/
/*- Configuration files with key value pairs -*/
configs(
unique int id: @config
@@ -1187,32 +1187,3 @@ configLocations(
);
@configLocatable = @config | @configName | @configValue;
/**
* The time taken for the extraction of a file.
* This table contains non-deterministic content.
*
* The sum of the `time` column for each (`file`, `timerKind`) pair
* is the total time taken for extraction of `file`. The `extractionPhase`
* column provides a granular view of the extraction time of the file.
*/
extraction_time(
int file : @file ref,
// see `com.semmle.js.extractor.ExtractionMetrics.ExtractionPhase`.
int extractionPhase: int ref,
// 0 for the elapsed CPU time in nanoseconds, 1 for the elapsed wallclock time in nanoseconds
int timerKind: int ref,
float time: float ref
)
/**
* Non-timing related data for the extraction of a single file.
* This table contains non-deterministic content.
*/
extraction_data(
int file : @file ref,
// the absolute path to the cache file
varchar(900) cacheFile: string ref,
boolean fromCache: boolean ref,
int length: int ref
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
description: Sync dbscheme fragments
compatibility: full
duplicateCode.rel: delete
similarCode.rel: delete
tokens.rel: delete
snapshotDate.rel: delete
svnentries.rel: delete
svnaffectedfiles.rel: delete
svnentrymsg.rel: delete
svnchurn.rel: delete

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Sync dbscheme fragments
compatibility: full

View File

@@ -16,9 +16,7 @@
* mechanism not work properly.
*/
/*
* External artifacts
*/
/*- DEPRECATED: External defects and metrics -*/
externalDefects(
unique int id : @externalDefect,
@@ -35,31 +33,44 @@ externalMetrics(
float value : float ref
);
/*- External data -*/
/**
* External data, loaded from CSV files during snapshot creation. See
* [Tutorial: Incorporating external data](https://help.semmle.com/wiki/display/SD/Tutorial%3A+Incorporating+external+data)
* for more information.
*/
externalData(
int id : @externalDataElement,
varchar(900) queryPath : string ref,
string path : string ref,
int column: int ref,
varchar(900) data : string ref
string value : string ref
);
/*- DEPRECATED: Snapshot date -*/
snapshotDate(unique date snapshotDate : date ref);
sourceLocationPrefix(varchar(900) prefix : string ref);
/*- Source location prefix -*/
/*
* Duplicate code
/**
* The source location of the snapshot.
*/
sourceLocationPrefix(string prefix : string ref);
/*- DEPRECATED: Duplicate code -*/
duplicateCode(
unique int id : @duplication,
varchar(900) relativePath : string ref,
int equivClass : int ref);
string relativePath : string ref,
int equivClass : int ref
);
similarCode(
unique int id : @similarity,
varchar(900) relativePath : string ref,
int equivClass : int ref);
string relativePath : string ref,
int equivClass : int ref
);
@duplication_or_similarity = @duplication | @similarity
@@ -69,7 +80,192 @@ tokens(
int beginLine : int ref,
int beginColumn : int ref,
int endLine : int ref,
int endColumn : int ref);
int endColumn : int ref
);
/*- DEPRECATED: Version control data -*/
svnentries(
unique int id : @svnentry,
string revision : string ref,
string author : string ref,
date revisionDate : date ref,
int changeSize : int ref
)
svnaffectedfiles(
int id : @svnentry ref,
int file : @file ref,
string action : string ref
)
svnentrymsg(
unique int id : @svnentry ref,
string message : string ref
)
svnchurn(
int commit : @svnentry ref,
int file : @file ref,
int addedLines : int ref,
int deletedLines : int ref
)
/*- Lines of code -*/
numlines(
int element_id: @sourceline ref,
int num_lines: int ref,
int num_code: int ref,
int num_comment: int ref
);
/*- 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
);
/*- XML Files -*/
xmlEncoding(
unique int id: @file ref,
string encoding: string ref
);
xmlDTDs(
unique int id: @xmldtd,
string root: string ref,
string publicId: string ref,
string systemId: string ref,
int fileid: @file ref
);
xmlElements(
unique int id: @xmlelement,
string name: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int fileid: @file ref
);
xmlAttrs(
unique int id: @xmlattribute,
int elementid: @xmlelement ref,
string name: string ref,
string value: string ref,
int idx: int ref,
int fileid: @file ref
);
xmlNs(
int id: @xmlnamespace,
string prefixName: string ref,
string URI: string ref,
int fileid: @file ref
);
xmlHasNs(
int elementId: @xmlnamespaceable ref,
int nsId: @xmlnamespace ref,
int fileid: @file ref
);
xmlComments(
unique int id: @xmlcomment,
string text: string ref,
int parentid: @xmlparent ref,
int fileid: @file ref
);
xmlChars(
unique int id: @xmlcharacters,
string text: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int isCDATA: int ref,
int fileid: @file ref
);
@xmlparent = @file | @xmlelement;
@xmlnamespaceable = @xmlelement | @xmlattribute;
xmllocations(
int xmlElement: @xmllocatable ref,
int location: @location_default ref
);
@xmllocatable = @xmlcharacters | @xmlelement | @xmlcomment | @xmlattribute | @xmldtd | @file | @xmlnamespace;
/*- 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;
/*- Python dbscheme -*/
/*
* Line metrics
@@ -86,68 +282,14 @@ py_docstringlines(int id : @py_scope ref,
py_alllines(int id : @py_scope ref,
int count : int ref);
/*
* Version history
*/
svnentries(
int id : @svnentry,
varchar(500) revision : string ref,
varchar(500) author : string ref,
date revisionDate : date ref,
int changeSize : int ref
)
svnaffectedfiles(
int id : @svnentry ref,
int file : @file ref,
varchar(500) action : string ref
)
svnentrymsg(
int id : @svnentry ref,
varchar(500) message : string ref
)
svnchurn(
int commit : @svnentry ref,
int file : @file ref,
int addedLines : int ref,
int deletedLines : int ref
)
/****************************
Python dbscheme
****************************/
files(unique int id: @file,
varchar(900) name: string ref);
folders(unique int id: @folder,
varchar(900) name: string ref);
@container = @folder | @file;
containerparent(int parent: @container ref,
unique int child: @container ref);
@sourceline = @file | @py_Module | @xmllocatable;
numlines(int element_id: @sourceline ref,
int num_lines: int ref,
int num_code: int ref,
int num_comment: int ref
);
@location = @location_ast | @location_default ;
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);
locations_ast(unique int id: @location_ast,
int module: @py_Module ref,
int beginLine: int ref,
@@ -1052,96 +1194,3 @@ py_decorated_object(int object : @py_object ref,
@py_object = @py_cobject | @py_flow_node;
@py_source_element = @py_ast_node | @container;
/* XML Files */
xmlEncoding (unique int id: @file ref, varchar(900) encoding: string ref);
xmlDTDs (unique int id: @xmldtd,
varchar(900) root: string ref,
varchar(900) publicId: string ref,
varchar(900) systemId: string ref,
int fileid: @file ref);
xmlElements (unique int id: @xmlelement,
varchar(900) name: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int fileid: @file ref);
xmlAttrs (unique int id: @xmlattribute,
int elementid: @xmlelement ref,
varchar(900) name: string ref,
varchar(3600) value: string ref,
int idx: int ref,
int fileid: @file ref);
xmlNs (int id: @xmlnamespace,
varchar(900) prefixName: string ref,
varchar(900) URI: string ref,
int fileid: @file ref);
xmlHasNs (int elementId: @xmlnamespaceable ref,
int nsId: @xmlnamespace ref,
int fileid: @file ref);
xmlComments (unique int id: @xmlcomment,
varchar(3600) text: string ref,
int parentid: @xmlparent ref,
int fileid: @file ref);
xmlChars (unique int id: @xmlcharacters,
varchar(3600) text: string ref,
int parentid: @xmlparent ref,
int idx: int ref,
int isCDATA: int ref,
int fileid: @file ref);
@xmlparent = @file | @xmlelement;
@xmlnamespaceable = @xmlelement | @xmlattribute;
xmllocations(int xmlElement: @xmllocatable ref,
int location: @location_default ref);
@xmllocatable = @xmlcharacters | @xmlelement | @xmlcomment | @xmlattribute | @xmldtd | @file | @xmlnamespace;
/**
* YAML
*/
#keyset[parent, idx]
yaml (unique int id: @yaml_node,
int kind: int ref,
int parent: @yaml_node_parent ref,
int idx: int ref,
varchar(900) tag: string ref,
varchar(900) 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,
varchar(900) anchor: string ref);
yaml_aliases (unique int alias: @yaml_alias_node ref,
varchar(900) target: string ref);
yaml_scalars (unique int scalar: @yaml_scalar_node ref,
int style: int ref,
varchar(900) value: string ref);
yaml_errors (unique int id: @yaml_error,
varchar(900) message: string ref);
yaml_locations(unique int locatable: @yaml_locatable ref,
int location: @location_default ref);
@yaml_locatable = @yaml_node | @yaml_error;

View File

@@ -1056,7 +1056,7 @@
<v>20</v>
</e>
<e>
<k>queryPath</k>
<k>path</k>
<v>2</v>
</e>
<e>
@@ -1064,14 +1064,14 @@
<v>5</v>
</e>
<e>
<k>data</k>
<k>value</k>
<v>41</v>
</e>
</columnsizes>
<dependencies>
<dep>
<src>id</src>
<trg>queryPath</trg>
<trg>path</trg>
<val>
<hist>
<budget>12</budget>
@@ -1103,7 +1103,7 @@
</dep>
<dep>
<src>id</src>
<trg>data</trg>
<trg>value</trg>
<val>
<hist>
<budget>12</budget>
@@ -1118,7 +1118,7 @@
</val>
</dep>
<dep>
<src>queryPath</src>
<src>path</src>
<trg>id</trg>
<val>
<hist>
@@ -1134,7 +1134,7 @@
</val>
</dep>
<dep>
<src>queryPath</src>
<src>path</src>
<trg>column</trg>
<val>
<hist>
@@ -1150,8 +1150,8 @@
</val>
</dep>
<dep>
<src>queryPath</src>
<trg>data</trg>
<src>path</src>
<trg>value</trg>
<val>
<hist>
<budget>12</budget>
@@ -1183,7 +1183,7 @@
</dep>
<dep>
<src>column</src>
<trg>queryPath</trg>
<trg>path</trg>
<val>
<hist>
<budget>12</budget>
@@ -1199,7 +1199,7 @@
</dep>
<dep>
<src>column</src>
<trg>data</trg>
<trg>value</trg>
<val>
<hist>
<budget>12</budget>
@@ -1214,7 +1214,7 @@
</val>
</dep>
<dep>
<src>data</src>
<src>value</src>
<trg>id</trg>
<val>
<hist>
@@ -1230,8 +1230,8 @@
</val>
</dep>
<dep>
<src>data</src>
<trg>queryPath</trg>
<src>value</src>
<trg>path</trg>
<val>
<hist>
<budget>12</budget>
@@ -1246,7 +1246,7 @@
</val>
</dep>
<dep>
<src>data</src>
<src>value</src>
<trg>column</trg>
<val>
<hist>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Sync dbscheme fragments
compatibility: full

BIN
ql/Cargo.lock generated

Binary file not shown.

View File

@@ -10,7 +10,6 @@ edition = "2018"
tree-sitter = ">= 0.20, < 0.21"
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "d08db734f8dc52f6bc04db53a966603122bc6985"}
tree-sitter-ql-dbscheme = { git = "https://github.com/erik-krogh/tree-sitter-ql-dbscheme.git", rev = "63e1344353f63931e88bfbc2faa2e78e1421b213"}
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}
tree-sitter-blame = {path = "../buramu/tree-sitter-blame"}
tree-sitter-json = {git = "https://github.com/tausbn/tree-sitter-json.git", rev = "745663ee997f1576fe1e7187e6347e0db36ec7a9"}
clap = { version = "4.2", features = ["derive"] }

View File

@@ -15,7 +15,7 @@ pub fn run(_: Options) -> std::io::Result<()> {
autobuilder::Autobuilder::new("ql", PathBuf::from(database))
.include_extensions(&[".ql", ".qll", ".dbscheme", ".json", ".jsonc", ".jsonl"])
.include_globs(&["**/qlpack.yml", "deprecated.blame"])
.include_globs(&["deprecated.blame"])
.size_limit("10m")
.run()
}

View File

@@ -42,12 +42,6 @@ pub fn run(options: Options) -> std::io::Result<()> {
node_types: tree_sitter_ql_dbscheme::NODE_TYPES,
file_extensions: vec!["dbscheme".into()],
},
simple::LanguageSpec {
prefix: "yaml",
ts_language: tree_sitter_ql_yaml::language(),
node_types: tree_sitter_ql_yaml::NODE_TYPES,
file_extensions: vec!["yml".into()],
},
simple::LanguageSpec {
prefix: "json",
ts_language: tree_sitter_json::language(),

View File

@@ -31,10 +31,6 @@ pub fn run(options: Options) -> std::io::Result<()> {
name: "Dbscheme".to_owned(),
node_types: tree_sitter_ql_dbscheme::NODE_TYPES,
},
Language {
name: "Yaml".to_owned(),
node_types: tree_sitter_ql_yaml::NODE_TYPES,
},
Language {
name: "Blame".to_owned(),
node_types: tree_sitter_blame::NODE_TYPES,

View File

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

View File

@@ -38,8 +38,6 @@ class AstNode extends TAstNode {
result = node.getLocation()
)
or
result = toGenerateYaml(this).getLocation()
or
result = toDbscheme(this).getLocation()
}
@@ -2573,126 +2571,49 @@ class BindingSet extends Annotation {
* Classes modeling YAML AST nodes.
*/
module YAML {
/** A node in a YAML file */
class YamlNode extends TYamlNode, AstNode {
/** Holds if the predicate is a root node (has no parent) */
predicate isRoot() { not exists(this.getParent()) }
private import codeql.yaml.Yaml as LibYaml
override AstNode getParent() { toGenerateYaml(result) = toGenerateYaml(this).getParent() }
}
private module YamlSig implements LibYaml::InputSig {
import codeql.Locations
/** DEPRECATED: Alias for YamlNode */
deprecated class YAMLNode = YamlNode;
class LocatableBase extends @yaml_locatable {
Location getLocation() { yaml_locations(this, result) }
/** A YAML comment. */
class YamlComment extends TYamlComment, YamlNode {
Yaml::Comment yamlcomment;
YamlComment() { this = TYamlComment(yamlcomment) }
override string getAPrimaryQlClass() { result = "YamlComment" }
}
/** DEPRECATED: Alias for YamlComment */
deprecated class YAMLComment = YamlComment;
/** A YAML entry. */
class YamlEntry extends TYamlEntry, YamlNode {
Yaml::Entry yamle;
YamlEntry() { this = TYamlEntry(yamle) }
/** Gets the key of this YAML entry. */
YamlKey getKey() {
exists(Yaml::Keyvaluepair pair |
pair.getParent() = yamle and
result = TYamlKey(pair.getKey())
)
string toString() { none() }
}
YamlListItem getListItem() { toGenerateYaml(result).getParent() = yamle }
class NodeBase extends LocatableBase, @yaml_node {
NodeBase getChildNode(int i) { yaml(result, _, this, i, _, _) }
/** Gets the value of this YAML entry. */
YamlValue getValue() {
exists(Yaml::Keyvaluepair pair |
pair.getParent() = yamle and
result = TYamlValue(pair.getValue())
)
string getTag() { yaml(this, _, _, _, result, _) }
string getAnchor() { yaml_anchors(this, result) }
override string toString() { yaml(this, _, _, _, _, result) }
}
override string getAPrimaryQlClass() { result = "YamlEntry" }
}
class ScalarNodeBase extends NodeBase, @yaml_scalar_node {
int getStyle() { yaml_scalars(this, result, _) }
/** DEPRECATED: Alias for YamlEntry */
deprecated class YAMLEntry = YamlEntry;
/** A YAML key. */
class YamlKey extends TYamlKey, YamlNode {
Yaml::Key yamlkey;
YamlKey() { this = TYamlKey(yamlkey) }
/**
* Gets the value of this YAML key.
*/
YamlValue getValue() {
exists(Yaml::Keyvaluepair pair |
pair.getKey() = yamlkey and result = TYamlValue(pair.getValue())
)
string getValue() { yaml_scalars(this, _, result) }
}
override string getAPrimaryQlClass() { result = "YamlKey" }
class CollectionNodeBase extends NodeBase, @yaml_collection_node { }
/** Gets the value of this YAML value. */
string getNamePart(int i) {
i = 0 and result = yamlkey.getChild(0).(Yaml::SimpleId).getValue()
or
exists(YamlKey child |
child = TYamlKey(yamlkey.getChild(1)) and
result = child.getNamePart(i - 1)
)
class MappingNodeBase extends CollectionNodeBase, @yaml_mapping_node { }
class SequenceNodeBase extends CollectionNodeBase, @yaml_sequence_node { }
class AliasNodeBase extends NodeBase, @yaml_alias_node {
string getTarget() { yaml_aliases(this, result) }
}
/**
* Gets all the name parts of this YAML key concatenated with `/`.
* Dashes are replaced with `/` (because we don't have that information in the generated AST).
*/
string getQualifiedName() {
result = concat(string part, int i | part = this.getNamePart(i) | part, "/" order by i)
class ParseErrorBase extends LocatableBase, @yaml_error {
string getMessage() { yaml_errors(this, result) }
}
}
/** DEPRECATED: Alias for YamlKey */
deprecated class YAMLKey = YamlKey;
/** A YAML list item. */
class YamlListItem extends TYamlListitem, YamlNode {
Yaml::Listitem yamllistitem;
YamlListItem() { this = TYamlListitem(yamllistitem) }
/**
* Gets the value of this YAML list item.
*/
YamlValue getValue() { result = TYamlValue(yamllistitem.getChild()) }
override string getAPrimaryQlClass() { result = "YamlListItem" }
}
/** DEPRECATED: Alias for YamlListItem */
deprecated class YAMLListItem = YamlListItem;
/** A YAML value. */
class YamlValue extends TYamlValue, YamlNode {
Yaml::Value yamlvalue;
YamlValue() { this = TYamlValue(yamlvalue) }
override string getAPrimaryQlClass() { result = "YamlValue" }
/** Gets the value of this YAML value. */
string getValue() { result = yamlvalue.getValue() }
}
import LibYaml::Make<YamlSig>
// to not expose the entire `File` API on `QlPack`.
private newtype TQLPack = MKQlPack(File file) { file.getBaseName() = "qlpack.yml" }
@@ -2705,15 +2626,16 @@ module YAML {
QLPack() { this = MKQlPack(file) }
private string getProperty(string name) {
exists(YamlEntry entry |
entry.isRoot() and
entry.getKey().getQualifiedName() = name and
result = entry.getValue().getValue().trim() and
entry.getLocation().getFile() = file
private YamlValue get(string name) {
exists(YamlMapping m |
m instanceof YamlDocument and
m.getFile() = file and
result = m.lookup(name)
)
}
private string getProperty(string name) { result = this.get(name).(YamlScalar).getValue() }
/** Gets the name of this qlpack */
string getName() { result = this.getProperty("name") }
@@ -2728,32 +2650,12 @@ module YAML {
/** Gets the file that this `QLPack` represents. */
File getFile() { result = file }
private predicate isADependency(YamlEntry entry) {
exists(YamlEntry deps |
deps.getLocation().getFile() = file and entry.getLocation().getFile() = file
|
deps.isRoot() and
deps.getKey().getQualifiedName() = ["dependencies", "libraryPathDependencies"] and
entry.getLocation().getStartLine() = 1 + deps.getLocation().getStartLine() and
entry.getLocation().getStartColumn() > deps.getLocation().getStartColumn()
)
or
exists(YamlEntry prev | this.isADependency(prev) |
prev.getLocation().getFile() = file and
entry.getLocation().getFile() = file and
entry.getLocation().getStartLine() = 1 + prev.getLocation().getStartLine() and
entry.getLocation().getStartColumn() = prev.getLocation().getStartColumn()
)
}
predicate hasDependency(string name, string version) {
exists(YamlEntry entry | this.isADependency(entry) |
entry.getKey().getQualifiedName().trim() = name and
entry.getValue().getValue() = version
or
name = entry.getListItem().getValue().getValue().trim() and
version = "\"*\""
)
version = this.get("dependencies").(YamlMapping).lookup(name).(YamlScalar).getValue()
or
name =
this.get("libraryPathDependencies").(YamlCollection).getAChild().(YamlScalar).getValue() and
version = "\"*\""
or
name = this.getProperty("libraryPathDependencies") and
version = "\"*\""

View File

@@ -61,11 +61,6 @@ newtype TAstNode =
TPredicateExpr(QL::PredicateExpr pe) or
TAnnotation(QL::Annotation annot) or
TAnnotationArg(QL::AnnotArg arg) or
TYamlComment(Yaml::Comment yc) or
TYamlEntry(Yaml::Entry ye) or
TYamlKey(Yaml::Key yk) or
TYamlListitem(Yaml::Listitem yli) or
TYamlValue(Yaml::Value yv) or
TBuiltinClassless(string ret, string name, string args) { isBuiltinClassless(ret, name, args) } or
TBuiltinMember(string qual, string ret, string name, string args) {
isBuiltinMember(qual, ret, name, args)
@@ -87,15 +82,10 @@ class TCall = TPredicateCall or TMemberCall or TNoneCall or TAnyCall;
class TTypeRef = TImport or TModuleExpr or TType;
class TYamlNode = TYamlComment or TYamlEntry or TYamlKey or TYamlListitem or TYamlValue;
class TSignatureExpr = TPredicateExpr or TType or TModuleExpr;
class TComment = TQLDoc or TBlockComment or TLineComment;
/** DEPRECATED: Alias for TYamlNode */
deprecated class TYAMLNode = TYamlNode;
private QL::AstNode toQLFormula(AST::AstNode n) {
n = TConjunction(result) or
n = TDisjunction(result) or
@@ -125,14 +115,6 @@ private QL::AstNode toQLExpr(AST::AstNode n) {
n = TDontCare(result)
}
Yaml::AstNode toGenerateYaml(AST::AstNode n) {
n = TYamlComment(result) or
n = TYamlEntry(result) or
n = TYamlKey(result) or
n = TYamlListitem(result) or
n = TYamlValue(result)
}
Dbscheme::AstNode toDbscheme(AST::AstNode n) { n = TDBRelation(result) }
/**

View File

@@ -1611,139 +1611,6 @@ module Dbscheme {
}
}
module Yaml {
/** The base class for all AST nodes */
class AstNode extends @yaml_ast_node {
/** Gets a string representation of this element. */
string toString() { result = this.getAPrimaryQlClass() }
/** Gets the location of this element. */
final L::Location getLocation() { yaml_ast_node_info(this, _, _, result) }
/** Gets the parent of this element. */
final AstNode getParent() { yaml_ast_node_info(this, result, _, _) }
/** Gets the index of this node among the children of its parent. */
final int getParentIndex() { yaml_ast_node_info(this, _, result, _) }
/** Gets a field or child node of this node. */
AstNode getAFieldOrChild() { none() }
/** Gets the name of the primary QL class for this element. */
string getAPrimaryQlClass() { result = "???" }
/** Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */
string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
}
/** A token. */
class Token extends @yaml_token, AstNode {
/** Gets the value of this token. */
final string getValue() { yaml_tokeninfo(this, _, result) }
/** Gets a string representation of this element. */
final override string toString() { result = this.getValue() }
/** Gets the name of the primary QL class for this element. */
override string getAPrimaryQlClass() { result = "Token" }
}
/** A reserved word. */
class ReservedWord extends @yaml_reserved_word, Token {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "ReservedWord" }
}
/** A class representing `comment` nodes. */
class Comment extends @yaml_comment, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Comment" }
/** Gets the child of this node. */
final Value getChild() { yaml_comment_def(this, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() { yaml_comment_def(this, result) }
}
/** A class representing `entry` nodes. */
class Entry extends @yaml_entry, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Entry" }
/** Gets the child of this node. */
final AstNode getChild() { yaml_entry_def(this, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() { yaml_entry_def(this, result) }
}
/** A class representing `key` nodes. */
class Key extends @yaml_key__, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Key" }
/** Gets the `i`th child of this node. */
final AstNode getChild(int i) { yaml_key_child(this, i, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() { yaml_key_child(this, _, result) }
}
/** A class representing `keyvaluepair` nodes. */
class Keyvaluepair extends @yaml_keyvaluepair, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Keyvaluepair" }
/** Gets the node corresponding to the field `key`. */
final Key getKey() { yaml_keyvaluepair_def(this, result, _) }
/** Gets the node corresponding to the field `value`. */
final Value getValue() { yaml_keyvaluepair_def(this, _, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() {
yaml_keyvaluepair_def(this, result, _) or yaml_keyvaluepair_def(this, _, result)
}
}
/** A class representing `listitem` nodes. */
class Listitem extends @yaml_listitem, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Listitem" }
/** Gets the child of this node. */
final Value getChild() { yaml_listitem_def(this, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() { yaml_listitem_def(this, result) }
}
/** A class representing `simpleId` tokens. */
class SimpleId extends @yaml_token_simple_id, Token {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "SimpleId" }
}
/** A class representing `value` tokens. */
class Value extends @yaml_token_value, Token {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Value" }
}
/** A class representing `yaml` nodes. */
class Yaml extends @yaml_yaml, AstNode {
/** Gets the name of the primary QL class for this element. */
final override string getAPrimaryQlClass() { result = "Yaml" }
/** Gets the `i`th child of this node. */
final Entry getChild(int i) { yaml_yaml_child(this, i, result) }
/** Gets a field or child node of this node. */
final override AstNode getAFieldOrChild() { yaml_yaml_child(this, _, result) }
}
}
module Blame {
/** The base class for all AST nodes */
class AstNode extends @blame_ast_node {

View File

@@ -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,6 +54,8 @@ diagnostics(
int location: @location_default ref
);
/*- Diagnostic messages: severity -*/
case @diagnostic.severity of
10 = @diagnostic_debug
| 20 = @diagnostic_info
@@ -49,7 +63,46 @@ case @diagnostic.severity of
| 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;
/*- 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 +979,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,81 +1166,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
);
yaml_comment_def(
unique int id: @yaml_comment,
int child: @yaml_token_value ref
);
@yaml_entry_child_type = @yaml_comment | @yaml_keyvaluepair | @yaml_listitem
yaml_entry_def(
unique int id: @yaml_entry,
int child: @yaml_entry_child_type ref
);
@yaml_key_child_type = @yaml_key__ | @yaml_token_simple_id
#keyset[yaml_key__, index]
yaml_key_child(
int yaml_key__: @yaml_key__ ref,
int index: int ref,
unique int child: @yaml_key_child_type ref
);
yaml_key_def(
unique int id: @yaml_key__
);
yaml_keyvaluepair_def(
unique int id: @yaml_keyvaluepair,
int key__: @yaml_key__ ref,
int value: @yaml_token_value ref
);
yaml_listitem_def(
unique int id: @yaml_listitem,
int child: @yaml_token_value ref
);
#keyset[yaml_yaml, index]
yaml_yaml_child(
int yaml_yaml: @yaml_yaml ref,
int index: int ref,
unique int child: @yaml_entry ref
);
yaml_yaml_def(
unique int id: @yaml_yaml
);
yaml_tokeninfo(
unique int id: @yaml_token,
int kind: int ref,
string value: string ref
);
case @yaml_token.kind of
0 = @yaml_reserved_word
| 1 = @yaml_token_simple_id
| 2 = @yaml_token_value
;
@yaml_ast_node = @yaml_comment | @yaml_entry | @yaml_key__ | @yaml_keyvaluepair | @yaml_listitem | @yaml_token | @yaml_yaml
@yaml_ast_node_parent = @file | @yaml_ast_node
#keyset[parent, parent_index]
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 +1229,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 +1311,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
);

File diff suppressed because it is too large Load Diff

View File

@@ -8,4 +8,5 @@ extractor: ql
dependencies:
codeql/typos: ${workspace}
codeql/util: ${workspace}
codeql/yaml: ${workspace}
warnOnImplicitThis: true

View File

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

10
ql/tools/pre-finalize.cmd Normal file
View File

@@ -0,0 +1,10 @@
@echo off
type NUL && "%CODEQL_DIST%\codeql" database index-files ^
--include=**/qlpack.yml ^
--size-limit=5m ^
--language yaml ^
-- ^
"%CODEQL_EXTRACTOR_QL_WIP_DATABASE%"
exit /b %ERRORLEVEL%

10
ql/tools/pre-finalize.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -eu
"$CODEQL_DIST/codeql" database index-files \
"--include=**/qlpack.yml" \
--size-limit=5m \
--language yaml \
-- \
"$CODEQL_EXTRACTOR_QL_WIP_DATABASE"

View File

@@ -11,4 +11,15 @@ type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
--working-dir=. ^
"%CODEQL_EXTRACTOR_QL_WIP_DATABASE%"
IF %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
--prune=**/*.testproj ^
--include-extension=.yml ^
--size-limit=5m ^
--language=yaml ^
--working-dir=. ^
"%CODEQL_EXTRACTOR_QL_WIP_DATABASE%"
exit /b %ERRORLEVEL%

View File

@@ -2,13 +2,20 @@
set -eu
exec "${CODEQL_DIST}/codeql" database index-files \
"${CODEQL_DIST}/codeql" database index-files \
--prune="**/*.testproj" \
--include-extension=.ql \
--include-extension=.qll \
--include-extension=.dbscheme \
--include-extension=.yml \
--size-limit=5m \
--language=ql \
--working-dir=.\
"$CODEQL_EXTRACTOR_QL_WIP_DATABASE"
exec "${CODEQL_DIST}/codeql" database index-files \
--prune="**/*.testproj" \
--include-extension=.yml \
--size-limit=5m \
--language=yaml \
--working-dir=.\
"$CODEQL_EXTRACTOR_QL_WIP_DATABASE"

View File

@@ -10,7 +10,7 @@ runs:
uses: actions/cache@v3
with:
path: ruby/extractor-pack
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/scripts/create-extractor-pack.sh', 'ruby/extractor/**/Cargo.lock', 'ruby/actions/create-extractor-pack/action.yml') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}-${{ hashFiles('ruby/codeql-extractor.yml', 'ruby/downgrades', 'ruby/tools', 'ruby/ql/lib/ruby.dbscheme', 'ruby/ql/lib/ruby.dbscheme.stats') }}
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/scripts/create-extractor-pack.sh', 'ruby/extractor/**/Cargo.lock', 'ruby/actions/create-extractor-pack/action.yml') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}-${{ hashFiles('ruby/codeql-extractor.yml', 'ruby/downgrades', 'ruby/tools', 'ruby/ql/lib/ruby.dbscheme', 'ruby/ql/lib/ruby.dbscheme.stats') }}
- name: Cache cargo
uses: actions/cache@v3
if: steps.cache-extractor.outputs.cache-hit != 'true'

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Sync dbscheme fragments
compatibility: full

View File

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

View File

@@ -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,6 +54,8 @@ diagnostics(
int location: @location_default ref
);
/*- Diagnostic messages: severity -*/
case @diagnostic.severity of
10 = @diagnostic_debug
| 20 = @diagnostic_info
@@ -49,7 +63,46 @@ case @diagnostic.severity of
| 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;
/*- 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 +1428,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 +1504,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
);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Sync dbscheme fragments
compatibility: full

View File

@@ -15,7 +15,7 @@ impl Autobuilder {
pub fn new(language: &str, database: PathBuf) -> Self {
Self {
language: language.to_string(),
database: database,
database,
include_extensions: vec![],
include_globs: vec![],
exclude_globs: vec![],
@@ -24,17 +24,17 @@ impl Autobuilder {
}
pub fn include_extensions(&mut self, exts: &[&str]) -> &mut Self {
self.include_extensions = exts.into_iter().map(|s| String::from(*s)).collect();
self.include_extensions = exts.iter().map(|s| String::from(*s)).collect();
self
}
pub fn include_globs(&mut self, globs: &[&str]) -> &mut Self {
self.include_globs = globs.into_iter().map(|s| String::from(*s)).collect();
self.include_globs = globs.iter().map(|s| String::from(*s)).collect();
self
}
pub fn exclude_globs(&mut self, globs: &[&str]) -> &mut Self {
self.exclude_globs = globs.into_iter().map(|s| String::from(*s)).collect();
self.exclude_globs = globs.iter().map(|s| String::from(*s)).collect();
self
}

View File

@@ -23,36 +23,22 @@ pub fn generate(
e
})?;
let mut dbscheme_writer = LineWriter::new(dbscheme_file);
write!(
writeln!(
dbscheme_writer,
"// CodeQL database schema for {}\n\
// Automatically generated from the tree-sitter grammar; do not edit\n\n",
// Automatically generated from the tree-sitter grammar; do not edit\n",
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),
],
)?;
writeln!(dbscheme_writer, include_str!("prefix.dbscheme"))?;
let mut ql_writer = LineWriter::new(File::create(ql_library_path)?);
write!(
writeln!(
ql_writer,
"/**\n\
* CodeQL library for {}
* Automatically generated from the tree-sitter grammar; do not edit\n\
*/\n\n",
*/\n",
languages[0].name
)?;
ql::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);
writeln!(&mut dbscheme_writer, "/*- {} dbscheme -*/", 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)
}

View File

@@ -0,0 +1,100 @@
/*- 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
;
/*- 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;