Example #1
0
bool
lldb_private::NameMatches (const char *name, 
                           NameMatchType match_type, 
                           const char *match)
{
    if (match_type == eNameMatchIgnore)
        return true;

    if (name == match)
        return true;

    if (name && match)
    {
        llvm::StringRef name_sref(name);
        llvm::StringRef match_sref(match);
        switch (match_type)
        {
        case eNameMatchIgnore: // This case cannot occur: tested before
            return true;
        case eNameMatchEquals:      return name_sref == match_sref;
        case eNameMatchContains:    return name_sref.find (match_sref) != llvm::StringRef::npos;
        case eNameMatchStartsWith:  return name_sref.startswith (match_sref);
        case eNameMatchEndsWith:    return name_sref.endswith (match_sref);
        case eNameMatchRegularExpression:
            {
                RegularExpression regex (match);
                return regex.Execute (name);
            }
            break;
        }
    }
    return false;
}
void
AddressSanitizerRuntime::ModulesDidLoad(lldb_private::ModuleList &module_list)
{
    if (IsActive())
        return;
    
    if (m_runtime_module) {
        Activate();
        return;
    }
    
    Mutex::Locker modules_locker(module_list.GetMutex());
    const size_t num_modules = module_list.GetSize();
    for (size_t i = 0; i < num_modules; ++i)
    {
        Module *module_pointer = module_list.GetModulePointerAtIndexUnlocked(i);
        const FileSpec & file_spec = module_pointer->GetFileSpec();
        if (! file_spec)
            continue;
        
        static RegularExpression g_asan_runtime_regex("libclang_rt.asan_(.*)_dynamic\\.dylib");
        if (g_asan_runtime_regex.Execute (file_spec.GetFilename().GetCString()) || module_pointer->IsExecutable())
        {
            if (ModuleContainsASanRuntime(module_pointer))
            {
                m_runtime_module = module_pointer->shared_from_this();
                Activate();
                return;
            }
        }
    }
}
Example #3
0
static bool
DecodeHostAndPort (const char *host_and_port, 
                   std::string &host_str, 
                   std::string &port_str, 
                   int32_t& port,
                   Error *error_ptr)
{
    RegularExpression regex ("([^:]+):([0-9]+)");
    if (regex.Execute (host_and_port, 2))
    {
        if (regex.GetMatchAtIndex (host_and_port, 1, host_str) &&
            regex.GetMatchAtIndex (host_and_port, 2, port_str))
        {
            port = Args::StringToSInt32 (port_str.c_str(), INT32_MIN);
            if (port != INT32_MIN)
            {
                if (error_ptr)
                    error_ptr->Clear();
                return true;
            }
        }
    }
    host_str.clear();
    port_str.clear();
    port = INT32_MIN;
    if (error_ptr)
        error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'", host_and_port);
    return false;
}
Example #4
0
   bool
   StringParser::IsValidEmailAddress(const String &sEmailAddress)
   {
      // Original: [^<>" ]+@[^<>" ]+\.[^<>" ]+
      // 
      // Rule set:
      // - Don't allow spaces anywhere in the address.
      // - Don't allow < or > or " anywhere.
      //

      // Temp fix for moontear noreply@workflow hard coded invalid domain issue
      // Less strict requires no suffix for localhost or noreply@workflow regularExpression = "[^<>\" ]+@[^<>\" ]+"
      String sValidEmailPattern = IniFileSettings::Instance()->GetValidEmailPattern();
      String regularExpression;

      // Override default pattern if one is defined
      if (sValidEmailPattern.empty())
          regularExpression = "[^<>\" ]+@[^<>\" ]+\\.[^<>\" ]+";
      else
          regularExpression = sValidEmailPattern;

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, sEmailAddress);
      return result;
   }
