source: tests/avltree/avl1.cfa @ 92bfda0

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 92bfda0 was b81fd95, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Fix bug where pointer and reference types allow unsound initialization and return. Fixes #189

There are two instances of the same basic change, which is using conversionCost instead of castCost for resolving...
A: an InitExpr?, always; affects variable initializations
B: a CastExpr?, for type-system-generated casts only; affects function returns

Changing the behaviour of the typechecker on initialization (do A) and cast (do B):
src/ResolvExpr/AlternativeFinder.cc
src/SynTree/Expression.h
testsinit1.*

Making type of string literal consistent with how C defines it (accommodate A):
src/Parser/ExpressionNode.cc

Making type system happy with incumbent use of void* (accommodate A):
libcfa/src/concurrency/kernel.cfa
libcfa/src/containers/list.hfa
tests/bugs/66.cfa
tests/avltree/avl1.cfa
tests/concurrent/signal/block.cfa
tests/searchsort.cfa

Making type system happy with incumbent plan-9 downcast (accommodate B):
libcfa/src/containers/list.hfa

Fixing previously incorrect constness of declarations (accommodate A):
tests/exceptions/defaults.cfa
libcfa/src/iostream.hfa

Fixing previously incorrect isGenerated classification of casts that desugaring introduces (accommodate B):
src/Concurrency/Keywords.cc
src/Concurrency/Waitfor.cc

Working around trac #207 (revealed by A):
tests/io2.cfa

Working around trac #208 (speculatively created by B):
libcfa/src/bits/locks.hfa
libcfa/src/concurrency/preemption.cfa

Misc:
tests/exceptions/conditional.cfa (accommodate A)

a _msg function for an exception was declared with wrong return type, so it was not compatible for assignment into the vtable instance

libcfa/src/stdlib.hfa

the compiler now prohibits a prior attempt to call a nonexistent realloc overload; calling alloc_align in its place

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include "avl.h"
2// #include "cwrap.h"
3#include <stdlib.hfa>
4
5forall(otype K | Comparable(K), otype V)
6void ?{}(tree(K, V) &t, K key, V value){
7  (t.key) { key };
8  (t.value) { value };
9  t.parent = NULL;
10  t.left = NULL;
11  t.right = NULL;
12  t.balance = 0;
13}
14
15forall(otype K, otype V)
16void ^?{}(tree(K, V) & t){
17  delete(t.left);
18  delete(t.right);
19  ^(t.key){};
20  ^(t.value){};
21}
22
23forall(otype K | Comparable(K), otype V)
24tree(K, V) * create(K key, V value) {
25  // infinite loop trying to resolve ... t = malloc();
26  tree(K, V) * t = ( tree(K, V) * ) malloc(sizeof(tree(K,V)));
27  (*t){ key, value };
28  return t;
29}
30
31// // Helper function to print trees
32// forall(otype K | Comparable(K), otype V)
33// void printTree(tree * t, int level){
34//   if (empty(t)){
35//     return;
36//   }
37
38//   printTree(t->left, level+1);
39//   printf("key: %d, value: %s, level: %d\n", t->key, t->value, level);
40//   printTree(t->right, level+1);
41// }
42
43// // inorder traversal of t
44// // prints each key, followed by the value
45// forall(otype K | Comparable(K), otype V)
46// void printTree(tree(K, V) * t){
47//     printTree(t, 0);
48// }
Note: See TracBrowser for help on using the repository browser.