The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
Parser.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: Parser.cs //
6 // Author: Francisco Ortin - francisco.ortin@gmail.com //
7 // Coauthor: Miguel Garcia - miguel.uniovi@gmail.com //
8 // Description: //
9 // Refactor parsing a set of source files. //
10 // -------------------------------------------------------------------------- //
11 // Create date: 04-04-2007 //
12 // Modification date: 23-02-2011 //
14 
15 using System;
16 using System.Collections.Generic;
17 using DynVarManagement;
18 using ErrorManagement;
19 using System.IO;
20 using TargetPlatforms;
21 
22 namespace Inference.Core {
26  public class Parser {
37  public static void Parse(string[] files, string outputFileName, TargetPlatform targetPlatform, string debugFilePath, string ilasmFileName, string typeTableFileName, bool run, bool serverOptimization = false)
38  {
39  if (files == null)
40  return;
41 #if DEBUG
42  ConsoleColor previousColor = Console.ForegroundColor;
43  Console.ForegroundColor = ConsoleColor.DarkGray;
44  Console.Error.WriteLine("Compiling...");
45  Console.ForegroundColor = previousColor;
46  long startTime = DateTime.Now.Ticks;
47 #endif
48  try {
49  // if we have at least one command-line argument
50  if (files.Length > 0) {
51  ErrorManager.Instance.ShowInConsole = true;
52  Program initApp = new Program();
53  // * filename : directoryname map
54  IDictionary<string, string> directories = new Dictionary<string, string>();
55 
56  // for each directory/file specified on the command line
57  for (int i = 0; i < files.Length; i++) {
58  if ((File.Exists(files[i])) || (Directory.Exists(files[i])))
59  initApp.LoadFile(new FileInfo(files[i]), directories);
60  else {
61  ErrorManager.Instance.NotifyError(new FileNotFoundError(files[i]));
62  return;
63  }
64  }
65  // starts the compilation process
66  initApp.Run(directories, outputFileName, debugFilePath, ilasmFileName, typeTableFileName, targetPlatform, run, serverOptimization);
67 
68  }
69  else
70  ErrorManager.Instance.NotifyError(new CommandLineArgumentsError());
71  } catch (System.Exception e) {
72  Program.ClearMemory();
73  Console.Error.WriteLine("Exception: " + e);
74  Console.Error.WriteLine(e.StackTrace);
75  }
76 #if DEBUG
77  double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
78  previousColor = Console.ForegroundColor;
79  Console.ForegroundColor = ConsoleColor.DarkGray;
80  System.Console.Out.WriteLine("Total compilation time: {0} seconds.", elapsedTime);
81  Console.ForegroundColor = previousColor;
82 #endif
83 
84  }
85 
86  }
87 }
88 
Represents the error occurred when the command line arguments specified are incorrect.
static void Parse(string[] files, string outputFileName, TargetPlatform targetPlatform, string debugFilePath, string ilasmFileName, string typeTableFileName, bool run, bool serverOptimization=false)
Compiles a project
Definition: Parser.cs:37
System.IO.FileInfo FileInfo
Definition: CSharpParser.cs:5
Parsing of a set of files
Definition: Parser.cs:26
Represents the error occurred when the file specified does not exist.