コード例 #1
0
    public Gem Create(string arguments)
    {
        var     tokens      = arguments.Split();
        var     clarityType = tokens[0];
        var     gemType     = tokens[1];
        Clarity clarity     = (Clarity)Enum.Parse(typeof(Clarity), clarityType);

        Gem gem = null;

        switch (gemType)
        {
        case "Ruby":
            gem = new RubyGem(clarity);
            break;

        case "Emerald":
            gem = new EmeraldGem(clarity);
            break;

        case "Amethyst":
            gem = new AmethystGem(clarity);
            break;
        }

        return(gem);
    }
コード例 #2
0
 protected Gem(Clarity clarity)
 {
     Clarity   = clarity;
     Strength += clarity.Bonus;
     Vitality += clarity.Bonus;
     Agility  += clarity.Bonus;
 }
コード例 #3
0
 public Discoverable(Guid id, Story story) : base(id, story)
 {
     this._tangibility   = Tangibility.Tangible;
     this._functionality = Functionality.Narrative;
     this._clarity       = Clarity.Explicit;
     this._delivery      = Delivery.Active;
 }
コード例 #4
0
 public Gem(int str, int agility, int vitality, Clarity clarity, Weapon weapon)
 {
     this.Strength = str;
     this.Agility  = agility;
     this.Vitality = vitality;
     DamageIncreasesByClarity(clarity);
 }
コード例 #5
0
 protected Gem(int strength, int agility, int vitality, Clarity clarity)
 {
     this.strength = strength;
     this.agility  = agility;
     this.vitality = vitality;
     this.clarity  = clarity;
 }
