Removed the 'verify' folder

This commit is contained in:
Daniel Marjamäki 2011-02-06 10:04:28 +01:00
parent f7dcf2d3b9
commit 2506c7db5c
8 changed files with 0 additions and 535 deletions

View File

@ -1,138 +0,0 @@
#include "codeeditor.h"
#include <QPainter>
#include <QTextBlock>
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
{
lineNumberArea = new LineNumberArea(this);
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(const QRect &, int)), this, SLOT(updateLineNumberArea(const QRect &, int)));
//connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
updateLineNumberAreaWidth(0);
//highlightCurrentLine();
}
int CodeEditor::lineNumberAreaWidth()
{
int digits = 1;
int max = qMax(1, blockCount());
while (max >= 10)
{
max /= 10;
++digits;
}
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
return space;
}
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
{
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
}
void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
{
if (dy)
lineNumberArea->scroll(0, dy);
else
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
if (rect.contains(viewport()->rect()))
updateLineNumberAreaWidth(0);
}
void CodeEditor::resizeEvent(QResizeEvent *e)
{
QPlainTextEdit::resizeEvent(e);
QRect cr = contentsRect();
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
/*
void CodeEditor::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (!isReadOnly())
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
*/
void CodeEditor::highlightErrors(const QList<int> &errorLines)
{
QList<QTextEdit::ExtraSelection> extraSelections;
for (int i = 0; i < errorLines.size(); ++i)
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::red).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
selection.cursor.movePosition(QTextCursor::Start);
selection.cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, errorLines[i] - 1);
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray);
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
int bottom = top + (int) blockBoundingRect(block).height();
while (block.isValid() && top <= event->rect().bottom())
{
if (block.isVisible() && bottom >= event->rect().top())
{
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::black);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
++blockNumber;
}
}

View File

@ -1,63 +0,0 @@
#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include <QPlainTextEdit>
#include <QObject>
#include <QList>
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
class LineNumberArea;
class CodeEditor : public QPlainTextEdit
{
Q_OBJECT
public:
CodeEditor(QWidget *parent = 0);
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void highlightErrors(const QList<int> &errorLines);
protected:
void resizeEvent(QResizeEvent *event);
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
//void highlightCurrentLine();
void updateLineNumberArea(const QRect &, int);
private:
QWidget *lineNumberArea;
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor)
{
codeEditor = editor;
}
QSize sizeHint() const
{
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event)
{
codeEditor->lineNumberAreaPaintEvent(event);
}
private:
CodeEditor *codeEditor;
};
#endif // CODEEDITOR_H

View File

@ -1,29 +0,0 @@
TARGET = cppcheck-verify
TEMPLATE = app
INCLUDEPATH += ../lib
SOURCES += main.cpp \
mainwindow.cpp \
../lib/tokenize.cpp \
../lib/token.cpp \
../lib/settings.cpp \
../lib/preprocessor.cpp \
../lib/path.cpp \
../lib/mathlib.cpp \
../lib/filelister_win32.cpp \
../lib/filelister_unix.cpp \
../lib/filelister.cpp \
../lib/errorlogger.cpp \
codeeditor.cpp
HEADERS += mainwindow.h \
../lib/tokenize.h \
../lib/token.h \
../lib/settings.h \
../lib/preprocessor.h \
../lib/path.h \
../lib/mathlib.h \
../lib/filelister_win32.h \
../lib/filelister_unix.h \
../lib/filelister.h \
../lib/errorlogger.h \
codeeditor.h
FORMS += mainwindow.ui

View File

@ -1,28 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -1,148 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "preprocessor.h"
#include "tokenize.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <QFileDialog>
static void arrayIndex(const Tokenizer &tokenizer, std::set<unsigned int> &errorlines);
static unsigned char readChar(std::istream &istr)
{
unsigned char ch = (unsigned char)istr.get();
// Handling of newlines..
if (ch == '\r')
{
ch = '\n';
if ((char)istr.peek() == '\n')
(void)istr.get();
}
return ch;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::open()
{
const std::string fileName = QFileDialog::getOpenFileName(this,
tr("Open File"),
"",
"cpp files (*.cpp)").toStdString();
if (fileName.empty())
return;
setWindowTitle(fileName.c_str());
Tokenizer tokenizer;
{
// Preprocess the file..
Preprocessor preprocessor;
std::ifstream fin(fileName.c_str());
std::string filedata;
std::list<std::string> configurations;
std::list<std::string> includePaths;
preprocessor.preprocess(fin,
filedata,
configurations,
fileName,
includePaths);
filedata = Preprocessor::getcode(filedata, "", fileName, NULL, NULL);
// Tokenize the preprocessed code..
std::istringstream istr(filedata);
tokenizer.tokenize(istr, fileName.c_str(), "");
}
// Check the tokens..
std::set<unsigned int> errorlines;
arrayIndex(tokenizer, errorlines);
// show report..
{
std::ostringstream report;
std::ifstream fin(fileName.c_str());
for (unsigned char c = readChar(fin); fin.good(); c = readChar(fin))
{
if (c & 0x80)
continue;
report << c;
}
ui->codeEditor->setPlainText(QString::fromStdString(report.str()));
QList<int> errorLines;
for (std::set<unsigned int>::const_iterator it = errorlines.begin(); it != errorlines.end(); ++it)
errorLines.push_back(*it);
ui->codeEditor->highlightErrors(errorLines);
}
}
/**
* Check that array indexes are within bounds
* 1. Locate array access through: [ .. ]
* 2. Try to determine if index is within bounds.
* 3. If it fails to determine that the index is within bounds then write warning
* \param tokenizer The tokenizer
* \param errout output stream to write warnings to
*/
static void arrayIndex(const Tokenizer &tokenizer, std::set<unsigned int> &errorlines)
{
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
{
// 1. Locate array access through: [ .. ]
if (tok->fileIndex() == 0 && tok->str() == "[")
{
// 2. try to determine if the array index is within bounds
// array declaration
if (Token::simpleMatch(tok, "[ ]"))
continue;
if (Token::Match(tok->tokAt(-2), "%type% %var% [ %num% ] ;|="))
continue;
// 3. If it fails to determine that the index is within bounds then write warning
errorlines.insert(tok->linenr());
}
}
}

View File

@ -1,43 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void open();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Cppcheck-Verify</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="CodeEditor" name="codeEditor">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="tabStopWidth">
<number>4</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionOpen">
<property name="text">
<string>Open..</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>CodeEditor</class>
<extends>QPlainTextEdit</extends>
<header>codeeditor.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,11 +0,0 @@
cppcheck-verify
===============
Experimental subproject for Cppcheck.
The goal is no false negatives.
Just use 'make' to build.