Changeset aca65621


Ignore:
Timestamp:
Jul 12, 2017, 4:40:02 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
0698aa1
Parents:
469f709
Message:

Convert several library files to use references

Location:
src/libcfa
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/maybe

    r469f709 raca65621  
    2929
    3030forall(otype T)
    31 void ?{}(maybe(T) * this);
     31void ?{}(maybe(T) & this);
    3232
    3333forall(otype T)
    34 void ?{}(maybe(T) * this, T value);
     34void ?{}(maybe(T) & this, T value);
    3535
    3636forall(otype T)
    37 void ?{}(maybe(T) * this, maybe(T) other);
     37void ?{}(maybe(T) & this, maybe(T) other);
    3838
    3939forall(otype T)
    40 void ^?{}(maybe(T) * this);
     40void ^?{}(maybe(T) & this);
    4141
    4242forall(otype T)
    43 maybe(T) ?=?(maybe(T) * this, maybe(T) other);
     43maybe(T) ?=?(maybe(T) & this, maybe(T) other);
    4444
    4545forall(otype T)
  • src/libcfa/containers/maybe.c

    r469f709 raca65621  
    1919
    2020forall(otype T)
    21 void ?{}(maybe(T) * this) {
    22         this->has_value = false;
     21void ?{}(maybe(T) & this) {
     22        this.has_value = false;
    2323}
    2424
    2525forall(otype T)
    26 void ?{}(maybe(T) * this, T value) {
    27         this->has_value = true;
    28         (&this->value){value};
     26void ?{}(maybe(T) & this, T value) {
     27        this.has_value = true;
     28        (this.value){value};
    2929}
    3030
    3131forall(otype T)
    32 void ?{}(maybe(T) * this, maybe(T) other) {
    33         this->has_value = other.has_value;
     32void ?{}(maybe(T) & this, maybe(T) other) {
     33        this.has_value = other.has_value;
    3434        if (other.has_value) {
    35                 (&this->value){other.value};
     35                (this.value){other.value};
    3636        }
    3737}
    3838
    3939forall(otype T)
    40 maybe(T) ?=?(maybe(T) * this, maybe(T) that) {
    41         if (this->has_value & that.has_value) {
    42                 this->value = that.value;
    43         } else if (this->has_value) {
    44                 ^(&this->value){};
    45                 this->has_value = false;
     40maybe(T) ?=?(maybe(T) & this, maybe(T) that) {
     41        if (this.has_value & that.has_value) {
     42                this.value = that.value;
     43        } else if (this.has_value) {
     44                ^(this.value){};
     45                this.has_value = false;
    4646        } else if (that.has_value) {
    47                 this->has_value = true;
    48                 (&this->value){that.value};
     47                this.has_value = true;
     48                (this.value){that.value};
    4949        }
     50        return this;
    5051}
    5152
    5253forall(otype T)
    53 void ^?{}(maybe(T) * this) {
    54         if (this->has_value) {
    55                 ^(&this->value){};
     54void ^?{}(maybe(T) & this) {
     55        if (this.has_value) {
     56                ^(this.value){};
    5657        }
    5758}
     
    8990        } else {
    9091                this->has_value = true;
    91                 (&this->value){value};
     92                (this->value){value};
    9293        }
    9394}
     
    9798        if (this->has_value) {
    9899                this->has_value = false;
    99                 ^(&this->value){};
     100                ^(this->value){};
    100101        }
    101102}
  • src/libcfa/containers/vector

    r469f709 raca65621  
    3131
    3232forall(otype T)
    33 void ?{}(heap_allocator(T)* this);
     33void ?{}(heap_allocator(T)& this);
    3434
    3535forall(otype T)
    36 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs);
     36void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs);
    3737
    3838forall(otype T)
    39 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs);
     39heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs);
    4040
    4141forall(otype T)
    42 void ^?{}(heap_allocator(T)* this);
     42void ^?{}(heap_allocator(T)& this);
    4343
    4444forall(otype T)
     
    6565//Initialization
    6666forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    67 void ?{}(vector(T, allocator_t)* this);
     67void ?{}(vector(T, allocator_t)& this);
    6868
    6969forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    70 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     70void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7171
    7272forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    73 vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs);
     73vector(T, allocator_t) ?=?(vector(T, allocator_t)& this, vector(T, allocator_t) rhs);
    7474
    7575forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    76 void ^?{}(vector(T, allocator_t)* this);
     76void ^?{}(vector(T, allocator_t)& this);
    7777
    7878forall(otype T, otype allocator_t = heap_allocator(T) | allocator_c(T, allocator_t))
  • src/libcfa/containers/vector.c

    r469f709 raca65621  
    2424//Initialization
    2525forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    26 void ?{}(vector(T, allocator_t)* this)
     26void ?{}(vector(T, allocator_t)& this)
    2727{
    28         (&this->storage){};
    29         this->size = 0;
     28        (this.storage){};
     29        this.size = 0;
    3030}
    3131
    3232forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs)
     33void ?{}(vector(T, allocator_t)& this, vector(T, allocator_t) rhs)
    3434{
    35         (&this->storage){ rhs.storage };
    36         copy_internal(this, &rhs);
     35        (this.storage){ rhs.storage };
     36        copy_internal(&this, &rhs);
    3737}
    3838
     
    4646
    4747forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
    48 void ^?{}(vector(T, allocator_t)* this)
     48void ^?{}(vector(T, allocator_t)& this)
    4949{
    50         clear(this);
    51         ^(&this->storage){};
     50        clear(&this);
     51        ^(this.storage){};
    5252}
    5353
     
    6666{
    6767        this->size--;
    68         ^(&data(&this->storage)[this->size]){};
     68        ^(data(&this->storage)[this->size]){};
    6969}
    7070
     
    7474        for(size_t i = 0; i < this->size; i++)
    7575        {
    76                 ^(&data(&this->storage)[this->size]){};
     76                ^(data(&this->storage)[this->size]){};
    7777        }
    7878        this->size = 0;
     
    8787        this->size = other->size;
    8888        for(size_t i = 0; i < this->size; i++) {
    89                 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
     89                (data(&this->storage)[this->size]){ data(&other->storage)[other->size] };
    9090        }
    9191}
     
    9494//Allocator
    9595forall(otype T)
    96 void ?{}(heap_allocator(T)* this)
     96void ?{}(heap_allocator(T)& this)
    9797{
    98         this->storage = 0;
    99         this->capacity = 0;
     98        this.storage = 0;
     99        this.capacity = 0;
    100100}
    101101
    102102forall(otype T)
    103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs)
     103void ?{}(heap_allocator(T)& this, heap_allocator(T) rhs)
    104104{
    105         this->capacity = rhs.capacity;
    106         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
     105        this.capacity = rhs.capacity;
     106        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
    107107}
    108108
    109109forall(otype T)
    110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs)
     110heap_allocator(T) ?=?(heap_allocator(T)& this, heap_allocator(T) rhs)
    111111{
    112         this->capacity = rhs.capacity;
    113         this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
    114         return *this;
     112        this.capacity = rhs.capacity;
     113        this.storage = (T*)realloc((void*)this.storage, this.capacity * sizeof(T));
     114        return this;
    115115}
    116116
    117117forall(otype T)
    118 void ^?{}(heap_allocator(T)* this)
     118void ^?{}(heap_allocator(T)& this)
    119119{
    120         free(this->storage);
     120        free(this.storage);
    121121}
    122122
  • src/libcfa/interpose.c

    r469f709 raca65621  
    1010// Author           : Thierry Delisle
    1111// Created On       : Wed Mar 29 16:10:31 2017
    12 // Last Modified By : 
    13 // Last Modified On : 
     12// Last Modified By :
     13// Last Modified On :
    1414// Update Count     : 0
    1515//
     
    5050
    5151        union { generic_fptr_t fptr; void* ptr; } originalFunc;
    52        
     52
    5353        #if defined( _GNU_SOURCE )
    5454                if ( version ) {
     
    6060                originalFunc.ptr = dlsym( library, symbol );
    6161        #endif // _GNU_SOURCE
    62        
     62
    6363        error = dlerror();
    64         if ( error ) abortf( "interpose_symbol : internal error, %s\n", error ); 
     64        if ( error ) abortf( "interpose_symbol : internal error, %s\n", error );
    6565
    6666        return originalFunc.fptr;
     
    7575forall(dtype T)
    7676static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) {
    77         union { 
     77        union {
    7878                generic_fptr_t gp;
    79                 T* tp; 
     79                T* tp;
    8080        } u;
    8181
  • src/libcfa/stdlib

    r469f709 raca65621  
    135135
    136136// allocation/deallocation and constructor/destructor, non-array types
    137 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
    138 forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
    139 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
     137forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );
     138forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr );
     139forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    140140
    141141// allocation/deallocation and constructor/destructor, array types
    142 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
    143 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
    144 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
     142forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );
     143forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );
     144forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
    145145
    146146//---------------------------------------
     
    201201double abs( double _Complex );
    202202long double abs( long double _Complex );
    203 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
     203forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
    204204T abs( T );
    205205
  • src/libcfa/stdlib.c

    r469f709 raca65621  
    3434        if ( nlen > olen ) {                                                            // larger ?
    3535                memset( nptr + olen, (int)fill, nlen - olen );  // initialize added storage
    36         } // 
     36        } //
    3737    return (T *)nptr;
    3838} // alloc
    3939
    4040// allocation/deallocation and constructor/destructor, non-array types
    41 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     41forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    4242T * new( Params p ) {
    4343        return (malloc()){ p };                                                         // run constructor
    4444} // new
    4545
    46 forall( dtype T | { void ^?{}( T * ); } )
     46forall( dtype T | { void ^?{}( T & ); } )
    4747void delete( T * ptr ) {
    4848        if ( ptr ) {                                                                            // ignore null
     
    5252} // delete
    5353
    54 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
     54forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } )
    5555void delete( T * ptr, Params rest ) {
    5656        if ( ptr ) {                                                                            // ignore null
     
    6363
    6464// allocation/deallocation and constructor/destructor, array types
    65 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     65forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    6666T * anew( size_t dim, Params p ) {
    6767        T *arr = alloc( dim );
     
    7272} // anew
    7373
    74 forall( dtype T | sized(T) | { void ^?{}( T * ); } )
     74forall( dtype T | sized(T) | { void ^?{}( T & ); } )
    7575void adelete( size_t dim, T arr[] ) {
    7676        if ( arr ) {                                                                            // ignore null
     
    8282} // adelete
    8383
    84 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     84forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    8585void adelete( size_t dim, T arr[], Params rest ) {
    8686        if ( arr ) {                                                                            // ignore null
Note: See TracChangeset for help on using the changeset viewer.