コード例 #6
0
ファイル: AddCommand.cs プロジェクト: yosifov/oop
        public string Execute(string[] data)
        {
            if (data.Length != 3)
            {
                return("Invalid command arguments");
            }

            try
            {
                var      weaponName     = data[0];
                int      gemIndex       = int.Parse(data[1]);
                string[] gemArgs        = data[2].Split();
                Clarity  gemClarityType = (Clarity)Enum.Parse(typeof(Clarity), gemArgs[0]);
                string   gemType        = gemArgs[1];
                var      currentGem     = this.gemFactory.CreateGem(gemType, gemClarityType);

                this.weapons.AddGemToWeapon(weaponName, gemIndex, currentGem);

                return($"{gemType} successfuly added to {weaponName}");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
コード例 #7
0
    public override void Execute()
    {
        string weaponName  = this.Data[1];
        int    socketIndex = int.Parse(this.Data[2]);

        string[] gemInfo = this.Data[3].Split();

        string  gemType = gemInfo[1];
        Clarity clarity = (Clarity)Enum.Parse(typeof(Clarity), gemInfo[0]);

        Weapon weapon = Weapons.StaticWeapons.FirstOrDefault(w => w.Name == weaponName);

        if (weapon == null)
        {
            return;
        }

        switch (gemType)
        {
        case "Ruby":
            weapon.AddGemInSocket(new Ruby(clarity), socketIndex);
            break;

        case "Emerald":
            weapon.AddGemInSocket(new Emerald(clarity), socketIndex);
            break;

        case "Amethyst":
            weapon.AddGemInSocket(new Amethyst(clarity), socketIndex);
            break;

        default:
            break;
        }
    }
コード例 #8
0
 public Gem(int strength, int agility, int vitality, Clarity clarity)
 {
     this.Strength = strength;
     this.Agility  = agility;
     this.Vitality = vitality;
     this.Clarity  = clarity;
 }
コード例 #9
0
ファイル: Gem.cs プロジェクト: stambi4a/AdvancedOOP
 protected Gem(int strengthPlus, int agilityPlus, int vitalityPlus, Clarity clarity)
 {
     this.Clarity = clarity;
     this.CalculateStrengthIncrease(strengthPlus);
     this.CalculateAgilityIncrease(agilityPlus);
     this.CalculateVitalityIncrease(vitalityPlus);
 }
コード例 #10
0
 public RubyGem(string name, Clarity clarity) : base(name, clarity)
 {
     this.Strength = 7;
     this.Agility  = 2;
     this.Vitality = 5;
     this.IncreaseStats();
 }
コード例 #11
0
 protected Gem(Clarity clarity, int strength, int agility, int vitality)
 {
     this.Strength = strength;
     this.Agility  = agility;
     this.Vitality = vitality;
     this.clarity  = clarity;
 }
コード例 #12
0
 public AmethystGem(string name, Clarity clarity) : base(name, clarity)
 {
     this.Strength = 2;
     this.Agility  = 8;
     this.Vitality = 4;
     this.IncreaseStats();
 }
コード例 #13
0
 public Gem(string clarity, int strength, int agility, int vitality)
 {
     this.clarity  = Enum.Parse <Clarity>(clarity);
     this.strength = strength + (int)this.clarity;
     this.agility  = agility + (int)this.clarity;
     this.vitality = vitality + (int)this.clarity;
 }
コード例 #14
0
ファイル: CppMidCompiler.cs プロジェクト: elasota/clarity
        public void EmitAll(Clarity.Rpa.HighFileBuilder builder, BinaryWriter writer)
        {
            // Generate locals and args
            Dictionary<VReg, Clarity.Rpa.HighLocal> localLookup = new Dictionary<VReg, Clarity.Rpa.HighLocal>();

            List<Clarity.Rpa.HighLocal> highArgs = new List<Clarity.Rpa.HighLocal>();
            List<Clarity.Rpa.HighLocal> highLocals = new List<Clarity.Rpa.HighLocal>();

            VRegsToHighLocals(m_args, highArgs, localLookup);
            VRegsToHighLocals(m_locals, highLocals, localLookup);
            VRegsToHighLocals(m_temporaries, highLocals, localLookup);

            Clarity.Rpa.HighLocal instanceLocal;
            if (m_method.Static)
                instanceLocal = null;
            else
            {
                instanceLocal = highArgs[0];
                highArgs.RemoveAt(0);
            }

            CppRegionEmitter emitter = new CppRegionEmitter(m_builder, m_mainRegion, m_regAllocator, localLookup);
            Clarity.Rpa.HighRegion mainRegion = emitter.Emit();

            Clarity.Pdb.PdbDebugInfo debugInfo = null;
            m_builder.AssemblyPdbs.TryGetValue(m_method.MethodDef.Table.MetaData.Assembly, out debugInfo);

            Clarity.Pdb.PdbDebugFunction debugFunction = null;
            if (debugInfo != null)
                debugFunction = debugInfo.GetFunction(m_method.MethodDef.MetadataToken);

            Clarity.Rpa.HighMethodBody methodBody = new Clarity.Rpa.HighMethodBody(mainRegion, instanceLocal, highArgs.ToArray(), highLocals.ToArray(), debugFunction != null);

            methodBody.Write(builder, writer);
        }
コード例 #15
0
 public EmeraldGem(string name, Clarity clarity) : base(name, clarity)
 {
     this.Strength = 1;
     this.Agility  = 4;
     this.Vitality = 9;
     this.IncreaseStats();
 }
コード例 #16
0
ファイル: Gem.cs プロジェクト: Anil1111/Csharp-OOP-Advanced-1
        protected Gem(int strength, int agility, int vitality, Clarity clarity)
        {
            int clarityMultiplier = (int)clarity;

            this.Strength = strength + clarityMultiplier;
            this.Agility  = agility + clarityMultiplier;
            this.Vitality = vitality + clarityMultiplier;
        }
コード例 #17
0
 public Amethyst(Clarity clarity)
     : base(clarity)
 {
     this.Strength = StrengthValue;
     this.Agility  = AgilityValue;
     this.Vitality = VitailityValue;
     this.ChangeStats();
 }
コード例 #18
0
ファイル: GemFactory.cs プロジェクト: GeorgiBarbutov/SoftUni
    public IGem CreateGem(string gemType, Clarity clarity)
    {
        Type type = Type.GetType(gemType);

        IGem gem = (IGem)Activator.CreateInstance(type, new object[] { clarity });

        return(gem);
    }
コード例 #19
0
ファイル: Gem.cs プロジェクト: Avarea/OOP-Advanced
 public Gem(string name, Clarity clarity)
 {
     this.Name     = name;
     this.Clarity  = clarity;
     this.Agility  = 0;
     this.Strength = 0;
     this.Vitality = 0;
 }
コード例 #20
0
ファイル: Gem.cs プロジェクト: BiserB/Educational
        public Gem(int strength, int agility, int vitality, Clarity clarity)
        {
            int modifier = (int)clarity;

            this.Strength = strength + modifier;
            this.Agility  = agility + modifier;
            this.Vitality = vitality + modifier;
            this.Clarity  = clarity;
        }
コード例 #21
0
ファイル: Gem.cs プロジェクト: GeorgiBarbutov/SoftUni
    protected Gem(int strengthBonus, int agilityBonus, int vitalityBonus, Clarity clarity)
    {
        this.StrenghtBonus = strengthBonus;
        this.AgilityBonus  = agilityBonus;
        this.VitalityBonus = vitalityBonus;
        this.Clarity       = clarity;

        IncreaseStats();
    }
コード例 #22
0
 protected Gem(Clarity clarity, string type, int strength, int agility, int vitality)
 {
     this.Clarity  = clarity;
     this.Type     = type;
     this.Strength = strength;
     this.Agility  = agility;
     this.Vitality = vitality;
     GetBonusFromClarity();
 }
コード例 #23
0
    public Gem CreateGem(string[] clarityGem)
    {
        Clarity clarity = (Clarity)Enum.Parse(typeof(Clarity), clarityGem[0]);
        Type    typeGem = Type.GetType(clarityGem[1]);
        Gem     gem     = (Gem)Activator.CreateInstance(typeGem, false);

        gem.Clarity = clarity;

        return(gem);
    }
コード例 #24
0
ファイル: Gem.cs プロジェクト: plamen-parvanov/SoftUni
        public Gem(Clarity clarity, int strenghtModifier, int agilityModifier,
                   int vitalityModifier)
        {
            this.Clarity          = clarity;
            this.StrenghtModifier = strenghtModifier;
            this.AgilityModifier  = agilityModifier;
            this.VitalityModifier = vitalityModifier;

            IncreaseAllStatsBaseOnClarity();
        }
コード例 #25
0
ファイル: GemFactory.cs プロジェクト: KostadinovK/CSharp-OOP
    public static Gem GetGem(string clarity, string type)
    {
        var     clarityType     = Type.GetType(clarity);
        Clarity clarityInstance = (Clarity)Activator.CreateInstance(clarityType);

        var typeOfGem = Type.GetType(type);
        Gem gem       = (Gem)Activator.CreateInstance(typeOfGem, new object[] { clarityInstance });

        return(gem);
    }
コード例 #26
0
ファイル: GemFactory.cs プロジェクト: kmyumyun/SoftUni
        public static Gem CreateGem(string[] args)
        {
            string[] gemInfo = args[0].Split();
            Clarity  clarity = (Clarity)Enum.Parse(typeof(Clarity), gemInfo[0]);

            Type type = Type.GetType("InfernoInfinity.Models.Gems." + gemInfo[1]);

            var obj = Activator.CreateInstance(type, new object[] { clarity });

            return((Gem)obj);
        }
コード例 #27
0
        public override void Execute()
        {
            var     name    = this.Data[0];
            var     index   = int.Parse(this.Data[1]);
            var     split   = this.Data[2].Split(" ", StringSplitOptions.RemoveEmptyEntries);
            Clarity clarity = (Clarity)Enum.Parse(typeof(Clarity), split[0]);
            var     gem     = this.GemFactory.CreateGem(split[1], clarity);
            var     weapon  = this.Repository.GetWeapon(name);

            weapon.AddGem(gem, index);
        }
コード例 #28
0
ファイル: Summs.cs プロジェクト: Oztpoor/BackupElo
        public static void Init()
        {
            try
            {
                menu = Load.MenuIni.AddSubMenu("SummonerSpells", "SummonerSpells");

                if (Mark.IsVaild() || Player.Spells.Any(s => s.Name.Equals("SummonerPoroThrow")))
                {
                    balls.Init();
                }
                if (Barrier.IsVaild())
                {
                    Borrier.Init();
                }
                if (Clarity.IsVaild())
                {
                    Clarty.Init();
                }
                if (Cleanse.IsVaild())
                {
                    Clanse.Init();
                }
                if (Exhaust.IsVaild())
                {
                    Exhust.Init();
                }
                if (Flash.IsVaild())
                {
                    Flish.Init();
                }
                if (Heal.IsVaild())
                {
                    Heel.Init();
                }
                if (Ignite.IsVaild())
                {
                    Ignoite.Init();
                }
                if (Smite.IsVaild())
                {
                    Smote.Init();
                }

                if (menu.LinkedValues.Count == 0)
                {
                    menu.AddGroupLabel("Your SummonerSpells are not Supported");
                }
            }
            catch (Exception ex)
            {
                Logger.Send("Error At KappaUtility.Brain.Activator.Spells.SummonerSpells.Init", ex, Logger.LogLevel.Error);
            }
        }
コード例 #29
0
        private static void Game_OnTick(EventArgs args)
        {
            if (!Summs.menu.CheckBoxValue("Clarity") || !Clarity.IsReady())
            {
                return;
            }

            if (EntityManager.Heroes.Allies.Any(a => a.Distance(Player.Instance) <= 750 && Summs.menu.CheckBoxValue("clarity" + a.Name()) && a.ManaPercent <= Summs.menu.SliderValue("mp" + a.Name())))
            {
                Clarity.Cast();
            }
        }
コード例 #30
0
        protected Gem(int strength, int agility, int vitality, string clarity)
        {
            this.strength = strength;
            this.agility  = agility;
            this.vitality = vitality;
            Clarity temp;

            if (!Enum.TryParse(clarity, true, out temp))
            {
                throw new ArgumentException("No such ClarityType!");
            }
            Clarity = temp;
        }
コード例 #31
0
    public IGem CreateGem(string args)
    {
        var     splittedArgs = args.Split().ToList();
        Clarity clarity      = (Clarity)Enum.Parse(typeof(Clarity), splittedArgs[0]);
        string  type         = splittedArgs[1];

        IGem gem = null;

        switch (type)
        {
        case "Ruby":
            gem = new Ruby();
            break;

        case "Emerald":
            gem = new Emerald();
            break;

        case "Amethyst":
            gem = new Amethyst();
            break;
        }

        int increaseStatsBy = 0;

        switch (clarity)
        {
        case Clarity.Chipped:
            increaseStatsBy = 1;
            break;

        case Clarity.Regular:
            increaseStatsBy = 2;
            break;

        case Clarity.Perfect:
            increaseStatsBy = 5;
            break;

        case Clarity.Flawless:
            increaseStatsBy = 10;
            break;
        }
        gem.Agility  += increaseStatsBy;
        gem.Strenght += increaseStatsBy;
        gem.Vitality += increaseStatsBy;

        return(gem);
    }
コード例 #32
0
ファイル: RpaTagFactory.cs プロジェクト: elasota/clarity
        public static MethodSpecTag CreateMethodSpec(Clarity.Rpa.MethodSlotType slotType, CppMethodSpec methodSpec)
        {
            if ((slotType == MethodSlotType.Static) != methodSpec.CppMethod.Static)
                throw new ArgumentException("Static flag mismatch");

            TypeSpecTag[] genericTypes = null;

            List<TypeSpecTag> genericTypesList = new List<TypeSpecTag>();

            if (methodSpec.GenericParameters != null)
                foreach (CLRTypeSpec type in methodSpec.GenericParameters)
                    genericTypesList.Add(CreateTypeTag(type));

            genericTypes = genericTypesList.ToArray();

            return new MethodSpecTag(slotType,
                genericTypes,
                (TypeSpecClassTag)CreateTypeTag(methodSpec.CppMethod.DeclaredInClassSpec),
                methodSpec.CppMethod.VtableSlotTag
                );
        }
コード例 #33
0
 public CppTranslatedOutboundEdge(Clarity.Rpa.HighCfgNodeHandle prev, Clarity.Rpa.HighCfgNodeHandle next, IList<Clarity.Rpa.HighSsaRegister> regs)
 {
     m_prevNode = prev;
     m_nextNode = next;
     m_regs = regs;
 }
コード例 #34
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void ExportDelegate(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            writer.Write(cls.IsMulticastDelegate);

            ExportGenericVariance(cls, writer);

            foreach (CppMethod method in cls.Methods)
            {
                if (method.Name == "Invoke")
                {
                    writer.Write(fileBuilder.IndexMethodSignatureTag(RpaTagFactory.CreateMethodSignature(method.MethodSignature)));
                    return;
                }
            }
            throw new ParseFailedException("Malformed delegate");
        }
コード例 #35
0
ファイル: CppCilExporter.cs プロジェクト: elasota/clarity
        public static void WriteMethodCode(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppBuilder builder, CppClass cls, CppMethod method)
        {
            List<VReg> args = new List<VReg>();
            if (!method.Static)
            {
                CppClass thisClass = builder.GetCachedClass(method.DeclaredInClassSpec);
                CLRTypeSpec thisTypeSpec = method.DeclaredInClassSpec;
                VType vt = new VType(thisClass.IsValueType ? VType.ValTypeEnum.ManagedPtr : VType.ValTypeEnum.ReferenceValue, thisTypeSpec);
                args.Add(new VReg(builder, "bThis", vt, args.Count, VReg.UsageEnum.Argument));
            }

            foreach (CLRMethodSignatureInstanceParam param in method.MethodSignature.ParamTypes)
            {
                CLRTypeSpec spec = param.Type;
                VType vt;
                switch (param.TypeOfType)
                {
                    case CLRSigParamOrRetType.TypeOfTypeEnum.ByRef:
                        vt = new VType(VType.ValTypeEnum.ManagedPtr, spec);
                        break;
                    case CLRSigParamOrRetType.TypeOfTypeEnum.Value:
                        vt = new VType(ValTypeForTypeSpec(builder, spec), spec);
                        break;
                    default:
                        throw new ArgumentException();
                }
                args.Add(new VReg(builder, "bParam", vt, args.Count, VReg.UsageEnum.Argument));
            }

            List<VReg> locals = new List<VReg>();

            CLRSigLocalVarSig localVarSig = method.MethodDef.Method.LocalVarSig;
            if (localVarSig != null)
            {
                foreach (CLRSigLocalVar localVar in localVarSig.LocalVars)
                {
                    if (localVar.Constraints != null && localVar.Constraints.Length > 0)
                        throw new NotSupportedException("Local var constraints are not supported");
                    if (localVar.CustomMods != null && localVar.CustomMods.Length > 0)
                        throw new NotSupportedException("Local var custom mods are not supported");

                    CLRTypeSpec localTypeSpec = builder.Assemblies.InternVagueType(localVar.Type);

                    VReg vreg = null;
                    switch (localVar.VarKind)
                    {
                        case CLRSigLocalVar.LocalVarKind.ByRef:
                            vreg = new VReg(builder, "bLocal", new VType(VType.ValTypeEnum.ManagedPtr, localTypeSpec), locals.Count, VReg.UsageEnum.Local);
                            break;
                        case CLRSigLocalVar.LocalVarKind.Default:
                            vreg = new VReg(builder, "bLocal", new VType(CppCilExporter.ValTypeForTypeSpec(builder, localTypeSpec), localTypeSpec), locals.Count, VReg.UsageEnum.Local);
                            break;
                        default:
                            throw new NotImplementedException();
                    }

                    locals.Add(vreg);
                }
            }

            foreach (VReg vReg in locals)
                vReg.Liven();
            foreach (VReg vReg in args)
                vReg.Liven();

            List<VReg> temporaries = new List<VReg>();

            ExceptionHandlingRegion mainRegion = new ExceptionHandlingRegion(null, builder, method, 0, (uint)method.MethodDef.Method.Instructions.Length - 1, null);
            {
                CfgBuilder cfgBuilder = new CfgBuilder(mainRegion, builder, cls, method, args.ToArray(), locals.ToArray(), temporaries);
                mainRegion.RootCfgNode = cfgBuilder.RootNode;
            }

            CppMidCompiler midCompiler = new CppMidCompiler(builder, cls, method, mainRegion, "bTLFrame", args.ToArray(), locals.ToArray(), temporaries.ToArray());

            midCompiler.EmitAll(fileBuilder, writer);

            //MidCompile(builder, cls, method, mainRegion, args.ToArray(), locals.ToArray(), writer.BaseStream);

            foreach (VReg vReg in locals)
            {
                if (!vReg.IsAlive || vReg.IsZombie)
                    throw new Exception("Internal error: local vreg was killed");
            }
            foreach (VReg vReg in args)
            {
                if (!vReg.IsAlive || vReg.IsZombie)
                    throw new Exception("Internal error: arg vreg was killed");
            }
        }
コード例 #36
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void ExportEnum(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            CLRTypeSpecClass underlyingType = (CLRTypeSpecClass)cls.GetEnumUnderlyingType();

            bool foundUnderlyingType = false;
            uint numLiterals = 0;
            foreach (CppField fld in cls.Fields)
            {
                CLRFieldRow fieldRow = fld.Field;
                if (fieldRow.Literal)
                    numLiterals++;
            }

            Clarity.Rpa.HighTypeDef.EnumUnderlyingType underlyingTypeSymbol;
            string typeName = underlyingType.TypeDef.TypeName;
            switch (typeName)
            {
                case "Byte":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt8;
                    break;
                case "SByte":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int8;
                    break;
                case "Int16":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int16;
                    break;
                case "UInt16":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt16;
                    break;
                case "Int32":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int32;
                    break;
                case "UInt32":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt32;
                    break;
                case "Int64":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.Int64;
                    break;
                case "UInt64":
                    underlyingTypeSymbol = Clarity.Rpa.HighTypeDef.EnumUnderlyingType.UInt64;
                    break;
                default:
                    throw new ArgumentException();
            }

            writer.Write((byte)underlyingTypeSymbol);
            writer.Write(numLiterals);
            foreach (CppField fld in cls.Fields)
            {
                CLRFieldRow fieldRow = fld.Field;
                if (fieldRow.Literal)
                {
                    writer.Write(fileBuilder.IndexString(fld.Name));
                    ArraySegment<byte> constantValue = fieldRow.AttachedConstants[0].Value;
                    writer.Write(constantValue.Array, constantValue.Offset, constantValue.Count);
                }
            }
        }
コード例 #37
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void ExportMethodCode(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls, CppMethod method)
        {
            if (method.Abstract)
                throw new ArgumentException("Can't export code of an abstract method");

            if (method.MethodDef.Method == null)
                writer.Write(true);
            else
            {
                writer.Write(false);

                if (!method.Abstract && method.MethodDef.Method != null)
                    CppCilExporter.WriteMethodCode(fileBuilder, writer, this, cls, method);
            }
        }
コード例 #38
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
 private void WriteInterfaceBinding(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppVtableSlot decl, CppVtableSlot body)
 {
     writer.Write(fileBuilder.IndexMethodDeclTag(decl.VtableSlotTag));
     writer.Write(fileBuilder.IndexMethodDeclTag(body.VtableSlotTag));
 }
コード例 #39
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void WriteInterfaceImplementations(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            if (cls.TypeDef.Semantics != CLRTypeDefRow.TypeSemantics.Class)
                throw new ArgumentException();

            List<CppVtableSlot> requiredVTableSlots = new List<CppVtableSlot>();

            uint numNewInterfaces = (uint)cls.NewlyImplementedInterfaces.Count;
            uint numReimplementedInterfaces = (uint)cls.ReimplementedInterfaces.Count;

            List<KeyValuePair<CLRTypeSpec, bool>> reqBindings = new List<KeyValuePair<CLRTypeSpec, bool>>();

            foreach (CLRTypeSpec ts in cls.NewlyImplementedInterfaces)
                reqBindings.Add(new KeyValuePair<CLRTypeSpec, bool>(ts, false));
            foreach (CLRTypeSpec ts in cls.ReimplementedInterfaces)
                reqBindings.Add(new KeyValuePair<CLRTypeSpec, bool>(ts, true));

            writer.Write((uint)reqBindings.Count);

            List<BoundInterfaceMethodImpl> boundImpls = new List<BoundInterfaceMethodImpl>();

            foreach (CLRMethodImplRow methodImpl in cls.TypeDef.MethodImplementations)
            {
                CppVtableSlot decl = ResolveMethodImplReference(methodImpl.MethodDeclaration);
                CppVtableSlot body = ResolveMethodImplReference(methodImpl.MethodBody);
                CLRTypeSpec spec = m_assemblies.InternTypeDefOrRefOrSpec(methodImpl.Class);

                if (decl.Equals(body))
                {
                    // Roslyn sometimes emits redundant MethodImpls that override the vtable slot
                    // that the method already occupies via ReuseSlot.  We want to ignore these.
                    continue;
                }

                boundImpls.Add(new BoundInterfaceMethodImpl(spec, decl, body));
            }

            foreach (KeyValuePair<CLRTypeSpec, bool> convPair in reqBindings)
            {
                CLRTypeSpec conv = convPair.Key;
                bool isReimpl = convPair.Value;

                writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(conv)));

                CppClass ifcClass = this.GetCachedClass(conv);

                writer.Write((uint)ifcClass.Methods.Count);

                foreach (CppMethod method in ifcClass.Methods)
                {
                    CppVtableSlot slot = method.CreatesSlot;
                    if (slot == null)
                        throw new ArgumentException();

                    bool isExplicitlyBound = false;
                    for (int i = 0; i < boundImpls.Count; i++)
                    {
                        BoundInterfaceMethodImpl bimi = boundImpls[i];
                        if (bimi.InterfaceSlot.DisambigSpec.Equals(conv) &&
                            bimi.InterfaceSlot.Name == slot.Name && bimi.InterfaceSlot.Signature.Equals(slot.Signature))
                        {
                            isExplicitlyBound = true;

                            writer.Write(true);    // HACK - FIXME
                            WriteInterfaceBinding(fileBuilder, writer, bimi.InterfaceSlot, bimi.ClassSlot);
                            boundImpls.RemoveAt(i);
                            break;
                        }
                    }

                    if (!isExplicitlyBound)
                    {
                        // Look for a matching slot
                        // This should follow the rules of II.12.2
                        // Because Clarity does not support virtual generic methods, maintaining a
                        // per-slot implementation list is not necessary.  However, duplicate slots
                        // from generic type substitution are still allowed.
                        //
                        // We depend on visible vtable slots being in method declaration order already,
                        // so the only thing we really need to do is return the first one.
                        //
                        // .NET has some additional non-standardized behavior: If a reimplemented interface
                        // doesn't have a new match since the last time it was implemented, then the implementation
                        // has NO MATCHES.  This matters because since interface dispatch is done per-class,
                        // per-method, a variant interface that does have a match will take priority if it's
                        // higher in the class hierarchy.
                        //
                        // See TestInheritedImplementationDeprioritization for an example of this.
                        bool haveMatch = WriteSignatureMatchedBinding(fileBuilder, writer, cls, slot, conv);

                        // If there's no match, but this is a reimplementation, then use the old implementation
                        // Allows TestInheritedReimpl to pass.
                        if (!haveMatch)
                        {
                            if (!isReimpl)
                                throw new ParseFailedException("Unmatched interface method");

                            writer.Write(false);    // HACK - FIXME
                        }
                    }
                }
            }

            if (boundImpls.Count > 0)
                throw new NotSupportedException("Don't support non-interface override thunks yet");
        }
