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

Skip to content

Commit b0a9348

Browse files
zlaski-semmlegeoffw0
authored andcommitted
[CPP-418] Add QLDoc entries for typedef types, user types, bitwise operations and built-in operations.
1 parent 1f35f4b commit b0a9348

5 files changed

Lines changed: 420 additions & 82 deletions

File tree

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private predicate isIntegralType(@builtintype type, int kind) {
362362
}
363363

364364
/**
365-
* A C/C++ integral or enum type.
365+
* A C/C++ integral or `enum` type.
366366
*
367367
* The definition of "integral type" in the C++ Standard excludes `enum` types,
368368
* but because an `enum` type holds a value of its underlying integral type,
@@ -569,7 +569,7 @@ class PlainCharType extends CharType {
569569

570570
/**
571571
* The C/C++ `unsigned char` type (which is distinct from plain `char`
572-
* even when `char` is unsigned by default).
572+
* even when `char` is `unsigned` by default).
573573
* ```
574574
* unsigned char e, f;
575575
* ```
@@ -582,7 +582,7 @@ class UnsignedCharType extends CharType {
582582

583583
/**
584584
* The C/C++ `signed char` type (which is distinct from plain `char`
585-
* even when `char` is signed by default).
585+
* even when `char` is `signed` by default).
586586
* ```
587587
* signed char c, d;
588588
* ```
@@ -928,17 +928,17 @@ class Decltype extends Type, @decltype {
928928
*/
929929
Type getBaseType() { decltypes(underlyingElement(this), _, unresolveElement(result), _) }
930930

931-
override string getCanonicalQLClass() { result = "Decltype" }
932-
933931
/**
934932
* Whether an extra pair of parentheses around the expression would change the semantics of this decltype.
935933
*
936934
* The following example shows the effect of an extra pair of parentheses:
937-
* struct A { double x; };
938-
* const A* a = new A();
939-
* decltype( a->x ); // type is double
940-
* decltype((a->x)); // type is const double&
941-
* Consult the C++11 standard for more details.
935+
* ```
936+
* struct A { double x; };
937+
* const A* a = new A();
938+
* decltype( a->x ); // type is double
939+
* decltype((a->x)); // type is const double&
940+
* ```
941+
* Please consult the C++11 standard for more details.
942942
*/
943943
predicate parenthesesWouldChangeMeaning() { decltypes(underlyingElement(this), _, _, true) }
944944

