Changeset 239

Show
Ignore:
Timestamp:
02/26/07 23:21:21 (2 years ago)
Author:
Alan Knowles
Message:

eak commited threaded compile from wrong machine.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/leds/LanguageD.d

    r237 r239  
    5454    private import std.date; 
    5555    private import std.stdio; 
     56    private import std.thread; 
    5657     
    5758    this(CodeView codeview) 
     
    418419    { 
    419420         
    420          
     421         
    421422        //return  (new CodeLookup(codeview)).getLookupList(codeview, start); 
    422423        String[] list; 
     
    437438         
    438439        Module sourceModule = this.getCachedModule(); 
    439         CodeBlock container =   sourceModule.getContainerForLine(codeview.getLineNumber()); 
     440        CodeBlock container = sourceModule.getContainerForLine(codeview.getLineNumber()); 
    440441        if (!container) { 
    441442            writefln("no container found?"); 
     
    450451        } 
    451452        // do lookup on '*.*' 
    452          
     453         
    453454        Element lookupwith = null; 
    454455        for(int i=0;i< bits.length-1; i++) { 
     
    464465            } 
    465466            // got a parent 
    466             container = type.moduleObj; // use the scope of the definition. 
    467             lookupwith = container.getTypeElement(type); 
     467            container = cast(CodeBlock)type.parent; // use the scope of the definition. 
     468            lookupwith = null; 
     469            if (container) { 
     470                lookupwith = container.getTypeElement(type); 
     471            } 
    468472            if (!lookupwith) { 
    469473                writefln("cant find defintion of type %s" , type.returnType); 
     
    511515        } 
    512516    } 
     517 
    513518     
    514519    /** 
     
    574579        writefln("getPropValue(\"dmd\",\"dmd\") = ", l); 
    575580 
    576         // dmd doesn't need to be a file if it's on the executables path 
    577 //      if (!Path.isFile(l)) 
    578 //      { 
    579 //          //writefln("dmd command does not exist"); 
    580 //          codeview.getWorkspace().getSystemConsole.print( 
    581 //                  "Can not find dmd '" ~ l.toString() ~ "' so compile test does not work\n"); 
    582 //          return correct; 
    583 //      } 
     581      
    584582         
    585583        version(Win32) 
     
    602600         
    603601        compileCommand = SystemConsole.expandCommand(compileCommand); 
    604         //debug(flow ) System.writefln("CodeView.checkSintax 7"); 
    605         codeview.getWorkspace().getSystemConsole.print("Compile Command: \n" ~  compileCommand.toString() ~ "\n"); 
    606         SpawnWrapper sp = new SpawnWrapper(compileCommand.toString()); 
    607         sp.start(); 
    608         while(1 && GtkD.eventsPending()) { 
    609             GtkD.mainIteration(); 
    610             if (sp.getState() == Thread.TS.TERMINATED) { 
    611                 break; 
    612             } 
    613         } 
    614          
    615         //Spawn spawn = new Spawn(compileCommand.toString()); 
    616         //correct = spawn.commandLineSync()!=0; 
    617         //debug(flow ) System.writefln("CodeView.checkSintax 8"); 
    618         codeview.getWorkspace().getSystemConsole.print("Compile Result:\n" ~ sp.outputstring ~ "\n"); 
    619         //checkSyntax( spawn.getOutputString(), spawn.getErrorString()); 
    620         checkSyntax( SpawnWrapper.outputstring, SpawnWrapper.errorstring); 
    621         //workspace.getStatusbar().addBackgroundProcess(); 
    622         //debug(flow ) System.writefln("CodeView.checkSintax 9"); 
     602          
     603  
     604        // show message that we are compiling  
     605        codeview.getWorkspace().getSystemConsole.print( 
     606            "Compile Command: \n" ~  compileCommand.toString() ~ "\n......\n"); 
     607         
     608        // create a thread and wait for it to finish.. 
     609        auto compilethread = new CompilerThread(compileCommand); 
     610        int id  = compilethread.id; 
     611        compilethread.start(); 
     612        char[] res; 
     613        while(true) 
     614        { 
     615            if (GtkD.eventsPending()) { 
     616                GtkD.mainIteration();    
     617            } 
     618            res =  getCompileCompleted(id); 
     619            if (res is null) { 
     620                continue; 
     621            } 
     622            break; 
     623        } 
     624        // display the results. 
     625      
     626        codeview.getWorkspace().getSystemConsole.print( 
     627            "Compile Command: \n" ~  compileCommand.toString() ~ "\n" ~ 
     628            "Compile Result:\n" ~ res ~ "\n"); 
     629        checkSyntax( res ); 
     630          
    623631        codeview.endSintaxCheck(); 
    624632         
     
    627635        return correct; 
    628636    } 
    629     bool syntaxCorrect = false; 
    630       
    631     private import std.thread; 
    632     class SpawnWrapper : Thread 
    633     { 
    634         char[] command;; 
    635         this(char[] cmd) 
    636         { 
    637             command = cmd; 
    638         } 
    639         static char[] errorstring = ""; 
    640         static char[] outputstring = ""; 
     637 
     638     
     639    /** 
     640     * Support for threaded compile - which is usefull on slow filesystems  
     641     * (eg. davfs mounted) 
     642     * we store the results in a synconized static array 
     643     *  
     644     */ 
     645    static int compileNo = 0; 
     646    static char[][int] completedCompiles;  
     647     
     648    synchronized static void flagCompileCompleted(int id, char[] str) 
     649    { 
     650        completedCompiles[id] = str; 
     651    } 
     652     
     653    synchronized static char[] getCompileCompleted(int id) 
     654    { 
     655        if (id in completedCompiles) { 
     656            char[] ret = completedCompiles[id]; 
     657            completedCompiles.remove(id); 
     658            return ret; 
     659        } 
     660        return null; 
     661         
     662    } 
     663     
     664    class CompilerThread : Thread 
     665    { 
     666        String cmd; 
     667        int id; 
     668         
     669        this(String cmd)  
     670        { 
     671            this.id = LanguageD.compileNo++; 
     672            this.cmd = cmd; 
     673        } 
    641674         
    642675        int run() 
    643676        { 
    644             Spawn spawn = new Spawn(command); 
     677            writefln("running %s", cmd.toString()); 
     678            Spawn spawn = new Spawn(cmd.toString()); 
    645679            spawn.commandLineSync(); 
    646             setStrings(spawn); 
     680             
     681            writefln("completed %s", spawn.getOutputString()); 
     682            LanguageD.flagCompileCompleted(id, spawn.getOutputString()); 
    647683            return 1; 
    648684        } 
    649         synchronized void setStrings(Spawn spawn)  
    650         { 
    651              
    652             SpawnWrapper.outputstring = spawn.getOutputString() ; 
    653             SpawnWrapper.errorstring =spawn.getErrorString(); 
    654              
    655         } 
    656     } 
    657  
    658     bit checkSyntax(char[] grabOutput, char[] grabError) 
     685         
     686    } 
     687     
     688     
     689  
     690 
     691    bit checkSyntax(char[] grabOutput) 
    659692    { 
    660693        foreach ( String line ; (new String(grabOutput)).splitLines() ) 
     
    833866    { 
    834867        // tidy it up.. 
    835       
    836       
     868       
    837869        String[] strs = s.split("("); 
    838870        s = strs.length ? strs[0] : new String(""); 
     
    842874        if (s.toString() in Token.stdKeyword) { 
    843875            codeview.getWorkspace().getSystemConsole.print("D Keyword: " ~ s.toString()); 
     876            return; 
    844877        } 
    845878         
     
    11031136    { 
    11041137         
     1138         
    11051139        // commStr ??? 
    11061140        //Function funct;