コード例 #40
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void ExportClassDefinitions(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            if (cls.IsDelegate || cls.IsEnum)
                throw new ArgumentException();

            if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Interface)
                ExportGenericVariance(cls, writer);

            if (!cls.IsValueType && cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Class)
            {
                writer.Write(cls.TypeDef.IsSealed);
                writer.Write(cls.TypeDef.IsAbstract);
                if (cls.ParentTypeSpec == null)
                    writer.Write((uint)0);
                else
                    writer.Write(1 + fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(cls.ParentTypeSpec)));
            }

            writer.Write((uint)cls.ExplicitInterfaces.Count);
            foreach (CLRTypeSpec typeSpec in cls.ExplicitInterfaces)
                writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(typeSpec)));

            WriteVtableThunks(fileBuilder, writer, cls);

            if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Class)
            {
                uint numNonAbstractMethods = 0;

                foreach (CppMethod method in cls.Methods)
                {
                    if (!method.Abstract)
                        numNonAbstractMethods++;
                }

                writer.Write(numNonAbstractMethods);

                foreach (CppMethod method in cls.Methods)
                {
                    if (method.Abstract)
                        continue;

                    writer.Write(method.Static);
                    writer.Write(fileBuilder.IndexMethodSignatureTag(RpaTagFactory.CreateMethodSignature(method.MethodSignature)));
                    writer.Write(fileBuilder.IndexString(method.Name));
                    ExportMethodCode(fileBuilder, writer, cls, method);
                }

                uint numInstanceFields = 0;
                foreach (CppField field in cls.Fields)
                {
                    CLRFieldRow fieldDef = field.Field;
                    if (!fieldDef.Literal && !fieldDef.Static)
                        numInstanceFields++;
                }

                writer.Write(numInstanceFields);
                foreach (CppField field in cls.Fields)
                {
                    CLRFieldRow fieldDef = field.Field;
                    if (!fieldDef.Literal && !fieldDef.Static)
                    {
                        writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(field.Type)));
                        writer.Write(fileBuilder.IndexString(field.Name));
                    }
                }

                WriteInterfaceImplementations(fileBuilder, writer, cls);
            }
        }
