| 56 | | **Do you need dependent types?** I.e., can parameters to some of the types be arbitrary expressions, or do they have to be constants? |
| 57 | | |
| 58 | | **Do you need typedefs?** |
| 59 | | |
| 60 | | Question about types. In the following, where in the state is the length of the array field stored? |
| 61 | | |
| 62 | | {{{ |
| 63 | | #include <stdio.h> |
| 64 | | int n=10; |
| 65 | | int main() { |
| 66 | | struct S {int a[n];}; |
| 67 | | struct S x1; |
| 68 | | n=20; |
| 69 | | struct S x2; |
| 70 | | printf("%ld, %ld\n", sizeof(x1), sizeof(x2)); |
| 71 | | x2.a[10]=1; // error caught by CIVL |
| 72 | | fflush(stdout); |
| 73 | | } |
| 74 | | }}} |
| 75 | | |
| 76 | | |
| | 56 | The types are: |
| | 57 | |
| | 58 | * `$dytype` : dynamic type: a value of this type represents a "dynamic type", a type which is created at runtime. For example when the type name `int[n]` is evaluated, the result is a value of type `$dytype`. |
| 110 | | When are two types equal? |
| 111 | | |
| 112 | | What are two types compatible? |
| 113 | | |
| 114 | | == Type names == |
| 115 | | |
| 116 | | **Do we need another syntactic category for code that specifies a dynamic type**, for example |
| 117 | | * `int[n*m+3]`. |
| 118 | | |
| 119 | | This can be used in `sizeof`, ... |
| 120 | | |
| 121 | | **Do we need to clearly distinguish dynamic type names and static type names?** |
| | 91 | Type names: |
| | 92 | |
| | 93 | A type name is a syntactic element that names a type, together with possibly more information that makes the type "complete". All of the names listed above are type names, such as `int[]`, but so is `int[n*m]`. |
| | 94 | |
| | 95 | The expression `$dytypeof(typeName)` takes a type name and returns a value of type `$dytype` representing that type. |
| | 96 | |
| | 97 | The expression `$init_val(d)` takes a `$dytype` value `d` and returns the initial value for an object of type `d`. |
| | 98 | |
| | 99 | Example: |
| | 100 | {{{ |
| | 101 | // type definitions |
| | 102 | struct S { int a[];} |
| | 103 | |
| | 104 | // variable decls |
| | 105 | int n; |
| | 106 | $dytype _S; |
| | 107 | struct S x1; |
| | 108 | struct S x2; |
| | 109 | |
| | 110 | // statements (leaving out the chooses and whens for brevity) |
| | 111 | n=10; |
| | 112 | _S=$dytypeof(struct S { int a[n]; }; |
| | 113 | x1=$init_val(_S); |
| | 114 | n=20; |
| | 115 | x2=$init_val(_S); |
| | 116 | }}} |
| | 117 | |
| | 118 | is semantically equivalent to the C code |
| | 119 | |
| | 120 | {{{ |
| | 121 | int n = 10; |
| | 122 | struct S { int a[n]; }; |
| | 123 | struct S x1; |
| | 124 | n=20; |
| | 125 | struct S x2; |
| | 126 | }}} |
| 187 | | * `$initial_value(T; e1,...,en)` |
| 188 | | * e1,...,en are expressions of integer type |
| 189 | | * the type of this expression is T[e1]...[en] |
| 190 | | * array value with base type `T` and lengths e1,...,en |
| 191 | | * **do we need this for more types?** E.g., structs of arrays of structs of arrays of ...? |
| 192 | | * `$typeof(...)`: what is this for? |