Example #1
0
void QmlCodeParser::parseSourceFile(const Location& location,
                                    const QString& filePath,
                                    Tree *tree)
{
    QFile in(filePath);
    if (!in.open(QIODevice::ReadOnly)) {
        location.error(tr("Cannot open QML file '%1'").arg(filePath));
        return;
    }

    QString document = in.readAll();
    in.close();

    Location fileLocation(filePath);

    QString newCode = document;
    extractPragmas(newCode);
    lexer->setCode(newCode, 1);

    QSet<QString> topicCommandsAllowed = topicCommands();
    QSet<QString> otherMetacommandsAllowed = otherMetaCommands();
    QSet<QString> metacommandsAllowed = topicCommandsAllowed +
        otherMetacommandsAllowed;

    QDeclarativeJS::NodePool m_nodePool(filePath, &engine);

    if (parser->parse()) {
        QDeclarativeJS::AST::UiProgram *ast = parser->ast();
        QmlDocVisitor visitor(filePath, newCode, &engine, tree, metacommandsAllowed);
        QDeclarativeJS::AST::Node::accept(ast, &visitor);
    }
}
Example #2
0
void QsCodeParser::parseHeaderFile(const Location& location,
                                   const QString& filePath,
                                   Tree *tree)
{
    qsTre = tree;

    FILE *in = fopen(QFile::encodeName(filePath), "r");
    if (in == 0) {
	location.error(tr("Cannot open Qt Script class list '%1'")
			.arg(filePath));
	return;
    }

    Location fileLocation(filePath);
    Tokenizer fileTokenizer(fileLocation, in);
    int tok = fileTokenizer.getToken();
    while (tok != Tok_Eoi) {
	if (tok == Tok_Ident) {
	    ClassNode *quickClass = new ClassNode(qsTre->root(),
						   fileTokenizer.lexeme());
	    quickClass->setLocation(fileTokenizer.location());
	}
        else {
	    fileTokenizer.location().error(tr("Unexpected token '%1' in Qt"
					       " Script class list")
					    .arg(fileTokenizer.lexeme()));
	    break;
	}
	tok = fileTokenizer.getToken();
    }
    fclose(in);
}
Example #3
0
/*!
  Parses the source file identified by \a filePath and adds its
  parsed contents to the database. The \a location is used for
  reporting errors.
 */
void PureDocParser::parseSourceFile(const Location& location, const QString& filePath)
{
    QFile in(filePath);
    currentFile_ = filePath;
    if (!in.open(QIODevice::ReadOnly)) {
        location.error(tr("Can't open source file '%1' (%2)").arg(filePath).arg(strerror(errno)));
        currentFile_.clear();
        return;
    }

    reset();
    Location fileLocation(filePath);
    Tokenizer fileTokenizer(fileLocation, in);
    tokenizer = &fileTokenizer;
    readToken();

    /*
      The set of open namespaces is cleared before parsing
      each source file. The word "source" here means cpp file.
     */
    qdb_->clearOpenNamespaces();

    processQdocComments();
    in.close();
    currentFile_.clear();
}