Changeset 4a1bc44


Ignore:
Timestamp:
Aug 31, 2021, 4:34:22 PM (3 years ago)
Author:
Jacob Prud'homme <jafprudhomme@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
dd698b4
Parents:
0660962c
Message:

Used in-English-order variable declaration syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseconfig.cfa

    r0660962c r4a1bc44  
    1212static vtable(Missing_Config_Entries) Missing_Config_Entries_vt;
    1313
    14 void ?{}( Missing_Config_Entries & this, unsigned int num_missing ) {
     14[ void ] ?{}( & Missing_Config_Entries this, unsigned int num_missing ) {
    1515        this.virtual_table = &Missing_Config_Entries_vt;
    1616        this.num_missing = num_missing;
    1717}
    1818
    19 void msg( Missing_Config_Entries * ex ) {
     19[ void ] msg( * Missing_Config_Entries ex ) {
    2020        serr | nlOff;
    2121        serr | "The config file is missing " | ex->num_missing;
     
    3131static vtable(Parse_Failure) Parse_Failure_vt;
    3232
    33 void ?{}( Parse_Failure & this, char * failed_key, char * failed_value ) {
     33[ void ] ?{}( & Parse_Failure this, [] char failed_key, [] char failed_value ) {
    3434        this.virtual_table = &Parse_Failure_vt;
    3535
     
    4040}
    4141
    42 void ^?{}( Parse_Failure & this ) with ( this ) {
     42[ void ] ^?{}( & Parse_Failure this ) with ( this ) {
    4343        free( failed_key );
    4444        free( failed_value );
    4545}
    4646
    47 void msg( Parse_Failure * ex ) {
     47[ void ] msg( * Parse_Failure ex ) {
    4848        serr | "Config entry " | ex->failed_key | " could not be parsed. It has value " | ex->failed_value | ".";
    4949}
     
    5252static vtable(Validation_Failure) Validation_Failure_vt;
    5353
    54 void ?{}( Validation_Failure & this, char * failed_key, char * failed_value ) {
     54[ void ] ?{}( & Validation_Failure this, [] char failed_key, [] char failed_value ) {
    5555        this.virtual_table = &Validation_Failure_vt;
    5656
     
    6161}
    6262
    63 void ^?{}( Validation_Failure & this ) with ( this ) {
     63[ void ] ^?{}( & Validation_Failure this ) with ( this ) {
    6464        free( failed_key );
    6565        free( failed_value );
    6666}
    6767
    68 void msg( Validation_Failure * ex ) {
     68[ void ] msg( * Validation_Failure ex ) {
    6969        serr | "Config entry " | ex->failed_key | " could not be validated. It has value " | ex->failed_value | ".";
    7070}
     
    7777struct KVPairs {
    7878        size_t size, max_size;
    79         * [ char *, char * ] data;
     79        * [ * char, * char ] data;
    8080};
    8181
    82 void ?{}( KVPairs & kvp ) with ( kvp ) {                                // default constructor
     82[ void ] ?{}( & KVPairs kvp ) with ( kvp ) {                            // default constructor
    8383        size = 0; max_size = 0; data = 0p;
    8484}
    8585
    86 void ?{}( KVPairs & kvp, size_t size ) {                                // initialization
     86[ void ] ?{}( & KVPairs kvp, size_t size ) {                            // initialization
    8787        kvp.[ size, max_size ] = [ 0, size ];
    8888        kvp.data = alloc( size );
    8989}
    9090
    91 void ^?{}( KVPairs & kvp ) with ( kvp ) {                               // destructor
     91[ void ] ^?{}( & KVPairs kvp ) with ( kvp ) {                           // destructor
    9292        for ( i; size ) free( data[i] );
    9393        free( data );
     
    9595}
    9696
    97 void add_kv_pair( KVPairs & kv_pairs, char * k, char * v ) with ( kv_pairs ) {
     97[ void ] add_kv_pair( & KVPairs kv_pairs, [] char key, [] char value ) with ( kv_pairs ) {
    9898        if ( max_size == 0 ) {
    9999                max_size = 1;
     
    104104        }
    105105
    106         data[size].0 = alloc( strlen( k ) );
    107         data[size].1 = alloc( strlen( v ) );
    108         strcpy( data[size].0, k );
    109         strcpy( data[size].1, v );
     106        data[size].0 = alloc( strlen( key ) );
     107        data[size].1 = alloc( strlen( value ) );
     108        strcpy( data[size].0, key );
     109        strcpy( data[size].1, value );
    110110        ++size;
    111111}
    112112
    113113
    114 bool comments( ifstream & in, char name[] ) {
     114[ bool ] comments( & ifstream in, [] char name ) {
    115115        while () {
    116116                in | name;
     
    122122
    123123// Parse configuration from a file formatted in tabular (CS 343) style
    124 KVPairs * parse_tabular_config_format( const char * config_file, size_t num_entries ) {
     124[ * KVPairs ] parse_tabular_config_format( * const char config_file, size_t num_entries ) {
    125125        // TODO: Change this to a unique_ptr when we fully support returning them (move semantics)
    126126        * KVPairs kv_pairs = new( num_entries );
     
    130130                open( in, config_file );                                        // open the configuration file for input
    131131
    132                 char key[64];
    133                 char value[256];
     132                [64] char key;
     133                [256] char value;
    134134
    135135                while () {                                                                      // parameter names can appear in any order
     
    154154
    155155// Parse configuration values from intermediate format
    156 void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format ) {
     156[ void ] parse_config( [] const char config_file, [] config_entry entries, size_t num_entries, config_format format ) {
    157157        * KVPairs kv_pairs = 0p;
    158158        choose ( format ) {
     
    172172                        // Parse the data
    173173                        if ( !entries[j].parse( src_value, entries[j].variable ) ) {
    174                                 Parse_Failure * ex = new( src_key, src_value );
     174                                * Parse_Failure ex = new( src_key, src_value );
    175175                                delete( kv_pairs );
    176176                                throw *ex;
     
    179179                        // Validate the data
    180180                        if ( !entries[j].validate( entries[j].variable ) ) {
    181                                 Validation_Failure * ex = new( src_key, src_value );
     181                                * Validation_Failure ex = new( src_key, src_value );
    182182                                delete( kv_pairs );
    183183                                throw *ex;
     
    203203
    204204forall(T | Relational( T ))
    205 bool is_nonnegative( T & value ) {
     205[ bool ] is_nonnegative( & T value ) {
    206206        T zero_val = 0;
    207207        return value >= zero_val;
     
    209209
    210210forall(T | Relational( T ))
    211 bool is_positive( T & value ) {
     211[ bool ] is_positive( & T value ) {
    212212        T zero_val = 0;
    213213        return value > zero_val;
     
    215215
    216216forall(T | Relational( T ))
    217 bool is_nonpositive( T & value ) {
     217[ bool ] is_nonpositive( & T value ) {
    218218        T zero_val = 0;
    219219        return value <= zero_val;
     
    221221
    222222forall(T | Relational( T ))
    223 bool is_negative( T & value ) {
     223[ bool ] is_negative( & T value ) {
    224224        T zero_val = 0;
    225225        return value < zero_val;
Note: See TracChangeset for help on using the changeset viewer.