示例#1
0
            private static IToken BuildCodeElementFromType(CodeElementType type, Token lastTokenBeforeError, string informationText)
            {
                CodeElement codeElement = null;

                switch (type)
                {
                case CodeElementType.ProgramIdentification:
                    codeElement = new ProgramIdentification();
                    break;

                case CodeElementType.ProgramEnd:
                    codeElement = new ProgramEnd();
                    break;

                case CodeElementType.ClassIdentification:
                    codeElement = new ClassIdentification();
                    break;

                case CodeElementType.ClassEnd:
                    codeElement = new ClassEnd();
                    break;

                case CodeElementType.FactoryIdentification:
                    codeElement = new FactoryIdentification();
                    break;

                case CodeElementType.FactoryEnd:
                    codeElement = new FactoryEnd();
                    break;

                case CodeElementType.ObjectIdentification:
                    codeElement = new ObjectIdentification();
                    break;

                case CodeElementType.ObjectEnd:
                    codeElement = new ObjectEnd();
                    break;

                case CodeElementType.MethodIdentification:
                    codeElement = new MethodIdentification();
                    break;

                case CodeElementType.MethodEnd:
                    codeElement = new MethodEnd();
                    break;

                case CodeElementType.EnvironmentDivisionHeader:
                    codeElement = new EnvironmentDivisionHeader();
                    break;

                case CodeElementType.DataDivisionHeader:
                    codeElement = new DataDivisionHeader();
                    break;

                case CodeElementType.ProcedureDivisionHeader:
                    codeElement = new ProcedureDivisionHeader();
                    break;

                case CodeElementType.DeclarativesHeader:
                    codeElement = new DeclarativesHeader();
                    break;

                case CodeElementType.DeclarativesEnd:
                    codeElement = new DeclarativesEnd();
                    break;

                case CodeElementType.SectionHeader:
                    codeElement = new SectionHeader();
                    break;

                case CodeElementType.ConfigurationSectionHeader:
                    codeElement = new ConfigurationSectionHeader();
                    break;

                case CodeElementType.InputOutputSectionHeader:
                    codeElement = new InputOutputSectionHeader();
                    break;

                case CodeElementType.FileSectionHeader:
                    codeElement = new FileSectionHeader();
                    break;

                case CodeElementType.WorkingStorageSectionHeader:
                    codeElement = new WorkingStorageSectionHeader();
                    break;

                case CodeElementType.LocalStorageSectionHeader:
                    codeElement = new LocalStorageSectionHeader();
                    break;

                case CodeElementType.LinkageSectionHeader:
                    codeElement = new LinkageSectionHeader();
                    break;

                case CodeElementType.ParagraphHeader:
                    codeElement = new ParagraphHeader();
                    break;

                case CodeElementType.FileControlParagraphHeader:
                    codeElement = new FileControlParagraphHeader();
                    break;

                case CodeElementType.IOControlParagraphHeader:
                    codeElement = new IOControlParagraphHeader();
                    break;

                case CodeElementType.SentenceEnd:
                    codeElement = new SentenceEnd();
                    break;

                case CodeElementType.FileDescriptionEntry:
                    codeElement = new FileDescriptionEntry();
                    break;

                case CodeElementType.DataDescriptionEntry:
                    codeElement = new DataDescriptionEntry();
                    break;

                case CodeElementType.DataRedefinesEntry:
                    codeElement = new DataRedefinesEntry();
                    break;

                case CodeElementType.DataRenamesEntry:
                    codeElement = new DataRenamesEntry();
                    break;

                case CodeElementType.DataConditionEntry:
                    codeElement = new DataConditionEntry();
                    break;

                case CodeElementType.FileControlEntry:
                    codeElement = new FileControlEntry();
                    break;

                case CodeElementType.IOControlEntry:
                    codeElement = new RerunIOControlEntry();
                    break;

                case CodeElementType.SourceComputerParagraph:
                    codeElement = new SourceComputerParagraph();
                    break;

                case CodeElementType.ObjectComputerParagraph:
                    codeElement = new ObjectComputerParagraph();
                    break;

                case CodeElementType.SpecialNamesParagraph:
                    codeElement = new SpecialNamesParagraph();
                    break;

                case CodeElementType.RepositoryParagraph:
                    codeElement = new RepositoryParagraph();
                    break;

                case CodeElementType.AcceptStatement:
                    codeElement = new AcceptFromInputDeviceStatement();
                    break;

                case CodeElementType.AddStatement:
                    codeElement = new AddSimpleStatement();
                    break;

                case CodeElementType.AlterStatement:
                    codeElement = new AlterStatement();
                    break;

                case CodeElementType.CallStatement:
                    codeElement = new CallStatement();
                    break;

                case CodeElementType.CancelStatement:
                    codeElement = new CancelStatement();
                    break;

                case CodeElementType.CloseStatement:
                    codeElement = new CloseStatement();
                    break;

                case CodeElementType.ComputeStatement:
                    codeElement = new ComputeStatement();
                    break;

                case CodeElementType.ContinueStatement:
                    codeElement = new ContinueStatement();
                    break;

                case CodeElementType.DeleteStatement:
                    codeElement = new DeleteStatement();
                    break;

                case CodeElementType.DisplayStatement:
                    codeElement = new DisplayStatement();
                    break;

                case CodeElementType.DivideStatement:
                    codeElement = new DivideSimpleStatement();
                    break;

                case CodeElementType.EntryStatement:
                    codeElement = new EntryStatement();
                    break;

                case CodeElementType.EvaluateStatement:
                    codeElement = new EvaluateStatement();
                    break;

                case CodeElementType.ExecStatement:
                    codeElement = new ExecStatement();
                    break;

                case CodeElementType.ExitMethodStatement:
                    codeElement = new ExitMethodStatement();
                    break;

                case CodeElementType.ExitProgramStatement:
                    codeElement = new ExitProgramStatement();
                    break;

                case CodeElementType.ExitStatement:
                    codeElement = new ExitStatement();
                    break;

                case CodeElementType.GobackStatement:
                    codeElement = new GobackStatement();
                    break;

                case CodeElementType.GotoStatement:
                    codeElement = new GotoSimpleStatement();
                    break;

                case CodeElementType.IfStatement:
                    codeElement = new IfStatement();
                    break;

                case CodeElementType.InitializeStatement:
                    codeElement = new InitializeStatement();
                    break;

                case CodeElementType.InspectStatement:
                    codeElement = new InspectTallyingStatement();
                    break;

                case CodeElementType.InvokeStatement:
                    codeElement = new InvokeStatement();
                    break;

                case CodeElementType.MergeStatement:
                    codeElement = new MergeStatement();
                    break;

                case CodeElementType.MoveStatement:
                    codeElement = new MoveSimpleStatement(null, null, null);
                    break;

                case CodeElementType.MultiplyStatement:
                    codeElement = new MultiplySimpleStatement();
                    break;

                case CodeElementType.NextSentenceStatement:
                    codeElement = new NextSentenceStatement();
                    break;

                case CodeElementType.OpenStatement:
                    codeElement = new OpenStatement();
                    break;

                case CodeElementType.PerformProcedureStatement:
                    codeElement = new PerformProcedureStatement();
                    break;

                case CodeElementType.PerformStatement:
                    codeElement = new PerformStatement();
                    break;

                case CodeElementType.ReadStatement:
                    codeElement = new ReadStatement();
                    break;

                case CodeElementType.ReleaseStatement:
                    codeElement = new ReleaseStatement();
                    break;

                case CodeElementType.ReturnStatement:
                    codeElement = new ReturnStatement();
                    break;

                case CodeElementType.RewriteStatement:
                    codeElement = new RewriteStatement();
                    break;

                case CodeElementType.SearchStatement:
                    codeElement = new SearchSerialStatement();
                    break;

                case CodeElementType.SetStatement:
                    codeElement = new SetStatementForAssignment();
                    break;

                case CodeElementType.SortStatement:
                    codeElement = new SortStatement();
                    break;

                case CodeElementType.StartStatement:
                    codeElement = new StartStatement();
                    break;

                case CodeElementType.StopStatement:
                    codeElement = new StopStatement();
                    break;

                case CodeElementType.StringStatement:
                    codeElement = new StringStatement();
                    break;

                case CodeElementType.SubtractStatement:
                    codeElement = new SubtractSimpleStatement();
                    break;

                case CodeElementType.UnstringStatement:
                    codeElement = new UnstringStatement();
                    break;

                case CodeElementType.UseStatement:
                    codeElement = new UseAfterIOExceptionStatement();
                    break;

                case CodeElementType.WriteStatement:
                    codeElement = new WriteStatement();
                    break;

                case CodeElementType.XmlGenerateStatement:
                    codeElement = new XmlGenerateStatement();
                    break;

                case CodeElementType.XmlParseStatement:
                    codeElement = new XmlParseStatement();
                    break;

                case CodeElementType.AtEndCondition:
                    codeElement = new AtEndCondition();
                    break;

                case CodeElementType.NotAtEndCondition:
                    codeElement = new NotAtEndCondition();
                    break;

                case CodeElementType.AtEndOfPageCondition:
                    codeElement = new AtEndOfPageCondition();
                    break;

                case CodeElementType.NotAtEndOfPageCondition:
                    codeElement = new NotAtEndOfPageCondition();
                    break;

                case CodeElementType.OnExceptionCondition:
                    codeElement = new OnExceptionCondition();
                    break;

                case CodeElementType.NotOnExceptionCondition:
                    codeElement = new NotOnExceptionCondition();
                    break;

                case CodeElementType.OnOverflowCondition:
                    codeElement = new OnOverflowCondition();
                    break;

                case CodeElementType.NotOnOverflowCondition:
                    codeElement = new NotOnOverflowCondition();
                    break;

                case CodeElementType.InvalidKeyCondition:
                    codeElement = new InvalidKeyCondition();
                    break;

                case CodeElementType.NotInvalidKeyCondition:
                    codeElement = new NotInvalidKeyCondition();
                    break;

                case CodeElementType.OnSizeErrorCondition:
                    codeElement = new OnSizeErrorCondition();
                    break;

                case CodeElementType.NotOnSizeErrorCondition:
                    codeElement = new NotOnSizeErrorCondition();
                    break;

                case CodeElementType.ElseCondition:
                    codeElement = new ElseCondition();
                    break;

                case CodeElementType.WhenCondition:
                    codeElement = new WhenCondition();
                    break;

                case CodeElementType.WhenOtherCondition:
                    codeElement = new WhenOtherCondition();
                    break;

                case CodeElementType.WhenSearchCondition:
                    codeElement = new WhenSearchCondition();
                    break;

                case CodeElementType.AddStatementEnd:
                    codeElement = new AddStatementEnd();
                    break;

                case CodeElementType.CallStatementEnd:
                    codeElement = new CallStatementEnd();
                    break;

                case CodeElementType.ComputeStatementEnd:
                    codeElement = new ComputeStatementEnd();
                    break;

                case CodeElementType.DeleteStatementEnd:
                    codeElement = new DeleteStatementEnd();
                    break;

                case CodeElementType.DivideStatementEnd:
                    codeElement = new DivideStatementEnd();
                    break;

                case CodeElementType.EvaluateStatementEnd:
                    codeElement = new EvaluateStatementEnd();
                    break;

                case CodeElementType.IfStatementEnd:
                    codeElement = new IfStatementEnd();
                    break;

                case CodeElementType.InvokeStatementEnd:
                    codeElement = new InvokeStatementEnd();
                    break;

                case CodeElementType.MultiplyStatementEnd:
                    codeElement = new MultiplyStatementEnd();
                    break;

                case CodeElementType.PerformStatementEnd:
                    codeElement = new PerformStatementEnd();
                    break;

                case CodeElementType.ReadStatementEnd:
                    codeElement = new ReadStatementEnd();
                    break;

                case CodeElementType.ReturnStatementEnd:
                    codeElement = new ReturnStatementEnd();
                    break;

                case CodeElementType.RewriteStatementEnd:
                    codeElement = new RewriteStatementEnd();
                    break;

                case CodeElementType.SearchStatementEnd:
                    codeElement = new SearchStatementEnd();
                    break;

                case CodeElementType.StartStatementEnd:
                    codeElement = new StartStatementEnd();
                    break;

                case CodeElementType.StringStatementEnd:
                    codeElement = new StringStatementEnd();
                    break;

                case CodeElementType.SubtractStatementEnd:
                    codeElement = new SubtractStatementEnd();
                    break;

                case CodeElementType.UnstringStatementEnd:
                    codeElement = new UnstringStatementEnd();
                    break;

                case CodeElementType.WriteStatementEnd:
                    codeElement = new WriteStatementEnd();
                    break;

                case CodeElementType.XmlStatementEnd:
                    codeElement = new XmlStatementEnd();
                    break;

                case CodeElementType.LibraryCopy:
                    codeElement = new LibraryCopyCodeElement();
                    break;

                case CodeElementType.FunctionDeclarationHeader:
                    codeElement = new FunctionDeclarationHeader(null, AccessModifier.Private, FunctionType.Undefined);
                    break;

                case CodeElementType.FunctionDeclarationEnd:
                    codeElement = new FunctionDeclarationEnd();
                    break;

                default:
                    throw new NotImplementedException();
                }
                if (lastTokenBeforeError != null)
                {
                    var missingToken = new MissingToken(TokenType.InvalidToken, informationText, lastTokenBeforeError.TokensLine, lastTokenBeforeError.StopIndex);
                    codeElement.ConsumedTokens.Add(missingToken);
                }
                return(codeElement);
            }
