From f4d900dfb64d95f121dd8565dd269be061ef8509 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 29 Jun 2017 11:50:55 -0700 Subject: Overhaul `RefPtr` and `String` - `RefPtr` no longer tries to have distinct cases for interal-vs-external reference counts. Instead we always require an internal reference count. - Types the used `RefPtr` but weren't `RefObject` were made to inherit `RefObject` - The `ReferenceCounted` base class was removed, so that only `RefObject` remains - Implicit conversion from `RefPtr` to `T*` added - This created some complicates for other types that relied on implicit conversions, so this isn't a net cleanup right now - The main type that got messed up by the above was `String`, which previously held a `RefPtr`. This change thus *also* includes a major overhaul of `String`: - `String` now holds all its data via indirection, using a `StringRepresentation` that is a `RefObject`. This object holds a length, capacity, and directly stores the character data in its allocation. This means that `sizeof(String)==sizeof(void*)` - It is now possible to directly mutate a `String` by appending to its representation (we just need to ensure it has a reference count of `1`, possibly by cloning it). This means that `StringBuilder` is now basically just an idomatic use of `String` - A couple operations that just return sub-ranges of a `String` now return `StringSlice` to avoid allocation when it isn't needed. This required more work. - Indices into strings changed from `int` to `UInt` (which is pointer-sized). This had a bunch of follow-on changes because the value `-1` sometimes needs to be special-cased in code that uses indices. Further cleanups are probably needed here. --- source/slang/syntax.h | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'source/slang/syntax.h') diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 05d3b6a79..b4d7e146e 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -664,26 +664,11 @@ namespace Slang : IsLeftValue(false) {} - QualType(RefPtr type) - : type(type) - , IsLeftValue(false) - {} - QualType(ExpressionType* type) : type(type) , IsLeftValue(false) {} - void operator=(RefPtr t) - { - *this = QualType(t); - } - - void operator=(ExpressionType* t) - { - *this = QualType(t); - } - ExpressionType* Ptr() { return type.Ptr(); } operator RefPtr() { return type; } @@ -1444,7 +1429,7 @@ namespace Slang return type->Equals(other.Ptr()); } ExpressionType* Ptr() { return type.Ptr(); } - operator RefPtr() + operator ExpressionType*() { return type; } @@ -1473,7 +1458,7 @@ namespace Slang inline RefPtr GetType(DeclRef const& declRef) { - return declRef.Substitute(declRef.getDecl()->Type); + return declRef.Substitute(declRef.getDecl()->Type.Ptr()); } inline RefPtr getInitExpr(DeclRef const& declRef) @@ -1519,7 +1504,7 @@ namespace Slang inline RefPtr GetTargetType(DeclRef const& declRef) { - return declRef.Substitute(declRef.getDecl()->targetType); + return declRef.Substitute(declRef.getDecl()->targetType.Ptr()); } // Declaration of a type that represents some sort of aggregate @@ -1620,7 +1605,7 @@ namespace Slang inline RefPtr GetType(DeclRef const& declRef) { - return declRef.Substitute(declRef.getDecl()->Type); + return declRef.Substitute(declRef.getDecl()->Type.Ptr()); } // A type alias of some kind (e.g., via `typedef`) @@ -2423,12 +2408,12 @@ namespace Slang inline RefPtr GetSub(DeclRef const& declRef) { - return declRef.Substitute(declRef.getDecl()->sub); + return declRef.Substitute(declRef.getDecl()->sub.Ptr()); } inline RefPtr GetSup(DeclRef const& declRef) { - return declRef.Substitute(declRef.getDecl()->sup); + return declRef.Substitute(declRef.getDecl()->sup.Ptr()); } class GenericValueParamDecl : public VarDeclBase @@ -2482,7 +2467,7 @@ namespace Slang // - class SyntaxVisitor + class SyntaxVisitor : public RefObject { protected: DiagnosticSink * sink = nullptr; -- cgit v1.2.3