File: msvccompiler.cpp

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (135 lines) | stat: -rw-r--r-- 5,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * This file is part of KDevelop
 *
 * Copyright 2010 Patrick Spendrin <ps_ml@gmx.de>
 * Copyright 2013 Kevin Funk <kfunk@kde.org>
 * Copyright 2014 Sergey Kalinichev <kalinichev.so.0@gmail.com>
 *
 * 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 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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 "msvccompiler.h"

#include <QDir>
#include <QProcessEnvironment>

#include <KProcess>

#include <debug.h>

using namespace KDevelop;

Defines MsvcCompiler::defines(Utils::LanguageType, const QString&) const
{
    Defines ret;
    //Get standard macros from kdevmsvcdefinehelpers
    KProcess proc;
    proc.setOutputChannelMode( KProcess::MergedChannels );
    proc.setTextModeEnabled( true );

    // we want to use kdevmsvcdefinehelper as a pseudo compiler backend which
    // returns the defines used in msvc. there is no such thing as -dM with cl.exe
    proc << path() << QStringLiteral("/nologo") << QStringLiteral("/Bxkdevmsvcdefinehelper") << QStringLiteral("empty.cpp");

    // this will fail, so check on that as well
    if ( proc.execute( 5000 ) == 2 ) {
        QString line;
        proc.readLine(); // read the filename

        while ( proc.canReadLine() ) {
            QByteArray buff = proc.readLine();
            qCDebug(DEFINESANDINCLUDES) << "msvcstandardmacros:" << buff;
            if ( !buff.isEmpty() ) {
                line = QString::fromUtf8(buff);
                if ( line.startsWith( QLatin1String("#define ") ) ) {
                    line = line.midRef(8).trimmed().toString();
                    int pos = line.indexOf(QLatin1Char(' '));

                    if ( pos != -1 ) {
                        ret[line.left(pos)] = line.mid(pos + 1);
                    } else {
                        ret[line] = QLatin1String("");
                    }
                }
            }
        }
    } else {
        qCDebug(DEFINESANDINCLUDES) << QLatin1String("Unable to read standard c++ macro definitions from ") + path();
        while ( proc.canReadLine() ){
            qCDebug(DEFINESANDINCLUDES)  << proc.readLine();
        }
        qCDebug(DEFINESANDINCLUDES)  << proc.exitCode();
    }

    // MSVC builtin attributes
    {
        ret[QStringLiteral("__cdecl")] = QLatin1String("");
        ret[QStringLiteral("__fastcall")] = QLatin1String("");
        ret[QStringLiteral("__stdcall")] = QLatin1String("");
        ret[QStringLiteral("__thiscall")] = QLatin1String("");
    }

    // MSVC builtin types
    // see http://msdn.microsoft.com/en-us/library/cc953fe1.aspx
    {
        ret[QStringLiteral("__int8")] = QStringLiteral("char");
        ret[QStringLiteral("__int16")] = QStringLiteral("short");
        ret[QStringLiteral("__int32")] = QStringLiteral("int");
        ret[QStringLiteral("__int64")] = QStringLiteral("long long");
        ret[QStringLiteral("__int16")] = QStringLiteral("short");
        ret[QStringLiteral("__ptr32")] = QLatin1String("");
        ret[QStringLiteral("__ptr64")] = QLatin1String("");
    }

    // MSVC specific modifiers
    // see http://msdn.microsoft.com/en-us/library/vstudio/s04b5w00.aspx
    {
        ret[QStringLiteral("__sptr")] = QLatin1String("");
        ret[QStringLiteral("__uptr")] = QLatin1String("");
        ret[QStringLiteral("__unaligned")] = QLatin1String("");
        ret[QStringLiteral("__w64")] = QLatin1String("");
    }

    // MSVC function specifiers
    // see http://msdn.microsoft.com/de-de/library/z8y1yy88.aspx
    {
        ret[QStringLiteral("__inline")] = QLatin1String("");
        ret[QStringLiteral("__forceinline")] = QLatin1String("");
    }

    return ret;
}

Path::List MsvcCompiler::includes(Utils::LanguageType, const QString&) const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
    const QStringList _includePaths = QProcessEnvironment::systemEnvironment().value(QStringLiteral("INCLUDE")).split(QLatin1Char(';'), Qt::SkipEmptyParts);
#else
    const QStringList _includePaths = QProcessEnvironment::systemEnvironment().value(QStringLiteral("INCLUDE")).split(QLatin1Char(';'), QString::SkipEmptyParts);
#endif
    Path::List includePaths;
    includePaths.reserve(_includePaths.size());
    for (const QString& include : _includePaths) {
        includePaths.append( Path( QDir::fromNativeSeparators( include ) ) );
    }
    return includePaths;
}

MsvcCompiler::MsvcCompiler(const QString& name, const QString& path, bool editable, const QString& factoryName):
    ICompiler(name, path, factoryName, editable)
{}