File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,15 +45,24 @@ codeql_pkg_files(
4545 otherwise = ["//unified/extractor" ],
4646 win64 = ["//unified/extractor-unsupported-os:extractor" ],
4747 ),
48- prefix = "tools/{CODEQL_PLATFORM}" ,
48+ prefix = "{CODEQL_PLATFORM}" ,
49+ )
50+
51+ pkg_filegroup (
52+ name = "tools" ,
53+ srcs = [
54+ ":extractor-arch" ,
55+ "//unified/tools" ,
56+ "//unified/tools/builtins" ,
57+ ],
58+ prefix = "tools" ,
4959)
5060
5161codeql_pack (
5262 name = "unified" ,
5363 srcs = [
5464 ":codeql-extractor-yml" ,
5565 ":dbscheme-group" ,
56- ":extractor-arch" ,
57- "//unified/tools" ,
66+ ":tools" ,
5867 ],
5968)
Original file line number Diff line number Diff line change 1- use clap:: Args ;
2- use std:: path:: PathBuf ;
3-
41use crate :: languages;
2+ use clap:: Args ;
53use codeql_extractor:: extractor:: desugaring;
64use codeql_extractor:: trap;
7-
5+ use std:: path:: Path ;
6+ use std:: path:: PathBuf ;
7+ use std:: { env, fs} ;
88#[ derive( Args ) ]
99pub struct Options {
1010 /// Sets a custom source archive folder
@@ -31,6 +31,24 @@ pub fn run(options: Options) -> std::io::Result<()> {
3131 lang. prefix = "unified" ;
3232 }
3333
34+ let builtins_path = env:: var ( "CODEQL_EXTRACTOR_UNIFIED_ROOT" )
35+ . map ( |path| Path :: new ( & path) . join ( "tools" ) . join ( "builtins" ) )
36+ . expect ( "failed to read CODEQL_EXTRACTOR_UNIFIED_ROOT environment variable" ) ;
37+ let builtins_dir = fs:: read_dir ( builtins_path) . expect ( "failed to read builtins directory" ) ;
38+ let mut file_list = fs:: OpenOptions :: new ( )
39+ . append ( true )
40+ . open ( & options. file_list )
41+ . expect ( "failed to open file list" ) ;
42+ for entry in builtins_dir {
43+ let entry = entry. expect ( "failed to read builtins directory" ) ;
44+ let path = entry. path ( ) ;
45+ if path. extension ( ) . is_some_and ( |ext| ext == "swift" ) {
46+ use std:: io:: Write ;
47+ writeln ! ( file_list, "{}" , path. display( ) ) . expect ( "failed to write to file list" ) ;
48+ }
49+ }
50+ drop ( file_list) ;
51+
3452 let extractor = desugaring:: Extractor {
3553 prefix : "unified" . to_string ( ) ,
3654 languages,
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ module Folder = Impl::Folder;
3737/** A file. */
3838class File extends Container , Impl:: File {
3939 /** Holds if this file was extracted from ordinary source code. */
40- predicate fromSource ( ) { any ( ) }
40+ predicate fromSource ( ) { exists ( this . getRelativePath ( ) ) }
4141
4242 /**
4343 * Gets the number of lines containing code in this file. This value
Original file line number Diff line number Diff line change 1+ /**
2+ * Provides classes for builtins.
3+ */
4+
5+ private import unified
6+
7+ /** The folder containing builtins. */
8+ class BuiltinsFolder extends Folder {
9+ BuiltinsFolder ( ) {
10+ this .getBaseName ( ) = "builtins" and
11+ this .getParentContainer ( ) .getBaseName ( ) = "tools"
12+ }
13+ }
14+
15+ private class BuiltinsTypesFile extends File {
16+ BuiltinsTypesFile ( ) {
17+ this .getBaseName ( ) = "types.swift" and
18+ this .getParentContainer ( ) instanceof BuiltinsFolder
19+ }
20+ }
21+
22+ /**
23+ * A builtin type, such as `Bool` and `String`.
24+ *
25+ * Builtin types are represented as structs.
26+ */
27+ class BuiltinClassLikeDeclaration extends ClassLikeDeclaration {
28+ BuiltinClassLikeDeclaration ( ) { this .getFile ( ) instanceof BuiltinsTypesFile }
29+ }
Original file line number Diff line number Diff line change @@ -42,7 +42,9 @@ private module Ast implements AstSig<Location> {
4242
4343 Callable getEnclosingCallable ( AstNode node ) { result = node .getEnclosingCallable ( ) }
4444
45- class Callable = U:: Callable ;
45+ class Callable extends U:: Callable {
46+ Callable ( ) { this .fromSource ( ) }
47+ }
4648
4749 AstNode callableGetBody ( Callable c ) { result = c .getBody ( ) }
4850
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ module Unified {
1515 /** Gets the file containing this AST node. */
1616 File getFile ( ) { result = this .getLocation ( ) .getFile ( ) }
1717
18+ /** Holds if this AST node comes from ordinary source code. */
19+ predicate fromSource ( ) { this .getFile ( ) .fromSource ( ) }
20+
1821 /** Holds if this AST node has a modifier with the given text. */
1922 predicate hasModifier ( string text ) {
2023 exists ( Modifier mod |
Original file line number Diff line number Diff line change 11import unified
22
3- query predicate identifier ( Identifier node , string value ) { value = node .getValue ( ) }
3+ query predicate identifier ( Identifier node , string value ) {
4+ node .fromSource ( ) and value = node .getValue ( )
5+ }
46
57query predicate namedPattern ( NamedPattern node , string value ) { value = node .getName ( ) }
68
Original file line number Diff line number Diff line change 11import unified
22
3- query predicate comments ( Comment c , string text ) { text = c .getCommentText ( ) }
3+ query predicate comments ( Comment c , string text ) { c . fromSource ( ) and text = c .getCommentText ( ) }
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ func test() {
1111 let local = 2 // name=local2
1212 local // $ definition=local2
1313 Derived . member // $ definition=Derived definition=Base.member
14- let _: Derived . Nested ? // $ definition=Derived definition=Base.Nested
14+ let _: Derived . Nested ? // $ definition=Derived definition=Base.Nested definition=Optional
1515}
1616
1717typealias Alias = Derived // $ definition=Derived
18- let _: Alias . Nested ? // $ definition=Alias definition=Base.Nested
18+ let _: Alias . Nested ? // $ definition=Alias definition=Base.Nested definition=Optional
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ private class A {
1515 return self . y // $ not handled by static name binding
1616 }
1717
18- class func z( ) -> Int { // name=A.type.z
18+ class func z( ) -> Int { // $ access=Int // name=A.type.z
1919 return 789
2020 }
2121
@@ -37,7 +37,7 @@ private class B : A { // $ access=A
3737 return self . y // $ not handled by static name binding
3838 }
3939
40- class func z( ) -> Int { // name=B.type.z
40+ class func z( ) -> Int { // $ access=Int // name=B.type.z
4141 return 789
4242 }
4343
You can’t perform that action at this time.
0 commit comments