Commit 14ddfc45 authored by hjk's avatar hjk

Merge branch '0.9.1-beta' of git@scm.dev.nokia.troll.no:creator/mainline into 0.9.1-beta

parents 8d3a774f bf7486c0
......@@ -138,19 +138,9 @@ void Document::addIncludeFile(const QString &fileName)
_includedFiles.append(fileName);
}
QByteArray Document::definedMacros() const
void Document::appendMacro(const Macro &macro)
{
return _definedMacros;
}
void Document::appendMacro(const QByteArray &macroName, const QByteArray &text)
{
int index = macroName.indexOf('(');
if (index == -1)
_macroNames.insert(macroName);
else
_macroNames.insert(macroName.left(index));
_definedMacros += text;
_definedMacros.append(macro);
}
void Document::addMacroUse(unsigned offset, unsigned length)
......@@ -251,11 +241,6 @@ void Document::stopSkippingBlocks(unsigned stop)
_skippedBlocks.back() = Block(start, stop);
}
QSet<QByteArray> Document::macroNames() const
{
return _macroNames;
}
bool Document::parse(ParseMode mode)
{
TranslationUnit::ParseMode m = TranslationUnit::ParseTranlationUnit;
......
......@@ -36,6 +36,8 @@
#include <CPlusPlusForwardDeclarations.h>
#include "pp-macro.h"
#include <QByteArray>
#include <QList>
#include <QSet>
......@@ -45,6 +47,8 @@
namespace CPlusPlus {
class Macro;
class CPLUSPLUS_EXPORT Document
{
Document(const Document &other);
......@@ -63,10 +67,7 @@ public:
QStringList includedFiles() const;
void addIncludeFile(const QString &fileName);
QByteArray definedMacros() const;
QSet<QByteArray> macroNames() const;
void appendMacro(const QByteArray &macroName, const QByteArray &text);
void appendMacro(const Macro &macro);
void addMacroUse(unsigned offset, unsigned length);
......@@ -81,6 +82,9 @@ public:
Scope *globalSymbols() const; // ### deprecate?
Namespace *globalNamespace() const;
QList<Macro> definedMacros() const
{ return _definedMacros; }
Symbol *findSymbolAt(unsigned line, unsigned column) const;
void setSource(const QByteArray &source);
......@@ -191,8 +195,7 @@ private:
TranslationUnit *_translationUnit;
Namespace *_globalNamespace;
QList<DiagnosticMessage> _diagnosticMessages;
QByteArray _definedMacros;
QSet<QByteArray> _macroNames;
QList<Macro> _definedMacros;
QList<Block> _skippedBlocks;
QList<Block> _macroUses;
};
......
......@@ -48,6 +48,7 @@ TypeOfExpression::TypeOfExpression():
void TypeOfExpression::setDocuments(const QMap<QString, Document::Ptr> &documents)
{
m_documents = documents;
m_lookupContext = LookupContext();
}
QList<TypeOfExpression::Result> TypeOfExpression::operator()(const QString &expression,
......
......@@ -54,6 +54,9 @@ public:
/**
* Sets the documents used to evaluate expressions. Should be set before
* calling this functor.
*
* Also clears the lookup context, so can be used to make sure references
* to the documents previously used are removed.
*/
void setDocuments(const QMap<QString, Document::Ptr> &documents);
......
......@@ -21,7 +21,16 @@ HEADERS += \
TypeOfExpression.h \
TypePrettyPrinter.h \
ResolveExpression.h \
LookupContext.h
LookupContext.h \
pp-cctype.h \
pp-engine.h \
pp-fwd.h \
pp-macro-expander.h \
pp-scanner.h \
pp-client.h \
pp-environment.h \
pp-internal.h \
pp-macro.h
SOURCES += \
SimpleLexer.cpp \
......@@ -35,6 +44,9 @@ SOURCES += \
TypeOfExpression.cpp \
TypePrettyPrinter.cpp \
ResolveExpression.cpp \
LookupContext.cpp
LookupContext.cpp \
pp-engine.cpp \
pp-environment.cpp \
pp-macro-expander.cpp
RESOURCES += cplusplus.qrc
......@@ -53,22 +53,24 @@
#ifndef PP_CCTYPE_H
#define PP_CCTYPE_H
#include <CPlusPlusForwardDeclarations.h>
#include <cctype>
namespace rpp {
namespace CPlusPlus {
inline bool pp_isalpha (int __ch)
inline bool CPLUSPLUS_EXPORT pp_isalpha (int __ch)
{ return std::isalpha ((unsigned char) __ch) != 0; }
inline bool pp_isalnum (int __ch)
inline bool CPLUSPLUS_EXPORT pp_isalnum (int __ch)
{ return std::isalnum ((unsigned char) __ch) != 0; }
inline bool pp_isdigit (int __ch)
inline bool CPLUSPLUS_EXPORT pp_isdigit (int __ch)
{ return std::isdigit ((unsigned char) __ch) != 0; }
inline bool pp_isspace (int __ch)
inline bool CPLUSPLUS_EXPORT pp_isspace (int __ch)
{ return std::isspace ((unsigned char) __ch) != 0; }
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_CCTYPE_H
......@@ -34,15 +34,17 @@
#ifndef PP_CLIENT_H
#define PP_CLIENT_H
#include <CPlusPlusForwardDeclarations.h>
#include <QByteArray>
#include <QString>
#include <QFile>
namespace rpp {
namespace CPlusPlus {
class Macro;
class Client
class CPLUSPLUS_EXPORT Client
{
Client(const Client &other);
void operator=(const Client &other);
......@@ -60,7 +62,7 @@ public:
virtual ~Client()
{ }
virtual void macroAdded(const QByteArray &macroId, const QByteArray &text) = 0;
virtual void macroAdded(const Macro &macro) = 0;
virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature.
virtual void startExpandingMacro(unsigned offset,
......@@ -74,6 +76,6 @@ public:
virtual void stopSkippingBlocks(unsigned offset) = 0;
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_CLIENT_H
......@@ -57,7 +57,6 @@
#include <QtDebug>
#include <algorithm>
using namespace rpp;
using namespace CPlusPlus;
namespace {
......@@ -907,16 +906,8 @@ void pp::processDefine(TokenIterator firstToken, TokenIterator lastToken)
env.bind(macro);
QByteArray macroText;
macroText.reserve(64);
macroText += "#define ";
macroText += macroId;
macroText += ' ';
macroText += macro.definition;
macroText += '\n';
client->macroAdded(macroId, macroText);
if (client)
client->macroAdded(macro);
}
void pp::processIf(TokenIterator firstToken, TokenIterator lastToken)
......@@ -1020,13 +1011,10 @@ void pp::processUndef(TokenIterator firstToken, TokenIterator lastToken)
if (tk->is(T_IDENTIFIER)) {
const QByteArray macroName = tokenText(*tk);
env.remove(macroName);
const Macro *macro = env.remove(macroName);
QByteArray macroText;
macroText += "#undef ";
macroText += macroName;
macroText += '\n';
client->macroAdded(macroName, macroText);
if (client && macro)
client->macroAdded(*macro);
}
}
......
......@@ -62,7 +62,7 @@ namespace CPlusPlus {
class Token;
}
namespace rpp {
namespace CPlusPlus {
struct Value
{
......@@ -134,7 +134,7 @@ namespace rpp {
#undef PP_DEFINE_BIN_OP
};
class pp
class CPLUSPLUS_EXPORT pp
{
Client *client;
Environment &env;
......@@ -200,7 +200,7 @@ namespace rpp {
Value evalExpression(TokenIterator firstToken,
TokenIterator lastToken,
const QByteArray &source) const;
const QByteArray &source) const;
QVector<CPlusPlus::Token> tokenize(const QByteArray &text) const;
......@@ -226,6 +226,6 @@ namespace rpp {
bool isQtReservedWord(const QByteArray &name) const;
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_ENGINE_H
......@@ -54,7 +54,7 @@
#include "pp.h"
#include <cstring>
using namespace rpp;
using namespace CPlusPlus;
Environment::Environment ()
: currentLine(0),
......@@ -115,12 +115,12 @@ Macro *Environment::bind(const Macro &__macro)
return m;
}
void Environment::remove (const QByteArray &name)
Macro *Environment::remove (const QByteArray &name)
{
Macro macro;
macro.name = name;
macro.hidden = true;
bind(macro);
return bind(macro);
}
bool Environment::isBuiltinMacro(const QByteArray &s) const
......
......@@ -53,14 +53,16 @@
#ifndef PP_ENVIRONMENT_H
#define PP_ENVIRONMENT_H
#include "CPlusPlusForwardDeclarations.h"
#include <QVector>
#include <QByteArray>
namespace rpp {
namespace CPlusPlus {
struct Macro;
class Macro;
class Environment
class CPLUSPLUS_EXPORT Environment
{
public:
Environment();
......@@ -70,7 +72,7 @@ public:
Macro *macroAt(unsigned index) const;
Macro *bind(const Macro &macro);
void remove(const QByteArray &name);
Macro *remove(const QByteArray &name);
Macro *resolve(const QByteArray &name) const;
bool isBuiltinMacro(const QByteArray &name) const;
......@@ -104,6 +106,6 @@ private:
int _hash_count;
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_ENVIRONMENT_H
......@@ -55,7 +55,7 @@
#include <QByteArray>
namespace rpp {
namespace CPlusPlus {
namespace _PP_internal {
inline bool comment_p (const char *__first, const char *__last)
......@@ -73,6 +73,6 @@ inline bool comment_p (const char *__first, const char *__last)
}
} // _PP_internal
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_INTERNAL_H
......@@ -35,7 +35,7 @@
#include "pp-macro-expander.h"
#include <QDateTime>
using namespace rpp;
using namespace CPlusPlus;
MacroExpander::MacroExpander (Environment &env, pp_frame *frame)
: env(env), frame(frame),
......
......@@ -53,7 +53,7 @@
#ifndef PP_MACRO_EXPANDER_H
#define PP_MACRO_EXPANDER_H
namespace rpp {
namespace CPlusPlus {
struct pp_frame
{
......@@ -97,7 +97,7 @@ namespace rpp {
int generated_lines;
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_MACRO_EXPANDER_H
......@@ -53,43 +53,44 @@
#ifndef PP_MACRO_H
#define PP_MACRO_H
#include <CPlusPlusForwardDeclarations.h>
#include <QByteArray>
#include <QVector>
namespace rpp {
namespace CPlusPlus {
class CPLUSPLUS_EXPORT Macro
{
public:
QByteArray name;
QByteArray definition;
QVector<QByteArray> formals;
QByteArray fileName;
int line;
Macro *next;
unsigned hashcode;
struct Macro
union
{
QByteArray name;
QByteArray definition;
QVector<QByteArray> formals;
QByteArray fileName;
int line;
int lines;
Macro *next;
unsigned hashcode;
unsigned state;
union
struct
{
unsigned state;
struct
{
unsigned hidden: 1;
unsigned function_like: 1;
unsigned variadics: 1;
};
unsigned hidden: 1;
unsigned function_like: 1;
unsigned variadics: 1;
};
};
inline Macro():
inline Macro():
line(0),
lines(0),
next(0),
hashcode(0),
state(0)
{ }
};
{ }
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_MACRO_H
......@@ -53,7 +53,7 @@
#ifndef PP_SCANNER_H
#define PP_SCANNER_H
namespace rpp {
namespace CPlusPlus {
struct pp_skip_blanks
{
......@@ -373,7 +373,7 @@ struct pp_skip_argument
}
};
} // namespace rpp
} // namespace CPlusPlus
#endif // PP_SCANNER_H
......
......@@ -34,6 +34,8 @@
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectnodes.h"
#include "cmakestep.h"
#include "makestep.h"
#include <extensionsystem/pluginmanager.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -188,7 +190,7 @@ QString CMakeProject::buildDirectory(const QString &buildConfiguration) const
{
Q_UNUSED(buildConfiguration)
//TODO
return "";
return QFileInfo(m_fileName).absolutePath();
}
ProjectExplorer::BuildStepConfigWidget *CMakeProject::createConfigWidget()
......@@ -225,13 +227,29 @@ QStringList CMakeProject::files(FilesMode fileMode) const
void CMakeProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer)
{
// TODO
Q_UNUSED(writer)
Q_UNUSED(writer);
}
void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
{
// TODO
Q_UNUSED(reader)
Q_UNUSED(reader);
if (buildConfigurations().isEmpty()) {
// No build configuration, adding those
// TODO do we want to create one build configuration per target?
// or how do we want to handle that?
CMakeStep *cmakeStep = new CMakeStep(this);
MakeStep *makeStep = new MakeStep(this);
insertBuildStep(0, cmakeStep);
insertBuildStep(1, makeStep);
addBuildConfiguration("all");
setActiveBuildConfiguration("all");
}
// Restoring is fine
}
......@@ -376,12 +394,36 @@ void CMakeCbpParser::parseBuild()
void CMakeCbpParser::parseTarget()
{
m_targetOutput.clear();
m_targetType = false;
while(!atEnd()) {
readNext();
if (isEndElement()) {
if (m_targetType && !m_targetOutput.isEmpty()) {
qDebug()<<"found target "<<m_targetOutput;
m_targets.insert(m_targetOutput);
}
return;
} else if (name() == "Compiler") {
parseCompiler();
} else if (name() == "Option") {
parseTargetOption();
} else if (isStartElement()) {
parseUnknownElement();
}
}
}
void CMakeCbpParser::parseTargetOption()
{
if (attributes().hasAttribute("output"))
m_targetOutput = attributes().value("output").toString();
else if (attributes().hasAttribute("type") && attributes().value("type") == "1")
m_targetType = true;
while(!atEnd()) {
readNext();
if (isEndElement()) {
return;
} else if (isStartElement()) {
parseUnknownElement();
}
......
......@@ -123,13 +123,18 @@ private:
void parseProject();
void parseBuild();
void parseTarget();
void parseTargetOption();
void parseCompiler();
void parseAdd();
void parseUnit();
void parseUnknownElement();
QSet<QString> m_targets;
QList<ProjectExplorer::FileNode *> m_fileList;
QStringList m_includeFiles;
QString m_targetOutput;
bool m_targetType;
};
class CMakeFile : public Core::IFile
......
......@@ -54,7 +54,7 @@ bool CMakeStep::init(const QString &buildConfiguration)
setEnabled(buildConfiguration, true);
setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration));
setCommand(buildConfiguration, "cmake"); // TODO give full path here?
setArguments(buildConfiguration, QStringList()); // TODO
setArguments(buildConfiguration, QStringList() << "-GUnix Makefiles"); // TODO
setEnvironment(buildConfiguration, m_pro->environment(buildConfiguration));
return AbstractProcessStep::init(buildConfiguration);
}
......
......@@ -699,7 +699,9 @@ void CppCodeCompletion::addMacros(const LookupContext &context)
continue;
processed.insert(fn);
if (Document::Ptr doc = context.document(fn)) {
macroNames += doc->macroNames();
foreach (const Macro macro, doc->definedMacros()) {
macroNames.insert(macro.name);
}
todo += doc->includedFiles();
}
}
......@@ -1025,6 +1027,10 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
void CppCodeCompletion::cleanup()
{
m_completions.clear();
// Set empty map in order to avoid referencing old versions of the documents
// until the next completion
typeOfExpression.setDocuments(QMap<QString, Document::Ptr>());
}
int CppCodeCompletion::findStartOfName(const TextEditor::ITextEditor *editor)
......
......@@ -31,7 +31,7 @@
**
***************************************************************************/
#include "pp.h"
#include <cplusplus/pp.h>
#include "cppmodelmanager.h"
#include "cpphoverhandler.h"
......@@ -107,7 +107,7 @@ static const char pp_configuration[] =
namespace CppTools {
namespace Internal {
class CppPreprocessor: public rpp::Client
class CppPreprocessor: public CPlusPlus::Client
{
public:
CppPreprocessor(QPointer<CppModelManager> modelManager);
......@@ -129,12 +129,11 @@ protected:
void mergeEnvironment(CPlusPlus::Document::Ptr doc);
void mergeEnvironment(CPlusPlus::Document::Ptr doc, QSet<QString> *processed);
virtual void macroAdded(const QByteArray &macroName,
const QByteArray &macroText);
virtual void macroAdded(const Macro &macro);
virtual void startExpandingMacro(unsigned offset,
const rpp::Macro &macro,
const Macro &macro,
const QByteArray &originalText);