GCC Middle and Back End API Reference
json Namespace Reference

Data Structures

class  array
 
class  error
 
class  float_number
 
class  integer_number
 
class  literal
 
class  location_map
 
class  object
 
struct  result
 
class  string
 
class  value
 

Typedefs

typedef result< std::unique_ptr< value >, std::unique_ptr< error > > parser_result_t
 

Enumerations

enum  kind {
  JSON_OBJECT , JSON_ARRAY , JSON_INTEGER , JSON_FLOAT ,
  JSON_STRING , JSON_TRUE , JSON_FALSE , JSON_NULL
}
 

Functions

parser_result_t parse_utf8_string (size_t length, const char *utf8_buf, bool allow_comments, location_map *out_loc_map)
 
parser_result_t parse_utf8_string (const char *utf8, bool allow_comments, location_map *out_loc_map)
 

Detailed Description

JSON parsing
   Copyright (C) 2017-2022 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
JSON trees
   Copyright (C) 2017-2024 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Implementation of JSON, a lightweight data-interchange format.

See http://www.json.org/
and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
and https://tools.ietf.org/html/rfc7159

Supports parsing text into a DOM-like tree of json::value *, directly
creating such trees, and dumping json::value * to text.   
TODO: `libcpp/mkdeps.cc` wants JSON writing support for p1689r5 output;
extract this code and move to libiberty.   
Timing variables for measuring compiler performance.
Copyright (C) 2000-2024 Free Software Foundation, Inc.
Contributed by Alex Samuel <samuel@codesourcery.com>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

Typedef Documentation

◆ parser_result_t

typedef result<std::unique_ptr<value>, std::unique_ptr<error> > json::parser_result_t
Typedef for the result of parsing JSON: ownership of either a
json::value * or of a json::error *.   

Enumeration Type Documentation

◆ kind

enum json::kind
An enum for discriminating the subclasses of json::value.   
Enumerator
JSON_OBJECT 
JSON_ARRAY 
JSON_INTEGER 
JSON_FLOAT 
JSON_STRING 
JSON_TRUE 
JSON_FALSE 
JSON_NULL 

Function Documentation

◆ parse_utf8_string() [1/2]

json::parser_result_t json::parse_utf8_string ( const char * utf8,
bool allow_comments,
location_map * out_loc_map )
extern
Attempt to parse the nil-terminated UTF-8 encoded buffer at
UTF8_BUF.
If ALLOW_COMMENTS is true, then allow C and C++ style-comments in the
buffer, as an extension to JSON, otherwise forbid them.
If successful, return a non-NULL json::value *.
if there was a problem, return NULL and write an error
message to err_out, which must be deleted by the caller.
If OUT_LOC_MAP is non-NULL, notify *OUT_LOC_MAP about
source locations of nodes seen during parsing.   

References parse_utf8_string().

◆ parse_utf8_string() [2/2]

parser_result_t json::parse_utf8_string ( size_t length,
const char * utf8_buf,
bool allow_comments,
location_map * out_loc_map )
extern
Functions for parsing JSON buffers.   
Attempt to parse the UTF-8 encoded buffer at UTF8_BUF
of the given LENGTH.
If ALLOW_COMMENTS is true, then allow C and C++ style-comments in the
buffer, as an extension to JSON, otherwise forbid them.
If successful, return an json::value in the result.
if there was a problem, return a json::error in the result.
If OUT_LOC_MAP is non-NULL, notify *OUT_LOC_MAP about
source locations of nodes seen during parsing.   

References r.

Referenced by parse_utf8_string().