Skip to content

Commit f76ce8b

Browse files
authored
Merge pull request #6686 from hvitved/cpp/files-folders-drop-columns
C++: Drop redundant columns from `files` and `folders` relations
2 parents 33ef634 + b69033f commit f76ce8b

File tree

6 files changed

+4308
-595
lines changed

6 files changed

+4308
-595
lines changed

cpp/ql/lib/semmle/code/cpp/File.qll

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Container extends Locatable, @container {
171171
* To get the full path, use `getAbsolutePath`.
172172
*/
173173
class Folder extends Container, @folder {
174-
override string getAbsolutePath() { folders(underlyingElement(this), result, _) }
174+
override string getAbsolutePath() { folders(underlyingElement(this), result) }
175175

176176
override Location getLocation() {
177177
result.getContainer() = this and
@@ -190,7 +190,7 @@ class Folder extends Container, @folder {
190190
* DEPRECATED: use `getAbsolutePath` instead.
191191
* Gets the name of this folder.
192192
*/
193-
deprecated string getName() { folders(underlyingElement(this), result, _) }
193+
deprecated string getName() { folders(underlyingElement(this), result) }
194194

195195
/**
196196
* DEPRECATED: use `getAbsolutePath` instead.
@@ -208,17 +208,7 @@ class Folder extends Container, @folder {
208208
* DEPRECATED: use `getBaseName` instead.
209209
* Gets the last part of the folder name.
210210
*/
211-
deprecated string getShortName() {
212-
exists(string longnameRaw, string longname |
213-
folders(underlyingElement(this), _, longnameRaw) and
214-
longname = longnameRaw.replaceAll("\\", "/")
215-
|
216-
exists(int index |
217-
result = longname.splitAt("/", index) and
218-
not exists(longname.splitAt("/", index + 1))
219-
)
220-
)
221-
}
211+
deprecated string getShortName() { result = this.getBaseName() }
222212

223213
/**
224214
* DEPRECATED: use `getParentContainer` instead.
@@ -242,7 +232,7 @@ class Folder extends Container, @folder {
242232
* `getStem` and `getExtension`. To get the full path, use `getAbsolutePath`.
243233
*/
244234
class File extends Container, @file {
245-
override string getAbsolutePath() { files(underlyingElement(this), result, _, _, _) }
235+
override string getAbsolutePath() { files(underlyingElement(this), result) }
246236

247237
override string toString() { result = Container.super.toString() }
248238

@@ -336,7 +326,13 @@ class File extends Container, @file {
336326
* for example, for "file.tar.gz", this predicate will have the result
337327
* "tar.gz", while `getExtension` will have the result "gz".
338328
*/
339-
string getExtensions() { files(underlyingElement(this), _, _, result, _) }
329+
string getExtensions() {
330+
exists(string name, int firstDotPos |
331+
name = this.getBaseName() and
332+
firstDotPos = min([name.indexOf("."), name.length() - 1]) and
333+
result = name.suffix(firstDotPos + 1)
334+
)
335+
}
340336

341337
/**
342338
* Gets the short name of this file, that is, the prefix of its base name up
@@ -351,7 +347,16 @@ class File extends Container, @file {
351347
* for example, for "file.tar.gz", this predicate will have the result
352348
* "file", while `getStem` will have the result "file.tar".
353349
*/
354-
string getShortName() { files(underlyingElement(this), _, result, _, _) }
350+
string getShortName() {
351+
exists(string name, int firstDotPos |
352+
name = this.getBaseName() and
353+
firstDotPos = min([name.indexOf("."), name.length()]) and
354+
result = name.prefix(firstDotPos)
355+
)
356+
or
357+
this.getAbsolutePath() = "" and
358+
result = ""
359+
}
355360
}
356361

357362
/**

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,14 @@ diagnostics(
310310
int location: @location_default ref
311311
);
312312

313-
/*
314-
fromSource(0) = unknown,
315-
fromSource(1) = from source,
316-
fromSource(2) = from library
317-
*/
318313
files(
319314
unique int id: @file,
320-
string name: string ref,
321-
string simple: string ref,
322-
string ext: string ref,
323-
int fromSource: int ref
315+
string name: string ref
324316
);
325317

326318
folders(
327319
unique int id: @folder,
328-
string name: string ref,
329-
string simple: string ref
320+
string name: string ref
330321
);
331322

332323
@container = @folder | @file

0 commit comments

Comments
 (0)