Skip to content

Commit 16b2633

Browse files
committed
Moved IdentifiersList class on his own file
1 parent 3556171 commit 16b2633

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

IdentifiersList.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of arduino-preprocessor.
3+
*
4+
* Copyright 2017 BCMI LABS SA
5+
*
6+
* arduino-preprocessor is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
#include "IdentifiersList.h"
31+
32+
void IdentifiersList::dump(ostream &out) {
33+
out << "Undeclared identifiers:\n";
34+
for (IdentifierLocation *m : * this) {
35+
const FullSourceLoc &sl = m->location.getSpellingLoc();
36+
out << " " << sl.getSpellingLineNumber() << ":" << sl.getSpellingColumnNumber();
37+
out << " " << m->identifier << "\n";
38+
}
39+
}
40+
41+
IdentifierLocation *IdentifiersList::findFirst(string name) {
42+
for (IdentifierLocation *m : * this) {
43+
if (m->identifier == name)
44+
return m;
45+
}
46+
return nullptr;
47+
}

IdentifiersList.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of arduino-preprocessor.
3+
*
4+
* Copyright 2017 BCMI LABS SA
5+
*
6+
* arduino-preprocessor is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
#pragma once
31+
32+
#include <clang/AST/AST.h>
33+
34+
#include <string>
35+
#include <iostream>
36+
#include <list>
37+
38+
using namespace clang;
39+
using namespace std;
40+
41+
typedef struct {
42+
FullSourceLoc location;
43+
string identifier;
44+
} IdentifierLocation;
45+
46+
class IdentifiersList : public list<IdentifierLocation *> {
47+
public:
48+
IdentifierLocation *findFirst(string name);
49+
void dump(ostream &out);
50+
};

main.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,14 @@
4747

4848
#include "Config.h"
4949
#include "CommandLine.h"
50+
#include "IdentifiersList.h"
5051

5152
using namespace clang;
5253
using namespace clang::ast_matchers;
5354
using namespace clang::tooling;
5455
using namespace llvm;
5556
using namespace std;
5657

57-
typedef struct {
58-
FullSourceLoc location;
59-
string identifier;
60-
} IdentifierLocation;
61-
62-
class IdentifiersList : public list<IdentifierLocation *> {
63-
public:
64-
65-
void dump() {
66-
outs() << "Undeclared identifiers:\n";
67-
for (IdentifierLocation *m : * this) {
68-
const FullSourceLoc &sl = m->location.getSpellingLoc();
69-
outs() << " " << sl.getSpellingLineNumber() << ":" << sl.getSpellingColumnNumber();
70-
outs() << " " << m->identifier << "\n";
71-
}
72-
}
73-
74-
IdentifierLocation *findFirst(string name) {
75-
for (IdentifierLocation *m : * this) {
76-
if (m->identifier == name)
77-
return m;
78-
}
79-
return nullptr;
80-
}
81-
};
82-
8358
IdentifiersList undeclaredIdentifiers;
8459

8560
class UndefinedIdentifiersCollector : public DiagnosticConsumer {
@@ -254,7 +229,10 @@ class INOPreprocessAction : public ASTFrontendAction {
254229

255230
virtual void EndSourceFileAction() override {
256231
if (debugOutput) {
257-
undeclaredIdentifiers.dump();
232+
ostringstream out;
233+
undeclaredIdentifiers.dump(out);
234+
out.flush();
235+
outs() << out.str();
258236
}
259237

260238
const FileID mainFileID = rewriter.getSourceMgr().getMainFileID();

package-arduino-preprocessor.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ CXXFLAGS=`clang/bin/llvm-config --cxxflags`
108108
LDFLAGS=`clang/bin/llvm-config --ldflags`
109109
LLVMLIBS=`clang/bin/llvm-config --libs --system-libs`
110110
CLANGLIBS=`ls clang/lib/libclang*.a | sed s/.*libclang/-lclang/ | sed s/.a$//`
111-
SOURCES="main.cpp CommandLine.cpp"
111+
SOURCES="main.cpp CommandLine.cpp IdentifiersList.cpp"
112112
$CXX $SOURCES -o objdir/arduino-preprocessor $CXXFLAGS $LDFLAGS -Wl,--start-group $LLVMLIBS $CLANGLIBS -Wl,--end-group
113113

114114
rm -f arduino-preprocessor-${OUTPUT_VERSION}-${OUTPUT_TAG}.tar.bz2

0 commit comments

Comments
 (0)