bool DOMImplementation::isXMLMIMEType(const String& mimeType)
{
    if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "text/xsl")
        return true;
    static const char* validChars = "[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]"; // per RFCs: 3023, 2045
    static RegularExpression xmlTypeRegExp(DeprecatedString("^") + validChars + "+/" + validChars + "+\\+xml$");
    if (xmlTypeRegExp.match(mimeType.deprecatedString()) > -1)
        return true;
    return false;
}
Example #6
0
bool
Mangled::NameMatches (const RegularExpression& regex, lldb::LanguageType language) const
{
    if (m_mangled && regex.Execute (m_mangled.AsCString()))
        return true;

    ConstString demangled = GetDemangledName(language);
    if (demangled && regex.Execute (demangled.AsCString()))
        return true;
    return false;
}
Example #7
0
//------------------------------------------------------------------
/// Returns true if the filespec represents an implementation source
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
/// extension).
///
/// @return
///     \b true if the filespec represents an implementation source
///     file, \b false otherwise.
//------------------------------------------------------------------
bool
FileSpec::IsSourceImplementationFile () const
{
    ConstString extension (GetFileNameExtension());
    if (extension)
    {
        static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$",
                llvm::Regex::IgnoreCase);
        return g_source_file_regex.Execute (extension.GetCString());
    }
    return false;
}
Example #8
0
bool CPlusPlusLanguage::ExtractContextAndIdentifier(
    const char *name, llvm::StringRef &context, llvm::StringRef &identifier) {
  static RegularExpression g_basename_regex(llvm::StringRef(
      "^(([A-Za-z_][A-Za-z_0-9]*::)*)(~?[A-Za-z_~][A-Za-z_0-9]*)$"));
  RegularExpression::Match match(4);
  if (g_basename_regex.Execute(llvm::StringRef::withNullAsEmpty(name),
                               &match)) {
    match.GetMatchAtIndex(name, 1, context);
    match.GetMatchAtIndex(name, 3, identifier);
    return true;
  }
  return false;
}
Example #9
0
   bool
   StringParser::IsValidDomainName(const String &sDomainName)
   {
      // Original: ^(\[([0-9]{1,3}\.){3}[0-9]{1,3}\]|(?=.{1,255}$)((?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\.(?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$
      // Conversion:
      // 1) Replace \ with \\
      // 2) Replace " with \"

      String regularExpression = "^(\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\]|(?=.{1,255}$)((?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\\.(?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$";

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, sDomainName);
      return result;
   }
Example #10
0
   bool
   StringParser::IsValidEmailAddress(const String &sEmailAddress)
   {
      // Original: ^(("[^<>@\\]+")|([^<> @\\"]+))@(\[([0-9]{1,3}\.){3}[0-9]{1,3}\]|(?=.{1,255}$)((?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\.(?!-|\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$
      // 
      // Conversion:
      // 1) Replace \ with \\
      // 2) Replace " with \"

      String regularExpression = "^((\"[^<>@\\\\]+\")|([^<> @\\\\\"]+))@(\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\]|(?=.{1,255}$)((?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9])(|\\.(?!-|\\.)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]){1,126})$";

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, sEmailAddress);
      return result;
   }
