changeset 520:f203c5248d0b

Added 'compile' command. Fixes in config.d: changed 'auto' to 'var'; fixed format argument indices. dil.Lexer and dil.Parser add their errors to infoMan. Fix in enum TOK: Cent belongs to sublist of integral types.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 15 Dec 2007 22:25:18 +0100
parents 9ebc799c7dc5
children 772ffdb18fd4
files trunk/src/config.d trunk/src/dil/HtmlEntities.d trunk/src/dil/Lexer.d trunk/src/dil/Module.d trunk/src/dil/Parser.d trunk/src/dil/Settings.d trunk/src/dil/TokensEnum.d trunk/src/main.d
diffstat 8 files changed, 85 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/config.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/config.d	Sat Dec 15 22:25:18 2007 +0100
@@ -1,16 +1,16 @@
 // Relative paths are resolved from the directory of dil's executable.
 
 // Path to the language file.
-auto langfile = "lang_en.d";
+var langfile = "lang_en.d";
 // An array of import paths to look for modules.
-auto import_paths = [];
+var import_paths = [];
 /*
   Customizing error messages.
-  1: file path to the source text.
-  2: line number.
-  3: column number.
-  4: error message.
+  0: file path to the source text.
+  1: line number.
+  2: column number.
+  3: error message.
 */
-auto lexer_error = "{1}({2},{3})L: {4}";
-auto parser_error = "{1}({2},{3})P: {4}";
-auto semantic_error = "{1}({2},{3})S: {4}";
+var lexer_error = "{0}({1},{2})L: {3}";
+var parser_error = "{0}({1},{2})P: {3}";
+var semantic_error = "{0}({1},{2})S: {3}";
--- a/trunk/src/dil/HtmlEntities.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/HtmlEntities.d	Sat Dec 15 22:25:18 2007 +0100
@@ -274,4 +274,4 @@
   if (d)
     return *d;
   return 0xFFFF;
-}
\ No newline at end of file
+}
--- a/trunk/src/dil/Lexer.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/Lexer.d	Sat Dec 15 22:25:18 2007 +0100
@@ -35,6 +35,7 @@
   char* end;        /// Points one character past the end of the source text.
 
   // Members used for error messages:
+  InformationManager infoMan;
   LexerError[] errors;
   /// Always points to the beginning of the current line.
   char* lineBegin;
@@ -50,9 +51,10 @@
       text     = the UTF-8 source code.
       filePath = the path to the source code; used for error messages.
   +/
-  this(string text, string filePath)
+  this(string text, string filePath, InformationManager infoMan = null)
   {
     this.filePath = this.errorPath = filePath;
+    this.infoMan = infoMan;
 
     this.text = text;
     if (text.length == 0 || text[$-1] != 0)
@@ -2385,7 +2387,10 @@
     lineNum = this.errorLineNumber(lineNum);
     auto location = new Location(errorPath, lineNum, lineBegin, columnPos);
     auto msg = Format(_arguments, _argptr, GetMsg(mid));
-    errors ~= new LexerError(location, msg);
+    auto error = new LexerError(location, msg);
+    errors ~= error;
+    if (infoMan !is null)
+      infoMan ~= error;
   }
 
   Token* getTokens()
--- a/trunk/src/dil/Module.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/Module.d	Sat Dec 15 22:25:18 2007 +0100
@@ -3,6 +3,7 @@
   License: GPL3
 +/
 module dil.Module;
+
 import dil.SyntaxTree;
 import dil.Declarations;
 import dil.Parser;
@@ -10,6 +11,7 @@
 import dil.Lexer;
 import dil.File;
 import dil.Scope;
+import dil.Information;
 import tango.io.FilePath;
 import tango.io.FileConst;
 import common;
@@ -23,6 +25,7 @@
   string moduleFQN; /// Fully qualified name of the module.
   string packageName;
   string moduleName;
+
   Declarations root; /// The root of the AST.
   ImportDeclaration[] imports;
   ModuleDeclaration moduleDecl;
@@ -30,19 +33,27 @@
 
   Module[] modules;
 
+  InformationManager infoMan;
+
   this(string filePath, bool isLightweight = false)
   {
     this.filePath = filePath;
     this.isLightweight = isLightweight;
   }
 
+  this(string filePath, InformationManager infoMan)
+  {
+    this(filePath, false);
+    this.infoMan = infoMan;
+  }
+
   void parse()
   {
     auto sourceText = loadFile(filePath);
     if (this.isLightweight)
       this.parser = new ImportParser(sourceText, filePath);
     else
-      this.parser = new Parser(sourceText, filePath);
+      this.parser = new Parser(sourceText, filePath, infoMan);
 
     this.root = parser.start();
 
--- a/trunk/src/dil/Parser.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/Parser.d	Sat Dec 15 22:25:18 2007 +0100
@@ -27,6 +27,7 @@
   Token* token; /// Current non-whitespace token.
   Token* prevToken; /// Previous non-whitespace token.
 
+  InformationManager infoMan;
   ParserError[] errors;
 
   ImportDeclaration[] imports; /// ImportDeclarations in the source text.
@@ -47,7 +48,8 @@
   +/
   this(char[] srcText, string filePath, InformationManager infoMan = null)
   {
-    lx = new Lexer(srcText, filePath);
+    this.infoMan = infoMan;
+    lx = new Lexer(srcText, filePath, infoMan);
   }
 
   protected void init()
@@ -4437,7 +4439,10 @@
     }
     auto location = token.getLocation();
     auto msg = Format(_arguments, _argptr, formatMsg);
