コード例 #1
0
        public ImportedMethod TryImportCurrentMethod()
        {
            if (_currentMethod != null)
            {
                return(_currentMethod);
            }

            IntPtr metadataBlock;
            uint   blockSize;

            try
            {
                metadataBlock = InstructionAddress.ModuleInstance.GetMetaDataBytesPtr(out blockSize);
            }
            catch (DkmException)
            {
                // This can fail when dump debugging if the full heap is not available
                return(null);
            }

            ImportedModule module = Session.Importer.ImportModule(metadataBlock, blockSize);

            _currentMethod = module.GetMethod(InstructionAddress.MethodId.Token);
            return(_currentMethod);
        }
コード例 #2
0
        private static string TryGetFrameReturnTypeHelper(DkmInspectionContext inspectionContext, DkmStackWalkFrame frame)
        {
            ImportedMethod currentMethod = TryGetCurrentMethod(inspectionContext, frame);

            if (currentMethod == null)
            {
                return(null);
            }

            return(currentMethod.ReturnType.ToString());
        }
        public void InitializeSymbols()
        {
            ImportedMethod currentMethod = Scope.TryImportCurrentMethod();

            if (currentMethod == null)
            {
                return; // Nothing to evaluate if we can't get the current method
            }
            // Add compiler intrinsics
            AddIntrinsics();

            // Add debugger intrinsics
            // (Not implemented yet)

            // Add globals
            ImportedType type = currentMethod.DeclaringType;

            foreach (ImportedField importedfield in type.GetFields())
            {
                IrisType irisType = importedfield.FieldType;
                if (irisType != IrisType.Invalid)
                {
                    SymbolTable.Add(importedfield.Name, irisType, StorageClass.Global, importedfield);
                }
            }

            // Add methods
            foreach (ImportedMethod importedMethod in type.GetMethods())
            {
                Method method = importedMethod.ConvertToIrisMethod();
                if (IsValidMethod(method))
                {
                    SymbolTable.Add(importedMethod.Name, method, StorageClass.Global, importedMethod);
                }
            }

            // Create symbol for query method and transition the SymbolTable to method scope
            _irisMethod = currentMethod.ConvertToIrisMethod();
            SymbolTable.OpenMethod("$.query", _irisMethod);

            // Add symbols for parameters
            foreach (Variable param in _irisMethod.GetParameters())
            {
                SymbolTable.Add(param.Name, param.Type, StorageClass.Argument);
            }

            // Add symbols for local variables
            foreach (LocalVariable local in Scope.GetLocals())
            {
                SymbolTable.Add(local.Name, local.Type, StorageClass.Local, local.Slot);
            }
        }
コード例 #4
0
        public LocalVariable[] GetLocals()
        {
            if (_cachedLocals != null)
            {
                return(_cachedLocals);
            }

            ImportedMethod method = TryImportCurrentMethod();

            _cachedLocals = GetLocalsImpl(method).ToArray();

            return(_cachedLocals);
        }
コード例 #5
0
        protected void ImportMethod(
            FilePosition fp,
            string symbolName,
            ImportedModule module,
            string declaringTypeName,
            string methodName,
            bool instance,
            IrisType returnType,
            IrisType[] paramTypes)
        {
            ImportedType declaringType = module.TryGetTypeByName(declaringTypeName);

            if (declaringType == null)
            {
                CompileErrors.Add(fp, String.Format("Cannot find imported type '{0}'.", declaringTypeName));
                return;
            }

            ImportedMethod importedMethod = declaringType.TryFindMethod(methodName, instance, returnType, paramTypes);

            if (importedMethod == null)
            {
                CompileErrors.Add(fp, String.Format("Cannot find imported function or procedure '{0}.{1}'.", declaringTypeName, methodName));
                return;
            }

            Method method = importedMethod.ConvertToIrisMethod();
            bool   containsInvalidType = method.ReturnType == IrisType.Invalid;

            foreach (Variable param in method.GetParameters())
            {
                if (containsInvalidType)
                {
                    break;
                }

                if (param.Type == IrisType.Invalid)
                {
                    containsInvalidType = true;
                }
            }

            if (containsInvalidType)
            {
                CompileErrors.Add(fp, String.Format("The function or procedure '{0}.{1}' contains types that are not supported by the language.", declaringTypeName, methodName));
            }
            else
            {
                SymbolTable.Add(symbolName, method, StorageClass.Global, importedMethod);
            }
        }
コード例 #6
0
        private string GetEmittedMethodName(Symbol methodSymbol)
        {
            string name;

            if (!_methodNameCache.TryGetValue(methodSymbol.Location, out name))
            {
                Method method = methodSymbol.Type as Method;
                if (method == null || _programName == null)
                {
                    // "method" will be null if the symbol is undefined.
                    // There should already be a compile error emitted for the undefined symbol.
                    // "m_programName" is null in some unit testing cases.
                    name = "_Unknown";
                }
                else if (methodSymbol.ImportInfo != null)
                {
                    ImportedMethod importedMethod = (ImportedMethod)methodSymbol.ImportInfo;
                    StringBuilder  nameBuilder    = new StringBuilder();
                    if (!importedMethod.IsStatic)
                    {
                        nameBuilder.Append("instance ");
                    }

                    nameBuilder.Append(IrisTypeToCilTypeName(importedMethod.ReturnType));
                    nameBuilder.Append(' ');
                    AppendImportedMemberName(nameBuilder, importedMethod);
                    AppendParameterList(nameBuilder, importedMethod.GetParameters());

                    name = nameBuilder.ToString();
                }
                else
                {
                    StringBuilder nameBuilder = new StringBuilder();
                    nameBuilder.Append(IrisTypeToCilTypeName(method.ReturnType));
                    nameBuilder.Append(' ');
                    nameBuilder.Append(_programName);
                    nameBuilder.Append("::");
                    nameBuilder.Append(methodSymbol.Name);
                    AppendParameterList(nameBuilder, method.GetParameters());

                    name = nameBuilder.ToString();
                }
                _methodNameCache.Add(methodSymbol.Location, name);
            }

            return(name);
        }
