Search in sources :

Example 1 with ImportDeclaration

use of dyvilx.tools.compiler.ast.imports.ImportDeclaration in project Dyvil by Dyvil.

the class ImportDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case KEYWORD:
            switch(type) {
                case GenSrcSymbols.USING:
                    this.mask = KindedImport.USING_DECLARATION;
                // Fallthrough
                case GenSrcSymbols.IMPORT:
                    this.declaration = new ImportDeclaration(token.raw());
                    if (this.template == null) {
                        pm.report(token, "import.context");
                    }
                    this.mode = OPEN_PAREN;
                    return;
            }
            throw new Error();
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                pm.report(token, "import.open_paren");
                pm.popParser(true);
                return;
            }
            pm.pushParser(new ImportParser(this.declaration, this.mask));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            switch(type) {
                case BaseSymbols.CLOSE_PARENTHESIS:
                    if (this.template != null && this.declaration.getImport() != null) {
                        this.template.addImport(this.declaration);
                    }
                    pm.popParser();
                    return;
                case Tokens.EOF:
                    pm.report(token, "import.close_paren");
                    pm.popParser();
                    return;
            }
            pm.report(token, "import.close_paren");
            return;
    }
}
Also used : ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) ImportParser(dyvilx.tools.compiler.parser.header.ImportParser)

Example 2 with ImportDeclaration

use of dyvilx.tools.compiler.ast.imports.ImportDeclaration in project Dyvil by Dyvil.

the class HeaderContext method getImplicitMatches.

@Override
public void getImplicitMatches(MatchList<IMethod> list, IValue value, IType targetType) {
    // See comment in getMethodMatches for rationale
    this.header.getImplicitMatches(list, value, targetType);
    if (list.hasCandidate()) {
        return;
    }
    final ImportDeclaration[] imports = this.header.importDeclarations;
    for (int i = 0; i < this.header.importCount; i++) {
        final IImportContext importContext = imports[i].getContext();
        final MatchList<IMethod> subList = list.emptyCopy();
        importContext.getImplicitMatches(subList, value, targetType);
        list.addAll(subList);
    }
}
Also used : IImportContext(dyvilx.tools.compiler.ast.imports.IImportContext) ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 3 with ImportDeclaration

use of dyvilx.tools.compiler.ast.imports.ImportDeclaration in project Dyvil by Dyvil.

the class ExternalHeader method resolveImports.

private void resolveImports() {
    this.resolved |= IMPORTS;
    for (int i = 0; i < this.importCount; i++) {
        final ImportDeclaration declaration = this.importDeclarations[i];
        declaration.resolveTypes(null, this);
        declaration.resolve(null, this);
    }
}
Also used : ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration)

Example 4 with ImportDeclaration

use of dyvilx.tools.compiler.ast.imports.ImportDeclaration in project Dyvil by Dyvil.

the class HeaderContext method read.

@Override
public void read(DataInput in) throws IOException {
    this.headerDeclaration = new HeaderDeclaration(this);
    this.headerDeclaration.read(in);
    this.name = this.headerDeclaration.getName();
    // Import Declarations
    int imports = in.readShort();
    for (int i = 0; i < imports; i++) {
        ImportDeclaration id = new ImportDeclaration(null);
        id.read(in);
        this.addImport(id);
    }
    int operators = in.readShort();
    for (int i = 0; i < operators; i++) {
        Operator op = Operator.read(in);
        this.addOperator(op);
    }
    int typeAliases = in.readShort();
    for (int i = 0; i < typeAliases; i++) {
        TypeAlias ta = new TypeAlias();
        ta.read(in);
        this.addTypeAlias(ta);
    }
}
Also used : IOperator(dyvilx.tools.compiler.ast.expression.operator.IOperator) Operator(dyvilx.tools.compiler.ast.expression.operator.Operator) ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) TypeAlias(dyvilx.tools.compiler.ast.type.alias.TypeAlias) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias)

Example 5 with ImportDeclaration

use of dyvilx.tools.compiler.ast.imports.ImportDeclaration in project Dyvil by Dyvil.

the class HeaderContext method getMethodMatches.

@Override
public void getMethodMatches(MatchList<IMethod> list, IValue receiver, Name name, ArgumentList arguments) {
    // For ordinary headers, this is a no-op, since they (currently) cannot host any free-standing functions
    // The REPL however can, so we need this call
    this.header.getMethodMatches(list, receiver, name, arguments);
    if (list.hasCandidate()) {
        return;
    }
    final ImportDeclaration[] imports = this.header.importDeclarations;
    for (int i = 0; i < this.header.importCount; i++) {
        final IImportContext importContext = imports[i].getContext();
        final MatchList<IMethod> subList = list.emptyCopy();
        importContext.getMethodMatches(subList, receiver, name, arguments);
        list.addAll(subList);
    }
}
Also used : IImportContext(dyvilx.tools.compiler.ast.imports.IImportContext) ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Aggregations

ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)7 IImportContext (dyvilx.tools.compiler.ast.imports.IImportContext)3 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 ITypeAlias (dyvilx.tools.compiler.ast.type.alias.ITypeAlias)2 IOperator (dyvilx.tools.compiler.ast.expression.operator.IOperator)1 Operator (dyvilx.tools.compiler.ast.expression.operator.Operator)1 Package (dyvilx.tools.compiler.ast.structure.Package)1 TypeAlias (dyvilx.tools.compiler.ast.type.alias.TypeAlias)1 ImportParser (dyvilx.tools.compiler.parser.header.ImportParser)1