-    errors ~= new ParserError(location, msg);
+    auto error = new ParserError(location, msg);
+    errors ~= error;
+    if (infoMan !is null)
+      infoMan ~= error;
   }
 
   /// Collection of error messages with no MID yet.
--- a/trunk/src/dil/Settings.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/Settings.d	Sat Dec 15 22:25:18 2007 +0100
@@ -16,7 +16,7 @@
   string[] messages;
   /// Array of import paths to look for modules.
   string[] importPaths;
-  string lexerErrorFormat = "{1}({2},{3})L: {4}";
-  string parserErrorFormat = "{1}({2},{3})L: {4}";
-  string semanticErrorFormat = "{1}({2},{3})L: {4}";
+  string lexerErrorFormat = "{0}({1},{2})L: {3}";
+  string parserErrorFormat = "{0}({1},{2})P: {3}";
+  string semanticErrorFormat = "{0}({1},{2})S: {3}";
 }
--- a/trunk/src/dil/TokensEnum.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/dil/TokensEnum.d	Sat Dec 15 22:25:18 2007 +0100
@@ -89,7 +89,7 @@
   */
   Abstract, Alias, Align, Asm, Assert, Auto, Body,
   Break, Case, Cast, Catch,
-  Cent, Class, Const, Continue,
+  Class, Const, Continue,
   Debug, Default, Delegate, Delete, Deprecated, Do,
   Else, Enum, Export, Extern, False, Final,
   Finally, For, Foreach, Foreach_reverse, Function, Goto,
@@ -102,7 +102,7 @@
   Typeof, Union, Unittest,
   Version, Volatile, While, With,
   // Integral types.
-  Char,   Wchar,   Dchar, Bool, Ucent,
+  Char,   Wchar,   Dchar, Bool, Cent, Ucent,
   Byte,   Ubyte,   Short, Ushort,
   Int,    Uint,    Long,  Ulong,
   Float,  Double,  Real,
--- a/trunk/src/main.d	Sat Dec 15 19:00:23 2007 +0100
+++ b/trunk/src/main.d	Sat Dec 15 22:25:18 2007 +0100
@@ -11,7 +11,9 @@
 import dil.Settings;
 import dil.SettingsLoader;
 import dil.CompilerInfo;
+import dil.Module;
 import dil.Declarations, dil.Expressions, dil.SyntaxTree;
+import dil.Information;
 import dil.File;
 import cmd.Generate;
 import cmd.Statistics;
@@ -33,6 +35,33 @@
   string command = args[1];
   switch (command)
   {
+  case "c", "compile":
+    if (args.length < 2)
+      return printHelp("compile");
+
+    auto infoMan = new InformationManager();
+    auto filePaths = args[2..$];
+    foreach (filePath; filePaths)
+    {
+      auto mod = new Module(filePath, infoMan);
+      mod.parse();
+    }
+
+    foreach (info; infoMan.info)
+    {
+      char[] errorFormat;
+      if (info.classinfo is LexerError.classinfo)
+        errorFormat = GlobalSettings.lexerErrorFormat;
+      else if (info.classinfo is ParserError.classinfo)
+        errorFormat = GlobalSettings.parserErrorFormat;
+      else if (info.classinfo is SemanticError.classinfo)
+        errorFormat = GlobalSettings.semanticErrorFormat;
+      else
+        continue;
+      auto err = cast(Problem)info;
+      Stderr.formatln(errorFormat, err.filePath, err.loc, err.col, err.getMsg);
+    }
+    break;
   case "gen", "generate":
     char[] fileName;
     DocOption options = DocOption.Tokens;
@@ -160,16 +189,14 @@
       parse(args[2]);
     break;
   case "?", "help":
-    if (args.length == 3)
-      printHelp(args[2]);
-    else
-      Stdout(helpMain());
+    printHelp(args.length >= 3 ? args[2] : "");
     break;
   default:
   }
 }
 
 const char[] COMMANDS =
+  "  compile (c)\n"
   "  generate (gen)\n"
   "  help (?)\n"
   "  importgraph (igraph)\n"
@@ -196,6 +223,19 @@
   char[] msg;
   switch (command)
   {
+  case "c", "compile":
+    msg = "Compile D source files.
+Usage:
+  dil compile file.d [file2.d, ...] [Options]
+
+  This command only parses the source files and does little semantic analysis.
+  Errors are printed to standard error output.
+
+Options:
+
+Example:
+  dil c src/main.d";
+    break;
   case "gen", "generate":
     msg = GetMsg(MID.HelpGenerate);
     break;