summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-09-06 00:50:53 +0200
committerAraq <rumpf_a@web.de>2014-09-06 00:50:53 +0200
commit7f7b13a45f73c6d9dcca3ce8388833189d77426c (patch)
tree79780167960b4aaae49e733ecb94afc39b5e4828 /compiler
parent5fb12144b31a97fd208fb286de557f913b97e108 (diff)
downloadNim-7f7b13a45f73c6d9dcca3ce8388833189d77426c.tar.gz
nimfix handles helloworld
Diffstat (limited to 'compiler')
-rw-r--r--compiler/astalgo.nim8
-rw-r--r--compiler/commands.nim3
-rw-r--r--compiler/main.nim37
-rw-r--r--compiler/modules.nim11
-rw-r--r--compiler/nim.nimrod.cfg2
-rw-r--r--compiler/nimfix.nim10
-rw-r--r--compiler/options.nim1
7 files changed, 27 insertions, 45 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index 8918888a3..110b0c26e 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -626,6 +626,12 @@ proc strTableAdd(t: var TStrTable, n: PSym) =
   strTableRawInsert(t.data, n)
   inc(t.counter)
 
+proc reallySameIdent(a, b: string): bool {.inline.} =
+  when defined(nimfix):
+    result = a[0] == b[0]
+  else:
+    result = true
+
 proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
   # returns true if n is already in the string table:
   # It is essential that `n` is written nevertheless!
@@ -635,7 +641,7 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
   while true:
     var it = t.data[h]
     if it == nil: break
-    if it.name.id == n.name.id:
+    if it.name.id == n.name.id and reallySameIdent(it.name.s, n.name.s):
       t.data[h] = n           # overwrite it with newer definition!
       return true             # found it
     h = nextTry(h, high(t.data))
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 2a2e0c4ee..596cdafba 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -308,8 +308,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
     expectArg(switch, arg, pass, info)
     options.docSeeSrcUrl = arg
   of "mainmodule", "m":
-    expectArg(switch, arg, pass, info)
-    optMainModule = arg
+    discard "allow for backwards compatibility, but don't do anything"
   of "define", "d": 
     expectArg(switch, arg, pass, info)
     defineSymbol(arg)
diff --git a/compiler/main.nim b/compiler/main.nim
index 0bb057df5..47da96a03 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -211,25 +211,6 @@ proc commandSuggest =
                    else: gProjectMainIdx
     compileProject(projFile)
 
-proc wantMainModule =
-  if gProjectFull.len == 0:
-    if optMainModule.len == 0:
-      fatal(gCmdLineInfo, errCommandExpectsFilename)
-    else:
-      gProjectName = optMainModule
-      gProjectFull = gProjectPath / gProjectName
-
-  gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx
-
-proc requireMainModuleOption =
-  if optMainModule.len == 0:
-    fatal(gCmdLineInfo, errMainModuleMustBeSpecified)
-  else:
-    gProjectName = optMainModule
-    gProjectFull = gProjectPath / gProjectName
-
-  gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx
-
 proc resetMemory =
   resetCompilationLists()
   ccgutils.resetCaches()
@@ -293,30 +274,24 @@ proc mainCommand* =
     # current path is always looked first for modules
     prependStr(searchPaths, gProjectPath)
   setId(100)
-  passes.gIncludeFile = includeModule
-  passes.gImportModule = importModule
   case command.normalize
   of "c", "cc", "compile", "compiletoc":
     # compile means compileToC currently
     gCmd = cmdCompileToC
-    wantMainModule()
     commandCompileToC()
   of "cpp", "compiletocpp":
     extccomp.cExt = ".cpp"
     gCmd = cmdCompileToCpp
     if cCompiler == ccGcc: setCC("gcc")
-    wantMainModule()
     defineSymbol("cpp")
     commandCompileToC()
   of "objc", "compiletooc":
     extccomp.cExt = ".m"
     gCmd = cmdCompileToOC
-    wantMainModule()
     defineSymbol("objc")
     commandCompileToC()
   of "run":
     gCmd = cmdRun
-    wantMainModule()
     when hasTinyCBackend:
       extccomp.setCC("tcc")
       commandCompileToC()
@@ -324,39 +299,32 @@ proc mainCommand* =
       rawMessage(errInvalidCommandX, command)
   of "js", "compiletojs":
     gCmd = cmdCompileToJS
-    wantMainModule()
     commandCompileToJS()
   of "compiletollvm":
     gCmd = cmdCompileToLLVM
-    wantMainModule()
     when hasLLVM_Backend:
       CommandCompileToLLVM()
     else:
       rawMessage(errInvalidCommandX, command)
   of "pretty":
     gCmd = cmdPretty
-    wantMainModule()
     commandPretty()
   of "doc":
     gCmd = cmdDoc
     loadConfigs(DocConfig)
