Exemple #1
0
bool TokenStream::GetNextToken( std::string* buffer, char* delimiters, int totalDelimiters )
{
    startIndex_ = endIndex_;

    bool inString = false;
    int length = ( int )data_.length( );

    if( startIndex_ >= length - 1 )
        return false;

    while( startIndex_ < length && isValidIdentifier( data_[startIndex_],
        delimiters, totalDelimiters ) == false )
    {
        startIndex_++;
    }

    endIndex_ = startIndex_ + 1;

	if( startIndex_ < length )
	{
		if( data_[startIndex_] == '"' )
			inString = !inString;
	}

    if( startIndex_ < length )
    {
        while( endIndex_ < length && ( isValidIdentifier( data_[endIndex_], delimiters,
            totalDelimiters ) || inString == true ) )
        {
            if( data_[endIndex_] == '"' )
                inString = !inString;

            endIndex_++;
        }

        if( buffer != NULL )
        {
            int size = ( endIndex_ - startIndex_ );
            int index = startIndex_;

            buffer->reserve( size + 1 );
            buffer->clear( );

            for( int i = 0; i < size; i++ )
            {
                buffer->push_back( data_[index++] );
            }
        }

        return true;
    }

    return false;
}
Identifier::Identifier (String::CharPointerType start, String::CharPointerType end)
    : name (StringPool::getGlobalPool().getPooledString (start, end))
{
    /* An Identifier string must be suitable for use as a script variable or XML
       attribute, so it can only contain this limited set of characters.. */
    jassert (isValidIdentifier (toString()));
}
Identifier::Identifier (const char* nm)
    : name (StringPool::getGlobalPool().getPooledString (nm))
{
    /* An Identifier string must be suitable for use as a script variable or XML
       attribute, so it can only contain this limited set of characters.. */
    jassert (isValidIdentifier (toString()));
}
void Shader::ShaderProgram::addUniformsFromCode(const String& code, const Args& args) {

    TextInput ti(TextInput::FROM_STRING, code);
    while (ti.hasMore()) {
        const Token nextToken = ti.peek();
        if ((nextToken.type() == Token::SYMBOL) && (nextToken.string() != "#")) {
            bool isUniform = false;
            const GLenum type = getDeclarationType(ti, isUniform);
            if (isUniform && (type != GL_NONE)) {
                // Read the name
                const String& name = ti.readSymbol();
                if (isValidIdentifier(name) && !beginsWith(name, "_noset_")) {
                    int arraySize = -1;

                    if ((ti.peek().type() == Token::SYMBOL) && (ti.peek().string() == "[")) {
                        ti.readSymbol("[");
                        parseTokenIntoIntegerLiteral(ti.read(), args, arraySize);
                        ti.readSymbol("]");
                    }

                    // Read until the semi-colon
                    while (ti.read().string() != ";");

                    if (arraySize < 0) { 
                        // Not an array
                        bool created;
                        UniformDeclaration& d = uniformDeclarationTable.getCreate(name, created);

                        // See if this variable is already declared.
                        if (created) {
                            int index = -1;
                            d.fillOutDummy(name, index, type);
                        }

                    } else { 
                        // An array
                        bool created;

                        for (int i = 0; i < arraySize; ++i) {
                            UniformDeclaration& d = uniformDeclarationTable.getCreate(name + format("[%d]", i), created);
                            // See if this variable is already declared.
                            if (created) {
                                d.fillOutDummy(name, i, type);
                            }
                        }
                    }
                }
            } else {
                ti.readUntilNewlineAsString();
            }
        } else {
            // Consume the entire line
            ti.readUntilNewlineAsString();
        }
    }
}
Exemple #5
0
bool isValidIdentifier( char c, char* delimiters, int totalDelimiters )
{
    if( delimiters == 0 || totalDelimiters == 0 )
        return isValidIdentifier( c );

    for( int i = 0; i < totalDelimiters; i++ )
    {
        if( c == delimiters[i] )
            return false;
    }
      
    return true;
}
void Shader::ShaderProgram::addVertexAttributesFromSource(const Array<PreprocessedShaderSource>& preprocessedSource) {
    
    const String& code = preprocessedSource[VERTEX].preprocessedCode;

    TextInput::Settings settings;
    settings.simpleFloatSpecials = false;
    TextInput ti(TextInput::FROM_STRING, code, settings);

    while (ti.hasMore()) {
        Token nextToken = ti.peek();
        if ((nextToken.type() == Token::SYMBOL) && (nextToken.string() != "#")) {
            const GLenum type = getDeclarationType(ti);
            if (type != GL_NONE) {
                // Read the name
                const String& name = ti.readSymbol();
            
                // If there is not a variable name following the type, then 
                // this is not a variable declaration. It may be a geometry shader declaration.
                if (isValidIdentifier(name)) {
                    int elementNum = 1;
                    if ((ti.peek().type() == Token::SYMBOL) && (ti.peek().string() == "[")) {
                        ti.readSymbol("[");
                        elementNum = (int)ti.readNumber();
                        ti.readSymbol("]");
                    }

                    bool created;
                    // See if this variable is already declared.
                    AttributeDeclaration& d = attributeDeclarationTable.getCreate(name, created);
                
                    if (created) {
                        d.location = -1;
                        d.name = name;
                        d.elementNum = elementNum;
                        d.type = type;
                    }
                }

                // Read until the semicolon
                while (ti.read().string() != ";");

            } else {
                ti.readUntilNewlineAsString();
            }
           
        } else {
            // Consume the entire line
            ti.readUntilNewlineAsString();
        }
    }
}
Exemple #7
0
bool TokenStream::MoveToNextLine( std::string* buffer )
{
    int length = ( int )data_.length( );

    if( startIndex_ < length && endIndex_ < length )
    {
        endIndex_ = startIndex_;

        while( endIndex_ < length && ( isValidIdentifier( data_[endIndex_] ) ||
            data_[endIndex_] == ' ' ) )
        {
            endIndex_++;
        }

        if( ( endIndex_ - startIndex_ ) == 0 )
            return false;

        if( endIndex_ - startIndex_ >= length )
            return false;

        if( buffer != NULL )
        {
            int size = ( endIndex_ - startIndex_ );
            int index = startIndex_;

            buffer->reserve( size + 1 );
            buffer->clear( );

            for( int i = 0; i < size; i++ )
            {
                buffer->push_back( data_[index++] );
            }
        }
    }
    else
    {
        return false;
    }

    endIndex_++;
    startIndex_ = endIndex_ + 1;

   return true;
}
Exemple #8
0
void XPathDataModel::setForeach(const std::string& item,
                                const std::string& array,
                                const std::string& index,
                                uint32_t iteration) {

    XPathValue<std::string> arrayResult = _xpath.evaluate_expr(array, _doc);
    assert(arrayResult.type() == NODE_SET);

#if 0
    std::cout << "Array Size: " << arrayResult.asNodeSet().size() << std::endl;
    for (size_t i = 0; i < arrayResult.asNodeSet().size(); i++) {
        std::cout << arrayResult.asNodeSet()[i] << std::endl;
    }
#endif

    assert(arrayResult.asNodeSet().size() >= iteration);


    NodeSet<std::string> arrayNodeSet;
    arrayNodeSet.push_back(arrayResult.asNodeSet()[iteration]);

    if (!isDeclared(item)) {
        if (!isValidIdentifier(item))
            ERROR_EXECUTION_THROW("Expression '" + item + "' not a valid identifier.");
        Element<std::string> container = _doc.createElement("data");
        container.setAttribute("id", item);
        container.appendChild(arrayResult.asNodeSet()[iteration].cloneNode(true));
        _datamodel.appendChild(container);
        _varResolver.setVariable(item, arrayNodeSet);
    }
    XPathValue<std::string> itemResult = _varResolver.resolveVariable("", item);
    assign(itemResult, arrayNodeSet, Element<std::string>());

    if (index.length() > 0) {
        NodeSet<std::string> indexNodeSet;
        Text<std::string> indexElem = _doc.createTextNode(toStr(iteration));
        indexNodeSet.push_back(indexElem);

        if (!isDeclared(index)) {
            Element<std::string> container = _doc.createElement("data");
            container.setAttribute("id", index);
            container.appendChild(indexElem);
            _datamodel.appendChild(container);

            NodeSet<std::string> indexVarNodeSet;
            indexVarNodeSet.push_back(container);
            _varResolver.setVariable(index, indexVarNodeSet);
        }
        XPathValue<std::string> indexResult = _varResolver.resolveVariable("", index);
        assign(indexResult, indexNodeSet, Element<std::string>());
    }


#if 0
    std::cout << _datamodel << std::endl << std::endl;
    std::cout << "Index: " << indexResult.asNodeSet().size() << std::endl;
    for (size_t i = 0; i < indexResult.asNodeSet().size(); i++) {
        std::cout << indexResult.asNodeSet()[i] << std::endl;
    }
    std::cout << std::endl;
#endif


}