コード例 #41
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void WriteVtableThunk(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls, CppMethod method, CppVtableSlot slot)
        {
            CLRMethodSignatureInstance slotSig = slot.Signature;

            writer.Write(fileBuilder.IndexMethodDeclTag(slot.VtableSlotTag));
            writer.Write(fileBuilder.IndexMethodSignatureTag(RpaTagFactory.CreateMethodSignature(slot.Signature)));

            if (cls.TypeDef.Semantics != CLRTypeDefRow.TypeSemantics.Interface)
            {
                writer.Write(method.Abstract);

                if (!method.Abstract)
                {
                    if (method.NumGenericParameters == 0)
                        writer.Write(method.Final);

                    if (method.Static)
                        throw new Exception("VTable slot implemented by static method");

                    writer.Write(fileBuilder.IndexMethodDeclTag(method.VtableSlotTag));
                }
            }
        }
コード例 #42
0
ファイル: CppRegionEmitter.cs プロジェクト: elasota/clarity
 private void AliasSsaRegister(Clarity.Rpa.HighSsaRegister src, SsaRegister copy)
 {
     if (m_ssaToEmittedSsa.ContainsKey(copy))
         throw new Exception();
     m_ssaToEmittedSsa.Add(copy, src);
 }
コード例 #43
0
ファイル: CppRegionEmitter.cs プロジェクト: elasota/clarity
 private SsaRegister EmitPassiveConversion_PermitRefs(Clarity.Rpa.CodeLocationTag codeLocation, SsaRegister sourceReg, CLRTypeSpec destType, CppCfgNodeOutline outline, IList<Clarity.Rpa.HighInstruction> instrs)
 {
     switch (sourceReg.VType.ValType)
     {
         case VType.ValTypeEnum.ManagedPtr:
             if (sourceReg.VType.TypeSpec.Equals(destType))
                 return sourceReg;
             throw new ArgumentException();
         default:
             return EmitPassiveConversion(codeLocation, sourceReg, destType, outline, instrs);
     }
 }