Example #11
0
static bool IsValidBasename(const llvm::StringRef &basename) {
  // Check that the basename matches with the following regular expression or is
  // an operator name:
  // "^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$"
  // We are using a hand written implementation because it is significantly more
  // efficient then
  // using the general purpose regular expression library.
  size_t idx = 0;
  if (basename.size() > 0 && basename[0] == '~')
    idx = 1;

  if (basename.size() <= idx)
    return false; // Empty string or "~"

  if (!std::isalpha(basename[idx]) && basename[idx] != '_')
    return false; // First charater (after removing the possible '~'') isn't in
                  // [A-Za-z_]

  // Read all characters matching [A-Za-z_0-9]
  ++idx;
  while (idx < basename.size()) {
    if (!std::isalnum(basename[idx]) && basename[idx] != '_')
      break;
    ++idx;
  }

  // We processed all characters. It is a vaild basename.
  if (idx == basename.size())
    return true;

  // Check for basename with template arguments
  // TODO: Improve the quality of the validation with validating the template
  // arguments
  if (basename[idx] == '<' && basename.back() == '>')
    return true;

  // Check if the basename is a vaild C++ operator name
  if (!basename.startswith("operator"))
    return false;

  static RegularExpression g_operator_regex(
      llvm::StringRef("^(operator)( "
                      "?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
                      "\\[\\]|[\\^<>=!\\/"
                      "*+-]+)(<.*>)?(\\[\\])?$"));
  std::string basename_str(basename.str());
  return g_operator_regex.Execute(basename_str, nullptr);
}
Example #12
0
uint32_t
Symtab::AppendSymbolIndexesMatchingRegExAndType (const RegularExpression &regexp, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& indexes)
{
    Mutex::Locker locker (m_mutex);

    uint32_t prev_size = indexes.size();
    uint32_t sym_end = m_symbols.size();

    for (uint32_t i = 0; i < sym_end; i++)
    {
        if (symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type)
        {
            if (CheckSymbolAtIndex(i, symbol_debug_type, symbol_visibility) == false)
                continue;

            const char *name = m_symbols[i].GetMangled().GetName().AsCString();
            if (name)
            {
                if (regexp.Execute (name))
                    indexes.push_back(i);
            }
        }
    }
    return indexes.size() - prev_size;

}
Example #13
0
static Vector<pair<int, String> > getRegularExpressionMatchesByLines(const RegularExpression& regex, const String& text)
{
    Vector<pair<int, String> > result;
    if (text.isEmpty())
        return result;

    int lineNumber = 0;
    unsigned start = 0;
    while (start < text.length()) {
        size_t lineEnd = text.find('\n', start);
        if (lineEnd == notFound)
            lineEnd = text.length();
        else
            lineEnd++;

        String line = text.substring(start, lineEnd - start);
        if (line.endsWith("\r\n"))
            line = line.left(line.length() - 2);
        if (line.endsWith('\n'))
            line = line.left(line.length() - 1);

        int matchLength;
        if (regex.match(line, 0, &matchLength) != -1)
            result.append(pair<int, String>(lineNumber, line));

        start = lineEnd;
        lineNumber++;
    }
    return result;
}
Example #14
0
void
SourceManager::File::FindLinesMatchingRegex (RegularExpression& regex, uint32_t start_line, uint32_t end_line, std::vector<uint32_t> &match_lines)
{
    TimeValue curr_mod_time (m_file_spec.GetModificationTime());
    if (m_mod_time != curr_mod_time)
    {
        m_mod_time = curr_mod_time;
        m_data_sp = m_file_spec.ReadFileContents ();
        m_offsets.clear();
    }
    
    match_lines.clear();
    
    if (!LineIsValid(start_line) || (end_line != UINT32_MAX && !LineIsValid(end_line)))
        return;
    if (start_line > end_line)
        return;
        
    for (uint32_t line_no = start_line; line_no < end_line; line_no++)
    {
        std::string buffer;
        if (!GetLine (line_no, buffer))
            break;
        if (regex.Execute(buffer.c_str()))
        {
            match_lines.push_back(line_no);
        }
    }
}
Example #15
0
bool
Variable::NameMatches (const RegularExpression& regex) const
{
    if (regex.Execute (m_name.AsCString()))
        return true;
    return m_mangled.NameMatches (regex);
}
Example #16
0
bool
Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
                          std::string &host_str,
                          std::string &port_str,
                          int32_t& port,
                          Error *error_ptr)
{
    static RegularExpression g_regex ("([^:]+):([0-9]+)");
    RegularExpression::Match regex_match(2);
    if (g_regex.Execute (host_and_port.data(), &regex_match))
    {
        if (regex_match.GetMatchAtIndex (host_and_port.data(), 1, host_str) &&
            regex_match.GetMatchAtIndex (host_and_port.data(), 2, port_str))
        {
            bool ok = false;
            port = StringConvert::ToUInt32 (port_str.c_str(), UINT32_MAX, 10, &ok);
            if (ok && port <= UINT16_MAX)
            {
                if (error_ptr)
                    error_ptr->Clear();
                return true;
            }
            // port is too large
            if (error_ptr)
                error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'", host_and_port.data());
            return false;
        }
    }

    // If this was unsuccessful, then check if it's simply a signed 32-bit integer, representing
    // a port with an empty host.
    host_str.clear();
    port_str.clear();
    bool ok = false;
    port = StringConvert::ToUInt32 (host_and_port.data(), UINT32_MAX, 10, &ok);
    if (ok && port < UINT16_MAX)
    {
        port_str = host_and_port;
        if (error_ptr)
            error_ptr->Clear();
        return true;
    }

    if (error_ptr)
        error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'", host_and_port.data());
    return false;
}
Example #17
0
bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
                               std::string &host_str, std::string &port_str,
                               int32_t &port, Status *error_ptr) {
  static RegularExpression g_regex(
      llvm::StringRef("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)"));
  RegularExpression::Match regex_match(2);
  if (g_regex.Execute(host_and_port, &regex_match)) {
    if (regex_match.GetMatchAtIndex(host_and_port.data(), 1, host_str) &&
        regex_match.GetMatchAtIndex(host_and_port.data(), 2, port_str)) {
      // IPv6 addresses are wrapped in [] when specified with ports
      if (host_str.front() == '[' && host_str.back() == ']')
        host_str = host_str.substr(1, host_str.size() - 2);
      bool ok = false;
      port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
      if (ok && port <= UINT16_MAX) {
        if (error_ptr)
          error_ptr->Clear();
        return true;
      }
      // port is too large
      if (error_ptr)
        error_ptr->SetErrorStringWithFormat(
            "invalid host:port specification: '%s'", host_and_port.data());
      return false;
    }
  }

  // If this was unsuccessful, then check if it's simply a signed 32-bit
  // integer, representing a port with an empty host.
  host_str.clear();
  port_str.clear();
  bool ok = false;
  port = StringConvert::ToUInt32(host_and_port.data(), UINT32_MAX, 10, &ok);
  if (ok && port < UINT16_MAX) {
    port_str = host_and_port;
    if (error_ptr)
      error_ptr->Clear();
    return true;
  }

  if (error_ptr)
    error_ptr->SetErrorStringWithFormat("invalid host:port specification: '%s'",
                                        host_and_port.data());
  return false;
}
Example #18
0
bool
Variable::NameMatches (const RegularExpression& regex) const
{
    if (regex.Execute (m_name.AsCString()))
        return true;
    if (m_mangled)
        return m_mangled.NameMatches (regex, GetLanguage());
    return false;
}
Example #19
0
   bool
   StringParser::WildcardMatch(const String &pattern, const String &value)
   {
      // Convert the pattern to a regular expression.
      String regularExpression;

      for (int i = 0; i < pattern.GetLength(); i++)
      {
         wchar_t c = pattern[i];

         switch (c)
         {
            case '\\':
            case '|':
            case '.':
            case '^':
            case '$':
            case '+':
            case '(':
            case ')':
            case '[':
            case ']':
            case '{':
            case '}':
               regularExpression.append(_T("\\"));
               regularExpression += c;
               break;
            case '*':
               regularExpression.append(_T(".*"));
               break;
            case '?':
               regularExpression.append(_T("."));
               break;
            default:
               regularExpression += c;
               break;

         }
      }

      RegularExpression regexpEvaluator;
      bool result = regexpEvaluator.TestExactMatch(regularExpression, value);
      return result;
   }
