// resolve a stem variable entry, creating a new one if not found
 inline RexxVariable *getStemVariable(RexxString *stemName)
 {
     RexxVariable *variable = resolveVariable(stemName);
     if (variable == OREF_NULL)
     {
         variable = createStemVariable(stemName);
     }
     return variable;
 }
 // get a variable entry, creating a new one if necessary
 inline RexxVariable *getVariable(RexxString *name)
 {
     // find the entry
     RexxVariable *variable = resolveVariable(name);
     if (variable == OREF_NULL)
     {
         // create a new one if not there.
         variable = createVariable(name);
     }
     return variable;
 }
示例#3
0
void MakefileHandler::parse( const QString& folder, bool recursive )
{
    //look for either Makefile.am.in, Makefile.am, or Makefile.in, in that order
    AutoTools::ProjectAST* ast;
    int ret = -1;
    QString filePath = folder + "/Makefile.am.in";
    if ( QFile::exists( filePath ) )
        ret = AutoTools::Driver::parseFile( filePath, &ast );
    else
    {
        filePath = folder + "/Makefile.am";
        if ( QFile::exists( filePath ) )
            ret = AutoTools::Driver::parseFile( filePath, &ast );
        else
        {
            filePath = folder + "/Makefile.in";
            if ( QFile::exists( filePath ) )
                ret = AutoTools::Driver::parseFile( filePath, &ast );
            else
                kdDebug(9020) << k_funcinfo << "no appropriate file to parse in "
                              << folder << endl;
        }
    }

    if ( ret != 0 )
    {
        return;
    }

    kdDebug(9020) << k_funcinfo << filePath << " was parsed correctly. Adding information" << endl;
    Q_ASSERT( ast != 0 );
    d->projects[filePath] = ast;
    d->folderToFileMap[folder] = filePath;

    if ( recursive && ast && ast->hasChildren() )
    {
        QValueList<AutoTools::AST*> astChildList = ast->children();
        QValueList<AutoTools::AST*>::iterator it(astChildList.begin()), clEnd(astChildList.end());
        for ( ; it != clEnd; ++it )
        {
            if ( (*it)->nodeType() == AutoTools::AST::AssignmentAST )
            {
                AutoTools::AssignmentAST* assignment = static_cast<AutoTools::AssignmentAST*>( (*it) );
                if ( assignment->scopedID == "SUBDIRS"  )
                {
                    QString list = assignment->values.join( QString::null );
                    list.simplifyWhiteSpace();
                    kdDebug(9020) << k_funcinfo << "subdirs is " << list << endl;
                    QStringList subdirList = QStringList::split( " ",  list );
                    QStringList::iterator vit = subdirList.begin();
                    for ( ; vit != subdirList.end(); ++vit )
                    {
                        QString realDir = ( *vit );
                        if ( realDir.startsWith( "\\" ) )
                            realDir.remove( 0, 1 );

                        realDir = realDir.stripWhiteSpace();
                        if ( realDir != "." && realDir != ".." && !realDir.isEmpty() )
                        {
                            if ( isVariable( realDir ) )
                            {
                                kdDebug(9020) << k_funcinfo << "'" << realDir << "' is a variable" << endl;
                                realDir = resolveVariable( realDir, ast );
                            }

                            kdDebug(9020) << k_funcinfo << "Beginning parsing of '" << realDir << "'" << endl;
                            parse( folder + '/' + realDir, recursive );
                        }
                    }
                }
            }
        }
    }
}
示例#4
0
RpmBuildPlugin::Hash RpmBuildPlugin::solveVariables(const List &variables,         //variables to solve
                                                    const List &constants          //constants (solved)
                                                   ) const
{
    Hash hash;

    append(hash, constants);    //fill list of solved constants/variables with constants

    std::function<bool(const Pair &var)> resolveVariable;

    resolveVariable = [&](const Pair &var) -> bool
    {

        auto error = [&](const QString &variable, const QString &value, const QString &message)
        {
            debug(DebugLevel::Error) << "Could not resolve variable \"" << variable << "\""
                                     << "with value \"" << value << "\""
                                     << ". Error message: " << message;
        };

        assert(hash.contains(var.first) == false);

        //check first char of value
        if (var.second.size() == 0)
            hash[var.first] = var.second;
        else
        {
            const char operation = var.second[0].toAscii() ;

            switch (operation)
            {
                case '=':       //just use variable's value
                    hash[var.first] = replaceVariables(var.second.mid(1), hash);   //do not use first char which is '='
                    break;

                case 'r':       //regexp
                {
                    //Format for this operation:
                    //  "r:expression:regexp:result"
                    // ie: "r:abc:a(.*):_%1_" will return "_bc_".  (%1 is equivalent of \1)
                    // This operation is +- equivalent of:
                    // echo $expression | sed -e "s/$regexp/$result/"
                    // Instead of ":" as separator, any other char may be used.

                    const QString value = var.second.mid(1);   //all chars except 1. char
                    const size_t size = value.size();
                    if (size >= sizeof(":::"))                 //minimal regexp is: ":::"
                    {
                        const QString solvedValue = replaceVariables(value, hash);  //replace all variables with theirs values
                        const char splitter = solvedValue[0].toAscii();  //use first char as splitter

                        //do splitting
                        const QStringList regexpParts = solvedValue.mid(1).split(splitter);  //ommit first ':'

                        //we are expecting 3 parts
                        if (regexpParts.size() == 3)
                        {
                            QRegExp regexp(regexpParts[1]);        //second part is a pattern

                            if (regexp.exactMatch(regexpParts[0])) //enter string to be matched (first part)
                            {
                                //now try to commit matched expression to result
                                const QStringList captured = regexp.capturedTexts();  //list of captured texts "(.*)"
                                QString result = regexpParts[2];

                                for (int i = 1; i < captured.size(); i++)
                                {
                                    //this operation will replace each "%n" in result part of regexp with corresponding captured text.
                                    //This is why we use %n instead of \n, as %n is used by QString algorithms to replace args
                                    result = result.arg(captured[i]);
                                }

                                hash[var.first] = result;
                            }
                            else
                                error(var.first, var.second, "Could not match regular expression.");
                        }
                        else
                            error(var.first, var.second,
                                  QString("Variable's value should consist of 3 parts, but %1 were found.")
                                  .arg(regexpParts.size()));
                    }
                    else
                        error(var.first, var.second, "Variable's value is too short even for simples regular expression.");
                }
                break;

                default:
                    debug(DebugLevel::Error) << "unknown variable operator: \"" << operation << "\"";
                    break;
            }
        }

        return true;
    };

    for (const Pair &var: variables)
    {
        //try to resolve value

        if (hash.contains(var.first) == false)  //not resolved yet?
            resolveVariable(var);
    }

    return hash;
}