- Timestamp:
- Aug 31, 2021, 4:34:22 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- dd698b4
- Parents:
- 0660962c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r0660962c r4a1bc44 12 12 static vtable(Missing_Config_Entries) Missing_Config_Entries_vt; 13 13 14 void ?{}( Missing_Config_Entries &this, unsigned int num_missing ) {14 [ void ] ?{}( & Missing_Config_Entries this, unsigned int num_missing ) { 15 15 this.virtual_table = &Missing_Config_Entries_vt; 16 16 this.num_missing = num_missing; 17 17 } 18 18 19 void msg( Missing_Config_Entries *ex ) {19 [ void ] msg( * Missing_Config_Entries ex ) { 20 20 serr | nlOff; 21 21 serr | "The config file is missing " | ex->num_missing; … … 31 31 static vtable(Parse_Failure) Parse_Failure_vt; 32 32 33 void ?{}( Parse_Failure & this, char * failed_key, char *failed_value ) {33 [ void ] ?{}( & Parse_Failure this, [] char failed_key, [] char failed_value ) { 34 34 this.virtual_table = &Parse_Failure_vt; 35 35 … … 40 40 } 41 41 42 void ^?{}( Parse_Failure &this ) with ( this ) {42 [ void ] ^?{}( & Parse_Failure this ) with ( this ) { 43 43 free( failed_key ); 44 44 free( failed_value ); 45 45 } 46 46 47 void msg( Parse_Failure *ex ) {47 [ void ] msg( * Parse_Failure ex ) { 48 48 serr | "Config entry " | ex->failed_key | " could not be parsed. It has value " | ex->failed_value | "."; 49 49 } … … 52 52 static vtable(Validation_Failure) Validation_Failure_vt; 53 53 54 void ?{}( Validation_Failure & this, char * failed_key, char *failed_value ) {54 [ void ] ?{}( & Validation_Failure this, [] char failed_key, [] char failed_value ) { 55 55 this.virtual_table = &Validation_Failure_vt; 56 56 … … 61 61 } 62 62 63 void ^?{}( Validation_Failure &this ) with ( this ) {63 [ void ] ^?{}( & Validation_Failure this ) with ( this ) { 64 64 free( failed_key ); 65 65 free( failed_value ); 66 66 } 67 67 68 void msg( Validation_Failure *ex ) {68 [ void ] msg( * Validation_Failure ex ) { 69 69 serr | "Config entry " | ex->failed_key | " could not be validated. It has value " | ex->failed_value | "."; 70 70 } … … 77 77 struct KVPairs { 78 78 size_t size, max_size; 79 * [ char *, char *] data;79 * [ * char, * char ] data; 80 80 }; 81 81 82 void ?{}( KVPairs &kvp ) with ( kvp ) { // default constructor82 [ void ] ?{}( & KVPairs kvp ) with ( kvp ) { // default constructor 83 83 size = 0; max_size = 0; data = 0p; 84 84 } 85 85 86 void ?{}( KVPairs &kvp, size_t size ) { // initialization86 [ void ] ?{}( & KVPairs kvp, size_t size ) { // initialization 87 87 kvp.[ size, max_size ] = [ 0, size ]; 88 88 kvp.data = alloc( size ); 89 89 } 90 90 91 void ^?{}( KVPairs &kvp ) with ( kvp ) { // destructor91 [ void ] ^?{}( & KVPairs kvp ) with ( kvp ) { // destructor 92 92 for ( i; size ) free( data[i] ); 93 93 free( data ); … … 95 95 } 96 96 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 ) { 98 98 if ( max_size == 0 ) { 99 99 max_size = 1; … … 104 104 } 105 105 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 ); 110 110 ++size; 111 111 } 112 112 113 113 114 bool comments( ifstream & in, char name[]) {114 [ bool ] comments( & ifstream in, [] char name ) { 115 115 while () { 116 116 in | name; … … 122 122 123 123 // 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 ) { 125 125 // TODO: Change this to a unique_ptr when we fully support returning them (move semantics) 126 126 * KVPairs kv_pairs = new( num_entries ); … … 130 130 open( in, config_file ); // open the configuration file for input 131 131 132 char key[64];133 char value[256];132 [64] char key; 133 [256] char value; 134 134 135 135 while () { // parameter names can appear in any order … … 154 154 155 155 // 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 ) { 157 157 * KVPairs kv_pairs = 0p; 158 158 choose ( format ) { … … 172 172 // Parse the data 173 173 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 ); 175 175 delete( kv_pairs ); 176 176 throw *ex; … … 179 179 // Validate the data 180 180 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 ); 182 182 delete( kv_pairs ); 183 183 throw *ex; … … 203 203 204 204 forall(T | Relational( T )) 205 bool is_nonnegative( T &value ) {205 [ bool ] is_nonnegative( & T value ) { 206 206 T zero_val = 0; 207 207 return value >= zero_val; … … 209 209 210 210 forall(T | Relational( T )) 211 bool is_positive( T &value ) {211 [ bool ] is_positive( & T value ) { 212 212 T zero_val = 0; 213 213 return value > zero_val; … … 215 215 216 216 forall(T | Relational( T )) 217 bool is_nonpositive( T &value ) {217 [ bool ] is_nonpositive( & T value ) { 218 218 T zero_val = 0; 219 219 return value <= zero_val; … … 221 221 222 222 forall(T | Relational( T )) 223 bool is_negative( T &value ) {223 [ bool ] is_negative( & T value ) { 224 224 T zero_val = 0; 225 225 return value < zero_val;
Note: See TracChangeset
for help on using the changeset viewer.