@@ -1007,7 +1007,7 @@ class PointerType extends DerivedType {
10071007
/**
10081008
* A C++ reference type. See 4.9.1.
10091009
*
1010-
* For C++11 code bases, this includes both _lvalue_ references (&) and _rvalue_ references (&&).
1010+
* For C++11 code bases, this includes both _lvalue_ references (`&`) and _rvalue_ references (`&&`).
10111011
* To distinguish between them, use the LValueReferenceType and RValueReferenceType classes.
10121012
*/
10131013
class ReferenceType extends DerivedType {
@@ -1033,7 +1033,7 @@ class ReferenceType extends DerivedType {
10331033
}
10341034

10351035
/**
1036-
* A C++11 lvalue reference type (e.g. `int&`).
1036+
* A C++11 lvalue reference type (e.g. `int &`).
10371037
* ```
10381038
* int a;
10391039
* int& b = a;
@@ -1046,8 +1046,8 @@ class LValueReferenceType extends ReferenceType {
10461046
}
10471047

10481048
/**
1049-
* A C++11 rvalue reference type (e.g. `int&&`). It is used to
1050-
* implement "move" semantics for object construction and assignments.
1049+
* A C++11 rvalue reference type (e.g., `int &&`). It is used to
1050+
* implement "move" semantics for object construction and assignment.
10511051
* ```
10521052
* class C {
10531053
* E e;
@@ -1251,7 +1251,7 @@ class FunctionReferenceType extends FunctionPointerIshType {
12511251
}
12521252

12531253
/**
1254-
* A block type, for example int(^)(char, float).
1254+
* A block type, for example, `int(^)(char, float)`.
12551255
*
12561256
* Block types (along with blocks themselves) are a language extension
12571257
* supported by Clang, and by Apple's branch of GCC.

cpp/ql/src/semmle/code/cpp/TypedefType.qll

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import semmle.code.cpp.Type
22
private import semmle.code.cpp.internal.ResolveClass
33

44
/**
5-
* A C/C++ typedef type. See 4.9.1.
6-
*
7-
* Represents either of the following typedef styles:
8-
*
9-
* * CTypedefType: typedef <type> <name>;
10-
* * UsingAliasTypedefType: using <name> = <type>;
5+
* A C/C++ typedef type. See 4.9.1. For example the types declared on each line of the following code:
6+
* ```
7+
* typedef int my_int;
8+
* using my_int2 = int;
9+
* ```
1110
*/
1211
class TypedefType extends UserType {
1312
TypedefType() {
@@ -48,7 +47,10 @@ class TypedefType extends UserType {
4847
}
4948

5049
/**
51-
* A traditional C/C++ typedef type. See 4.9.1.
50+
* A traditional C/C++ typedef type. See 4.9.1. For example the type declared in the following code:
51+
* ```
52+
* typedef int my_int;
53+
* ```
5254
*/
5355
class CTypedefType extends TypedefType {
5456
CTypedefType() { usertypes(underlyingElement(this), _, 5) }
@@ -61,7 +63,10 @@ class CTypedefType extends TypedefType {
6163
}
6264

6365
/**
64-
* A using alias C++ typedef type.
66+
* A using alias C++ typedef type. For example the type declared in the following code:
67+
* ```
68+
* using my_int2 = int;
69+
* ```
6570
*/
6671
class UsingAliasTypedefType extends TypedefType {
6772
UsingAliasTypedefType() { usertypes(underlyingElement(this), _, 14) }
@@ -74,7 +79,11 @@ class UsingAliasTypedefType extends TypedefType {
7479
}
7580

7681
/**
77-
* A C++ typedef type that is directly enclosed by a function.
82+
* A C++ `typedef` type that is directly enclosed by a function. For example the type declared inside the function `foo` in
83+
* the following code:
84+
* ```
85+
* int foo(void) { typedef int local; }
86+
* ```
7887
*/
7988
class LocalTypedefType extends TypedefType {
8089
LocalTypedefType() { isLocal() }
@@ -83,7 +92,11 @@ class LocalTypedefType extends TypedefType {
8392
}
8493

8594
/**
86-
* A C++ typedef type that is directly enclosed by a class, struct or union.
95+
* A C++ `typedef` type that is directly enclosed by a `class`, `struct` or `union`. For example the type declared inside
96+
* the class `C` in the following code:
97+
* ```
98+
* class C { typedef int nested; };
99+
* ```
87100
*/
88101
class NestedTypedefType extends TypedefType {
89102
NestedTypedefType() { this.isMember() }

cpp/ql/src/semmle/code/cpp/UserType.qll

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import semmle.code.cpp.Function
55
private import semmle.code.cpp.internal.ResolveClass
66

77
/**
8-
* A C/C++ user-defined type. Examples include `Class`, `Struct`, `Union`,
9-
* `Enum`, and `TypedefType`.
8+
* A C/C++ user-defined type. Examples include `class`, `struct`, `union`,
9+
* `enum` and `typedef` types.
10+
* ```
11+
* enum e1 { val1, val2 } b;
12+
* enum class e2: short { val3, val4 } c;
13+
* typedef int my_int;
14+
* class C { int a, b; };
15+
* ```
1016
*/
1117
class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @usertype {
1218
/**
@@ -88,6 +94,11 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
8894

8995
/**
9096
* A particular definition or forward declaration of a C/C++ user-defined type.
97+
* ```
98+
* class C;
99+
* typedef int ti;
100+
* extern void foo(int);
101+
* ```
91102
*/
92103
class TypeDeclarationEntry extends DeclarationEntry, @type_decl {
93104
override UserType getDeclaration() { result = getType() }

cpp/ql/src/semmle/code/cpp/exprs/BitwiseOperation.qll

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ abstract class UnaryBitwiseOperation extends UnaryOperation { }
77

88
/**
99
* A C/C++ complement expression.
10+
* ```
11+
* unsigned c = ~a;
12+
* ```
1013
*/
1114
class ComplementExpr extends UnaryBitwiseOperation, @complementexpr {
1215
override string getOperator() { result = "~" }
@@ -23,6 +26,9 @@ abstract class BinaryBitwiseOperation extends BinaryOperation { }
2326

2427
/**
2528
* A C/C++ left shift expression.
29+
* ```
30+
* unsigned c = a << b;
31+
* ```
2632
*/
2733
class LShiftExpr extends BinaryBitwiseOperation, @lshiftexpr {
2834
override string getOperator() { result = "<<" }
@@ -34,6 +40,9 @@ class LShiftExpr extends BinaryBitwiseOperation, @lshiftexpr {
3440

3541
/**
3642
* A C/C++ right shift expression.
43+
* ```
44+
* unsigned c = a >> b;
45+
* ```
3746
*/
3847
class RShiftExpr extends BinaryBitwiseOperation, @rshiftexpr {
3948
override string getOperator() { result = ">>" }
@@ -44,7 +53,10 @@ class RShiftExpr extends BinaryBitwiseOperation, @rshiftexpr {
4453
}
4554

4655
/**
47-
* A C/C++ bitwise and expression.
56+
* A C/C++ bitwise AND expression.
57+
* ```
58+
* unsigned c = a & b;
59+
* ```
4860
*/
4961
class BitwiseAndExpr extends BinaryBitwiseOperation, @andexpr {
5062
override string getOperator() { result = "&" }
@@ -55,7 +67,10 @@ class BitwiseAndExpr extends BinaryBitwiseOperation, @andexpr {
5567
}
5668

5769
/**
58-
* A C/C++ bitwise or expression.
70+
* A C/C++ bitwise OR expression.
71+
* ```
72+
* unsigned c = a | b;
73+
* ```
5974
*/
6075
class BitwiseOrExpr extends BinaryBitwiseOperation, @orexpr {
6176
override string getOperator() { result = "|" }
@@ -66,7 +81,10 @@ class BitwiseOrExpr extends BinaryBitwiseOperation, @orexpr {
6681
}
6782

6883
/**
69-
* A C/C++ bitwise xor expression.
84+
* A C/C++ bitwise XOR expression.
85+
* ```
86+
* unsigned c = a ^ b;
87+
* ```
7088
*/
7189
class BitwiseXorExpr extends BinaryBitwiseOperation, @xorexpr {
7290
override string getOperator() { result = "^" }

0 commit comments

Comments
 (0)