Cpp.CallSite Class
Namespace: Cpp
Superclasses: ObjectWithPosition
Description
CallSite class represents the position in your code in which a function
is invoked. This class inherits from the class ObjectWithPosition. You can use the predicates associated with this class and its
base class to construct queries related to call sites in your C/C++ code.
Predicates
You can report a defect on Raisable types. If a type is
Printable, it can be reported in the message. For
CallSite objects, print the string obtained by the predicate
Cpp.namespace.toString.
| Type | Raisable | Printable |
|---|---|---|
CallSite
| Yes | No |
Lang.Int
| No | Yes |
Lang.String
| No | Yes |
This class defines these predicates that act on the CallSite objects.
In addition, objects of CallSite class can access the predicates defined
by the base class ObjectWithPosition. An object of CallSite class is an object
of ObjectWithPosition class.
| Predicate Syntax | Description | Example |
|---|---|---|
is(CallSite &c)
| Retrieves all CallSite objects from your C/C++ code. |
This defect flags all call sites in the C/C++ code you analyze: defect FlagAllCallSites = when Cpp.CallSite.is(&callSite) raise "CallSite detected" on callSite |
callee(CallSite self, Cpp.Function.Function &f)
| Retrieves all CallSite objects in your C/++ code that calls
a function and stores the callee functions in f. |
This defect flags all callee sites in the C/C++ code you analyze: defect FlagAllCallees = when Cpp.CallSite.is(&callsite) and callsite.callee(&fun) raise "Callee detected" on fun |
caller(CallSite self, Cpp.Function.Function &cf)
| Retrieves all CallSite objects in your C/++ code that calls
a function and stores the caller functions in
f. |
This defect flags all caller sites in the C/C++ code you analyze: defect FlagAllCallers = when Cpp.CallSite.is(&callsite) and callsite.caller(&fun) raise "Callee detected" on fun |
isVirtual(CallSite self)
| Retrieves the CallSite objects in your C/C++ code that
invokes a virtual function. |
This defect flags all call sites that invoke virtual functions in the C/C++ code you analyze: defect FlagAllVirtualCallSites = when Cpp.CallSite.is(&callsite) and callsite.isVirtual() raise "Virtual CallSite detected" on callsite |
isIndirectCall(CallSite self)
| Retrieves the CallSite objects in your C/C++ code that
invokes a function indirectly using function pointer. |
This defect flags all callsites that invoke functions indirectly in the C/C++ code you analyze: defect FlagAllIndirectCallSites = when Cpp.CallSite.is(&callsite) and callsite.isIndirectCall() raise "Indirecttual CallSite detected" on callsite |
calledByRuntime(CallSite self)
| Retrieves the call sites that are invoked by C++ dynamic initializer functions. |
This defect flags all callsites that are invoked by C++ dynamic initializer functions: defect FlagAllCalledByRuntimeCallSites = when Cpp.CallSite.is(&callsite) and callsite.calledByRuntime() and callsite.toString(&msg) raise "CallSite called by runtime detected", msg on callsite |
toString(CallSite self, Lang.String
&callsite_name)
| Converts the object self to a string. The converted string
is stored in callsite_name and can be displayed as part of a
message. |
This defect flags all callsites that calls a function using more than 2 arguments. The callsite is specified in the message as a string: defect FlagCallSitesWithMoreThan2Args =
when
Cpp.CallSite.is(&callsite)
and callsite.numberOfArguments(&nargs)
and nargs > 2
and callsite.toString(&msg)
raise "CallSite with more than 2 arguments detected \"{msg}\""
on callsite |
numberOfArguments(CallSite self, Lang.Int &nArg)
| Retrieves the number of argument for the CallSite object
self and stores the integer value in
nArg. | |
explicitlyCastToVoid(CallSite self)
| Retrieves the CallSite objects in your C/C++ code where a
function is called and the value returned by the function is explicitly cast to
void. |
This defect flags all callsites where the return value of the called
function is explicitly cast to
defect FlagAllExplicitlyCastToVoid =
when
Cpp.CallSite.is(&callsite)
and callsite.explicitlyCastToVoid()
and callsite.toString(&msg)
raise "Explicitly cast to void detected \"{msg}\""
on callsite |
immediatelyDiscarded(CallSite self)
| Retrieves the CallSite objects in your C/C++ code where a
function is called and the returned value of the function is immediately discarded.
That is, the returned value is not assigned to any variable in the C/C++
code. |
This defect flags all callsites where the return value of the called function is explicitly cast to void: defect FlagAllExplicitlyCastToVoid =
when
Cpp.CallSite.is(&callsite)
and callsite.immediatelyDiscarded()
and callsite.toString(&msg)
raise "Immediately discarded returned value detected \"{msg}\""
on callsite |
Examples
In a new folder
CallSite, initialize a new coding standard. At the command line, enter:polyspace-query-language init
In the file
main.pql, enter this content:package main // Main PQL file defines the catalog of your PQL project. // The catalog is a collection of sections. catalog CallSiteExample = { #[Description("Example Section")] section ExampleSection = { #[Description("Virtual function output discarded"),Id(myRule)] rule ExampleRule = { defect Exampledefect = when Cpp.CallSite.is(&callsite) and callsite.extension(&extension) and extension == ".cpp" and callsite.numberOfArguments(&nargs) and nargs > 2 and callsite.isVirtual() and callsite.immediatelyDiscarded() and callsite.toString(&str) raise "Result of virtual function with >2 arguments discarded: \"{str}\"" on callsite } } }Create the coding standard
CallSite.pschk using this command at the command line:polyspace-query-language package
Using the generated coding standard, run a Bug Finder analysis on your source file. Foe example, at the command line, enter:
The analysis reports the a defect on the callsitepolyspace-bug-finder -sources src.cpp -lang cpp -checkers-activation-file CallSite.pschk
obj->compute.
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)