Changes in / [262a864:9a01745]
- Files:
-
- 5 edited
-
doc/proposals/enums.md (modified) (6 diffs)
-
src/CodeGen/OperatorTable.cpp (modified) (1 diff)
-
src/Validate/ReplaceTypedef.cpp (modified) (2 diffs)
-
tests/.expect/attributes.arm64.txt (modified) (1 diff)
-
tests/.expect/attributes.x86.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/enums.md
r262a864 r9a01745 8 8 -------------- 9 9 Because Cforall enumerations are encoded using their position, it can be 10 difficult to give them a stable encoding, this is important in seperate 11 compilation. 10 difficult to give them a stable encoding. The 12 11 13 12 The example (provided by Gregor Richards), is a system header that defines … … 42 41 Arrays that use an enumeration as their index. The entire enumeration type 43 42 (instead of a subset of int) is used in the index operation. 44 45 ```cfa46 enum() Colour {47 Red,48 Violet,49 Blue,50 Green51 Yellow,52 Orange,53 };54 55 // Declare an array with an index of an enumeration:56 int jarsOfPaint[Colour] = {0};57 58 // Index the array:59 printf("I have %d jars of blue paint.\n", jarsOfPaint[Blue]);60 jarsOfPaint[Green] = 3;61 jarsOfPaint[Red] += 1;62 63 // Use the function for higher order programming:64 int (*lookup)(int collection[Colour], Colour key) = ?[?];65 66 // ERROR! Use the enumeration index for safety:67 jarsOfPaint[0] = 0;68 ```69 43 70 44 Although described differently, this is actually a generalization of typed … … 106 80 Or one of the new safer Cforall arrays, as the features could be combined. 107 81 108 (Previously, a com bined declaration to declare both an enumeration and82 (Previously, a compined declaration to declare both an enumeration and 109 83 an enumerated array was proposed. That only covers the simple case that 110 84 typed enumerations already cover.) … … 116 90 generalized to work with the other features of ranges, such as going over 117 91 just part of the enumeration (see Ranges in doc/proposals/iterators.md). 118 119 This will work best with some alias labels that mark out the beginning of120 ranges. That is the ranges within the enum will often have to be an121 intended part of the interface.122 123 ```cfa124 for ( kind : DataKind.BeginIntegers +~ DataKind.EndIntegers ) { ... }125 ```126 127 Writing the declaration is a bit tricker, because of the lack of aliasing,128 but this should echo a common C pattern.129 92 130 93 Flag Set Enumerations … … 146 109 Vertical = Up | Down, 147 110 }; 148 ```149 150 Some example usages:151 ```cfa152 // If it is exactly Up/Upwards, then set exactly Down153 if ( Upwards == dirs ) {154 dirs = Down155 // Otherwise, if a vertical is set, unset them:156 } else if ( Vertical & dirs ) {157 dirs = dirs & ~Vertical;158 // Otherwise, if any direction is set then also set Up:159 } else if ( dirs ) {160 dirs |= Up;161 }162 111 ``` 163 112 … … 183 132 184 133 Note: Scoping rules are also waiting on the namespacing and module system. 185 186 Feature (and Storage) Control187 -----------------------------188 Right now features are very coursely grouped. You have exactly three options189 for your enumeration. However since there are more than two features this190 means there are some combinations you cannot have.191 192 For instance, labels (which are mostly useful for generating debug output)193 are not available for C style enum, but for both of the new Cforall enums,194 opaque and typed. However, there is no innate connection between the195 additional type safety of the opaque enum or the associated values/payloads196 of the typed enums.197 198 Enumerations do interact with on feature that shows this orthagonality,199 and that is the scoping "no export" marker, that can be applied to any200 enumeration to change the visibility rules of the enumeration and does not201 change anything else.202 203 This is not urgent, just not using the features you don't want is almost as204 clear and the compile-time, binary-size and runtime costs are all good enough205 for now (and some day all of those may have to be improved even when the206 feature is being used). Isolating independent features is just good design. -
src/CodeGen/OperatorTable.cpp
r262a864 r9a01745 76 76 } 77 77 78 // Filter out non-operator names: 79 if ( inputName.find_first_of( "?^*+-!", 0, 1 ) == std::string::npos ) return nullptr; 80 auto entry = inputTable.find( inputName ); 78 if ( inputName.find_first_of( "?^*+-!", 0, 1 ) == std::string::npos ) return nullptr; // prefilter 79 const OperatorInfo * ret = inputTable.find( inputName )->second; 81 80 // This can only happen if an invalid identifier name has been used. 82 assertf( entry != inputTable.end(), "Not a real operator: %s\n", inputName.c_str() );83 const OperatorInfo * ret = entry->second;84 81 assert( ret ); 85 82 return ret; -
src/Validate/ReplaceTypedef.cpp
r262a864 r9a01745 10 10 // Created On : Tue Jun 29 14:59:00 2022 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 20:50:42 202413 // Update Count : 512 // Last Modified On : Thu Dec 14 16:11:51 2023 13 // Update Count : 4 14 14 // 15 15 … … 135 135 }; 136 136 static bool dimensionPresenceMismatched( const ast::Type * t0, const ast::Type * t1) { 137 std::vector<const ast::ArrayType *> at0s = ast::Pass<ArrayTypeExtractor>::read( t0 ); 138 std::vector<const ast::ArrayType *> at1s = ast::Pass<ArrayTypeExtractor>::read( t1 ); 137 std::vector<const ast::ArrayType *> at0s = std::move( 138 ast::Pass<ArrayTypeExtractor>::read( t0 ) ); 139 std::vector<const ast::ArrayType *> at1s = std::move( 140 ast::Pass<ArrayTypeExtractor>::read( t1 ) ); 139 141 assert( at0s.size() == at1s.size() ); 140 142 for (size_t i = 0; i < at0s.size(); i++) { -
tests/.expect/attributes.arm64.txt
r262a864 r9a01745 1337 1337 return _X4_retS3Vad_1; 1338 1338 } 1339 __attribute__ (( noreturn )) void _X4fredFv___1(void){1340 __attribute__ ((unused)) signed int _X1ii_2;1341 switch ( 3 ) {1342 case 2:1343 {1344 {1345 ((void)4);1346 }1347 1348 }1349 case 1:1350 {1351 {1352 ((void)3);1353 }1354 1355 }1356 }1357 1358 }1359 __attribute__ ((noreturn)) void _X4maryFv___1(void){1360 struct __attribute__ ((aligned(64))) S {1361 signed int _X1ii_2;1362 };1363 inline void _X12_constructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){1364 {1365 ((void)((*_X4_dstS1S_2)._X1ii_2) /* ?{} */);1366 }1367 1368 }1369 inline void _X12_constructorFv_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){1370 {1371 ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2) /* ?{} */);1372 }1373 1374 }1375 inline void _X11_destructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){1376 {1377 ((void)((*_X4_dstS1S_2)._X1ii_2) /* ^?{} */);1378 }1379 1380 }1381 inline struct S _X16_operator_assignFS1S_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){1382 __attribute__ ((unused)) struct S _X4_retS1S_2;1383 {1384 ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2));1385 }1386 1387 {1388 ((void)_X12_constructorFv_S1SS1S_autogen___2((&_X4_retS1S_2), (*_X4_dstS1S_2)));1389 }1390 1391 return _X4_retS1S_2;1392 }1393 inline void _X12_constructorFv_S1Si_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, signed int _X1ii_2){1394 {1395 ((void)((*_X4_dstS1S_2)._X1ii_2=_X1ii_2) /* ?{} */);1396 }1397 1398 }1399 __attribute__ ((unused)) signed int _X1ii_2;1400 switch ( 3 ) {1401 case 2:1402 {1403 {1404 ((void)4);1405 }1406 1407 }1408 case 1:1409 {1410 {1411 ((void)3);1412 }1413 1414 }1415 }1416 1417 } -
tests/.expect/attributes.x86.txt
r262a864 r9a01745 1337 1337 return _X4_retS3Vad_1; 1338 1338 } 1339 __attribute__ (( noreturn )) void _X4fredFv___1(void){1340 __attribute__ ((unused)) signed int _X1ii_2;1341 switch ( 3 ) {1342 case 2:1343 {1344 {1345 ((void)4);1346 }1347 1348 }1349 case 1:1350 {1351 {1352 ((void)3);1353 }1354 1355 }1356 }1357 1358 }1359 __attribute__ ((noreturn)) void _X4maryFv___1(void){1360 struct __attribute__ ((aligned(64))) S {1361 signed int _X1ii_2;1362 };1363 inline void _X12_constructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){1364 {1365 ((void)((*_X4_dstS1S_2)._X1ii_2) /* ?{} */);1366 }1367 1368 }1369 inline void _X12_constructorFv_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){1370 {1371 ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2) /* ?{} */);1372 }1373 1374 }1375 inline void _X11_destructorFv_S1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2){1376 {1377 ((void)((*_X4_dstS1S_2)._X1ii_2) /* ^?{} */);1378 }1379 1380 }1381 inline struct S _X16_operator_assignFS1S_S1SS1S_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, __attribute__ ((unused)) struct S _X4_srcS1S_2){1382 __attribute__ ((unused)) struct S _X4_retS1S_2;1383 {1384 ((void)((*_X4_dstS1S_2)._X1ii_2=_X4_srcS1S_2._X1ii_2));1385 }1386 1387 {1388 ((void)_X12_constructorFv_S1SS1S_autogen___2((&_X4_retS1S_2), (*_X4_dstS1S_2)));1389 }1390 1391 return _X4_retS1S_2;1392 }1393 inline void _X12_constructorFv_S1Si_autogen___2(__attribute__ ((unused)) struct S *_X4_dstS1S_2, signed int _X1ii_2){1394 {1395 ((void)((*_X4_dstS1S_2)._X1ii_2=_X1ii_2) /* ?{} */);1396 }1397 1398 }1399 __attribute__ ((unused)) signed int _X1ii_2;1400 switch ( 3 ) {1401 case 2:1402 {1403 {1404 ((void)4);1405 }1406 1407 }1408 case 1:1409 {1410 {1411 ((void)3);1412 }1413 1414 }1415 }1416 1417 }
Note:
See TracChangeset
for help on using the changeset viewer.