예제 #1
0
        public CanCauseError <ICodeTemplate> FindTemplate(byte[] code, int index, IEnumerable <Priority> allowedPriorities)
        {
            int num = (int)code[index] + (int)code[index + 1] * 256;

            foreach (Priority allowedPriority in allowedPriorities)
            {
                List <ICodeTemplate> codeTemplateList;
                if (this.disassemblyCodes.TryGetValue(new KeyValuePair <Priority, int>(allowedPriority, num), out codeTemplateList) ||
                    num != 0 && this.disassemblyCodes.TryGetValue(new KeyValuePair <Priority, int>(allowedPriority, 0), out codeTemplateList))
                {
                    List <ICodeTemplate> collection = new List <ICodeTemplate>();
                    foreach (ICodeTemplate codeTemplate in codeTemplateList)
                    {
                        if (codeTemplate.CanBeDisassembled && codeTemplate.Matches(code, index))
                        {
                            collection.Add(codeTemplate);
                        }
                    }
                    if (collection.Count > 0)
                    {
                        return(CanCauseError <ICodeTemplate> .NoError(collection.Max <ICodeTemplate>(this.templateComparer)));
                    }
                }
            }
            return(CanCauseError <ICodeTemplate> .Error("No code found."));
        }
예제 #2
0
        private CanCauseError <ICodeTemplate> GetTemplateFrom(string codeName, Language.Types.Type[] parameterTypes, List <ICodeTemplate> templates)
        {
            IEnumerable <ICodeTemplate> codeTemplates = templates.Where <ICodeTemplate>((Func <ICodeTemplate, bool>)(template => template.Matches(parameterTypes)));

            if (codeTemplates.Any <ICodeTemplate>())
            {
                return(CanCauseError <ICodeTemplate> .NoError(codeTemplates.Min <ICodeTemplate>(this.templateComparer)));
            }
            return(CanCauseError <ICodeTemplate> .Error(parameterTypes.Length != 0? "Incorrect parameters in code {0} {1}" : "Incorrect parameters in code {0}", (object)codeName, (object)((IEnumerable <Language.Types.Type>)parameterTypes).ToElementWiseString <Nintenlord.Event_Assembler.Core.Code.Language.Types.Type>(" ", "", "")));
        }
예제 #3
0
        public CanCauseError <string> Replace(string textToEdit)
        {
            StringBuilder textToEdit1 = new StringBuilder(textToEdit);

            CanCauseError canCauseError = this.Replace(textToEdit1);

            if (canCauseError.CausedError)
            {
                return(CanCauseError <string> .Error(canCauseError.ToString()));
            }

            return(CanCauseError <string> .NoError(textToEdit1.ToString()));
        }
예제 #4
0
        public CanCauseError <string> Replace(string textToEdit)
        {
            StringBuilder bldr   = new StringBuilder(textToEdit);
            var           result = this.Replace(bldr);

            if (result.CausedError)
            {
                return(CanCauseError <string> .Error(result.ToString()));
            }
            else
            {
                return(CanCauseError <string> .NoError(bldr.ToString()));
            }
        }
예제 #5
0
        public CanCauseError <IExpression <T> > GetSymbolValue(string symbol)
        {
            IExpression <T> result;

            if (definedSymbols.TryGetValue(symbol, out result))
            {
                return(CanCauseError <IExpression <T> > .NoError(result));
            }

            if (ParentScope != null)
            {
                return(ParentScope.GetSymbolValue(symbol));
            }

            return(CanCauseError <IExpression <T> > .Error("Symbol {0} not defined", symbol));
        }
예제 #6
0
        public CanCauseError <IExpression <T> > GetSymbolValue(string symbol)
        {
            IExpression <T> value;

            if (definedSymbols.TryGetValue(symbol, out value))
            {
                return(CanCauseError <IExpression <T> > .NoError(value));
            }
            else if (ParentScope != null)
            {
                return(ParentScope.GetSymbolValue(symbol));
            }
            else
            {
                return(CanCauseError <IExpression <T> > .Error("Symbol {0} not defined", symbol));
            }
        }
예제 #7
0
        public CanCauseError <ICodeTemplate> FindTemplate(string name, Priority priority)
        {
            List <ICodeTemplate> codeTemplateList = this.assemblyCodes[name];

            foreach (KeyValuePair <KeyValuePair <Priority, int>, List <ICodeTemplate> > disassemblyCode in (IEnumerable <KeyValuePair <KeyValuePair <Priority, int>, List <ICodeTemplate> > >) this.disassemblyCodes)
            {
                if (disassemblyCode.Key.Key == priority)
                {
                    foreach (ICodeTemplate result in disassemblyCode.Value)
                    {
                        if (codeTemplateList.Contains(result))
                        {
                            return(CanCauseError <ICodeTemplate> .NoError(result));
                        }
                    }
                }
            }
            return(CanCauseError <ICodeTemplate> .Error("No code named {0} found in priority {1}", (object)name, (object)priority));
        }