void TemplightProtobufReader::loadBeginEntry(llvm::StringRef aSubBuffer) {
  // Set default values:
  LastBeginEntry.InstantiationKind = 0;
  LastBeginEntry.Name = "";
  LastBeginEntry.TimeStamp = 0.0;
  LastBeginEntry.MemoryUsage = 0;
  
  while ( aSubBuffer.size() ) {
    unsigned int cur_wire = llvm::protobuf::loadVarInt(aSubBuffer);
    switch( cur_wire ) {
      case llvm::protobuf::getVarIntWire<1>::value:
        LastBeginEntry.InstantiationKind = llvm::protobuf::loadVarInt(aSubBuffer);
        break;
      case llvm::protobuf::getStringWire<2>::value: {
        std::uint64_t cur_size = llvm::protobuf::loadVarInt(aSubBuffer);
        loadTemplateName(aSubBuffer.slice(0, cur_size));
        aSubBuffer = aSubBuffer.drop_front(cur_size);
        break;
      }
      case llvm::protobuf::getStringWire<3>::value: {
        std::uint64_t cur_size = llvm::protobuf::loadVarInt(aSubBuffer);
        loadLocation(aSubBuffer.slice(0, cur_size), fileNameMap, 
          LastBeginEntry.FileName, LastBeginEntry.Line, LastBeginEntry.Column);
        aSubBuffer = aSubBuffer.drop_front(cur_size);
        break;
      }
      case llvm::protobuf::getDoubleWire<4>::value:
        LastBeginEntry.TimeStamp = llvm::protobuf::loadDouble(aSubBuffer);
        break;
      case llvm::protobuf::getVarIntWire<5>::value:
        LastBeginEntry.MemoryUsage = llvm::protobuf::loadVarInt(aSubBuffer);
        break;
      case llvm::protobuf::getStringWire<6>::value: {
        std::uint64_t cur_size = llvm::protobuf::loadVarInt(aSubBuffer);
        loadLocation(aSubBuffer.slice(0, cur_size), fileNameMap, 
          LastBeginEntry.TempOri_FileName, LastBeginEntry.TempOri_Line, LastBeginEntry.TempOri_Column);
        aSubBuffer = aSubBuffer.drop_front(cur_size);
        break;
      }
      default:
        llvm::protobuf::skipData(aSubBuffer, cur_wire);
        break;
    }
  }
  
  LastChunk = TemplightProtobufReader::BeginEntry;
}
lldb::OptionValueSP
OptionValueArray::GetSubValue(const ExecutionContext *exe_ctx,
                              llvm::StringRef name, bool will_modify,
                              Status &error) const {
  if (name.empty() || name.front() != '[') {
    error.SetErrorStringWithFormat(
      "invalid value path '%s', %s values only support '[<index>]' subvalues "
      "where <index> is a positive or negative array index",
      name.str().c_str(), GetTypeAsCString());
    return nullptr;
  }

  name = name.drop_front();
  llvm::StringRef index, sub_value;
  std::tie(index, sub_value) = name.split(']');
  if (index.size() == name.size()) {
    // Couldn't find a closing bracket
    return nullptr;
  }

  const size_t array_count = m_values.size();
  int32_t idx = 0;
  if (index.getAsInteger(0, idx))
    return nullptr;

  uint32_t new_idx = UINT32_MAX;
  if (idx < 0) {
    // Access from the end of the array if the index is negative
    new_idx = array_count - idx;
  } else {
    // Just a standard index
    new_idx = idx;
  }

  if (new_idx < array_count) {
    if (m_values[new_idx]) {
      if (!sub_value.empty())
        return m_values[new_idx]->GetSubValue(exe_ctx, sub_value,
                                              will_modify, error);
      else
        return m_values[new_idx];
    }
  } else {
    if (array_count == 0)
      error.SetErrorStringWithFormat(
          "index %i is not valid for an empty array", idx);
    else if (idx > 0)
      error.SetErrorStringWithFormat(
          "index %i out of range, valid values are 0 through %" PRIu64,
          idx, (uint64_t)(array_count - 1));
    else
      error.SetErrorStringWithFormat("negative index %i out of range, "
                                      "valid values are -1 through "
                                      "-%" PRIu64,
                                      idx, (uint64_t)array_count);
  }
  return OptionValueSP();
}
Exemple #3
0
  void AutoloadCallback::report(clang::SourceLocation l, llvm::StringRef name,
                                llvm::StringRef header) {
    Sema& sema= m_Interpreter->getSema();

    unsigned id
      = sema.getDiagnostics().getCustomDiagID (DiagnosticsEngine::Level::Warning,
                                                 "Note: '%0' can be found in %1");
/*    unsigned idn //TODO: To be enabled after we have a way to get the full path
      = sema.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Level::Note,
                                                "Type : %0 , Full Path: %1")*/;

    if (header.startswith(llvm::StringRef(annoTag, lenAnnoTag)))
      sema.Diags.Report(l, id) << name << header.drop_front(lenAnnoTag);

  }
