compiler/resolution/preFold.cpp
// This function finds the enum constant that matches imm.
// imm stores a compile-time constant integer or string.
// It's used when casting from an param integer or a param string to the
// enum type.
This function finds the enum constant that matches imm.
imm stores a compile-time constant integer or string.
It's used when casting from an param integer or a param string to the
enum type.
This function finds the enum constant that matches imm . imm stores a compile - time constant integer or string . It ' s used when casting from an param integer or a param string to the enum type .
static Symbol* findMatchingEnumSymbol(Immediate* imm, EnumType* typeEnum) {
  uint64_t fromUint = 0;
  int64_t  fromInt  = 0;
  const char* fromString = NULL;
  bool haveUint = false;
  bool haveInt  = false;
  bool haveString = false;
  ensureEnumTypeResolved(typeEnum);
  if (imm->const_kind == NUM_KIND_INT) {
    haveInt = true;
    fromInt = imm->int_value();
  } else if (imm->const_kind == NUM_KIND_UINT) {
    haveUint = true;
    fromUint = imm->uint_value();
  } else if (imm->const_kind == CONST_KIND_STRING) {
    haveString = true;
    fromString = imm->string_value();
  }
  INT_ASSERT(haveInt || haveUint || haveString);
  for_enums(constant, typeEnum) {
    uint64_t cUint = 0;
    int64_t   cInt = 0;
    bool   gotUint = false;
    bool   gotInt  = false;
    const char* extendedName = NULL;
    gotInt  = get_int(constant->init, &cInt);
    gotUint = get_uint(constant->init, &cUint);
    if (haveString)
      extendedName = astr(typeEnum->symbol->name, ".", constant->sym->name);
    bool match = false;
    if (haveString &&
        (fromString == constant->sym->name ||
         fromString == extendedName))
      match = true;
    else if (gotInt && haveInt && cInt == fromInt)
      match = true;
    else if (gotUint && haveUint && cUint == fromUint)
      match = true;
    else if (gotInt && haveUint && cInt >= 0 &&
             (uint64_t)cInt == fromUint)
      match = true;
    else if (gotUint && haveInt && fromInt >= 0 &&
             cUint == (uint64_t)fromInt)
      match = true;
    if (match) {
      return constant->sym;
    }
  }
  return NULL;
}
static Symbol * findMatchingEnumSymbol ( Immediate * imm , EnumType * typeEnum ) { uint64_t fromUint = 0 ; int64_t fromInt = 0 ; const char * fromString = NULL ; bool haveUint = false ; bool haveInt = false ; bool haveString = false ; ensureEnumTypeResolved ( typeEnum ) ; if ( imm -> const_kind == NUM_KIND_INT ) { haveInt = true ; fromInt = imm -> int_value ( ) ; } else if ( imm -> const_kind == NUM_KIND_UINT ) { haveUint = true ; fromUint = imm -> uint_value ( ) ; } else if ( imm -> const_kind == CONST_KIND_STRING ) { haveString = true ; fromString = imm -> string_value ( ) ; } INT_ASSERT ( haveInt || haveUint || haveString ) ; for_enums ( constant , typeEnum ) { uint64_t cUint = 0 ; int64_t cInt = 0 ; bool gotUint = false ; bool gotInt = false ; const char * extendedName = NULL ; gotInt = get_int ( constant -> init , & cInt ) ; gotUint = get_uint ( constant -> init , & cUint ) ; if ( haveString ) extendedName = astr ( typeEnum -> symbol -> name , " " , constant -> sym -> name ) ; bool match = false ; if ( haveString && ( fromString == constant -> sym -> name || fromString == extendedName ) ) match = true ; else if ( gotInt && haveInt && cInt == fromInt ) match = true ; else if ( gotUint && haveUint && cUint == fromUint ) match = true ; else if ( gotInt && haveUint && cInt >= 0 && ( uint64_t ) cInt == fromUint ) match = true ; else if ( gotUint && haveInt && fromInt >= 0 && cUint == ( uint64_t ) fromInt ) match = true ; if ( match ) { return constant -> sym ; } } return NULL ; }
This function finds the enum constant that matches imm.
This function finds the enum constant that matches imm .
// string matches name // both int // both uint // int/uint and int >= 0 // uint/int and int >= 0