예제 #1
0
        public override object VisitForeignFunDecl(PParser.ForeignFunDeclContext context)
        {
            // FUN name=Iden
            Function fun = (Function)nodesToDeclarations.Get(context);

            // LPAREN funParamList? RPAREN
            Variable[] paramList = context.funParamList() != null
                ? (Variable[])Visit(context.funParamList())
                : new Variable[0];
            fun.Signature.Parameters.AddRange(paramList);

            // (COLON type)?
            fun.Signature.ReturnType = ResolveType(context.type());

            // SEMI
            // no function body
            fun.Role |= FunctionRole.Foreign;

            // Creates
            foreach (PParser.IdenContext createdInterface in context._interfaces)
            {
                if (CurrentScope.Lookup(createdInterface.GetText(), out Interface @interface))
                {
                    fun.AddCreatesInterface(@interface);
                }
                else
                {
                    throw Handler.MissingDeclaration(createdInterface, "interface", createdInterface.GetText());
                }
            }
            return(fun);
        }