static bool
GetIdentifier (llvm::StringRef &s, llvm::StringRef &identifier)
{
    if (!s.empty())
    {
        char ch = s[0];
        if (isalpha(ch) || ch == '_')
        {
            size_t i;
            for (i = 1; i < s.size(); ++i)
            {
                ch = s[i];
                if (isalnum(ch) || ch == '_')
                    continue;
                else
                    break;
            }
            identifier = s.substr(0, i);
            s = s.drop_front(i);
            return true;
        }
    }
    return false;
}
Status OptionValueString::SetValueFromString(llvm::StringRef value,
                                             VarSetOperationType op) {
  Status error;

  std::string value_str = value.str();
  value = value.trim();
  if (value.size() > 0) {
    switch (value.front()) {
    case '"':
    case '\'': {
      if (value.size() <= 1 || value.back() != value.front()) {
        error.SetErrorString("mismatched quotes");
        return error;
      }
      value = value.drop_front().drop_back();
    } break;
    }
    value_str = value.str();
  }

  switch (op) {
  case eVarSetOperationInvalid:
  case eVarSetOperationInsertBefore:
  case eVarSetOperationInsertAfter:
  case eVarSetOperationRemove:
    if (m_validator) {
      error = m_validator(value_str.c_str(), m_validator_baton);
      if (error.Fail())
        return error;
    }
    error = OptionValue::SetValueFromString(value, op);
    break;

  case eVarSetOperationAppend: {
    std::string new_value(m_current_value);
    if (value.size() > 0) {
      if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
        std::string str;
        Args::EncodeEscapeSequences(value_str.c_str(), str);
        new_value.append(str);
      } else
        new_value.append(value);
    }
    if (m_validator) {
      error = m_validator(new_value.c_str(), m_validator_baton);
      if (error.Fail())
        return error;
    }
    m_current_value.assign(new_value);
    NotifyValueChanged();
  } break;

  case eVarSetOperationClear:
    Clear();
    NotifyValueChanged();
    break;

  case eVarSetOperationReplace:
  case eVarSetOperationAssign:
    if (m_validator) {
      error = m_validator(value_str.c_str(), m_validator_baton);
      if (error.Fail())
        return error;
    }
    m_value_was_set = true;
    if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) {
      Args::EncodeEscapeSequences(value_str.c_str(), m_current_value);
    } else {
      SetCurrentValue(value_str);
    }
    NotifyValueChanged();
    break;
  }
  return error;
}
lldb::OptionValueSP
OptionValueProperties::GetSubValue(const ExecutionContext *exe_ctx,
  llvm::StringRef name, bool will_modify,
                                   Error &error) const {
  lldb::OptionValueSP value_sp;
  if (name.empty())
    return OptionValueSP();

  llvm::StringRef sub_name;
  ConstString key;
  size_t key_len = name.find_first_of(".[{");
  if (key_len != llvm::StringRef::npos) {
    key.SetString(name.take_front(key_len));
    sub_name = name.drop_front(key_len);
  } else
    key.SetString(name);

  value_sp = GetValueForKey(exe_ctx, key, will_modify);
  if (sub_name.empty() || !value_sp)
    return value_sp;

  switch (sub_name[0]) {
  case '.': {
    lldb::OptionValueSP return_val_sp;
    return_val_sp =
        value_sp->GetSubValue(exe_ctx, sub_name.drop_front(), will_modify, error);
    if (!return_val_sp) {
      if (Properties::IsSettingExperimental(sub_name.drop_front())) {
        size_t experimental_len =
            strlen(Properties::GetExperimentalSettingsName());
        if (sub_name[experimental_len + 1] == '.')
          return_val_sp = value_sp->GetSubValue(
              exe_ctx, sub_name.drop_front(experimental_len + 2), will_modify, error);
        // It isn't an error if an experimental setting is not present.
        if (!return_val_sp)
          error.Clear();
      }
    }
    return return_val_sp;
  }
  case '{':
    // Predicate matching for predicates like
    // "<setting-name>{<predicate>}"
    // strings are parsed by the current OptionValueProperties subclass
    // to mean whatever they want to. For instance a subclass of
    // OptionValueProperties for a lldb_private::Target might implement:
    // "target.run-args{arch==i386}"   -- only set run args if the arch is
    // i386
    // "target.run-args{path=/tmp/a/b/c/a.out}" -- only set run args if the
    // path matches
    // "target.run-args{basename==test&&arch==x86_64}" -- only set run args
    // if executable basename is "test" and arch is "x86_64"
    if (sub_name[1]) {
      llvm::StringRef predicate_start = sub_name.drop_front();
      size_t pos = predicate_start.find_first_of('}');
      if (pos != llvm::StringRef::npos) {
        auto predicate = predicate_start.take_front(pos);
        auto rest = predicate_start.drop_front(pos);
        if (PredicateMatches(exe_ctx, predicate)) {
          if (!rest.empty()) {
            // Still more subvalue string to evaluate
            return value_sp->GetSubValue(exe_ctx, rest,
                                          will_modify, error);
          } else {
            // We have a match!
            break;
          }
        }
      }
    }
    // Predicate didn't match or wasn't correctly formed
    value_sp.reset();
    break;

  case '[':
    // Array or dictionary access for subvalues like:
    // "[12]"       -- access 12th array element
    // "['hello']"  -- dictionary access of key named hello
    return value_sp->GetSubValue(exe_ctx, sub_name, will_modify, error);

  default:
    value_sp.reset();
    break;
  }
  return value_sp;
}
//===----------------------------------------------------------------------===//
// parser<mcld::ZOption>
//===----------------------------------------------------------------------===//
bool parser<mcld::ZOption>::parse(llvm::cl::Option &O,
                                  llvm::StringRef ArgName,
                                  llvm::StringRef Arg,
                                  mcld::ZOption &Val)
{
  if (0 == Arg.compare("combreloc"))
    Val.setKind(ZOption::CombReloc);
  else if (0 == Arg.compare("nocombreloc"))
    Val.setKind(ZOption::NoCombReloc);
  else if (0 == Arg.compare("defs"))
    Val.setKind(ZOption::Defs);
  else if (0 == Arg.compare("execstack"))
    Val.setKind(ZOption::ExecStack);
  else if (0 == Arg.compare("noexecstack"))
    Val.setKind(ZOption::NoExecStack);
  else if (0 == Arg.compare("initfirst"))
    Val.setKind(ZOption::InitFirst);
  else if (0 == Arg.compare("interpose"))
    Val.setKind(ZOption::InterPose);
  else if (0 == Arg.compare("loadfltr"))
    Val.setKind(ZOption::LoadFltr);
  else if (0 == Arg.compare("muldefs"))
    Val.setKind(ZOption::MulDefs);
  else if (0 == Arg.compare("nocopyreloc"))
    Val.setKind(ZOption::NoCopyReloc);
  else if (0 == Arg.compare("nodefaultlib"))
    Val.setKind(ZOption::NoDefaultLib);
  else if (0 == Arg.compare("nodelete"))
    Val.setKind(ZOption::NoDelete);
  else if (0 == Arg.compare("nodlopen"))
    Val.setKind(ZOption::NoDLOpen);
  else if (0 == Arg.compare("nodump"))
    Val.setKind(ZOption::NoDump);
  else if (0 == Arg.compare("relro"))
    Val.setKind(ZOption::Relro);
  else if (0 == Arg.compare("norelro"))
    Val.setKind(ZOption::NoRelro);
  else if (0 == Arg.compare("lazy"))
    Val.setKind(ZOption::Lazy);
  else if (0 == Arg.compare("now"))
    Val.setKind(ZOption::Now);
  else if (0 == Arg.compare("origin"))
    Val.setKind(ZOption::Origin);
  else if (Arg.startswith("common-page-size=")) {
    Val.setKind(ZOption::CommPageSize);
    long long unsigned size = 0;
    Arg.drop_front(17).getAsInteger(0, size);
    Val.setPageSize(static_cast<uint64_t>(size));
  } else if (Arg.startswith("max-page-size=")) {
    Val.setKind(ZOption::MaxPageSize);
    long long unsigned size = 0;
    Arg.drop_front(14).getAsInteger(0, size);
    Val.setPageSize(static_cast<uint64_t>(size));
  }

  if (ZOption::Unknown == Val.kind())
    llvm::report_fatal_error(llvm::Twine("unknown -z option: `") +
                             Arg +
                             llvm::Twine("'\n"));
  return false;
}