Skip to content

Commit

Permalink
fixes, implementations, manual
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Aug 25, 2024
1 parent 0f6ae65 commit 240134e
Show file tree
Hide file tree
Showing 23 changed files with 5,705 additions and 4,708 deletions.
72 changes: 65 additions & 7 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,26 @@ https://files.lhmouse.com/standards/ISO%20C%20N2176.pdf
When compiling to versions < C11 \_Static\_Assert is removed.
### C11 Anonymous structures and unions
TODO
It is implemented, however the conversion to C99, C89 was not implemented.
```c
struct v {
union { /* anonymous union*/
struct { int i, j; }; /* anonymous structure*/
struct { long k, l; } w;
};
int m;
} v1;
int main(){
v1.i = 2; /* valid*/
v1.w.k = 5; /* valid*/
}
```

I think a possible alternative to convert to C89,C99 is insert a name.


### C11 \_Noreturn

Expand Down Expand Up @@ -694,6 +713,8 @@ Becomes < C11
}
```

TODO considering a macro. For instance, ALIGNOF_INT

### C11 _Alignas or C23 alignas

Not implemented.
Expand Down Expand Up @@ -740,10 +761,28 @@ int main()
In < C11 it is replaced by one space;

### C23 u8 character prefix
Not implemented yet.

Implemented.
https://open-std.org/JTC1/SC22/WG14/www/docs/n2418.pdf

```c
int main(){
unsigned char c = u8'~';
}
```

When compiling to < C23 becomes.

```c
int main(){
unsigned char c = ((unsigned char)'~');
}
```


### C23 No function declarators without prototypes

Implemented.
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n2841.htm

```c
Expand All @@ -759,6 +798,7 @@ https://open-std.org/JTC1/SC22/WG14/www/docs/n2432.pdf


### C23 Improved Tag Compatibility

Not implemented yet.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf
Expand Down Expand Up @@ -1043,8 +1083,24 @@ https://open-std.org/JTC1/SC22/WG14/www/docs/n2930.pdf

### C23 Improved Normal Enumerations

//TODO

https://open-std.org/JTC1/SC22/WG14/www/docs/n3029.htm

```c
enum a {
a0 = 0xFFFFFFFFFFFFFFFFULL
};

static_assert(_Generic(a0,
unsigned long long: 0,
int: 1,
default: 2 == 0));
```
The type of the enum must be adjusted.
### C23 constexpr
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3018.htm
Expand Down Expand Up @@ -1150,7 +1206,7 @@ https://open-std.org/JTC1/SC22/WG14/www/docs/n2448.pdf

### C23 [[unsequenced]] and [[reproducible]]

Parsed.
//TODO

https://open-std.org/JTC1/SC22/WG14/www/docs/n2956.htm

Expand All @@ -1174,12 +1230,14 @@ Conversion < C23 not defined. Maybe a define.
#endif

```

Its is implemented in cake.
Conversion < C23 not defined. Maybe a define.
Conversion < C23 not defined.


### C23 \#warning

When compiling to versions < 23 it is commented out.
When compiling to versions < 23 the line is commented out.

```c
int main()
Expand All @@ -1201,6 +1259,8 @@ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2686.pdf

### C23 \#embed

Partially implemented.