コード例 #7
0
 private IEnumerable <LocalVariable> GetLocalsImpl(ImportedMethod method)
 {
     if (method != null)
     {
         // Get the local symbols from the PDB (symbol file).  If symbols aren't loaded, we
         // can't show any local variables
         DkmClrLocalVariable[] symbols = GetLocalSymbolsFromPdb().ToArray();
         if (symbols.Length != 0)
         {
             // To determine the local types, we need to decode the local variable signature
             // token.  Get the token from the debugger, then use the Iris Compiler's importer
             // to get the variables types.  We can then construct the correlated list of local
             // types and names.
             int localVarSigToken = InstructionAddress.ModuleInstance.GetLocalSignatureToken(CurrentMethodToken);
             ImmutableArray <IrisType> localTypes = method.Module.DecodeLocalVariableTypes(localVarSigToken);
             foreach (DkmClrLocalVariable localSymbol in symbols)
             {
                 int slot = localSymbol.Slot;
                 yield return(new LocalVariable(localSymbol.Name, localTypes[slot], slot));
             }
         }
     }
 }
コード例 #8
0
        private static string TryGetFrameNameHelper(DkmInspectionContext inspectionContext, DkmStackWalkFrame frame, DkmVariableInfoFlags argumentFlags)
        {
            ImportedMethod currentMethod = TryGetCurrentMethod(inspectionContext, frame);

            if (currentMethod == null)
            {
                return(null);
            }

            string name = currentMethod.Name;

            if (argumentFlags == DkmVariableInfoFlags.None)
            {
                return(name);
            }

            var type = currentMethod.DeclaringType;

            if (type.IsStatic && type.Name == "Functions")
            {
                ; // No prefix for 'normal' functions
            }
            else
            {
                // static or instance method ?
                if (currentMethod.IsStatic)
                {
                    name = type.FullName + "." + name;
                }
                else
                {
                    name = type.FullName + ":" + name;
                }
            }

            Variable[] args = currentMethod.GetParameters();
            if (args.Length == 0)
            {
                return(name + "()");
            }

            StringBuilder nameBuilder = new StringBuilder();

            nameBuilder.Append(name);
            nameBuilder.Append('(');

            bool first     = true;
            bool showTypes = argumentFlags.HasFlag(DkmVariableInfoFlags.Types);
            bool showNames = argumentFlags.HasFlag(DkmVariableInfoFlags.Names);

            foreach (Variable arg in args)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    nameBuilder.Append(", ");
                }

                XSharpType argType = arg.Type;
                if (showNames)
                {
                    nameBuilder.Append(arg.Name);
                }

                if (showNames && showTypes)
                {
                    if (arg.In && arg.Out)
                    {
                        nameBuilder.Append(" REF ");
                    }
                    else if (arg.Out)
                    {
                        nameBuilder.Append(" OUT ");
                    }
                    else
                    {
                        nameBuilder.Append(" AS ");
                    }
                }

                if (showTypes)
                {
                    nameBuilder.Append(argType.ToString());
                }
            }

            nameBuilder.Append(')');
            var result = nameBuilder.ToString();

            if (result.Contains(clArgs))
            {
                result = result.Replace(clArgs, "[ClipperArguments]");
            }
            return(result);
        }
コード例 #9
0
        private static string TryGetFrameNameHelper(DkmInspectionContext inspectionContext, DkmStackWalkFrame frame, DkmVariableInfoFlags argumentFlags)
        {
            ImportedMethod currentMethod = TryGetCurrentMethod(inspectionContext, frame);

            if (currentMethod == null)
            {
                return(null);
            }

            string name = currentMethod.Name;

            if (string.Equals(name, "$.main", StringComparison.Ordinal))
            {
                return("<Main Block>");
            }

            if (argumentFlags == DkmVariableInfoFlags.None)
            {
                return(name);
            }

            Variable[] args = currentMethod.GetParameters();
            if (args.Length == 0)
            {
                return(name);
            }

            StringBuilder nameBuilder = new StringBuilder();

            nameBuilder.Append(name);
            nameBuilder.Append('(');

            bool first     = true;
            bool showTypes = argumentFlags.HasFlag(DkmVariableInfoFlags.Types);
            bool showNames = argumentFlags.HasFlag(DkmVariableInfoFlags.Names);

            foreach (Variable arg in args)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    nameBuilder.Append("; ");
                }

                IrisType argType = arg.Type;
                if (argType.IsByRef)
                {
                    nameBuilder.Append("var ");
                    argType = argType.GetElementType();
                }

                if (showNames)
                {
                    nameBuilder.Append(arg.Name);
                }

                if (showNames && showTypes)
                {
                    nameBuilder.Append(" : ");
                }

                if (showTypes)
                {
                    nameBuilder.Append(argType);
                }
            }

            nameBuilder.Append(')');
            return(nameBuilder.ToString());
        }
コード例 #10
0
ファイル: WindowsX64CodeGenerator.cs プロジェクト: polsys/cle
 /// <summary>
 /// Adds an import table entry for the given method.
 /// </summary>
 /// <param name="method">Information about the method to import.</param>
 /// <param name="methodIndex">The compiler internal index for identifying the method.</param>
 public void EmitImport(ImportedMethod method, int methodIndex)
 {
     _peWriter.AddImport(methodIndex, method.ImportName, method.ImportLibrary);
 }