-    wantMainModule()
     commandDoc()
   of "doc2":
     gCmd = cmdDoc
     loadConfigs(DocConfig)
-    wantMainModule()
     defineSymbol("nimdoc")
     commandDoc2()
   of "rst2html":
     gCmd = cmdRst2html
     loadConfigs(DocConfig)
-    wantMainModule()
     commandRst2Html()
   of "rst2tex":
     gCmd = cmdRst2tex
     loadConfigs(DocTexConfig)
-    wantMainModule()
     commandRst2TeX()
   of "jsondoc":
     gCmd = cmdDoc
@@ -370,12 +338,11 @@ proc mainCommand* =
     commandBuildIndex()
   of "gendepend":
     gCmd = cmdGenDepend
-    wantMainModule()
     commandGenDepend()
   of "dump":
     gCmd = cmdDump
     if getConfigVar("dump.format") == "json":
-      requireMainModuleOption()
+      wantMainModule()
 
       var definedSymbols = newJArray()
       for s in definedSymbolNames(): definedSymbols.elems.add(%s)
@@ -399,7 +366,6 @@ proc mainCommand* =
       for it in iterSearchPath(searchPaths): msgWriteln(it)
   of "check":
     gCmd = cmdCheck
-    wantMainModule()
     commandCheck()
   of "parse":
     gCmd = cmdParse
@@ -423,7 +389,6 @@ proc mainCommand* =
     if gEvalExpr != "":
       commandEval(gEvalExpr)
     else:
-      wantMainModule()
       commandSuggest()
   of "serve":
     isServing = true
diff --git a/compiler/modules.nim b/compiler/modules.nim
index 8939afd5a..dd8ccedb1 100644
--- a/compiler/modules.nim
+++ b/compiler/modules.nim
@@ -185,8 +185,17 @@ proc compileSystemModule* =
     systemFileIdx = fileInfoIdx(options.libpath/"system.nim")
     discard compileModule(systemFileIdx, {sfSystemModule})
 
-proc compileProject*(projectFile = gProjectMainIdx) =
+proc wantMainModule* =
+  if gProjectFull.len == 0:
+    fatal(gCmdLineInfo, errCommandExpectsFilename)
+  gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx
+
+proc compileProject*(projectFileIdx = -1'i32) =
+  wantMainModule()
+  passes.gIncludeFile = includeModule
+  passes.gImportModule = importModule
   let systemFileIdx = fileInfoIdx(options.libpath / "system.nim")
+  let projectFile = if projectFileIdx < 0: gProjectMainIdx else: projectFileIdx
   if projectFile == systemFileIdx:
     discard compileModule(projectFile, {sfMainModule, sfSystemModule})
   else:
diff --git a/compiler/nim.nimrod.cfg b/compiler/nim.nimrod.cfg
index 5a892bad0..ba7697c4c 100644
--- a/compiler/nim.nimrod.cfg
+++ b/compiler/nim.nimrod.cfg
@@ -1,7 +1,5 @@
 # Special configuration file for the Nim project
 
-mainModule:"nimrod.nim"
-
 # gc:markAndSweep
 
 hint[XDeclaredButNotUsed]:off
diff --git a/compiler/nimfix.nim b/compiler/nimfix.nim
index 3fbf27e54..60ebb48e5 100644
--- a/compiler/nimfix.nim
+++ b/compiler/nimfix.nim
@@ -11,7 +11,7 @@
 
 import strutils, os, parseopt
 import options, commands, modules, sem, passes, passaux, pretty, msgs, nimconf,
-  extccomp, condsyms
+  extccomp, condsyms, lists
 
 const Usage = """
 Nimfix - Tool to patch Nim code
@@ -36,6 +36,11 @@ proc mainCommand =
   registerPass semPass
   registerPass prettyPass
   gCmd = cmdPretty
+  appendStr(searchPaths, options.libpath)
+  if gProjectFull.len != 0:
+    # current path is always looked first for modules
+    prependStr(searchPaths, gProjectPath)
+
   compileProject()
   pretty.overwriteFiles()
 
@@ -68,7 +73,8 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
       else:
         processSwitch(pass, p)
     of cmdArgument:
-      if processArgument(pass, p, argsCount): break
+      options.gProjectName = unixToNativePath(p.key)
+      # if processArgument(pass, p, argsCount): break
 
 proc handleCmdLine() =
   if paramCount() == 0:
diff --git a/compiler/options.nim b/compiler/options.nim
index 11c8241ef..cb2173554 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -152,7 +152,6 @@ var
   gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
   gProjectFull* = "" # projectPath/projectName
   gProjectMainIdx*: int32 # the canonical path id of the main module
-  optMainModule* = "" # the main module that should be used for idetools commands
   nimcacheDir* = ""
   command* = "" # the main command (e.g. cc, check, scan, etc)
   commandArgs*: seq[string] = @[] # any arguments after the main command
a> 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887