コード例 #44
0
ファイル: CppRegionEmitter.cs プロジェクト: elasota/clarity
        private SsaRegister EmitPassiveConversion(Clarity.Rpa.CodeLocationTag codeLocation, SsaRegister sourceReg, CLRTypeSpec destType, CppCfgNodeOutline outline, IList<Clarity.Rpa.HighInstruction> instrs)
        {
            if (sourceReg.VType.ValType == VType.ValTypeEnum.DelegateSimpleMethod ||
                sourceReg.VType.ValType == VType.ValTypeEnum.DelegateVirtualMethod)
                return sourceReg;

            if (sourceReg.VType.TypeSpec.Equals(destType))
                return sourceReg;

            if (sourceReg.VType.ValType == VType.ValTypeEnum.Null)
            {
                SsaRegister nullReg = new SsaRegister(new VType(VType.ValTypeEnum.Null, destType));
                nullReg.MakeUsable();
                nullReg.GenerateUniqueID(m_regAllocator);

                outline.AddRegister(nullReg);
                return nullReg;
            }

            SsaRegister newReg;
            switch (sourceReg.VType.ValType)
            {
                case VType.ValTypeEnum.ConstantReference:
                case VType.ValTypeEnum.ReferenceValue:
                    newReg = new SsaRegister(new VType(VType.ValTypeEnum.ReferenceValue, destType));
                    break;
                case VType.ValTypeEnum.ValueValue:
                case VType.ValTypeEnum.ConstantValue:
                    newReg = new SsaRegister(new VType(VType.ValTypeEnum.ValueValue, destType));
                    break;
                default:
                    throw new ArgumentException();
            }

            newReg.MakeUsable();
            newReg.GenerateUniqueID(m_regAllocator);

            instrs.Add(new Clarity.Rpa.Instructions.PassiveConvertInstruction(
                codeLocation,
                InternSsaRegister(newReg),
                InternSsaRegister(sourceReg)
                ));

            return newReg;
        }
