Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b53963a

Browse files
committed
C++: QLDoc.
1 parent 702b10f commit b53963a

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,18 @@ class SideEffectOperandNode extends Node, IndirectOperand {
526526
Expr getArgument() { result = call.getArgument(argumentIndex).getUnconvertedResultExpression() }
527527
}
528528

529+
/**
530+
* INTERNAL: do not use.
531+
*
532+
* A node representing the value of a global variable just before returning
533+
* from a function body.
534+
*/
529535
class FinalGlobalValue extends Node, TFinalGlobalValue {
530536
Ssa::GlobalUse globalUse;
531537

532538
FinalGlobalValue() { this = TFinalGlobalValue(globalUse) }
533539

540+
/** Gets the underlying SSA use. */
534541
Ssa::GlobalUse getGlobalUse() { result = globalUse }
535542

536543
override Declaration getEnclosingCallable() { result = this.getFunction() }
@@ -549,11 +556,18 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
549556
override string toStringImpl() { result = globalUse.toString() }
550557
}
551558

559+
/**
560+
* INTERNAL: do not use.
561+
*
562+
* A node representing the value of a global variable just after entering
563+
* a function body.
564+
*/
552565
class InitialGlobalValue extends Node, TInitialGlobalValue {
553566
Ssa::GlobalDef globalDef;
554567

555568
InitialGlobalValue() { this = TInitialGlobalValue(globalDef) }
556569

570+
/** Gets the underlying SSA definition. */
557571
Ssa::GlobalDef getGlobalDef() { result = globalDef }
558572

559573
override Declaration getEnclosingCallable() { result = this.getFunction() }
@@ -1262,6 +1276,7 @@ class VariableNode extends Node, TVariableNode {
12621276
/** Gets the variable corresponding to this node. */
12631277
Variable getVariable() { result = v }
12641278

1279+
/** Gets the indirection index of this node. */
12651280
int getIndirectionIndex() { result = indirectionIndex }
12661281

12671282
override Declaration getFunction() { none() }

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@ private module SourceVariables {
3434
bindingset[ind]
3535
SourceVariable() { any() }
3636

37+
/** Gets a textual representation of this element. */
3738
abstract string toString();
3839

40+
/**
41+
* Gets the number of loads performed on the base source variable
42+
* to reach the value of this source variable.
43+
*/
3944
int getIndirection() { result = ind }
4045

46+
/**
47+
* Gets the base source variable (i.e., the variable without any
48+
* indirections) of this source variable.
49+
*/
4150
abstract BaseSourceVariable getBaseVariable();
4251
}
4352

@@ -192,6 +201,10 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
192201
/** Holds if this definition or use has index `index` in block `block`. */
193202
abstract predicate hasIndexInBlock(IRBlock block, int index);
194203

204+
/**
205+
* Holds if this definition (or use) has index `index` in block `block`,
206+
* and is a definition (or use) of the variable `sv`
207+
*/
195208
final predicate hasIndexInBlock(IRBlock block, int index, SourceVariable sv) {
196209
this.hasIndexInBlock(block, index) and
197210
sv = this.getSourceVariable()
@@ -216,6 +229,10 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
216229
*/
217230
abstract BaseSourceVariableInstruction getBase();
218231

232+
/**
233+
* Gets the base source variable (i.e., the variable without
234+
* any indirection) of this definition or use.
235+
*/
219236
final BaseSourceVariable getBaseSourceVariable() {
220237
this.getBase().getBaseSourceVariable() = result
221238
}
@@ -437,10 +454,12 @@ class GlobalUse extends UseImpl, TGlobalUse {
437454

438455
override FinalGlobalValue getNode() { result.getGlobalUse() = this }
439456

440-
override int getIndirection() { result = ind + 1 } // TODO
457+
override int getIndirection() { result = ind + 1 }
441458

459+
/** Gets the global variable associated with this use. */
442460
Cpp::GlobalOrNamespaceVariable getVariable() { result = global }
443461

462+
/** Gets the `IRFunction` whose body is exited from after this use. */
444463
IRFunction getIRFunction() { result = f }
445464

446465
final override predicate hasIndexInBlock(IRBlock block, int index) {
@@ -454,6 +473,10 @@ class GlobalUse extends UseImpl, TGlobalUse {
454473

455474
final override Cpp::Location getLocation() { result = f.getLocation() }
456475

476+
/**
477+
* Gets the type of this use after specifiers have been deeply stripped
478+
* and typedefs have been resolved.
479+
*/
457480
Type getUnspecifiedType() { result = global.getUnspecifiedType() }
458481

459482
override predicate isCertain() { any() }
@@ -468,34 +491,49 @@ class GlobalDef extends TGlobalDef {
468491

469492
GlobalDef() { this = TGlobalDef(global, f, indirectionIndex) }
470493

494+
/** Gets the global variable associated with this definition. */
471495
Cpp::GlobalOrNamespaceVariable getVariable() { result = global }
472496

497+
/** Gets the `IRFunction` whose body is evaluated after this definition. */
473498
IRFunction getIRFunction() { result = f }
474499

500+
/** Gets the global variable associated with this definition. */
475501
int getIndirectionIndex() { result = indirectionIndex }
476502

503+
/** Holds if this definition or use has index `index` in block `block`. */
477504
final predicate hasIndexInBlock(IRBlock block, int index) {
478505
exists(EnterFunctionInstruction enter |
479506
enter = f.getEnterFunctionInstruction() and
480507
block.getInstruction(index) = enter
481508
)
482509
}
483510

511+
/** Gets the global variable associated with this definition. */
484512
SourceVariable getSourceVariable() { sourceVariableIsGlobal(result, global, f, indirectionIndex) }
485513

514+
/**
515+
* Holds if this definition has index `index` in block `block`, and
516+
* is a definition of the variable `sv`
517+
*/
486518
final predicate hasIndexInBlock(IRBlock block, int index, SourceVariable sv) {
487519
this.hasIndexInBlock(block, index) and
488520
sv = this.getSourceVariable()
489521
}
490522

523+
/** Gets the location of this element. */
491524
final Cpp::Location getLocation() { result = f.getLocation() }
492525

526+
/** Gets a textual representation of this element. */
493527
string toString() {
494528
if indirectionIndex = 0
495529
then result = global.toString()
496530
else result = global.toString() + " indirection"
497531
}
498532

533+
/**
534+
* Gets the type of this use after specifiers have been deeply stripped
535+
* and typedefs have been resolved.
536+
*/
499537
Type getUnspecifiedType() { result = global.getUnspecifiedType() }
500538
}
501539

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ newtype TBaseSourceVariable =
325325
TBaseCallVariable(AllocationInstruction call)
326326

327327
abstract class BaseSourceVariable extends TBaseSourceVariable {
328+
/** Gets a textual representation of this element. */
328329
abstract string toString();
329330

331+
/** Gets the type of this base source variable. */
330332
abstract DataFlowType getType();
331333
}
332334

@@ -441,6 +443,7 @@ predicate isModifiableAt(CppType cppType, int indirectionIndex) {
441443
}
442444

443445
abstract class BaseSourceVariableInstruction extends Instruction {
446+
/** Gets the base source variable accessed by this instruction. */
444447
abstract BaseSourceVariable getBaseSourceVariable();
445448
}
446449

0 commit comments

Comments
 (0)