示例#1
0
// Command = ConstDeclaration | Expression | FuncDeclaration
QString Parser::command()
{
	QString result;

	// const declaration
	if (m_lexer->lexeme().type == LexemeConst) {
		result = constDeclaration();
		ensureNoMoreLexemes();
	}

	// func declaration
	else if (m_lexer->lexeme().type == LexemeFunc) {
		result = functionDeclaration();
		ensureNoMoreLexemes();
	}

	// Expression
	else {
		Rpn::CodeThread codeThread = expression(); // convert expression to RPN
		ensureNoMoreLexemes();
		Rpn::Operand expressionResult = m_calculator->calculate(codeThread);

		PrettyPrinter printer(m_document);
		result = QString("%1 = %2").arg(printer.process(codeThread)).arg(expressionResult.toString());
	}

	return result;
}
示例#2
0
  void insideBlock(BlockNode* node) {
    variableDeclaration(node->scope());
    functionDeclaration(node->scope());

    for (uint32_t i = 0; i < node->nodes(); i++) {
      indent();
      AstNode* current = node->nodeAt(i);
      current->visit(this);
      if (current->isCallNode() || current->isBinaryOpNode() ||
          current->isUnaryOpNode() || current->isStringLiteralNode() ||
          current->isDoubleLiteralNode() || current->isIntLiteralNode() ||
          current->isLoadNode())
        _output << ";";
      _output << endl;
    }
  }
示例#3
0
void AddMethodDialog::accept()
{
	m_cppSupport->partController() ->editDocument( KURL( m_klass->fileName() ) );
	KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() );
	if ( !editIface )
	{
		/// @todo show messagebox
		QDialog::accept();
		return ;
	}

	int line, column;
	m_klass->getEndPosition( &line, &column );

	// compute the insertion point map
	QMap<QString, QPair<int, int> > points;
	QStringList accessList;

	const FunctionList functionList = m_klass->functionList();
	for ( FunctionList::ConstIterator it = functionList.begin(); it != functionList.end(); ++it )
	{
		int funEndLine, funEndColumn;
		( *it ) ->getEndPosition( &funEndLine, &funEndColumn );
		QString access = accessID( *it );
		QPair<int, int> funEndPoint = qMakePair( funEndLine, funEndColumn );

		if ( !points.contains( access ) || points[ access ] < funEndPoint )
		{
			accessList.remove( access );
			accessList.push_back( access ); // move 'access' at the end of the list

			points[ access ] = funEndPoint;
		}
	}

	int insertedLine = 0;

	accessList += newAccessList( accessList );

	for ( QStringList::iterator it = accessList.begin(); it != accessList.end(); ++it )
	{
		QListViewItem* item = methods->firstChild();
		while ( item )
		{
			QListViewItem * currentItem = item;

			item = item->nextSibling();

			if ( currentItem->text( 1 ) != *it )
				continue;

			QString access = ( *it ).lower();

			bool isInline = currentItem->text( 0 ) == "True";
			QString str = isInline ? functionDefinition( currentItem ) : functionDeclaration( currentItem );

			QPair<int, int> pt;
			if ( points.contains( *it ) )
			{
				pt = points[ *it ];
			}
			else
			{
			str.prepend( access + ":\n" );
				points[ *it ] = qMakePair( line - 1, 0 );
				pt = points[ *it ]; // end of class declaration
			}

			editIface->insertText( pt.first + insertedLine + 1, 0 /*pt.second*/, str );
			insertedLine += str.contains( QChar( '\n' ) );
		}
	}

	m_cppSupport->backgroundParser() ->addFile( m_klass->fileName() );

	QString str;
	QListViewItem* item = methods->firstChild();
	while ( item )
	{
		QListViewItem * currentItem = item;

		item = item->nextSibling();

		QString str = functionDefinition( currentItem );
		if ( str.isEmpty() )
			continue;

		QString implementationFile = currentItem->text( 5 );
		if ( currentItem->text( 0 ) == "True" )
			implementationFile = m_klass->fileName();

		QFileInfo fileInfo( implementationFile );
		if ( !QFile::exists( fileInfo.absFilePath() ) )
		{
			if ( KDevCreateFile * createFileSupp = m_cppSupport->extension<KDevCreateFile>( "KDevelop/CreateFile" ) )
				createFileSupp->createNewFile( fileInfo.extension(), fileInfo.dirPath( true ), fileInfo.baseName() );
		}

		m_cppSupport->partController() ->editDocument( KURL( implementationFile ) );
		editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() );
		if ( !editIface )
			continue;

		bool isInline = currentItem->text( 0 ) == "True";
		if ( !isInline )
		{
			editIface->insertLine( editIface->numLines(), QString::fromLatin1( "" ) );
			editIface->insertText( editIface->numLines() - 1, 0, str );
			m_cppSupport->backgroundParser() ->addFile( implementationFile );
		}
	}

	QDialog::accept();
}