コード例 #45
0
ファイル: HighFileBuilder.cs プロジェクト: elasota/clarity
        public uint IndexTypeSpecTag(Clarity.Rpa.TypeSpecTag typeSpecTag)
        {
            uint index;
            if (m_typeSpecTagsDict.TryGetValue(typeSpecTag, out index))
                return index;

            typeSpecTag.Write(this, m_typeCatalogWriter);

            index = (uint)m_typeSpecTagsDict.Count;
            m_typeSpecTagsDict.Add(typeSpecTag, index);

            return index;
        }
コード例 #46
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void ExportClassStatics(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            if (!cls.HaveNewStaticFields)
            {
                writer.Write((uint)0);
                return;
            }

            uint numStaticFields = 0;
            foreach (CppField field in cls.Fields)
                if (field.Field.Static && !field.Field.Literal)
                    numStaticFields++;

            writer.Write(numStaticFields);
            foreach (CppField field in cls.Fields)
            {
                if (field.Field.Static && !field.Field.Literal)
                {
                    writer.Write(fileBuilder.IndexTypeSpecTag(RpaTagFactory.CreateTypeTag(field.Type)));
                    writer.Write(fileBuilder.IndexString(field.Name));
                }
            }
        }
コード例 #47
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        public void ExportTypeDef(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CLRTypeDefRow typeDef)
        {
            CppClass cls = GetCachedClass(new CLRTypeSpecClass(typeDef));

            Clarity.Rpa.TypeSemantics sem;
            if (cls.IsDelegate)
                sem = Clarity.Rpa.TypeSemantics.Delegate;
            else if (cls.IsEnum)
                sem = Clarity.Rpa.TypeSemantics.Enum;
            else if (cls.IsValueType)
                sem = Clarity.Rpa.TypeSemantics.Struct;
            else if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Interface)
                sem = Clarity.Rpa.TypeSemantics.Interface;
            else
                sem = Clarity.Rpa.TypeSemantics.Class;

            writer.Write((byte)sem);
            writer.Write(fileBuilder.IndexTypeNameTag(RpaTagFactory.CreateTypeNameTag(typeDef)));

            if (sem == Clarity.Rpa.TypeSemantics.Delegate)
            {
                ExportDelegate(fileBuilder, writer, cls);
            }
            else if (sem == Clarity.Rpa.TypeSemantics.Enum)
            {
                ExportEnum(fileBuilder, writer, cls);
            }
            else
            {
                ExportClassDefinitions(fileBuilder, writer, cls);
                ExportClassStubs(cls);

                if (sem == Clarity.Rpa.TypeSemantics.Class || sem == Clarity.Rpa.TypeSemantics.Struct)
                    ExportClassStatics(fileBuilder, writer, cls);
            }
        }
コード例 #48
0
ファイル: CppBuilder.cs プロジェクト: elasota/clarity
        private void WriteVtableThunks(Clarity.Rpa.HighFileBuilder fileBuilder, BinaryWriter writer, CppClass cls)
        {
            uint numNewSlots = 0;
            uint numReplacedSlots = 0;

            foreach (CppMethod method in cls.Methods)
            {
                if (method.CreatesSlot != null)
                    numNewSlots++;
                else if (method.ReplacesStandardSlot != null)
                    numReplacedSlots++;
            }

            if (cls.TypeDef.Semantics == CLRTypeDefRow.TypeSemantics.Interface)
            {
                if (numReplacedSlots != 0)
                    throw new Exception();
            }
            else
            {
                writer.Write(numReplacedSlots);

                foreach (CppMethod method in cls.Methods)
                {
                    if (method.CreatesSlot == null && method.ReplacesStandardSlot != null)
                        WriteVtableThunk(fileBuilder, writer, cls, method, method.ReplacesStandardSlot);
                }
            }

            writer.Write(numNewSlots);

            foreach (CppMethod method in cls.Methods)
            {
                if (method.CreatesSlot != null)
                    WriteVtableThunk(fileBuilder, writer, cls, method, method.CreatesSlot);
            }
        }