Merge pull request #19773 from github/idrissrio/namespace-attributes

C++: Retrieve namespace attributes
This commit is contained in:
Idriss Riouak
2025-06-17 12:03:55 +02:00
committed by GitHub
13 changed files with 15294 additions and 4965 deletions

View File

@@ -0,0 +1,4 @@
---
category: feature
---
* Added a predicate `getAnAttribute` to `Namespace` to retrieve a namespace attribute.

View File

@@ -99,6 +99,11 @@ class Namespace extends NameQualifyingElement, @namespace {
/** Gets a file which declares (part of) this namespace. */
File getAFile() { result = this.getADeclarationEntry().getLocation().getFile() }
/** Gets an attribute of this namespace. */
Attribute getAnAttribute() {
namespaceattributes(underlyingElement(this), unresolveElement(result))
}
}
/**

View File

@@ -1139,6 +1139,11 @@ varattributes(
int spec_id: @attribute ref
);
namespaceattributes(
int namespace_id: @namespace ref,
int spec_id: @attribute ref
);
stmtattributes(
int stmt_id: @stmt ref,
int spec_id: @attribute 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,2 @@
description: Add a predicate `getAnAttribute` to `Namespace`
compatibility: backwards

View File

@@ -0,0 +1,11 @@
| file://:0:0:0:0 | MultiSquared | test.cpp:10:13:10:22 | deprecated |
| file://:0:0:0:0 | MultiSquared | test.cpp:10:25:10:36 | maybe_unused |
| file://:0:0:0:0 | MultiSquared | test.cpp:11:13:11:22 | deprecated |
| file://:0:0:0:0 | MultiSquared | test.cpp:11:25:11:36 | maybe_unused |
| file://:0:0:0:0 | NamespaceTest | test.cpp:1:26:1:35 | deprecated |
| file://:0:0:0:0 | NamespaceTest | test.cpp:2:26:2:35 | deprecated |
| file://:0:0:0:0 | NamespaceTest | test.cpp:3:26:3:37 | maybe_unused |
| test.cpp:4:53:4:61 | MultiAttr | test.cpp:4:26:4:35 | deprecated |
| test.cpp:4:53:4:61 | MultiAttr | test.cpp:4:38:4:49 | maybe_unused |
| test.cpp:6:43:6:56 | OuterNamespace::InnerNamespace | test.cpp:6:30:6:39 | deprecated |
| test.cpp:9:46:9:61 | NamespaceSquared | test.cpp:9:13:9:22 | deprecated |

View File

@@ -0,0 +1,4 @@
import cpp
from Namespace ns
select ns, ns.getAnAttribute()

View File

@@ -0,0 +1,11 @@
namespace __attribute__((deprecated)) NamespaceTest {}
namespace __attribute__((deprecated)) NamespaceTest {}
namespace __attribute__((maybe_unused)) NamespaceTest {}
namespace __attribute__((deprecated, maybe_unused)) MultiAttr {}
namespace OuterNamespace {
namespace __attribute__((deprecated)) InnerNamespace {}
}
namespace [[deprecated("NamespaceSquared")]] NamespaceSquared {}
namespace [[deprecated, maybe_unused]] MultiSquared {}
namespace [[deprecated, maybe_unused]] MultiSquared {}