Skip to content

Commit 9969302

Browse files
committed
u
1 parent f60fe95 commit 9969302

File tree

7 files changed

+32
-382
lines changed

7 files changed

+32
-382
lines changed

manual.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This approach makes Cake useful in real and existing programs.
66

77
When applicable, Cake uses the same command line options of MSVC and GCC.
88

9+
For static analysis see: [ownership](ownership.html)
10+
911
### Include directories
1012

1113
Include directories are specified in `cakeconfig.h` file.
@@ -2306,9 +2308,6 @@ We have some compile time functions to infer properties of types.
23062308

23072309
```c
23082310

2309-
_is_char()
2310-
The three types char, signed char, and unsigned char are collectively called the character types.
2311-
23122311
_is_pointer
23132312
Pointer to object or function
23142313

@@ -2318,24 +2317,10 @@ Array type
23182317
_is_function
23192318
A function type describes a function with specified return type.
23202319

2321-
_is_floating_point
2322-
float, double, and long double return true
2323-
2324-
_is_integral
2325-
The standard signed integer types and standard unsigned integer types are collectively called the
2326-
standard integer types;
2327-
2328-
_is_arithmetic
2329-
Integer and floating types are collectively called arithmetic types.
2330-
2331-
_is_scalar
2332-
Arithmetic types, pointer types, and the nullptr_t type are collectively called scalar types
2333-
23342320
```
23352321

2336-
Note: Type traits that can be easily created with \_Generic will be removed.
23372322
_
2338-
### Extension - Object lifetime checks
2323+
### Object lifetime checks
23392324

23402325
See [ownership](ownership.html)
23412326

ownership.md

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Last Updated 3 March 2025
2+
Last Updated 5 December 2025
33

44
This is a work in progress. Cake source is currently being used to validate the concepts. It's in the process of transitioning to include annotated nullable checks, which was the last feature added.
55

@@ -159,42 +159,8 @@ If `is_empty` changes, it could potentially invalidate the assert on the caller'
159159
Although a runtime check is in place, it is not as safe as a compile-time check because it may occur
160160
within a rarely used branch, allowing the bug to remain inactive.
161161
162-
For this reason, a 'contract' approach is also being developed in Cake, *__although it
163-
is still in the early stages of design__*.
164-
165-
We can specify the post-conditions for the results of true and false branches using `true` and `false`
166-
at the function declaration, as well as for void functions using `post`
167-
168-
```c
169-
#pragma safety enable
170-
171-
struct X {
172-
int * _Opt data;
173-
};
174-
175-
bool is_empty(const struct X * p)
176-
true(p->data == 0),
177-
false(p->data != 0)
178-
{
179-
return p->data == nullptr;
180-
}
181-
182-
void clear(struct X * p)
183-
post(p->data == 0)
184-
{
185-
p->data = nullptr;
186-
}
187-
188-
void f(struct X * p)
189-
{
190-
if (!is_empty(p)) {
191-
/*assert not required anymore*/
192-
*p->data = 1;
193-
}
194-
}
195-
```
196-
197-
<button onclick="Try(this)">try</button>
162+
For this reason, a 'contract' approach is also being developed in Cake with the objective of moving
163+
the assert to function `is_empty` contract.
198164
199165
The advantage of contracts, as mentioned earlier, is that the postconditions are
200166
located in a single place. This is useful not only to avoid code repetition but
@@ -203,9 +169,6 @@ which are assumed to be true and may be dangerous if they are out of sync
203169
with the implementation.
204170
On the other hand, placing the contracts alongside the function declaration
205171
keeps the contract closer to its implementation.
206-
Compilers (though Cake is not currently doing this yet) could create proxy
207-
functions to check postconditions at runtime. (See C++ 26 contracts)
208-
209172
210173
211174
#### Non nullable members initialization
@@ -309,17 +272,7 @@ void f() {
309272

310273
<button onclick="Try(this)">try</button>
311274

312-
We could remove this built-in some something like
313-
314-
```c
315-
#pragma nullable enable
316-
_Uninitialized void * _Opt malloc(unsigned int sz);
317-
```
318-
319-
This is not implemented yet.
320-
321-
322-
`calloc` has a built in semantics indicating the object is zero-initialized.
275+
`calloc` has a built in semantics indicating the object is zero-initialized.
323276

324277
```c
325278
#pragma nullable enable
@@ -454,7 +407,7 @@ struct X * _Opt makeX(const char* name)
454407
Since mutability may be useful for constructors and destructors,
455408
the idea of mutable could imply that change may happen only once.
456409
This naturally occurs when assigning a non-nullable pointer for the
457-
first time—because afterward, it cannot become nullable again.
410+
first timebecause afterward, it cannot become nullable again.
458411
Similarly, for const objects, it could mean that once initialized,
459412
a const object cannot change anymore. In this context, 'constructor'
460413
or 'destructor' might be a more suitable term.
@@ -1542,7 +1495,7 @@ int f(int c)
15421495
```
15431496
15441497
In the following example, Cake recognizes that the pointed object is 'maybe deleted.'
1545-
However, if the object is deleted, it doesn’t matter because the pointer is null.
1498+
However, if the object is deleted, it doesnt matter because the pointer is null.
15461499
These relationships between states are not tracked.
15471500
15481501
```c

src/cakeconfig.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//This was generated by running cake -autoconfig
22
//This file was generated reading the variable INCLUDE inside Visual Studio Command Prompt.
33
//echo %INCLUDE%
4-
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/include/"
5-
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.44.35207/ATLMFC/include/"
6-
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Auxiliary/VS/include/"
4+
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/include/"
5+
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/ATLMFC/include/"
6+
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include/"
77
#pragma dir "C:/Program Files (x86)/Windows Kits/10/include/10.0.26100.0/ucrt/"
88
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//um/"
99
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//shared/"
1010
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//winrt/"
1111
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.26100.0//cppwinrt/"
12-
#pragma dir "C:/Program Files (x86)/Windows Kits/NETFXSDK/4.8/include/um/"

src/file.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
void f(int n)
1+
#pragma safety enable
2+
3+
struct X { char* s; };
4+
struct X f()
25
{
3-
goto target;
4-
int a[n];
5-
target:
6+
struct X x = {};
7+
return x;
68
}

0 commit comments

Comments
 (0)