aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-07-28 10:07:19 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-07-28 12:14:43 +0200
commit1fe1c6d0b409e03b0015bba7efaa0607c0cdc0cc (patch)
treec1da815c75dee54f9d24c1e31bb14080c206f6d6
parentfb09f5cc01bb1d8d34abcff6a767991575376357 (diff)
C++: Tests: Remove plain-cplusplus
Change-Id: Ifdf4cd5ea478c87d585c9404caf8f4be6873f692 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r--.gitignore1
-rw-r--r--tests/manual/manual.pro1
-rw-r--r--tests/manual/plain-cplusplus/Preprocessor.cpp339
-rw-r--r--tests/manual/plain-cplusplus/Preprocessor.h135
-rw-r--r--tests/manual/plain-cplusplus/main.cpp160
-rw-r--r--tests/manual/plain-cplusplus/plain-cplusplus.pro28
6 files changed, 0 insertions, 664 deletions
diff --git a/.gitignore b/.gitignore
index 75cc619019..1faf39d51c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -136,7 +136,6 @@ tmp/
/tests/manual/qml-ast2dot/qml-ast2dot
/tests/manual/debugger/simple/libsimple_test_plugin.*dylib
/tests/manual/debugger/simple/simple_test_app
-/tests/manual/plain-cplusplus/plain-c++
/tests/manual/preprocessor/pp
/tests/tools/cplusplus-ast2png/cplusplus-ast2png
/tests/auto/aggregation/tst_aggregation
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index 3069364b82..a495851359 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -10,7 +10,6 @@ utils
unix {
# Uses popen
SUBDIRS += \
- plain-cplusplus \
# Profile library paths issues
process \
ssh
diff --git a/tests/manual/plain-cplusplus/Preprocessor.cpp b/tests/manual/plain-cplusplus/Preprocessor.cpp
deleted file mode 100644
index 876f18ae9b..0000000000
--- a/tests/manual/plain-cplusplus/Preprocessor.cpp
+++ /dev/null
@@ -1,339 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "Preprocessor.h"
-#include "Lexer.h"
-#include <list>
-#include <iostream>
-#include <cassert>
-
-using namespace CPlusPlus;
-
-std::ostream &operator << (std::ostream &out, const StringRef &s)
-{
- out.write(s.text(), s.size());
- return out;
-}
-
-struct Preprocessor::TokenBuffer
-{
- std::list<Token> tokens;
- const Macro *macro;
- TokenBuffer *next;
-
- template <typename _Iterator>
- TokenBuffer(_Iterator firstToken, _Iterator lastToken, const Macro *macro, TokenBuffer *next)
- : tokens(firstToken, lastToken), macro(macro), next(next) {}
-};
-
-Lexer *Preprocessor::switchLexer(Lexer *lex)
-{
- Lexer *previousLexer = _lexer;
- _lexer = lex;
- return previousLexer;
-}
-
-StringRef Preprocessor::switchSource(const StringRef &source)
-{
- StringRef previousSource = _source;
- _source = source;
- return previousSource;
-}
-
-const Preprocessor::Macro *Preprocessor::resolveMacro(const StringRef &name) const
-{
- std::map<StringRef, Macro>::const_iterator it = macros.find(name);
- if (it != macros.end()) {
- const Macro *m = &it->second;
- for (TokenBuffer *r = _tokenBuffer; r; r = r->next) {
- if (r->macro == m)
- return 0;
- }
- return m;
- }
-
- return 0;
-}
-
-void Preprocessor::collectActualArguments(Token *tk, std::vector<std::vector<Token> > *actuals)
-{
- lex(tk);
-
- assert(tk->is(T_LPAREN));
-
- lex(tk);
-
- std::vector<Token> tokens;
- scanActualArgument(tk, &tokens);
-
- actuals->push_back(tokens);
-
- while (tk->is(T_COMMA)) {
- lex(tk);
-
- std::vector<Token> tokens;
- scanActualArgument(tk, &tokens);
- actuals->push_back(tokens);
- }
-
- assert(tk->is(T_RPAREN));
- lex(tk);
-}
-
-void Preprocessor::scanActualArgument(Token *tk, std::vector<Token> *tokens)
-{
- int count = 0;
-
- while (tk->isNot(T_EOF_SYMBOL)) {
- if (tk->is(T_LPAREN)) {
- ++count;
- } else if (tk->is(T_RPAREN)) {
- if (! count)
- break;
-
- --count;
- } else if (! count && tk->is(T_COMMA)) {
- break;
- }
-
- tokens->push_back(*tk);
- lex(tk);
- }
-}
-
-void Preprocessor::lex(Token *tk)
-{
-_Lagain:
- if (_tokenBuffer) {
- if (_tokenBuffer->tokens.empty()) {
- TokenBuffer *r = _tokenBuffer;
- _tokenBuffer = _tokenBuffer->next;
- delete r;
- goto _Lagain;
- }
- *tk = _tokenBuffer->tokens.front();
- _tokenBuffer->tokens.pop_front();
- } else {
- _lexer->scan(tk);
- }
-
-_Lclassify:
- if (! inPreprocessorDirective) {
- if (tk->newline() && tk->is(T_POUND)) {
- handlePreprocessorDirective(tk);
- goto _Lclassify;
-
- } else if (tk->is(T_IDENTIFIER)) {
- const StringRef id = asStringRef(*tk);
-
- if (const Macro *macro = resolveMacro(id)) {
- std::vector<Token> body = macro->body;
-
- if (macro->isFunctionLike) {
- std::vector<std::vector<Token> > actuals;
- collectActualArguments(tk, &actuals);
-
- std::vector<Token> expanded;
- for (size_t i = 0; i < body.size(); ++i) {
- const Token &token = body[i];
-
- if (token.isNot(T_IDENTIFIER)) {
- expanded.push_back(token);
- } else {
- const StringRef id = asStringRef(token);
- size_t j = 0;
- for (; j < macro->formals.size(); ++j) {
- if (macro->formals[j] == id) {
- expanded.insert(expanded.end(), actuals[j].begin(), actuals[j].end());
- break;
- }
- }
-
- if (j == macro->formals.size())
- expanded.push_back(token);
- }
- }
-
- const Token currentTokenBuffer[] = { *tk };
- _tokenBuffer = new TokenBuffer(currentTokenBuffer, currentTokenBuffer + 1,
- /*macro */ 0, _tokenBuffer);
-
- body = expanded;
- }
-
- _tokenBuffer = new TokenBuffer(body.begin(), body.end(),
- macro, _tokenBuffer);
- goto _Lagain;
- }
- }
- }
-}
-
-void Preprocessor::handlePreprocessorDirective(Token *tk)
-{
- inPreprocessorDirective = true;
-
- lex(tk); // scan the directive
-
- if (tk->newline() && ! tk->joined())
- return; // nothing to do.
-
- const StringRef ppDefine("define", 6);
-
- if (tk->is(T_IDENTIFIER)) {
- const StringRef directive = asStringRef(*tk);
-
- if (directive == ppDefine)
- handleDefineDirective(tk);
- else
- skipPreprocesorDirective(tk);
- }
-
- inPreprocessorDirective = false;
-}
-
-bool Preprocessor::isValidToken(const Token &tk) const
-{
- if (tk.isNot(T_EOF_SYMBOL) && (! tk.newline() || tk.joined()))
- return true;
-
- return false;
-}
-
-void Preprocessor::handleDefineDirective(Token *tk)
-{
- lex(tk);
-
- if (tk->is(T_IDENTIFIER)) {
- const StringRef macroName = asStringRef(*tk);
- Macro macro;
-
- lex(tk);
-
- if (isValidToken(*tk) && tk->is(T_LPAREN) && ! tk->whitespace()) {
- macro.isFunctionLike = true;
-
- lex(tk); // skip `('
-
- if (isValidToken(*tk) && tk->is(T_IDENTIFIER)) {
- macro.formals.push_back(asStringRef(*tk));
-
- lex(tk);
-
- while (isValidToken(*tk) && tk->is(T_COMMA)) {
- lex(tk);
-
- if (isValidToken(*tk) && tk->is(T_IDENTIFIER)) {
- macro.formals.push_back(asStringRef(*tk));
- lex(tk);
- }
- }
- }
-
- if (isValidToken(*tk) && tk->is(T_RPAREN))
- lex(tk); // skip `)'
- }
-
- while (isValidToken(*tk)) {
- macro.body.push_back(*tk);
- lex(tk);
- }
-
- macros.insert(std::make_pair(macroName, macro));
- } else {
- skipPreprocesorDirective(tk);
- }
-}
-
-void Preprocessor::skipPreprocesorDirective(Token *tk)
-{
- do {
- lex(tk);
- } while (isValidToken(*tk));
-}
-
-StringRef Preprocessor::asStringRef(const Token &tk) const
-{ return StringRef(_source.begin() + tk.bytesBegin(), tk.bytes()); }
-
-Preprocessor::Preprocessor(std::ostream &out)
- : out(out), _lexer(0), inPreprocessorDirective(false)
-{ }
-
-void Preprocessor::operator()(const char *source, unsigned size, const StringRef &currentFileName)
-{
- _currentFileName = currentFileName;
- run(source, size);
-}
-
-void Preprocessor::run(const char *source, unsigned size)
-{
- _tokenBuffer = 0;
-
- const StringRef previousSource = switchSource(StringRef(source, size));
- Lexer thisLexer(source, source + size);
- thisLexer.setScanKeywords(false);
- Lexer *previousLexer = switchLexer(&thisLexer);
- inPreprocessorDirective = false;
-
- Token tk;
- unsigned lineno = 0;
- do {
- lex(&tk);
-
- if (lineno != tk.lineno) {
- if (lineno > tk.lineno || tk.lineno - lineno > 3) {
- out << std::endl << "#line " << tk.lineno << " \"" << _currentFileName << "\"" << std::endl;
- } else {
- for (unsigned i = lineno; i < tk.lineno; ++i)
- out << std::endl;
- }
-
- lineno = tk.lineno;
-
- } else {
- if (tk.newline())
- out << std::endl;
-
- if (tk.whitespace())
- out << ' ';
- }
-
- out << asStringRef(tk);
- lineno = tk.lineno;
- } while (tk.isNot(T_EOF_SYMBOL));
-
- out << std::endl;
-
- switchLexer(previousLexer);
- switchSource(previousSource);
-}
-
-
-
-
diff --git a/tests/manual/plain-cplusplus/Preprocessor.h b/tests/manual/plain-cplusplus/Preprocessor.h
deleted file mode 100644
index a30bd7751d..0000000000
--- a/tests/manual/plain-cplusplus/Preprocessor.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-#ifndef CPLUSPLUS_PREPROCESSOR_H
-#define CPLUSPLUS_PREPROCESSOR_H
-
-#include <CPlusPlusForwardDeclarations.h>
-#include <iosfwd>
-#include <vector>
-#include <map>
-#include <cstring>
-
-namespace CPlusPlus {
-
-class Lexer;
-class Token;
-
-class StringRef
-{
- const char *_text;
- unsigned _size;
-
-public:
- typedef const char *iterator;
- typedef const char *const_iterator;
-
- StringRef()
- : _text(0), _size(0) {}
-
- StringRef(const char *text, unsigned size)
- : _text(text), _size(size) {}
-
- StringRef(const char *text)
- : _text(text), _size(std::strlen(text)) {}
-
- inline const char *text() const { return _text; }
- inline unsigned size() const { return _size; }
-
- inline const_iterator begin() const { return _text; }
- inline const_iterator end() const { return _text + _size; }
-
- bool operator == (const StringRef &other) const
- {
- if (_size == other._size)
- return _text == other._text || ! std::strncmp(_text, other._text, _size);
-
- return false;
- }
-
- bool operator != (const StringRef &other) const
- { return ! operator == (other); }
-
- bool operator < (const StringRef &other) const
- { return std::lexicographical_compare(begin(), end(), other.begin(), other.end()); }
-};
-
-class CPLUSPLUS_EXPORT Preprocessor
-{
-public:
- Preprocessor(std::ostream &out);
-
- void operator()(const char *source, unsigned size, const StringRef &currentFileName);
-
-private:
- struct Macro
- {
- Macro(): isFunctionLike(false), isVariadic(false) {}
-
- std::vector<StringRef> formals;
- std::vector<Token> body;
- bool isFunctionLike: 1;
- bool isVariadic: 1;
- };
-
- void run(const char *source, unsigned size);
-
- Lexer *switchLexer(Lexer *lex);
- StringRef switchSource(const StringRef &source);
-
- const Macro *resolveMacro(const StringRef &name) const;
-
- StringRef asStringRef(const Token &tk) const;
- void lex(Token *tk);
- bool isValidToken(const Token &tk) const;
-
- void handlePreprocessorDirective(Token *tk);
- void handleDefineDirective(Token *tk);
- void skipPreprocesorDirective(Token *tk);
-
- void collectActualArguments(Token *tk, std::vector<std::vector<Token> > *actuals);
- void scanActualArgument(Token *tk, std::vector<Token> *tokens);
-
-private:
- struct TokenBuffer;
-
- std::ostream &out;
- StringRef _currentFileName;
- Lexer *_lexer;
- StringRef _source;
- TokenBuffer *_tokenBuffer;
- bool inPreprocessorDirective: 1;
- std::map<StringRef, Macro> macros;
-};
-
-} // end of namespace CPlusPlus
-
-CPLUSPLUS_EXPORT std::ostream &operator << (std::ostream &out, const CPlusPlus::StringRef &s);
-
-#endif // CPLUSPLUS_PREPROCESSOR_H
-
diff --git a/tests/manual/plain-cplusplus/main.cpp b/tests/manual/plain-cplusplus/main.cpp
deleted file mode 100644
index 3fb94be60b..0000000000
--- a/tests/manual/plain-cplusplus/main.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "Preprocessor.h"
-#include <CPlusPlus.h>
-
-#include <string>
-#include <cstdlib>
-#include <sstream>
-
-using namespace CPlusPlus;
-
-enum { BLOCK_SIZE = 4 * 1024};
-
-void parse(const char *fileName, const char *source, unsigned size);
-int runWithSystemPreprocessor(int argc, char *argv[]);
-int runWithNewPreprocessor(int argc, char *argv[]);
-
-struct V: public ASTVisitor
-{
- V(TranslationUnit *unit)
- : ASTVisitor(unit) {}
-
- virtual bool visit(FunctionDeclaratorAST *ast)
- {
- if (ast->as_cpp_initializer) {
- if (! (ast->symbol && ast->symbol->enclosingScope()))
- ; //translationUnit()->warning(ast->firstToken(), "resolved as function declaration");
- else if (ast->symbol->enclosingScope()->isNamespace() || ast->symbol->enclosingScope()->isTemplate())
- ; //translationUnit()->warning(ast->firstToken(), "resolved as function declaration");
- else if (ast->symbol->enclosingScope()->isBlock())
- ; //translationUnit()->warning(ast->firstToken(), "resolved as C++ initializer");
- else
- translationUnit()->warning(ast->firstToken(), "ambiguous function declarator or C++ intializer");
- }
- return true;
- }
-
- virtual bool visit(ExpressionOrDeclarationStatementAST *ast)
- {
- translationUnit()->warning(ast->firstToken(), "ambiguous expression or declaration statement");
- return true;
- }
-};
-
-int main(int argc, char *argv[])
-{
- if (getenv("CPLUSPLUS_WITH_NEW_PREPROCESSOR"))
- return runWithNewPreprocessor(argc, argv);
-
- return runWithSystemPreprocessor(argc, argv);
-}
-
-int runWithSystemPreprocessor(int argc, char *argv[])
-{
- std::string cmdline;
- cmdline += "gcc -E -xc++ -U__BLOCKS__ -D__restrict= -D__restrict__= -D__extension__= -D__imag__= -D__real__= -D__complex__= -D_Complex= -D__signed=signed";
-
- for (int i = 1; i < argc; ++i) {
- cmdline += ' ';
- cmdline += argv[i];
- }
-
- char block[BLOCK_SIZE];
-
- std::string preprocessedCode;
-
- if (FILE *fp = popen(cmdline.c_str(), "r")) {
- while (size_t sz = fread(block, 1, BLOCK_SIZE, fp))
- preprocessedCode.append(block, sz);
-
- pclose(fp);
-
- } else {
- fprintf(stderr, "c++: No such file or directory\n");
- return EXIT_FAILURE;
- }
-
- parse("<stdin>", preprocessedCode.c_str(), preprocessedCode.size());
- return EXIT_SUCCESS;
-}
-
-int runWithNewPreprocessor(int argc, char *argv[])
-{
- if (argc == 1) {
- fprintf(stderr, "c++: No such file or directory\n");
- return EXIT_FAILURE;
- }
-
- char block[BLOCK_SIZE];
-
- std::string source;
-
- if (FILE *fp = fopen(argv[1], "r")) {
- while (size_t sz = fread(block, 1, BLOCK_SIZE, fp))
- source.append(block, sz);
-
- fclose(fp);
-
- } else {
- fprintf(stderr, "c++: No such file or directory\n");
- return EXIT_FAILURE;
- }
-
- std::ostringstream out;
- Preprocessor pp(out);
- pp(source.c_str(), source.size(), StringRef(argv[1]));
-
- const std::string preprocessedCode = out.str();
- parse(argv[1], preprocessedCode.c_str(), preprocessedCode.size());
- return EXIT_SUCCESS;
-}
-
-void parse(const char *fileName, const char *source, unsigned size)
-{
- Control control;
-
- LanguageFeatures features;
- features.cxx11Enabled = true;
-
- TranslationUnit unit(&control, control.stringLiteral(fileName));
- unit.setSource(source, size);
- unit.setLanguageFeatures(features);
- unit.parse();
-
-#if 1
- Namespace *globalNamespace = control.newNamespace(0);
- Bind bind(&unit);
- bind(unit.ast()->asTranslationUnit(), globalNamespace);
-
- V v(&unit);
- v.accept(unit.ast());
-#endif
-}
diff --git a/tests/manual/plain-cplusplus/plain-cplusplus.pro b/tests/manual/plain-cplusplus/plain-cplusplus.pro
deleted file mode 100644
index 3272942d25..0000000000
--- a/tests/manual/plain-cplusplus/plain-cplusplus.pro
+++ /dev/null
@@ -1,28 +0,0 @@
-QT -= core gui
-greaterThan(QT_MAJOR_VERSION, 4):QT += widgets
-TARGET = plain-c++
-DEFINES += CPLUSPLUS_WITHOUT_QT
-
-macx {
- CONFIG -= app_bundle
- release:LIBS += -Wl,-exported_symbol -Wl,_main
-}
-
-include(../../../src/libs/3rdparty/cplusplus/cplusplus.pri)
-INCLUDEPATH += ../../../src/libs/3rdparty/cplusplus
-
-# Input
-HEADERS += Preprocessor.h
-SOURCES += Preprocessor.cpp
-SOURCES += main.cpp
-
-unix {
- debug:OBJECTS_DIR = $${OUT_PWD}/.obj/debug-shared
- release:OBJECTS_DIR = $${OUT_PWD}/.obj/release-shared
-
- debug:MOC_DIR = $${OUT_PWD}/.moc/debug-shared
- release:MOC_DIR = $${OUT_PWD}/.moc/release-shared
-
- RCC_DIR = $${OUT_PWD}/.rcc/
- UI_DIR = $${OUT_PWD}/.uic/
-}