| 519 | } |
| 520 | |
| 521 | bool GetPermutationInfo( const std::string& pragma, Permutation& permutation ) |
| 522 | { |
| 523 | const std::regex permutationExpr( "permutation[[:space:]]*\\([[:space:]]*" |
| 524 | "([[:alpha:]_][[:alnum:]_]*)[[:space:]]*,[[:space:]]*" |
| 525 | "(?:values[[:space:]]*=[[:space:]]*)?" |
| 526 | "\\([[:space:]]*" |
| 527 | "([[:alpha:]_][[:alnum:]_]*[[:space:]]*(?:=[[:space:]]*[[:digit:]]+[[:space:]]*)?" |
| 528 | "(?:,[[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*(?:=[[:space:]]*[[:digit:]]+[[:space:]]*)?)+)" |
| 529 | "[[:space:]]*\\)" |
| 530 | "(?:[[:space:]]*,[[:space:]]*(?:default[[:space:]]*=[[:space:]]*)?([[:alpha:]_][[:alnum:]_]*))?" |
| 531 | "(?:[[:space:]]*,[[:space:]]*(?:description[[:space:]]*=[[:space:]]*)?\"([^\"]*)\")?" |
| 532 | "(?:[[:space:]]*,[[:space:]]*(?:type[[:space:]]*=[[:space:]]*)?([[:alpha:]_][[:alnum:]_]*))?" |
| 533 | "[[:space:]]*\\)[[:space:]]*" ); |
| 534 | const std::regex valueExpr( "[[:space:]]*(?:,[[:space:]]*)?([[:alpha:]_][[:alnum:]_]*)(?:[[:space:]]*=[[:space:]]*([[:digit:]]+))?" ); |
| 535 | |
| 536 | std::smatch match; |
| 537 | if( !std::regex_match( pragma, match, permutationExpr ) ) |
| 538 | { |
| 539 | return false; |
| 540 | } |
| 541 | |
| 542 | permutation.name = match[1]; |
| 543 | permutation.defaultOption = match[match.size() - 3]; |
| 544 | permutation.description = match[match.size() - 2]; |
| 545 | |
| 546 | if( match[match.size() - 1] == "dynamic" ) |
| 547 | { |
| 548 | permutation.type = 1; |
| 549 | } |
| 550 | else if( match[match.size() - 1] == "static" ) |
| 551 | { |
| 552 | permutation.type = 0; |
| 553 | } |
| 554 | else if( !match[match.size() - 1].matched ) |
| 555 | { |
| 556 | permutation.type = 0; |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | bool takenValues[256]; |
| 564 | memset( takenValues, 0, sizeof( takenValues ) ); |
| 565 | |
| 566 | const std::string values = match[2]; |
| 567 | auto begin = values.begin(); |
| 568 | while( std::regex_search( begin, values.end(), match, valueExpr ) ) |
| 569 | { |
| 570 | PermutationOption opt; |
| 571 | opt.name = match[1]; |
| 572 | |
| 573 | opt.value = -1; |
| 574 | if( !match[2].str().empty() ) |
| 575 | { |
| 576 | opt.value = atoi( match[2].str().c_str() ); |
| 577 | if( opt.value < 0 || opt.value > 255 ) |
| 578 | { |
no test coverage detected