Example #1
0
        public IDisposable AddModule(AstModuleImpl module)
        {
            if (Scopes.Count > 0)
            {
                throw new InvalidOperationException(
                          "A Module must be added first before other AddFunction calls.");
            }

            var classBuilder = ClassBuilder.Create(this, module);
            var modScope     = new ModuleScope(this, classBuilder);

            Scopes.Push(modScope);

            // static constructor
            var method = new CSharp.Method(module.Identifier.SymbolName.CanonicalName.FullName, String.Empty)
            {
                AccessModifiers = AccessModifiers.None,
                MethodModifiers = MethodModifiers.Static,
            };

            classBuilder.ModuleClass.AddMethod(method);

            var funScope = new FunctionScope(this, method.GetBody(8));

            Scopes.Push(funScope);
            return(new LinkedScopes(funScope, modScope));
        }
Example #2
0
        public CSharp.Method AddFunction(AstFunctionDefinition function)
        {
            var method = new CSharp.Method(function.Identifier.SymbolName.CanonicalName.FullName, function.FunctionType.TypeReference.ToCode())
            {
                AccessModifiers = function.Symbol.SymbolLocality == AstSymbolLocality.Exported
                    ? AccessModifiers.Public : AccessModifiers.Private,
                MethodModifiers = MethodModifiers.Static,
            };

            foreach (var parameter in function.FunctionType.Parameters)
            {
                method.AddParameter(
                    new CSharp.Parameter(
                        parameter.Identifier.SymbolName.CanonicalName.FullName,
                        parameter.TypeReference.ToCode()
                        )
                    );
            }

            _moduleClass.AddMethod(method);

            return(method);
        }