PRQL Quick Reference
Code Query Language cheat sheet
Ready-to-use PRQL queries for rapid static code analysis, quality checks, technical debt management and architectural governance. Copy any query and paste it straight into the CppDepend query editor — or use Code Quest to run them interactively.
This reference is also part of the documentation: Docs → PRQL Quick Reference
Basic Queries
Get my public methods
from m in JustMyCode.Methods where m.IsPublic
select mGet my abstract classes
from t in JustMyCode.Types where t.IsAbstract
select tGet my generic classes
from t in JustMyCode.Types where t.IsGeneric
select tGet all struct definitions
from t in Application.Types where t.IsStructure
select tCode Implementation Queries
Get complex methods
from m in Methods where m.CyclomaticComplexity>15
select new{m,m.CyclomaticComplexity}Get big types
from t in Types where t.NbLinesOfCode>500
select new {t,t.NbLinesOfCode}Get not maintainable methods
from m in JustMyCode.Methods where m.MaintainabilityIndex<40
select new {m,m.MaintainabilityIndex}Get methods with too many parameters (>5)
warnif count > 0
from m in Application.Methods
where m.NbParameters > 5
select new { m, m.NbParameters }Architecture & C++ Safety Rules
Detect cyclic dependencies between namespaces
warnif count > 0
from n in Application.Namespaces
where n.DepthOfIsUsing(n) > 0
select new { Namespace = n, CyclicDependencies = n.NamespacesUsed.Where(n2 => n2.DepthOfIsUsing(n) > 0) }Detect classes with virtual methods missing virtual destructors
warnif count > 0
from t in Application.Types
where t.IsClass && t.Methods.Any(m => m.IsVirtual) && !t.Methods.Any(m => m.IsDestructor && m.IsVirtual)
select new { MissingVirtualDestructorIn = t }Find public fields using raw pointers
warnif count > 0
from f in Application.Fields
where f.IsPointer && !f.IsConst && f.IsPublic
select new { UnsafePublicPointerField = f }Detect direct UI access to Low-Level Storage layer
warnif count > 0
let uiMethods = Application.Namespaces.WithNameLike("UI").ChildMethods()
let storageMethods = Application.Namespaces.WithNameLike("Storage").ChildMethods()
from m in uiMethods
where m.IsUsing(storageMethods)
select new { IllegalCallFrom = m, Target = m.MethodsCalled.Intersect(storageMethods) }Issues & Technical Debt
Get high severity issues
from issue in Issues where issue.Severity==Severity.High
select issueGet debt of medium issues
from issue in Issues where issue.Severity==Severity.Medium
select new{issue,issue.Debt}Get issues in public generic methods
from issue in Issues where issue.CodeElement!=null &&
issue.CodeElement.AsMethod!=null && issue.CodeElement.AsMethod.IsPublic && issue.CodeElement.AsMethod.IsGeneric
select new{issue,issue.Debt}Top 10 code elements with highest technical debt
from issue in Issues
orderby issue.Debt descending
select new { issue.CodeElement, issue.Debt, issue.Severity }Technical debt of most coupled methods
from m in Application.Methods
where m.NbMethodsCalled > 10
let debt = m.Issues.Sum(i => i.Debt)
orderby m.NbMethodsCalled descending
select new {
Method = m,
CouplingCount = m.NbMethodsCalled,
TotalDebt = debt,
IssueCount = m.Issues.Count()
}Issues Diff Queries
Get new issues
from issue in Issues where issue.WasAdded()
select new {issue,issue.Debt}Get fixed issues
from issue in IssuesInBaseline where issue.WasFixed()
select new {issue,issue.Debt}Get new violated rules
from rule in Rules where rule.IsInNewerIssuesSet() && !rule.IsInOlderIssuesSet()
select ruleNewly introduced high complexity methods in current commit
warnif count > 0
from m in Application.Methods
where m.WasAdded() && m.CyclomaticComplexity > 10
select new { NewComplexMethod = m, m.CyclomaticComplexity }Code Design Queries
Get most coupled methods
from m in Methods where m.NbMethodsCalled>10 orderby m.NbMethodsCalled descending
select new{m,m.NbMethodsCalled}Get not cohesive types
from t in JustMyCode.Types where t.LCOM > 0.8 &&
t.NbFields > 10 && t.NbMethods >10 select tGet classes with many base classes
from t in Types where t.BaseClasses.Count()>4
select tTypes with excessive Efferent Coupling (>20 used types)
from t in Application.Types
where t.TypesUsed.Count() > 20
select new { Type = t, CouplingCount = t.TypesUsed.Count() }Code Diff Queries
Get added methods
from m in Methods where m.WasAdded()
select mGet removed public methods
from m in codeBase.OlderVersion().Application.Methods where m.IsPublic && m.WasRemoved()
select mGet changed generic classes
from t in Types where t.isGeneric && t.WasChanged()
select tMethods where LOC grew significantly (>30 LOC)
warnif count > 0
from m in Application.Methods
where m.IsCodeModified() && (m.NbLinesOfCode - m.OlderVersion().NbLinesOfCode) > 30
select new { m, CurrentLOC = m.NbLinesOfCode, OldLOC = m.OlderVersion().NbLinesOfCode }Dependencies & API Tracking
Get methods used by complex methods
from m in Methods where m.MethodsCallingMe.Where(m=>m.CyclomaticComplexity>15).Any()
select new{m,m.MethodsCallingMe}Get methods using complex methods
from m in Methods where m.MethodsCalled.Where(m=>m.CyclomaticComplexity>15).Any()
select new{m,m.MethodsCalled}Get methods using the Windows API
from m in Methods where m.MethodsCalled.Where(m=>m.ParentProject.Name=="Windows SDK").Any()
select new{m,m.MethodsCalled.Where(m=>m.ParentProject.Name=="Windows SDK")}Find all methods directly or transitively calling raw allocators (malloc)
let rawAllocators = ThirdParty.Methods.WithSimpleName("malloc")
from m in Application.Methods
where m.DepthOfIsUsing(rawAllocators) >= 1
select new { CallerMethod = m, Depth = m.DepthOfIsUsing(rawAllocators) }Statistics & Metrics
Get most popular methods
from m in Methods where m.NbMethodsCallingMe>20 orderby m.NbMethodsCallingMe descending
select new{m,m.NbMethodsCallingMe}Get most big classes
from t in Types where t.NbLinesOfCode>400 orderby t.NbLinesOfCode
select new{t,t.NbLinesOfCode}Get most used classes
from t in Types where t.NbTypesUsingMe>10 orderby t.NbTypesUsingMe
select new{t,t.TypesUsingMe}Top 10 dead code candidates (unused private methods)
from m in Application.Methods
where m.IsPrivate && m.NbMethodsCallingMe == 0 && !m.IsMain
select new { UnusedMethod = m, m.NbLinesOfCode }No query matches your search.
Run these queries on your own code
Download CppDepend, open the query editor, and get results on your codebase in minutes.