```c
#include <stdio.h>

Expand Down Expand Up @@ -1392,12 +1452,10 @@ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3038.htm

### C23 Variably-modified (VM) types


https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2778.pdf

## C2Y Transformations


### Extension - defer

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3199.htm
Expand Down
2 changes: 1 addition & 1 deletion src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int main()
" /out:cake.exe");

//Runs cake on its own source
execute_cmd("cake.exe -sarif -sarif-path \"../vc/.sarif\" -ownership=enable -Wstyle -fanalyzer -Wno-unused-parameter -Wno-unused-variable " CAKE_HEADER_FILES CAKE_SOURCE_FILES);
execute_cmd("cake.exe -sarif -sarif-path \"../vc/.sarif\" -ownership=enable -Wstyle -Wno-unused-parameter -Wno-unused-variable " CAKE_HEADER_FILES CAKE_SOURCE_FILES);


#endif
Expand Down
17 changes: 9 additions & 8 deletions src/cakeconfig.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//This was generated by running cake -autoconfig
This file was generated reading the output of
//echo | gcc -v -E - 2>&1

#pragma dir "/usr/lib/gcc/x86_64-linux-gnu/11/include"
#pragma dir "/usr/local/include"
#pragma dir "/usr/include/x86_64-linux-gnu"
#pragma dir "/usr/include"

//This file was generated reading the variable INCLUDE inside Visual Studio Command Prompt.
//echo %INCLUDE%
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.40.33807/include/"
#pragma dir "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include/"
#pragma dir "C:/Program Files (x86)/Windows Kits/10/include/10.0.22621.0/ucrt/"
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.22621.0//um/"
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.22621.0//shared/"
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.22621.0//winrt/"
#pragma dir "C:/Program Files (x86)/Windows Kits/10//include/10.0.22621.0//cppwinrt/"
2 changes: 2 additions & 0 deletions src/constant_value.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma safety enable

#include "constant_value.h"
#include <limits.h>
#include <stdio.h>
Expand Down
27 changes: 23 additions & 4 deletions src/expressions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://github.com/thradams/cake
*/

#pragma safety enable
//#pragma safety enable

#include "ownership.h"
#include <limits.h>
Expand Down Expand Up @@ -599,12 +599,12 @@ struct expression* _Owner _Opt character_constant_expression(struct parser_ctx*

if (*p != '\'')
{
compiler_diagnostic_message(W_MULTICHAR_ERROR, ctx, ctx->current, NULL, "Unicode character literals may not contain multiple characters.");
compiler_diagnostic_message(C_MULTICHAR_ERROR, ctx, ctx->current, NULL, "Unicode character literals may not contain multiple characters.");
}

if (c > 0x80)
{
compiler_diagnostic_message(W_MULTICHAR_ERROR, ctx, ctx->current, NULL, "Character too large for enclosing character literal type.");
compiler_diagnostic_message(C_CHARACTER_NOT_ENCODABLE_IN_A_SINGLE_CODE_UNIT, ctx, ctx->current, NULL, "character not encodable in a single code unit.");
}

p_expression_node->constant_value = constant_value_make_wchar_t((wchar_t)c);//, ctx->evaluation_is_disabled);
Expand Down Expand Up @@ -3573,14 +3573,31 @@ struct expression* _Owner _Opt multiplicative_expression(struct parser_ctx* ctx)
}

new_expression->first_token = ctx->current;
enum token_type op = ctx->current->type;
const enum token_type op = ctx->current->type;
parser_match(ctx);
if (ctx->current == NULL)
{
expression_delete(new_expression);
throw;
}

switch (op)
{
case '*':
new_expression->expression_type = MULTIPLICATIVE_EXPRESSION_MULT;
break;
case '/':
new_expression->expression_type = MULTIPLICATIVE_EXPRESSION_DIV;
break;
case '%':
new_expression->expression_type = MULTIPLICATIVE_EXPRESSION_MOD;
break;
default:
assert(false);
break;
}


new_expression->left = p_expression_node;
p_expression_node = NULL; // MOVED

Expand Down Expand Up @@ -4656,6 +4673,8 @@ struct expression* _Owner _Opt assignment_expression(struct parser_ctx* ctx)
if (p_expression_node == NULL)
throw;

assert(p_expression_node->expression_type != EXPRESSION_TYPE_INVALID);

while (ctx->current != NULL &&
(ctx->current->type == '=' ||
ctx->current->type == '*=' ||
Expand Down
22 changes: 19 additions & 3 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@


//C23 u8 character prefix
//https://open-std.org/JTC1/SC22/WG14/www/docs/n2418.pdf

static_assert(u8'÷' == 0xF7);
#pragma cake diagnostic check "-E1360"

static_assert(u8'ab');
#pragma cake diagnostic check "-E1370"

static_assert(u8'¡' != 0);
#pragma cake diagnostic check "-E1360"


static_assert(u8'~' == '~');
static_assert(_Generic(typeof(u8'~'), unsigned char : 1 , default: 0));

int main(){
int i = L'🍌';
}
unsigned char c = u8'~';
}
12 changes: 12 additions & 0 deletions src/flow_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3396,6 +3396,18 @@ struct flow_object* _Opt expression_get_object(struct flow_visit_ctx* ctx, stru
}
return p_object;
}
else if (p_expression->expression_type == UNARY_EXPRESSION_NEG ||
p_expression->expression_type == UNARY_EXPRESSION_PLUS)
{
struct flow_object* _Opt p_obj_right = expression_get_object(ctx, p_expression->right, nullable_enabled);
struct flow_object* _Opt p_object = make_object(ctx, &p_expression->type, NULL, p_expression);
if (p_object && p_obj_right)
{
p_object->current.state = p_obj_right->current.state;
}

return p_object;
}
//
else
{
Expand Down
Loading

0 comments on commit 240134e

Please sign in to comment.