blob: 71d8dc9b9712cc01e4a0ff422cb252753d6b2ced (
plain)
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
|
// file : Test/IDL2/Compiler/driver.cpp
// author : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id : $Id$
#include "CCF/CompilerElements/Context.hpp"
#include "CCF/CompilerElements/FileSystem.hpp"
#include "CCF/CompilerElements/Diagnostic.hpp"
#include "CCF/CompilerElements/TokenStream.hpp"
#include "CCF/CompilerElements/Preprocessor.hpp"
#include "CCF/IDL2/LexicalAnalyzer.hpp"
#include "CCF/IDL2/Parser.hpp"
#include "CCF/IDL2/SemanticGraph.hpp"
#include "CCF/IDL2/SemanticAction/Impl/Factory.hpp"
#include "../Traversal/Recreate/Generator.hpp"
#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using namespace CCF::CompilerElements;
using namespace CCF::IDL2;
using namespace CCF::IDL2::SemanticGraph;
int
main ()
{
try
{
Diagnostic::Stream dout;
fs::path file_path ("stdout");
InputStreamAdapter isa (std::cin);
CPP::Preprocessor pp (isa);
LexicalAnalyzer lexer (pp);
TokenList token_stream;
//@@ bad token comparison
for (TokenPtr token = lexer.next ();; token = lexer.next ())
{
token_stream.push_back (token);
if (ReferenceCounting::strict_cast<EndOfStream> (token) != 0) break;
}
if (token_stream.size () < 2)
{
cerr << "no tokens produced so nothing to parse" << endl;
return 0;
}
TranslationUnit tu;
// Compilation context.
//
CCF::CompilerElements::Context context;
context.set ("file-path", file_path);
context.set ("trace-semantic-action", false);
SemanticAction::Impl::Factory actions (context, dout, tu);
Parser parser (context, dout, lexer, actions);
Parsing::parse (token_stream.begin (),
token_stream.end (),
parser.start ());
if (dout.error_count () != 0) return -1;
IDL2::Generator g;
g.generate (tu);
}
catch (std::bad_cast const&)
{
cerr << "bad cast exception" << endl;
}
catch (InvalidName const&)
{
cerr << "invalid name exception" << endl;
}
catch (...)
{
cerr << "caught unknown exception" << endl;
return -1;
}
}
|