/>
CppDepend
Home/Docs/PRQL & Code Query/PRQL Quick Reference

PRQL Quick Reference

37 ready-to-use PRQL code queries, organized in 9 categories — copy them straight into the CppDepend query editor.

How to use this reference

Each query below is a complete, runnable PRQL query. Click Copy to copy a query to your clipboard, paste it into the CppDepend query editor, and run it against your codebase. Use the search box to filter queries by name.

New to the language? Start with the PRQL overview and the Validating PRQL Rules guide.

No query matches your search.

Basic Queries

Get my public methods
from m in JustMyCode.Methods where m.IsPublic 
select m
Get my abstract classes
from t in JustMyCode.Types where t.IsAbstract 
select t
Get my generic classes
from t in JustMyCode.Types where t.IsGeneric 
select t
Get all struct definitions
from t in Application.Types where t.IsStructure
select t

Code 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 issue
Get 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 rule
Newly 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 t
Get classes with many base classes
from t in Types where t.BaseClasses.Count()>4
select t
Types 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 m
Get removed public methods
from m in codeBase.OlderVersion().Application.Methods where m.IsPublic && m.WasRemoved()
select m
Get changed generic classes
from t in Types where t.isGeneric &&  t.WasChanged()
select t
Methods 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 }