Package org.openquark.cal.compiler.SourceModel

Examples of org.openquark.cal.compiler.SourceModel.TopLevelSourceElement


     */
    static SourceRange findNextTopLevelElement(SourceModel.ModuleDefn moduleDefn, SourcePosition position){
        final int nTopLevelDefns = moduleDefn.getNTopLevelDefns();
        SourceRange next = null;
        for (int i = 0; i < nTopLevelDefns; i++) {
            TopLevelSourceElement nthTopLevelDefn = moduleDefn.getNthTopLevelDefn(i);
            // skip the type declarations
            if (nthTopLevelDefn instanceof SourceModel.FunctionTypeDeclaration){
                continue;
            }
            SourceRange testSourcePosition = getScopedEntityNameSourceRange(nthTopLevelDefn);
View Full Code Here


     */
    static SourceRange findPreviousTopLevelElement(SourceModel.ModuleDefn moduleDefn, SourcePosition position){
        final int nTopLevelDefns = moduleDefn.getNTopLevelDefns();
        SourceRange next = null;
        for (int i = 0; i < nTopLevelDefns; i++) {
            TopLevelSourceElement nthTopLevelDefn = moduleDefn.getNthTopLevelDefn(i);
            // skip the type declarations
            if (nthTopLevelDefn instanceof SourceModel.FunctionTypeDeclaration){
                continue;
            }
            SourceRange testSourcePosition = getScopedEntityNameSourceRange(nthTopLevelDefn);
View Full Code Here

    static Pair<SourceElement, SourceRange> findContainingSourceElement(SourceModel.ModuleDefn moduleDefn, SourcePosition position){
        final int nTopLevelDefns = moduleDefn.getNTopLevelDefns();
        SourceRange next = null;
        SourceElement element = null;
        for (int i = 0; i < nTopLevelDefns; i++) {
            TopLevelSourceElement nthTopLevelDefn = moduleDefn.getNthTopLevelDefn(i);
            // Check for matching data constructor
            if (nthTopLevelDefn instanceof SourceModel.TypeConstructorDefn.AlgebraicType){
                SourceModel.TypeConstructorDefn.AlgebraicType algebraicType = (AlgebraicType) nthTopLevelDefn;
                for(DataConsDefn dataConsDefn : algebraicType.getDataConstructors()){
                    SourceRange testSourcePosition = dataConsDefn.getSourceRangeOfDefn();
                    if (testSourcePosition.containsPosition(position)){
                        if (next == null || next.contains(testSourcePosition)){
                            next = testSourcePosition;
                            element = dataConsDefn;
                            return new Pair<SourceElement, SourceRange>(element, element.getSourceRange());
                        }
                    }
                }
            }
            // check for matching class method
            else if (nthTopLevelDefn instanceof SourceModel.TypeClassDefn){
                SourceModel.TypeClassDefn typeClassDefn = (SourceModel.TypeClassDefn) nthTopLevelDefn;
                for(ClassMethodDefn classMethodDefn : typeClassDefn.getClassMethodDefns()){
                    SourceRange testSourcePosition = classMethodDefn.getSourceRangeOfClassDefn();
                    if (testSourcePosition.containsPosition(position)){
                        if (next == null || next.contains(testSourcePosition)){
                            next = testSourcePosition;
                            element = classMethodDefn;
                            return new Pair<SourceElement, SourceRange>(element, element.getSourceRange());
                        }
                    }
                }
            }
            // check for let expressions
            else if (nthTopLevelDefn instanceof SourceModel.FunctionDefn.Algebraic){
                SourceModel.FunctionDefn.Algebraic algebraic = (SourceModel.FunctionDefn.Algebraic) nthTopLevelDefn;
                if (algebraic.getDefiningExpr() instanceof SourceModel.Expr.Let){
                    SourceModel.Expr.Let let = (SourceModel.Expr.Let) algebraic.getDefiningExpr();
                    for(LocalDefn localDefn : let.getLocalDefinitions()){
                        SourceRange testSourcePosition = localDefn.getSourceRange();
                        if (testSourcePosition.containsPosition(position)){
                            if (next == null || next.contains(testSourcePosition)){
                                next = testSourcePosition;
                                element = localDefn;

                                if (localDefn instanceof LocalDefn.Function){
                                    SourceModel.LocalDefn.Function localFunction = (SourceModel.LocalDefn.Function) localDefn;
                                   
                                    // if there is a type declaration then use that to put the
                                    // cal doc in front of
                                    for(LocalDefn localTypeDefn : let.getLocalDefinitions()){                                   
                                        if (localTypeDefn instanceof SourceModel.LocalDefn.Function.TypeDeclaration){
                                            SourceModel.LocalDefn.Function.TypeDeclaration type = (SourceModel.LocalDefn.Function.TypeDeclaration) localTypeDefn;
                                            if (type.getName().equals(localFunction.getName())){
                                                element = type;                                               
                                            }
                                        }
                                    }
                                }
                                if (localDefn instanceof LocalDefn.Function.Definition){
                                    LocalDefn.Function.Definition def = (Definition) localDefn;
                                    Pair<SourceElement, SourceRange> innerMatch = findInnermostDef(def, position);
                                    if (innerMatch != null){
                                        element = innerMatch.fst();
                                        next = innerMatch.snd();
                                    }
                                }
                            }
                        }
                    }
                    if (element != null){
                        break;
                    }
                }
               
            }

            // check the current element
            SourceRange testSourcePosition = nthTopLevelDefn.getSourceRangeOfDefn();
            if (testSourcePosition.containsPosition(position)){
                if (next == null || next.contains(testSourcePosition)){
                    next = testSourcePosition;
                    element = nthTopLevelDefn;
                }
            }
        }

        if (element != null){
            // Find type declaration if any
            if (element instanceof SourceModel.FunctionDefn){
                SourceModel.FunctionDefn functionDefn = (FunctionDefn) element;
                String name = functionDefn.getName();
                for (int i = 0; i < nTopLevelDefns; i++) {
                    TopLevelSourceElement nthTopLevelDefn = moduleDefn.getNthTopLevelDefn(i);
                    if (nthTopLevelDefn instanceof FunctionTypeDeclaration){
                        FunctionTypeDeclaration type = (FunctionTypeDeclaration) nthTopLevelDefn;
                        if (type.getFunctionName().equals(name)){
                            element = type;
                            break;
View Full Code Here

            int nGeneratedFunctions = 0;
            int nGeneratedTypes = 0;
           
            int nTopLevelDefns = defn.getNTopLevelDefns();
            for (int i = 0; i < nTopLevelDefns; i++) {
                TopLevelSourceElement nthTopLevelDefn = defn.getNthTopLevelDefn(i);
               
                if (nthTopLevelDefn instanceof SourceModel.FunctionDefn.Foreign) {
                    nGeneratedFunctions++;
               
                } else if (nthTopLevelDefn instanceof SourceModel.TypeConstructorDefn.ForeignType) {
View Full Code Here

        final SourceModel.ModuleDefn sourceModel = moduleContainer.getSourceModel(functionName.getModuleName(), true, logger);
        // if there are errors then skip getting the type.
        if (logger.getNErrors() == 0){
            final int nDefs = sourceModel.getNTopLevelDefns();
            for(int iType = 0; iType < nDefs; ++iType){
                final TopLevelSourceElement element = sourceModel.getNthTopLevelDefn(iType);
                if (element instanceof FunctionTypeDeclaration){
                    FunctionTypeDeclaration typeDeclaration = (FunctionTypeDeclaration) element;
                    if (typeDeclaration.getFunctionName().equals(functionName.getUnqualifiedName())){
                        SourceRange sourceRangeOfType = typeDeclaration.getSourceRangeOfDefn();
                        return new Precise(sourceRangeOfType, functionName, null, false);
View Full Code Here

        ModuleTypeInfo moduleTypeInfo = moduleContainer.getModuleTypeInfo(classInstance.getModuleName());
        if (moduleTypeInfo == null){
            return null;
        }
        for( int i = 0; i < moduleSourceModel.getNTopLevelDefns(); ++i){
            TopLevelSourceElement topLevelDefn = moduleSourceModel.getNthTopLevelDefn(i);
            if (topLevelDefn instanceof SourceModel.InstanceDefn){
                SourceModel.InstanceDefn instanceDefn = (InstanceDefn) topLevelDefn;
                if (same(classInstance, instanceDefn, moduleTypeInfo)){
                    return instanceDefn.getSourceRangeOfName();
                }
View Full Code Here

        }
       
        // Find the top level element
        final int nTopLevelDefns = moduleDefn.getNTopLevelDefns();
        for(int i = 0; i < nTopLevelDefns; ++i){
            TopLevelSourceElement tlse = moduleDefn.getNthTopLevelDefn(i);
            SourceRange sourceRange = tlse.getSourceRangeOfDefn();
            SourcePosition pos = new SourcePosition(line, column);
            if (sourceRange != null && sourceRange.containsPosition(pos)){
                // The scope of the Algebraic type includes the data constructors so search for the possible
                // data constructor match first before going for the algebraic type
                if (tlse instanceof SourceModel.TypeConstructorDefn.AlgebraicType){
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.SourceModel.TopLevelSourceElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.