summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-json-value.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-11-24 10:52:11 -0500
committerGitHub <noreply@github.com>2021-11-24 10:52:11 -0500
commit7db340b75e7bf31e5a1e3ac1a3b4c651c6087f92 (patch)
treeea5c2e1f10b995ee73a0567bc93ddd0713e7ba67 /source/compiler-core/slang-json-value.h
parentbdc61bb8db321a8d788aa739b889354540a49ee0 (diff)
PersistentJSONValue (#2028)
* #include an absolute path didn't work - because paths were taken to always be relative. * Use 'Process' to communicate with an command line tool. * Remove slang-win-stream * Tidy up windows ProcessUtil. * First version of BufferedReadStream. * Windows working IPC for steams. * Test proxy count option. * Split Process/ProcessUtil. Process is platform dependant. ProcessUtil are functions that are platform independent. * First implementation of Unix Process interface. * Unix process compiles on cygwin. * Fix typo in unix process. * Separate unix pipe stream error of invalid access, from pipe availability. * Fix in standard line extraction. * Make fd non blocking. * Fix issues with Windows Process streams. * Added UnixPipe. * Some fixes around UnixPipeStream. * Make a unix stream closed explicit. * Hack to debug linux process/stream. * Revert to old linux pipe handling. * Pass executable path for unit tests. Split out CommandLine into own source. * Small improvements in process/command line. * Check process behavior with crash. * Make stderr and stdout unbuffered for crash testing. * Only turn disable buffering in crash test. * Disable crash test on CI. * Fix crash on clang/linux. * Enable crash test. Remove _appendBuffer as can use StreamUtil functionality. * Added inital processing for http headers. * Small improvements to HttpHeader. * First pass HTTPPacketConnection working on windows. * Enable other Process communication tests. * Update comments. * WIP JSON RPC. * Add terminate to Process. Made JSONRPC a Util. * Small tidy up around HTTPPacketConnection. * Improve process termination options. * WIP for test-server. * Add diagnostics error handling to test-server. * Improved JSON support. Parsing/creating JSON-RPC messages. * WIP JSONRPC parsing. * First pass RttiInfo support. * WIP converting between JSON/native types. * Project files. * Split out RttiUtil. Made RttiInfo constuction thread safe. * WIP RTTI<->JSON. * Add diagnostics to JSON<->native conversions. * Make RttiInfo for structs globals. Avoids problem around derived types (like pointers), being able to cause an abort. * Add pointer support to RTTI. Fixed some compilation issues on linux. * Add fixed array support. * Added Rtti unit test. * Add rtti unit test. * Split out quoted/unquoted key handling. Fix bugs in JSON value/container. Added JSON native test. * Make default array allocator use malloc/free. Remove the new[] handler (doesn't work on visuals studio). * Fix for linux warning. * Remove some test code. * Fix issues on x86 win. * Fix warning on aarch64. * Fix some bugs in JSON parsing/handling. Make Rtti work copy/dtor/ctor struct types. * Testing JSON<->native with fixed array. Make makeArrayView explicit if it's just a single value. Added array type. * Fix getting arrayView. * Improve JSON diagnostic name. * First pass refactor using Rtti for JSON RPC. * First pass of test server using RTTI/JSON-RPC. * Added JSONRPCConnection. * Fix some naming issues. * First pass of test-server working. * Added unit test support for JSON-RPC test server. * Fix compilation issues on linux around template handling. * Typo fix. * Fix a bug around SourceLoc lookup with JSONContainer. * Set the console type to console for ISlangWriters. * Small improvements to test-server. * Small improvements in test-server. * Small fix. * Remove test-proxy. Make test-process a process that can be used to unit test 'Process'. Adding mechanism to control spawning that will create a new process for every test. * Ability to remove source manager for JSONValue. * WIP SimpleJSONValue. * Add PersistentJSONValue * Testing around PersistentJSONValue. Bug fixes. * Small code improvements.
Diffstat (limited to 'source/compiler-core/slang-json-value.h')
-rw-r--r--source/compiler-core/slang-json-value.h77
1 files changed, 69 insertions, 8 deletions
diff --git a/source/compiler-core/slang-json-value.h b/source/compiler-core/slang-json-value.h
index 2e8707a87..25e74cb36 100644
--- a/source/compiler-core/slang-json-value.h
+++ b/source/compiler-core/slang-json-value.h
@@ -50,6 +50,8 @@ struct JSONValue
FloatValue,
StringValue,
+ StringRepresentation,
+
Array,
Object,
@@ -105,14 +107,14 @@ struct JSONValue
union
{
- Index rangeIndex; ///< Used for Array/Object
- Index length; ///< Length in bytes if it is a 'Lexeme'
- double floatValue; ///< Float value
- int64_t intValue; ///< Integer value
- JSONKey stringKey; ///< The pool key if it's a string
+ Index rangeIndex; ///< Used for Array/Object
+ Index length; ///< Length in bytes if it is a 'Lexeme'
+ double floatValue; ///< Float value
+ int64_t intValue; ///< Integer value
+ JSONKey stringKey; ///< The pool key if it's a string
+ StringRepresentation* stringRep; ///< Only ever used on a 'PersistentJSONValue'
};
-
static const Kind g_typeToKind[Index(Type::CountOf)];
static const OtherRttiInfo g_rttiInfo;
@@ -145,6 +147,65 @@ struct JSONKeyValue
static JSONKeyValue g_invalid;
};
+class JSONContainer;
+
+/* Is similar to JSONValue, but is designed to
+
+* Only be able to hold 'Simple' types (ie not array/object)
+* Does not reference/require JSONContainer.
+
+Not requiring JSONContainer means it's useful to hold state when JSONContainer goes out of scope.
+Care may need to be taken if sourceManager goes out of scope, sourceLocs may become invalid. This
+is true of a regular JSONValue.
+
+Care must also be taken because it is derived from JSONValue. It *can* be sliced and work correctly,
+but *requires* that the PersistentJSONValue with same value to stay in scope in general. In practice
+this is only an issue with StringRepresention type.
+*/
+class PersistentJSONValue : public JSONValue
+{
+public:
+ typedef JSONValue Super;
+ typedef PersistentJSONValue ThisType;
+
+ /// If it's a string type this will always work
+ String getString() const;
+ UnownedStringSlice getSlice() const;
+
+ /// Set to the value
+ void set(const JSONValue& in, JSONContainer* container);
+ /// Set directly to a string
+ void set(const UnownedStringSlice& slice, SourceLoc loc);
+
+ /// True if identical
+ bool operator==(const ThisType& rhs) const;
+ bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
+
+ /// Assignable
+ void operator=(const ThisType& rhs);
+
+ PersistentJSONValue(const JSONValue& in, JSONContainer* container) { _init(in, container); }
+ PersistentJSONValue(const JSONValue& in, JSONContainer* container, SourceLoc inLoc) { _init(in, container); loc = inLoc; }
+
+ /// Copy Ctor
+ PersistentJSONValue(const ThisType& rhs);
+ /// Default Ctor (will be set to invalid)
+ PersistentJSONValue() {}
+
+
+ ~PersistentJSONValue()
+ {
+ if (type == Type::StringRepresentation && stringRep)
+ {
+ stringRep->releaseReference();
+ }
+ }
+protected:
+ /// Assumes this has no valid data
+ void _init(const JSONValue& in, JSONContainer* container);
+ void _init(const UnownedStringSlice& slice, SourceLoc loc);
+};
+
class JSONContainer : public RefObject
{
public:
@@ -170,7 +231,7 @@ public:
/// Returns the index of key in obj, or -1 if not found
Index findObjectIndex(const JSONValue& obj, JSONKey key) const;
- /// Get the value in the object at key. REturns invalid if not found.
+ /// Get the value in the object at key. Returns invalid if not found.
JSONValue findObjectValue(const JSONValue& obj, JSONKey key) const;
/// Returns the index
@@ -201,7 +262,7 @@ public:
/// Get as a string. The contents will stay in scope as long as the container
UnownedStringSlice getString(const JSONValue& in);
- /// Gets the lexeme
+ /// Gets the lexeme
UnownedStringSlice getLexeme(const JSONValue& in);
/// Get a key for a name