github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/logopt/log_opts.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package logopt
     6  
     7  import (
     8  	"github.com/shogo82148/std/cmd/internal/obj"
     9  	"github.com/shogo82148/std/cmd/internal/src"
    10  )
    11  
    12  type VersionHeader struct {
    13  	Version   int    `json:"version"`
    14  	Package   string `json:"package"`
    15  	Goos      string `json:"goos"`
    16  	Goarch    string `json:"goarch"`
    17  	GcVersion string `json:"gc_version"`
    18  	File      string `json:"file,omitempty"`
    19  }
    20  
    21  type DocumentURI string
    22  
    23  type Position struct {
    24  	Line      uint `json:"line"`
    25  	Character uint `json:"character"`
    26  }
    27  
    28  // A Range in a text document expressed as (zero-based) start and end positions.
    29  // A range is comparable to a selection in an editor. Therefore the end position is exclusive.
    30  // If you want to specify a range that contains a line including the line ending character(s)
    31  // then use an end position denoting the start of the next line.
    32  type Range struct {
    33  	/*Start defined:
    34  	 * The range's start position
    35  	 */
    36  	Start Position `json:"start"`
    37  
    38  	/*End defined:
    39  	 * The range's end position
    40  	 */
    41  	End Position `json:"end"`
    42  }
    43  
    44  // A Location represents a location inside a resource, such as a line inside a text file.
    45  type Location struct {
    46  	// URI is
    47  	URI DocumentURI `json:"uri"`
    48  
    49  	// Range is
    50  	Range Range `json:"range"`
    51  }
    52  
    53  /* DiagnosticRelatedInformation defined:
    54   * Represents a related message and source code location for a diagnostic. This should be
    55   * used to point to code locations that cause or related to a diagnostics, e.g when duplicating
    56   * a symbol in a scope.
    57   */
    58  type DiagnosticRelatedInformation struct {
    59  
    60  	/*Location defined:
    61  	 * The location of this related diagnostic information.
    62  	 */
    63  	Location Location `json:"location"`
    64  
    65  	/*Message defined:
    66  	 * The message of this related diagnostic information.
    67  	 */
    68  	Message string `json:"message"`
    69  }
    70  
    71  // DiagnosticSeverity defines constants
    72  type DiagnosticSeverity uint
    73  
    74  const (
    75  	/*SeverityInformation defined:
    76  	 * Reports an information.
    77  	 */
    78  	SeverityInformation DiagnosticSeverity = 3
    79  )
    80  
    81  // DiagnosticTag defines constants
    82  type DiagnosticTag uint
    83  
    84  /*Diagnostic defined:
    85   * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
    86   * are only valid in the scope of a resource.
    87   */
    88  type Diagnostic struct {
    89  
    90  	/*Range defined:
    91  	 * The range at which the message applies
    92  	 */
    93  	Range Range `json:"range"`
    94  
    95  	/*Severity defined:
    96  	 * The diagnostic's severity. Can be omitted. If omitted it is up to the
    97  	 * client to interpret diagnostics as error, warning, info or hint.
    98  	 */
    99  	Severity DiagnosticSeverity `json:"severity,omitempty"`
   100  
   101  	/*Code defined:
   102  	 * The diagnostic's code, which usually appear in the user interface.
   103  	 */
   104  	Code string `json:"code,omitempty"`
   105  
   106  	/*Source defined:
   107  	 * A human-readable string describing the source of this
   108  	 * diagnostic, e.g. 'typescript' or 'super lint'. It usually
   109  	 * appears in the user interface.
   110  	 */
   111  	Source string `json:"source,omitempty"`
   112  
   113  	/*Message defined:
   114  	 * The diagnostic's message. It usually appears in the user interface
   115  	 */
   116  	Message string `json:"message"`
   117  
   118  	/*Tags defined:
   119  	 * Additional metadata about the diagnostic.
   120  	 */
   121  	Tags []DiagnosticTag `json:"tags,omitempty"`
   122  
   123  	/*RelatedInformation defined:
   124  	 * An array of related diagnostic information, e.g. when symbol-names within
   125  	 * a scope collide all definitions can be marked via this property.
   126  	 */
   127  	RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
   128  }
   129  
   130  // A LoggedOpt is what the compiler produces and accumulates,
   131  // to be converted to JSON for human or IDE consumption.
   132  type LoggedOpt struct {
   133  	pos          src.XPos
   134  	lastPos      src.XPos
   135  	compilerPass string
   136  	functionName string
   137  	what         string
   138  	target       []interface{}
   139  }
   140  
   141  const (
   142  	None logFormat = iota
   143  	Json0
   144  )
   145  
   146  var Format = None
   147  
   148  // LogJsonOption parses and validates the version,directory value attached to the -json compiler flag.
   149  func LogJsonOption(flagValue string)
   150  
   151  // NewLoggedOpt allocates a new LoggedOpt, to later be passed to either NewLoggedOpt or LogOpt as "args".
   152  // Pos is the source position (including inlining), what is the message, pass is which pass created the message,
   153  // funcName is the name of the function
   154  // A typical use for this to accumulate an explanation for a missed optimization, for example, why did something escape?
   155  func NewLoggedOpt(pos, lastPos src.XPos, what, pass, funcName string, args ...interface{}) *LoggedOpt
   156  
   157  // LogOpt logs information about a (usually missed) optimization performed by the compiler.
   158  // Pos is the source position (including inlining), what is the message, pass is which pass created the message,
   159  // funcName is the name of the function.
   160  func LogOpt(pos src.XPos, what, pass, funcName string, args ...interface{})
   161  
   162  // LogOptRange is the same as LogOpt, but includes the ability to express a range of positions,
   163  // not just a point.
   164  func LogOptRange(pos, lastPos src.XPos, what, pass, funcName string, args ...interface{})
   165  
   166  // Enabled returns whether optimization logging is enabled.
   167  func Enabled() bool
   168  
   169  // FlushLoggedOpts flushes all the accumulated optimization log entries.
   170  func FlushLoggedOpts(ctxt *obj.Link, slashPkgPath string)