Esempio n. 1
0
        public override AstFunc ConvertFromGenericToActual(CIntermediateLang cil, List <AstExpression> args, SourceInfo si)
        {
            AstFunc tmpFunc;

            if (!UsesThisPtr)
            {
                tmpFunc = base.ConvertFromGenericToActual(cil, args, si);
            }
            else
            {
                // hacky way to deal with thisptr...
                var thisptr = Params[0];
                Params.RemoveAt(0);
                tmpFunc = base.ConvertFromGenericToActual(cil, args, si);
                tmpFunc.Params.Insert(0, thisptr);
                Params.Insert(0, thisptr);
            }
            var actualFunc = new AstExtend(
                SourceInfo,
                Extends,
                Name,
                UsesThisPtr,
                tmpFunc.Params,
                tmpFunc.ReturnType,
                tmpFunc.Body)
            {
                Name        = Name,
                MangledName = GetMangledName(Name, tmpFunc.Params),
                CILFunction = tmpFunc.CILFunction,
            };

            return(actualFunc);
        }
Esempio n. 2
0
        public override void CDecl(CIntermediateLang cil)
        {
            if (LllCompiler.SymTable.LookupSymbol(MangledName) != null)
            {
                var ext    = LllCompiler.SymTable.LookupFunction(MangledName);
                var extAst = ext.Extra as AstExtend;
                if (extAst != null && !extAst.CanOverride)
                {
                    CILFunction = extAst.CILFunction;
                    return;
                }
            }
            var       cName      = NameGenerator.UniqName("ext", Name);
            var       extending  = LllCompiler.SymTable.LookupType(Extends);
            AstExtend overriding = null;

            if (extending.Extensions.ContainsKey(MangledName))
            {
                overriding = extending.Extensions[MangledName];
            }
            if (overriding != null && overriding.CanOverride)
            {
                LllCompiler.SymTable.SetSymbolAtGlobalScope(new LllFunction(cName, this));
                extending.Extensions[MangledName] = this;
            }
            else
            {
                LllCompiler.SymTable.AddSymbolAtGlobalScope(new LllFunction(cName, this));
                extending.Extensions.Add(MangledName, this);
            }
            if (!IsGeneric)
            {
                var retType = ReturnType.ToLllType();
                if (extending.IsPrimitive && UsesThisPtr)
                {
                    Params[0].Type.PointerDepth = 0;
                }
                CILFunction = cil.CreateFunction(
                    SourceInfo,
                    retType.CName,
                    retType.PointerDepth,
                    cName,
                    Params.Select(p => p.ToCILVariableDecl(cil)).ToList());
            }
        }