Changeset 1137

Show
Ignore:
Timestamp:
04/29/08 19:29:49 (8 months ago)
Author:
asterite
Message:

Fixed a bug with signatures.
Now requesting autocompletion inside a function shows it's overloads.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/core/Signature.java

    r1132 r1137  
    1313 
    1414import java.util.ArrayList; 
     15import java.util.EmptyStackException; 
    1516import java.util.List; 
    1617import java.util.Stack; 
     
    18271828            private char nextTemplateParameterName() { 
    18281829                // We don't care about crazy templates with more than 8 parameters 
    1829                 return (char) ('T' + templateParameters.peek().size()); 
     1830                try { 
     1831                    return (char) ('T' + templateParameters.peek().size()); 
     1832                } catch (EmptyStackException e) { 
     1833                    System.out.println(1); 
     1834                    return 'T'; 
     1835                } 
    18301836            } 
    18311837            @Override 
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1136 r1137  
    101101import descent.internal.compiler.parser.StringExp; 
    102102import descent.internal.compiler.parser.StructDeclaration; 
     103import descent.internal.compiler.parser.SuperExp; 
    103104import descent.internal.compiler.parser.SwitchStatement; 
    104105import descent.internal.compiler.parser.SymOffExp; 
     
    259260    boolean wantProperties = true; 
    260261    boolean wantMethodContextInfo = false; 
     262    boolean isCompletingThisCall = false; 
     263    boolean isCompletingSuperCall = false; 
    261264     
    262265    Scope rootScope; 
     
    12161219        doSemantic(); 
    12171220         
     1221        if (node.sourceE1 instanceof SuperExp) { 
     1222            isCompletingSuperCall = true;    
     1223        } else if (node.sourceE1 instanceof ThisExp) { 
     1224            isCompletingThisCall = true;     
     1225        } 
     1226         
    12181227        if (node.e1 != null && node.e1.type != null) { 
    12191228            currentName = CharOperation.NO_CHAR; 
     
    12241233                VarExp var = (VarExp) node.e1; 
    12251234                if (var.var instanceof FuncDeclaration) { 
    1226                     wantMethodContextInfo = true; 
    1227                     suggestMember(var.var, false, 0, null, INCLUDE_FUNCTIONS); 
     1235                    suggestContextInfo((FuncDeclaration) var.var); 
    12281236                } 
    12291237            } else if (node.e1 instanceof DotVarExp && node.e1.type instanceof TypeFunction) { 
    12301238                DotVarExp var = (DotVarExp) node.e1; 
    12311239                if (var.var instanceof FuncDeclaration) { 
    1232                     wantMethodContextInfo = true; 
    1233                     suggestMember(var.var, false, 0, null, INCLUDE_FUNCTIONS); 
     1240                    suggestContextInfo((FuncDeclaration) var.var); 
    12341241                } 
    12351242            } else if (node.e1.type instanceof TypeFunction && node.e1.type.next != null) { 
    12361243                trySuggestCall(node.e1.type.next, currentName, CharOperation.NO_CHAR, false /* dosen't matter here */); 
    12371244            } else { 
    1238                 // TODO check this 
     1245                wantMethodContextInfo = true; 
    12391246                trySuggestCall(node.e1.type, currentName, CharOperation.NO_CHAR, false /* dosen't matter here */); 
    12401247            } 
    12411248        } else if (node.e1 instanceof CallExp && node.e1 != node) { 
    12421249            completeCallExp((CallExp) node.e1); 
     1250        } else if (node.e1 instanceof SuperExp) { 
     1251             
     1252        } 
     1253    } 
     1254     
     1255    private void suggestContextInfo(FuncDeclaration func) { 
     1256        int includes = func instanceof CtorDeclaration ? INCLUDE_CONSTRUCTORS : INCLUDE_FUNCTIONS; 
     1257         
     1258        wantMethodContextInfo = true; 
     1259        suggestMember(func, false, 0, null, includes); 
     1260         
     1261        Dsymbol prev = func.overprevious; 
     1262        while(prev != null) { 
     1263            suggestMember(prev, false, 0, null, includes); 
     1264            prev = prev.overprevious; 
     1265        } 
     1266         
     1267        Dsymbol next = func.overnext; 
     1268        while(next != null) { 
     1269            suggestMember(next, false, 0, null, includes); 
     1270            if (next instanceof FuncDeclaration) { 
     1271                next = ((FuncDeclaration) next).overnext; 
     1272            } else if (next instanceof AliasDeclaration) { 
     1273                next = ((AliasDeclaration) next).overnext; 
     1274            } else { 
     1275                break; 
     1276            } 
    12431277        } 
    12441278    } 
     
    12521286            endPosition = actualCompletionPosition; 
    12531287             
    1254             wantMethodContextInfo = true; 
    1255             suggestMember(node.member, false, 0, null, INCLUDE_CONSTRUCTORS); 
     1288            suggestContextInfo((FuncDeclaration) node.member); 
    12561289        } 
    12571290    } 
     
    19431976                     
    19441977                    semanticContext.allowOvernextBySignature = true;                 
    1945                     Declaration funcDecl = func.overnext()
     1978                    Declaration funcDecl = func.overnext
    19461979                    if (funcDecl != null && funcDecl != sym) { 
    19471980                        suggestMember(funcDecl, ident, onlyStatics, flags, funcSignatures, includes); 
     
    22572290                        proposal.setName(currentName); 
    22582291                        if (wantMethodContextInfo) { 
    2259                             proposal.setCompletion(CharOperation.NO_CHAR); 
     2292                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    22602293                        } else { 
    22612294                            proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
     
    22642297                        proposal.setName(funcName); 
    22652298                        if (wantMethodContextInfo) { 
    2266                             proposal.setCompletion(CharOperation.NO_CHAR); 
     2299                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    22672300                        } else { 
    22682301                            proposal.setCompletion(CharOperation.concat(ident, "()".toCharArray())); 
     
    22932326                } 
    22942327                return; 
     2328            } 
     2329        } 
     2330    } 
     2331     
     2332    private void handleContextInfo(FuncDeclaration func, boolean funcNameIsOpCall, CompletionProposal proposal) { 
     2333        proposal.setCompletion(CharOperation.NO_CHAR); 
     2334        if (funcNameIsOpCall || func instanceof CtorDeclaration) { 
     2335            if (isCompletingThisCall) { 
     2336                proposal.setName(TOK.TOKthis.charArrayValue); 
     2337            } else if (isCompletingSuperCall) { 
     2338                proposal.setName(TOK.TOKsuper.charArrayValue); 
     2339            } else { 
     2340                proposal.setName(func.parent.ident.ident); 
    22952341            } 
    22962342        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java

    r1118 r1137  
    463463                next = fa.overnext; 
    464464            } else if ((f = d.isFuncDeclaration()) != null) { 
    465                 next = f.overnext()
     465                next = f.overnext
    466466 
    467467                TypeFunction tf = (TypeFunction) f.type; 
     
    14001400                    } 
    14011401 
    1402                     next = f.overnext()
     1402                    next = f.overnext
    14031403                } 
    14041404            } 
  • trunk/descent.core/src/descent/internal/compiler/parser/AliasDeclaration.java

    r1124 r1137  
    105105        if (overnext == null) { 
    106106            overnext = s; 
     107            s.overprevious = this; 
    107108            return true; 
    108109        } else { 
  • trunk/descent.core/src/descent/internal/compiler/parser/Dsymbol.java

    r1136 r1137  
    6464    public Dsymbol parent; 
    6565    public Loc loc; 
     66    public Dsymbol overprevious; // previous in overload list 
    6667 
    6768    public Dsymbol() { 
  • trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java

    r1128 r1137  
    625625                        return f; 
    626626                    } 
    627                     next = f.overnext()
     627                    next = f.overnext
    628628                } 
    629629            } 
     
    647647            } 
    648648            overnext = a; 
     649            a.overprevious = this; 
    649650            return true; 
    650651        } 
     
    665666        } 
    666667        overnext = f; 
     668        f.overprevious = this; 
    667669        return true; 
    668670    } 
     
    18641866    } 
    18651867     
    1866     public Declaration overnext() { 
    1867         return overnext; 
    1868     } 
    1869      
    18701868    public VarDeclaration vthis() { 
    18711869        return vthis; 
  • trunk/descent.core/src/descent/internal/compiler/parser/SemanticMixin.java

    r1128 r1137  
    154154            } 
    155155             
    156             if (aThis instanceof FuncDeclaration) { 
     156            if (aThis instanceof FuncDeclaration && !(aThis.parent instanceof TemplateInstance)) { 
    157157                aThis.type().appendSignature(sb); 
    158158            } 
     
    175175        sb.append(tempinst.name.ident); 
    176176         
     177        if (aThis instanceof FuncDeclaration) { 
     178            aThis.type().appendSignature(sb); 
     179        } 
     180         
    177181        appendTemplateParameters(tempdecl, sb); 
    178182         
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java

    r1128 r1137  
    687687 
    688688        beforePf.overnext = f; 
     689        f.overprevious = beforePf; 
    689690        return true; 
    690691    }