OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / ldparser.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "ldparser.h"
35 #include "projectexplorerconstants.h"
36 #include "taskwindow.h"
37
38 #include <QtCore/QDir>
39
40 using namespace ProjectExplorer;
41
42 namespace {
43     // opt. drive letter + filename: (2 brackets)
44     const char * const FILE_PATTERN = "(([A-Za-z]:)?[^:]+\\.[^:]+):";
45     // line no. or elf segment + offset: (1 bracket)
46     const char * const POSITION_PATTERN = "(\\d+|\\(\\.[a-zA-Z0-9]*.0x[a-fA-F0-9]+\\)):";
47     const char * const COMMAND_PATTERN = "^(.*[\\\\/])?([a-z0-9]+-[a-z0-9]+-[a-z0-9]+-)?(ld|gold)(-[0-9\\.]+)?(\\.exe)?: ";
48 }
49
50 LdParser::LdParser()
51 {
52     setObjectName(QLatin1String("LdParser"));
53     m_regExpLinker.setPattern(QString('^') +
54                               QString::fromLatin1(FILE_PATTERN) + '(' +
55                               QString::fromLatin1(FILE_PATTERN) + ")?(" +
56                               QLatin1String(POSITION_PATTERN) + ")?\\s(.+)$");
57     m_regExpLinker.setMinimal(true);
58
59     m_regExpGccNames.setPattern(COMMAND_PATTERN);
60     m_regExpGccNames.setMinimal(true);
61
62     m_regExpInFunction.setPattern("^In (static |member )*function ");
63     m_regExpInFunction.setMinimal(true);
64 }
65
66 void LdParser::stdError(const QString &line)
67 {
68     QString lne = line.trimmed();
69     if (lne.startsWith(QLatin1String("TeamBuilder ")) ||
70         lne.startsWith(QLatin1String("distcc["))) {
71         IOutputParser::stdError(line);
72         return;
73     }
74
75     if (lne.startsWith(QLatin1String("collect2:"))) {
76         emit addTask(Task(Task::Error,
77                           lne /* description */,
78                           QString() /* filename */,
79                           -1 /* linenumber */,
80                           Constants::TASK_CATEGORY_COMPILE));
81         return;
82     } else if (m_regExpGccNames.indexIn(lne) > -1) {
83         QString description = lne.mid(m_regExpGccNames.matchedLength());
84         Task task(Task::Error,
85                   description,
86                   QString(), /* filename */
87                   -1, /* line */
88                   Constants::TASK_CATEGORY_COMPILE);
89         if (description.startsWith(QLatin1String("warning: "))) {
90             task.type = Task::Warning;
91             task.description = description.mid(9);
92         } else if (description.startsWith(QLatin1String("fatal: ")))  {
93             task.description = description.mid(7);
94         }
95         emit addTask(task);
96         return;
97     } else if (m_regExpLinker.indexIn(lne) > -1) {
98         bool ok;
99         int lineno = m_regExpLinker.cap(7).toInt(&ok);
100         if (!ok)
101             lineno = -1;
102         QString filename = m_regExpLinker.cap(1);
103         if (!m_regExpLinker.cap(4).isEmpty()
104             && !m_regExpLinker.cap(4).startsWith(QLatin1String("(.text+0x")))
105             filename = m_regExpLinker.cap(4);
106         QString description = m_regExpLinker.cap(8).trimmed();
107         Task task(Task::Error, description, QDir::fromNativeSeparators(filename), lineno,
108                   Constants::TASK_CATEGORY_COMPILE);
109         if (m_regExpInFunction.indexIn(description) > -1 ||
110             description.startsWith(QLatin1String("At global scope")) ||
111             description.startsWith(QLatin1String("At top level")) ||
112             description.startsWith(QLatin1String("instantiated from ")) ||
113             description.startsWith(QLatin1String("In ")))
114             task.type = Task::Unknown;
115
116         emit addTask(task);
117         return;
118     }
119     IOutputParser::stdError(line);
120 }