Package org.apache.flex.compiler.internal.definitions

Examples of org.apache.flex.compiler.internal.definitions.FunctionDefinition


     @param iNode - the return statement. 
     *    Known to have a child 0 expression.
     */
    public void checkReturnValue(IASNode iNode)
    {
        FunctionDefinition func_def = SemanticUtils.getFunctionDefinition(iNode);
       
        if ( func_def != null )
        {
            try
            {
                IExpressionNode returnExpression = ((IReturnNode)iNode).getReturnValueNode();
                IDefinition return_type = func_def.resolveReturnType(project);

                //  void has its own special type logic.
                if ( ClassDefinition.getVoidClassDefinition().equals(return_type) )
                {
                    IDefinition value_type = ((ExpressionNodeBase)returnExpression).resolveType(project);
                    if ( value_type != null && ! value_type.equals(ClassDefinition.getVoidClassDefinition()) )
                        addProblem(new ReturnValueMustBeUndefinedProblem(returnExpression));
                }
                else if ( func_def.isConstructor() )
                {
                    addProblem(new ReturnValueInConstructorProblem(returnExpression));
                }
                else
                {
View Full Code Here


        }
    }

    private void setupConstructor(EnumSet<PostProcessStep> set, ASScope scope, Collection<ICompilerProblem> problems)
    {
        FunctionDefinition ctorDef = null;
        // If there's not an explicit constructor, use an implicit one.
        if (constructorNode == null)
        {
            // We don't have an explicit constructor
            // so we'll create one and add it to the ClassNode
            IdentifierNode constructorNameNode = new IdentifierNode(getName());
            constructorNameNode.setReferenceValue(getDefinition());
            constructorNameNode.span(getNameAbsoluteStart(), getNameAbsoluteEnd(), -1, -1);
            defaultConstructorNode = new FunctionNode(null, constructorNameNode);
            NamespaceIdentifierNode pub = new NamespaceIdentifierNode(INamespaceConstants.public_);
            pub.span(-1, -1, -1, -1);
            defaultConstructorNode.setNamespace(pub);
            defaultConstructorNode.normalize(true);
            defaultConstructorNode.setParent(contentsNode);
            ctorDef = defaultConstructorNode.buildDefinition();
            ctorDef.setImplicit();

            scope.addDefinition(ctorDef);

            assert constructorNode == defaultConstructorNode : "FunctionNode.buildDefinition should set the constructor node field";

        }
        else
        {
            ctorDef = constructorNode.getDefinition();
        }

        // We need to tell the constructor definition
        // that it is the definition of a constructor.
        assert ctorDef != null;
        ctorDef.setAsConstructor((ClassDefinition)scope.getDefinition());
    }
View Full Code Here

    void declareFunction(FunctionNode func)
    {
        func.parseFunctionBody(interfaceScope.getProblems());
        functionSemanticChecks(func);

        FunctionDefinition func_def = func.getDefinition();

        final String interfaceBaseName = interfaceNode.getShortName();

        // ignore a constructor in an interface.
        // functionSemanticChecks() will already have issued a diagnostic.
        if (func_def.getBaseName().equals(interfaceBaseName))
        {
            return;
        }

        // make the method info, including any default vaules of parameters. Will do semantic checks
        // on the default values, too.
        MethodInfo mi = interfaceScope.getGenerator().createMethodInfoWithDefaultArgumentValues(this.interfaceScope, func);

        ICompilerProject project = interfaceScope.getProject();

        ExpressionNodeBase return_type_expr = (ExpressionNodeBase)func.getReturnTypeNode();
        if ( return_type_expr != null )
        {
            Name return_type_name = return_type_expr.getMName(project);
            mi.setReturnType(return_type_name);
        }

        IMethodVisitor mv = this.emitter.visitMethod(mi);
        mv.visit();
        mv.visitEnd();

        Name funcName = func_def.getMName(project);

        itraits.visitMethodTrait(functionTraitKind(func, TRAIT_Method), funcName, 0, mi);
    }
View Full Code Here

     * This method performs the semantic analysis of a function declared in a class.
     * @param func  the FunctionNode to semantically analyze
     */
    void functionSemanticChecks(FunctionNode func)
    {
        final FunctionDefinition func_def = func.getDefinition();
        final String interfaceBaseName = interfaceNode.getShortName();

        // Check for constructor and log a problem.  If it is a constructor,
        // don't bother doing anymore checking
        if (func_def.getBaseName().equals(interfaceBaseName))
        {
            interfaceScope.addProblem(new ConstructorInInterfaceProblem(func));
            return;
        }

        // check the modifiers
        verifyFunctionModifiers(func);

        // Make sure the function doesn't have a namespace
        verifyFunctionNamespace(func, func_def);

        // Warn if there is no return type
        SemanticUtils.checkReturnValueHasNoTypeDeclaration(interfaceScope, func, func_def);

        // Interface methods can't have a body
        if( func.hasBody() )
        {
            interfaceScope.addProblem(new InterfaceMethodWithBodyProblem(SemanticUtils.getFunctionProblemNode(func)));
        }

        ICompilerProject project = interfaceScope.getProject();

        // Do some semantic checking on the function
        interfaceScope.getMethodBodySemanticChecker().checkFunctionDecl(func);

        //  Ensure the return type is defined.
        IDefinition return_type = func_def.resolveReturnType(project);

        if ( !SemanticUtils.isType(return_type) )
        {
            interfaceScope.getMethodBodySemanticChecker().addTypeProblem(func.getReturnTypeNode(), return_type, func_def.getReturnTypeAsDisplayString(), true);
        }

        Name funcName = func_def.getMName(project);

        if (funcName != null)
        {
            interfaceScope.getMethodBodySemanticChecker().checkInterfaceFunctionForConflictingDefinitions(func, func_def);
        }
View Full Code Here

    //

    @Override
    FunctionDefinition buildDefinition()
    {
        FunctionDefinition definition = super.buildDefinition();
        definition.setTypeReference(definition.getReturnTypeReference());
        return definition;
    }
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.definitions.FunctionDefinition

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.