[r1]: trunk / Cm / Cm.Compiler / Main.cpp  Maximize  Restore  History

Download this file

116 lines (111 with data), 3.3 kB

  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
#include <Cm.Core/Namespace.hpp>
#include <Cm.Core/BasicType.hpp>
#include <Cm.Core/Assert.hpp>
#include <Cm.Core/Error.hpp>
#include <Cm.Core/Pointer.hpp>
#include <Cm.Core/Util.hpp>
#include <Cm.Core/ConversionTable.hpp>
#include <Cm.Parser/SourceFile.hpp>
#include <iostream>
using Soul::Util::String;
using Soul::Util::IntToString;
using Soul::Util::ReadFile;
String version = "0.1.0.0";
using namespace Cm::Core;
using namespace Cm::Parser;
class InitDone
{
public:
InitDone()
{
NamespaceInit();
ConversionTableInit();
UtilInit();
BasicTypeInit();
PointerInit();
TypeInit();
}
~InitDone()
{
TypeDone();
PointerDone();
BasicTypeDone();
UtilDone();
ConversionTableDone();
NamespaceDone();
}
};
int main(int argc, const char* argv[])
{
std::vector<String> fileNames;
try
{
InitDone initDone;
std::cout << "Cmaj compiler version " << version << std::endl;
if (argc <= 1)
{
std::cout << "Usage: cmc [options] {file.cm}" << std::endl;
std::cout << "Options:\n";
std::cout << "-dp: debug parsing\n";
}
else
{
bool debugParse = false;
for (int i = 1; i < argc; ++i)
{
String arg = argv[i];
if (!arg.empty() && arg[0] == '-')
{
if (arg == "-dp")
{
debugParse = true;
}
}
else
{
fileNames.push_back(arg);
}
}
SourceFileGrammarPtr sourceFile = SourceFile::Create();
if (debugParse)
{
sourceFile->SetLog(&std::cout);
}
std::vector<ScopePtr> fileScopes;
std::cout << "Parsing..." << std::endl;
int n = fileNames.size();
for (int i = 0; i < n; ++i)
{
String fileName = fileNames[i];
String content = ReadFile(fileName);
ScopePtr fileScope(new Scope(fileName, Position(), GlobalScope(), Scope::fileScope));
fileScopes.push_back(fileScope);
std::cout << "> " << fileName << std::endl;
sourceFile->Parse(content, 0, fileName, fileScope);
}
std::cout << "Type checking..." << std::endl;
GlobalScope()->TypeCheck();
for (int i = 0; i < n; ++i)
{
ScopePtr fileScope = fileScopes[i];
fileScope->TypeCheck();
}
}
}
catch (const Cm::Core::AssertionFailed& ex)
{
std::cout << ex.Message() << " in file " << ex.File() << " at line " << IntToString(ex.Line()) << std::endl;
}
catch (const Cm::Core::TypeCheckException& ex)
{
PrintError(T0 + ex.Number(), fileNames, ex);
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
catch (...)
{
std::cout << "other exception occurred" << std::endl;
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks