当前位置: 首页>>代码示例>>C#>>正文


C# PascalABCCompiler.AddElement方法代码示例

本文整理汇总了C#中PascalABCCompiler.AddElement方法的典型用法代码示例。如果您正苦于以下问题:C# PascalABCCompiler.AddElement方法的具体用法?C# PascalABCCompiler.AddElement怎么用?C# PascalABCCompiler.AddElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PascalABCCompiler的用法示例。


在下文中一共展示了PascalABCCompiler.AddElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileUnit

        public CompilationUnit CompileUnit(PascalABCCompiler.TreeRealization.unit_node_list Units, SyntaxTree.unit_or_namespace SyntaxUsesUnit)
        {
            string UnitName = GetUnitFileName(SyntaxUsesUnit);
            //if (UnitName == null) throw new UnitNotFound(SyntaxUsesUnit.name,
            CompilationUnit CurrentUnit = UnitTable[UnitName];
            string name = Path.GetFileNameWithoutExtension(UnitName);
            if (Path.GetExtension(UnitName).ToLower() == CompilerOptions.CompiledUnitExtension)
            {
                string sfn = FindSourceFileName(Path.GetFileNameWithoutExtension(UnitName));
                if (sfn != null && UnitTable[sfn] != null)
                    CurrentUnit = UnitTable[sfn];
            }

            if (CurrentUnit != null)
                if (CurrentUnit.State != UnitState.BeginCompilation || CurrentUnit.SemanticTree != null)  //ИЗБАВИТЬСЯ ОТ ВТОРОГО УСЛОВИЯ
                {
                    Units.AddElement(CurrentUnit.SemanticTree);
                    Units.AddRange(GetReferences(CurrentUnit));
                    return CurrentUnit;
                }

            if (UnitName.ToLower().LastIndexOf(".dll") >= 0 || UnitName.ToLower().LastIndexOf(".exe") >= 0)
                if (File.Exists(UnitName))
                {
                    if (UnitTable.Count == 0) throw new ProgramModuleExpected(UnitName, null);
                    if ((CurrentUnit = ReadDLL(UnitName)) != null)
                    {
                        Units.AddElement(CurrentUnit.SemanticTree);
                        UnitTable[UnitName] = CurrentUnit;
                        return CurrentUnit;
                    }
                    else
                        //throw new DLLReadingError(UnitName);
                        throw new AssemblyReadingError(CurrentCompilationUnit.SyntaxTree.file_name, UnitName, SyntaxUsesUnit.source_context);
                }
            if (Path.GetExtension(UnitName).ToLower() == CompilerOptions.CompiledUnitExtension)
                if (File.Exists(UnitName))
                {
                    if (UnitTable.Count == 0) throw new ProgramModuleExpected(UnitName, null);
                    string SourceFileName = FindSourceFileName(Path.Combine(Path.GetDirectoryName(UnitName), Path.GetFileNameWithoutExtension(UnitName)));
                    try
                    {
                        //TODO: подумать как это нормально сделать
                        /*if (CompilerOptions.Debug)
                        {
                            PCUReader.PCUFileHeadState PCUFileHeadState = PCUReader.GetPCUFileHeadState(UnitName);
                            if (PCUFileHeadState.IsPCUFile && 
                                PCUFileHeadState.SupportedVersion && 
                                !PCUFileHeadState.IncludetDebugInfo && 
                                SourceFileName != null)
                            {
                                //перекомпилируем файл для получения отладочной информации
                                throw new Exception("");
                            }
                        }*/
                        if ((CurrentUnit = ReadPCU(UnitName)) != null)
                        {
                            Units.AddElement(CurrentUnit.SemanticTree);
                            Units.AddRange(GetReferences(CurrentUnit));
                            UnitTable[UnitName] = CurrentUnit;
                            return CurrentUnit;
                        }
                    }
                    catch (InvalidPCUFule)
                    {
                        //Перекомпилируем....
                    }
                    catch (Error)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        OnChangeCompilerState(this, CompilerState.PCUReadingError, UnitName);
#if DEBUG
                        if (!InternalDebug.SkipPCUErrors)
                            throw new Errors.CompilerInternalError("PCUReader", e);
#endif
                    }
                    if (SourceFileName == null)
                        throw new ReadPCUError(UnitName);
                    else
                        UnitName = SourceFileName;
                }
            string SourceText = null;
            Dictionary<SyntaxTree.syntax_tree_node, string> docs = null;
            if (CurrentUnit == null)
            {

                CurrentUnit = new CompilationUnit();
                if (FirstCompilationUnit == null)
                    FirstCompilationUnit = CurrentUnit;
                OnChangeCompilerState(this, CompilerState.BeginCompileFile, UnitName);
                SourceText = GetSourceFileText(UnitName);
                if (SourceText == null)
                    if (CurrentUnit == FirstCompilationUnit)
                        throw new SourceFileNotFound(UnitName);
                    else
                        throw new UnitNotFound(CurrentCompilationUnit.SyntaxTree.file_name, UnitName, SyntaxUsesUnit.source_context);

//.........这里部分代码省略.........
开发者ID:PascalABC-CompilerLaboratory,项目名称:pascalabcnet,代码行数:101,代码来源:Compiler.cs

示例2: CompileReference

 private CompilationUnit CompileReference(PascalABCCompiler.TreeRealization.unit_node_list Units, TreeRealization.compiler_directive cd)
 {
     TreeRealization.location loc = cd.location;
     SyntaxTree.SourceContext sc = null;
     if (loc!=null)
         sc = new SyntaxTree.SourceContext(loc.begin_line_num,loc.begin_column_num,loc.end_line_num,loc.end_column_num,0,0);
     string UnitName = null;
     try
     {
         UnitName = GetReferenceFileName(cd.directive, sc);
     }
     catch (AssemblyNotFound ex)
     {
         throw;
     }
     catch(Exception ex)
     {
         throw new InvalidAssemblyPathError(CurrentCompilationUnit.SyntaxTree.file_name, sc);
     }
     CompilationUnit CurrentUnit = null;
     if (UnitTable.Count == 0) throw new ProgramModuleExpected(UnitName, null);
     if ((CurrentUnit = ReadDLL(UnitName)) != null)
     {
         Units.AddElement(CurrentUnit.SemanticTree);
         UnitTable[UnitName] = CurrentUnit;
         return CurrentUnit;
     }
     else
         //throw new DLLReadingError(UnitName);
     	throw new AssemblyReadingError(CurrentCompilationUnit.SyntaxTree.file_name,UnitName,sc);
 }
开发者ID:PascalABC-CompilerLaboratory,项目名称:pascalabcnet,代码行数:31,代码来源:Compiler.cs


注:本文中的PascalABCCompiler.AddElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。