Example #1
0
File: Host.cs Project: tupipa/vcc
        internal static string FindMemberNameByLocation(string fileLoc, VccAssembly assem)
        {
            var colonPos = fileLoc.LastIndexOf(':');

            if (colonPos == -1 || colonPos == 0 || colonPos == fileLoc.Length - 1)
            {
                Logger.Instance.Error("invalid source location '{0}' .", fileLoc);
                errorCount++;
                return(null);
            }

            var  fileName = fileLoc.Substring(0, colonPos);
            uint fileLine;

            if (!uint.TryParse(fileLoc.Substring(colonPos + 1), out fileLine))
            {
                Logger.Instance.Error("invalid source location line '{0}' .", fileLoc.Substring(colonPos + 1));
                errorCount++;
                return(null);
            }

            var fullPath = Path.GetFullPath(fileName);

            foreach (var member in ((IAssembly)assem).NamespaceRoot.Members)
            {
                var ploc = new VisitorHelper.DeferredToken(member.Locations).GetToken() as IOriginalDocumentLocation;
                if (ploc != null &&
                    fullPath.Equals(Path.GetFullPath(ploc.OriginalDocumentLocation), StringComparison.OrdinalIgnoreCase) &&
                    ploc.StartLine <= fileLine &&
                    ploc.EndLine >= fileLine)
                {
                    return(member.Name.Value);
                }
            }

            Logger.Instance.Error("could not find source item with location '{0}'", fileLoc);
            errorCount++;
            return(null);
        }
Example #2
0
        internal static string FindMemberNameByLocation(string fileLoc, VccAssembly assem)
        {
            var colonPos = fileLoc.LastIndexOf(':');
              if (colonPos == -1 || colonPos == 0 || colonPos == fileLoc.Length - 1)
              {
            Logger.Instance.Error("invalid source location '{0}' .", fileLoc);
            errorCount++;
            return null;
              }

              var fileName = fileLoc.Substring(0, colonPos);
              uint fileLine;

              if (!uint.TryParse(fileLoc.Substring(colonPos + 1), out fileLine))
              {
            Logger.Instance.Error("invalid source location line '{0}' .", fileLoc.Substring(colonPos + 1));
            errorCount++;
            return null;
              }

              var fullPath = Path.GetFullPath(fileName);

              foreach (var member in ((IAssembly)assem).NamespaceRoot.Members)
              {
            var ploc = new VisitorHelper.DeferredToken(member.Locations).GetToken() as IOriginalDocumentLocation;
            if (ploc != null &&
              fullPath.Equals(Path.GetFullPath(ploc.OriginalDocumentLocation), StringComparison.OrdinalIgnoreCase) &&
              ploc.StartLine <= fileLine &&
              ploc.EndLine >= fileLine)
            {
              return member.Name.Value;
            }
              }

              Logger.Instance.Error( "could not find source item with location '{0}'", fileLoc);
              errorCount++;
              return null;
        }