Example #20
0
//------------------------------------------------------------------------------
// values: faustcode
ValueTree MDLParser::getFaustCodeTree(const String& line, RegularExpression& re)
{
    StringArray values;
    re.fullMatchValues(line, values, 1);

    ValueTree faustcodeTree(Ids::faustcode);
    faustcodeTree.setProperty(Ids::value, values[0].trim(), nullptr);

    return faustcodeTree;
}
Example #21
0
void
DWARFCompileUnit::ParseProducerInfo ()
{
    m_producer_version_major = UINT32_MAX;
    m_producer_version_minor = UINT32_MAX;
    m_producer_version_update = UINT32_MAX;

    const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly();
    if (die)
    {

        const char *producer_cstr = die->GetAttributeValueAsString(m_dwarf2Data, this, DW_AT_producer, NULL);
        if (producer_cstr)
        {
            RegularExpression llvm_gcc_regex("^4\\.[012]\\.[01] \\(Based on Apple Inc\\. build [0-9]+\\) \\(LLVM build [\\.0-9]+\\)$");
            if (llvm_gcc_regex.Execute (producer_cstr))
            {
                m_producer = eProducerLLVMGCC;
            }
            else if (strstr(producer_cstr, "clang"))
            {
                static RegularExpression g_clang_version_regex("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
                RegularExpression::Match regex_match(3);
                if (g_clang_version_regex.Execute (producer_cstr, &regex_match))
                {
                    std::string str;
                    if (regex_match.GetMatchAtIndex (producer_cstr, 1, str))
                        m_producer_version_major = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
                    if (regex_match.GetMatchAtIndex (producer_cstr, 2, str))
                        m_producer_version_minor = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
                    if (regex_match.GetMatchAtIndex (producer_cstr, 3, str))
                        m_producer_version_update = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10);
                }
                m_producer = eProducerClang;
            }
            else if (strstr(producer_cstr, "GNU"))
                m_producer = eProducerGCC;
        }
    }
    if (m_producer == eProducerInvalid)
        m_producer = eProcucerOther;
}
Example #22
0
//------------------------------------------------------------------------------
// values: params, identifier, sources
ValueTree MDLParser::getDisplayTree(const String& line, RegularExpression& re)
{
    StringArray values;
    re.fullMatchValues(line, values, 3);

    const Point<int> pos = getPos(line);

    ValueTree newTree(Ids::display);
    newTree.setProperty(Ids::posX, pos.getX(), nullptr);
    newTree.setProperty(Ids::posY, pos.getY(), nullptr);

    StringArray paramsArray = MDLHelper::getParamsFromString(values[0]);
    paramsArray.set(0, paramsArray[0].unquoted());
    newTree.addChild(ObjectFactory::createParamsTree(paramsArray), -1, nullptr);

    newTree.setProperty(Ids::identifier, values[1], nullptr);

    int posColon = values[2].indexOf(":");
    String sourcesLine;
    if(posColon > 0)
    {
        sourcesLine = values[2].substring(0, posColon);
        sourcesLine = MDLHelper::removeUnbalancedParentheses(sourcesLine);
        newTree.setProperty(Ids::optional, values[2].substring(posColon+1), nullptr);
    }
    else
    {
        newTree.setProperty(Ids::optional, "", nullptr);
        sourcesLine = values[2];
    }

        // remove unbalanced parentheses
    sourcesLine = MDLHelper::removeUnbalancedParentheses(sourcesLine);

    // remove surrounding paranthese if there are some.
    sourcesLine = MDLHelper::removeSurroundingParentheses(sourcesLine);

    StringArray sourcesList;
    sourcesList.addTokens(sourcesLine, "+", "\"");

    ValueTree displaySources(Ids::sources);
    for (int l = 0; l < sourcesList.size(); ++l)
    {
        if (sourcesList[l].trim().compare("0.0") != 0)
        {
            ValueTree displaySource(Ids::audiosource);
            displaySource.setProperty(Ids::value, sourcesList[l].trim(), nullptr);
            displaySources.addChild(displaySource, -1, nullptr);
        }
    }
    newTree.addChild(displaySources, -1, nullptr);

    return newTree;
}
Example #23
0
uint32_t
SymbolFileSymtab::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
{
    Timer scoped_timer (__PRETTY_FUNCTION__,
                        "SymbolFileSymtab::FindFunctions (regex = '%s')",
                        regex.GetText());
    // If we ever support finding STABS or COFF debug info symbols, 
    // we will need to add support here. We are not trying to find symbols
    // here, just "lldb_private::Function" objects that come from complete 
    // debug information. Any symbol queries should go through the symbol
    // table itself in the module's object file.
    return 0;
}
Example #24
0
void replace(String& string, const RegularExpression& target, const String& replacement)
{
    int index = 0;
    while (index < static_cast<int>(string.length())) {
        int matchLength;
        index = target.match(string, index, &matchLength);
        if (index < 0)
            break;
        string.replace(index, matchLength, replacement);
        index += replacement.length();
        if (!matchLength)
            break;  // Avoid infinite loop on 0-length matches, e.g. [a-z]*
    }
}
Example #25
0
static int countRegularExpressionMatches(const RegularExpression& regex, const String& content)
{
    int result = 0;
    int position;
    unsigned start = 0;
    int matchLength;
    while ((position = regex.match(content, start, &matchLength)) != -1) {
        if (start >= content.length())
            break;
        if (matchLength > 0)
            ++result;
        start = position + 1;
    }
    return result;
}
Example #26
0
//------------------------------------------------------------------------------
// values: param1, param2, identifier, startVertex, endVertex
ValueTree MDLParser::getWaveguideTree(const String& line, RegularExpression& re)
{
    StringArray values;
    re.fullMatchValues(line, values, 5);

    ValueTree waveguideTree(Ids::waveguide);

    StringArray paramsArray(values.begin(), 2);

    waveguideTree.addChild(ObjectFactory::createParamsTree(paramsArray),
                           -1, nullptr);

    waveguideTree.setProperty(Ids::identifier, values[2].trim(), nullptr);
    waveguideTree.setProperty(Ids::startVertex, values[3].trim(), nullptr);
    waveguideTree.setProperty(Ids::endVertex, values[4].trim(), nullptr);

    return waveguideTree;
}
Example #27
0
uint32_t Symtab::AppendSymbolIndexesMatchingRegExAndType(
    const RegularExpression &regexp, SymbolType symbol_type,
    std::vector<uint32_t> &indexes) {
  std::lock_guard<std::recursive_mutex> guard(m_mutex);

  uint32_t prev_size = indexes.size();
  uint32_t sym_end = m_symbols.size();

  for (uint32_t i = 0; i < sym_end; i++) {
    if (symbol_type == eSymbolTypeAny ||
        m_symbols[i].GetType() == symbol_type) {
      const char *name = m_symbols[i].GetName().AsCString();
      if (name) {
        if (regexp.Execute(name))
          indexes.push_back(i);
      }
    }
  }
  return indexes.size() - prev_size;
}
Example #28
0
//------------------------------------------------------------------------------
// values: param, identifier
ValueTree MDLParser::getTerminationTree(const String& line, RegularExpression& re)
{
    StringArray values;
    re.fullMatchValues(line, values, 2);

    const Point<int> pos = getPos(line);

    ValueTree terminationTree(Ids::termination);
    terminationTree.setProperty(Ids::posX, pos.x, nullptr);
    terminationTree.setProperty(Ids::posY, pos.y, nullptr);

    StringArray paramsArray = MDLHelper::getParamsFromString(values[0]);

    terminationTree.addChild(ObjectFactory::createParamsTree(paramsArray),
                             -1, nullptr);

    terminationTree.setProperty(Ids::identifier, values[1].trim(), nullptr);

    return terminationTree;
}
Example #29
0
void SourceManager::File::FindLinesMatchingRegex(
    RegularExpression &regex, uint32_t start_line, uint32_t end_line,
    std::vector<uint32_t> &match_lines) {
  match_lines.clear();

  if (!LineIsValid(start_line) ||
      (end_line != UINT32_MAX && !LineIsValid(end_line)))
    return;
  if (start_line > end_line)
    return;

  for (uint32_t line_no = start_line; line_no < end_line; line_no++) {
    std::string buffer;
    if (!GetLine(line_no, buffer))
      break;
    if (regex.Execute(buffer)) {
      match_lines.push_back(line_no);
    }
  }
}
Example #30
0
//------------------------------------------------------------------------------
// values: param1, identifier
ValueTree MDLParser::getJunctionTree(const String& line, RegularExpression& re)
{
    StringArray values;
    re.fullMatchValues(line, values, 2);

    const Point<int> pos = getPos(line);

    ValueTree junctTree(Ids::junction);
    junctTree.setProperty(Ids::posX, pos.x, nullptr);
    junctTree.setProperty(Ids::posY, pos.y, nullptr);

    ValueTree junctParams(Ids::parameters);
    ValueTree junctParam(Ids::parameter);
    junctParam.setProperty(Ids::value, values[0].trim(), nullptr);
    junctParams.addChild(junctParam, -1, nullptr);
    junctTree.addChild(junctParams, -1, nullptr);

    junctTree.setProperty(Ids::identifier, values[1].trim(), nullptr);

    return junctTree;
}