示例#2
0
 public static Type OnEnd <Type>(this Type current, MethodEnd method) where Type : Worker
 {
     current.onEnd = method;
     return(current);
 }
示例#3
0
        /// <summary>
        /// Loads the target architecture library and fills in the TargetILOps, MethodStartOp, MethodEndOp and StackSwitchOp
        /// fields.
        /// </summary>
        /// <returns>True if fully loaded without error. Otherwise, false.</returns>
        private static bool LoadTargetArchitecture()
        {
            bool OK = false;

            try
            {
                string CurrentAssemblyDir = System.IO.Path.GetDirectoryName(typeof(TargetArchitecture).Assembly.Location);
                string fileName           = null;
                switch (Options.TargetArchitecture)
                {
                case "x86":
                {
                    fileName = System.IO.Path.Combine(CurrentAssemblyDir, @"Drivers.Compiler.Architectures.x86.dll");
                    OK       = true;
                }
                break;

                case "mips":
                {
                    fileName = System.IO.Path.Combine(CurrentAssemblyDir, @"Drivers.Compiler.Architectures.MIPS32.dll");
                    OK       = true;
                }
                break;

                default:
                    OK = false;
                    throw new ArgumentException("Unrecognised target architecture!");
                }

                if (OK)
                {
                    fileName = System.IO.Path.GetFullPath(fileName);
                    TargetArchitectureAssembly = System.Reflection.Assembly.LoadFrom(fileName);
                }

                if (OK)
                {
                    Type[] AllTypes = TargetArchitectureAssembly.GetTypes();
                    foreach (Type aType in AllTypes)
                    {
                        if (aType.IsSubclassOf(typeof(IL.ILOp)))
                        {
                            if (aType.IsSubclassOf(typeof(MethodStart)))
                            {
                                MethodStartOp = (MethodStart)Activator.CreateInstance(aType);
                            }
                            else if (aType.IsSubclassOf(typeof(MethodEnd)))
                            {
                                MethodEndOp = (MethodEnd)Activator.CreateInstance(aType);
                            }
                            else if (aType.IsSubclassOf(typeof(StackSwitch)))
                            {
                                StackSwitchOp = (StackSwitch)Activator.CreateInstance(aType);
                            }
                            else
                            {
                                IL.ILOps.ILOpTargetAttribute[] targetAttrs = (IL.ILOps.ILOpTargetAttribute[])aType.GetCustomAttributes(typeof(IL.ILOps.ILOpTargetAttribute), true);
                                if (targetAttrs == null || targetAttrs.Length == 0)
                                {
                                    throw new Exception("ILScanner could not load target architecture ILOp because target attribute was not specified!");
                                }
                                else
                                {
                                    foreach (IL.ILOps.ILOpTargetAttribute targetAttr in targetAttrs)
                                    {
                                        TargetILOps.Add(targetAttr.Target, (IL.ILOp)Activator.CreateInstance(aType));
                                    }
                                }
                            }
                        }
                        else if (aType.IsSubclassOf(typeof(ASM.ASMOp)))
                        {
                            ASMOpTargetAttribute[] targetAttrs = (ASMOpTargetAttribute[])aType.GetCustomAttributes(typeof(ASMOpTargetAttribute), true);
                            foreach (ASMOpTargetAttribute targetAttr in targetAttrs)
                            {
                                TargetASMOps.Add(targetAttr.Target, aType);
                            }
                        }
                        else if (aType.IsSubclassOf(typeof(TargetArchitectureFunctions)))
                        {
                            TargetFunctions = (TargetArchitectureFunctions)Activator.CreateInstance(aType);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OK = false;
                Logger.LogError(Errors.ILCompiler_LoadTargetArchError_ErrorCode, "", 0,
                                string.Format(Errors.ErrorMessages[Errors.ILCompiler_LoadTargetArchError_ErrorCode],
                                              ex.Message));
            }

            return(OK);
        }
示例#4
0
        /// <summary>
        /// Loads the target architecture library and fills in the TargetILOps, MethodStartOp, MethodEndOp and StackSwitchOp
        /// fields.
        /// </summary>
        /// <returns>True if fully loaded without error. Otherwise, false.</returns>
        private static bool LoadTargetArchitecture()
        {
            bool OK = false;

            try
            {
                string CurrentAssemblyDir = System.IO.Path.GetDirectoryName(typeof(TargetArchitecture).Assembly.Location);
                string fileName = null;
                switch (Options.TargetArchitecture)
                {
                    case "x86":
                        {
                            fileName = System.IO.Path.Combine(CurrentAssemblyDir, @"Drivers.Compiler.Architectures.x86.dll");
                            OK = true;
                        }
                        break;
                    case "mips":
                        {
                            fileName = System.IO.Path.Combine(CurrentAssemblyDir, @"Drivers.Compiler.Architectures.MIPS32.dll");
                            OK = true;
                        }
                        break;
                    default:
                        OK = false;
                        throw new ArgumentException("Unrecognised target architecture!");
                }

                if (OK)
                {
                    fileName = System.IO.Path.GetFullPath(fileName);
                    TargetArchitectureAssembly = System.Reflection.Assembly.LoadFrom(fileName);
                }
                
                if (OK)
                {
                    Type[] AllTypes = TargetArchitectureAssembly.GetTypes();
                    foreach (Type aType in AllTypes)
                    {
                        if (aType.IsSubclassOf(typeof(IL.ILOp)))
                        {
                            if (aType.IsSubclassOf(typeof(MethodStart)))
                            {
                                MethodStartOp = (MethodStart)Activator.CreateInstance(aType);
                            }
                            else if (aType.IsSubclassOf(typeof(MethodEnd)))
                            {
                                MethodEndOp = (MethodEnd)Activator.CreateInstance(aType);
                            }
                            else if (aType.IsSubclassOf(typeof(StackSwitch)))
                            {
                                StackSwitchOp = (StackSwitch)Activator.CreateInstance(aType);
                            }
                            else
                            {
                                IL.ILOps.ILOpTargetAttribute[] targetAttrs = (IL.ILOps.ILOpTargetAttribute[])aType.GetCustomAttributes(typeof(IL.ILOps.ILOpTargetAttribute), true);
                                if (targetAttrs == null || targetAttrs.Length == 0)
                                {
                                    throw new Exception("ILScanner could not load target architecture ILOp because target attribute was not specified!");
                                }
                                else
                                {
                                    foreach (IL.ILOps.ILOpTargetAttribute targetAttr in targetAttrs)
                                    {
                                        TargetILOps.Add(targetAttr.Target, (IL.ILOp)Activator.CreateInstance(aType));
                                    }
                                }
                            }
                        }
                        else if (aType.IsSubclassOf(typeof(ASM.ASMOp)))
                        {
                            ASMOpTargetAttribute[] targetAttrs = (ASMOpTargetAttribute[])aType.GetCustomAttributes(typeof(ASMOpTargetAttribute), true);
                            foreach (ASMOpTargetAttribute targetAttr in targetAttrs)
                            {
                                TargetASMOps.Add(targetAttr.Target, aType);
                            }
                        }
                        else if (aType.IsSubclassOf(typeof(TargetArchitectureFunctions)))
                        {
                            TargetFunctions = (TargetArchitectureFunctions)Activator.CreateInstance(aType);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OK = false;
                Logger.LogError(Errors.ILCompiler_LoadTargetArchError_ErrorCode, "", 0,
                    string.Format(Errors.ErrorMessages[Errors.ILCompiler_LoadTargetArchError_ErrorCode],
                                    ex.Message));
            }

            return OK;
        }