diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-06-29 14:16:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-29 14:16:38 -0700 |
| commit | b2b08679a32506d629df84730f36639dab9f9593 (patch) | |
| tree | e9aad4ff9a6111d828ae2e4b217dc8145cda56dd /source/slang | |
| parent | 16613ed981fc5dc38966f5108e85b1aee36ef92f (diff) | |
| parent | f4d900dfb64d95f121dd8565dd269be061ef8509 (diff) | |
Merge pull request #51 from tfoleyNV/refptr-string-cleanup
Overhaul `RefPtr` and `String`
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/check.cpp | 64 | ||||
| -rw-r--r-- | source/slang/lexer.cpp | 3 | ||||
| -rw-r--r-- | source/slang/options.cpp | 6 | ||||
| -rw-r--r-- | source/slang/parameter-binding.cpp | 4 | ||||
| -rw-r--r-- | source/slang/parser.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 2 | ||||
| -rw-r--r-- | source/slang/syntax.h | 29 |
7 files changed, 48 insertions, 64 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 1424f6728..4966b102f 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -155,7 +155,7 @@ namespace Slang auto derefExpr = new DerefExpr(); derefExpr->Position = originalExpr->Position; derefExpr->base = base; - derefExpr->Type = ptrLikeType->elementType; + derefExpr->Type = QualType(ptrLikeType->elementType); // TODO(tfoley): handle l-value status here @@ -198,7 +198,7 @@ namespace Slang { auto overloadedExpr = new OverloadedExpr(); overloadedExpr->Position = originalExpr->Position; - overloadedExpr->Type = ExpressionType::Overloaded; + overloadedExpr->Type = QualType(ExpressionType::Overloaded); overloadedExpr->base = baseExpr; overloadedExpr->lookupResult2 = lookupResult; return overloadedExpr; @@ -236,7 +236,7 @@ namespace Slang } // TODO(tfoley): should we construct a new ErrorExpr here? - overloadedExpr->Type = ExpressionType::Error; + overloadedExpr->Type = QualType(ExpressionType::Error); return overloadedExpr; } @@ -518,7 +518,7 @@ namespace Slang RefPtr<ExpressionSyntaxNode> CreateErrorExpr(ExpressionSyntaxNode* expr) { - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); return expr; } @@ -787,7 +787,7 @@ namespace Slang { auto toInitializerListExpr = new InitializerListExpr(); toInitializerListExpr->Position = fromInitializerListExpr->Position; - toInitializerListExpr->Type = toType; + toInitializerListExpr->Type = QualType(toType); toInitializerListExpr->args = coercedArgs; @@ -960,7 +960,7 @@ namespace Slang auto castExpr = new TypeCastExpressionSyntaxNode(); castExpr->Position = fromExpr->Position; castExpr->TargetType.type = toType; - castExpr->Type = toType; + castExpr->Type = QualType(toType); castExpr->Expression = fromExpr; return castExpr; } @@ -1020,7 +1020,7 @@ namespace Slang // then coerce any initializer to the type if (initExpr) { - initExpr = Coerce(type, initExpr); + initExpr = Coerce(type.Ptr(), initExpr); } } else @@ -1668,7 +1668,7 @@ namespace Slang { if (function) { - stmt->Expression = Coerce(function->ReturnType, stmt->Expression); + stmt->Expression = Coerce(function->ReturnType.Ptr(), stmt->Expression); } else { @@ -1801,7 +1801,7 @@ namespace Slang // TODO(tfoley): should coercion of initializer lists be special-cased // here, or handled as a general case for coercion? - initExpr = Coerce(varDecl->Type, initExpr); + initExpr = Coerce(varDecl->Type.Ptr(), initExpr); varDecl->Expr = initExpr; } @@ -1903,7 +1903,7 @@ namespace Slang expr->Type = ExpressionType::GetFloat(); break; default: - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); throw "Invalid constant type."; break; } @@ -2167,7 +2167,7 @@ namespace Slang return CreateErrorExpr(subscriptExpr.Ptr()); } - subscriptExpr->Type = elementType; + subscriptExpr->Type = QualType(elementType); // TODO(tfoley): need to be more careful about this stuff subscriptExpr->Type.IsLeftValue = baseExpr->Type.IsLeftValue; @@ -2237,7 +2237,7 @@ namespace Slang auto elementType = CoerceToUsableType(TypeExp(baseExpr, baseTypeType->type)); auto arrayType = new ArrayExpressionType(); - arrayType->BaseType = elementType; + arrayType->BaseType = elementType.Ptr(); arrayType->ArrayLength = elementCount; typeResult = arrayType; @@ -2401,7 +2401,7 @@ namespace Slang { // TODO(tfoley): Actual checking logic needs to go here... - appExpr->Type = type; + appExpr->Type = QualType(type); return appExpr; } @@ -3290,7 +3290,7 @@ namespace Slang } context.mode = OverloadResolveContext::Mode::ForReal; - context.appExpr->Type = ExpressionType::Error; + context.appExpr->Type = QualType(ExpressionType::Error); if (!TryCheckOverloadCandidateArity(context, candidate)) goto error; @@ -3312,7 +3312,7 @@ namespace Slang { case OverloadCandidate::Flavor::Func: context.appExpr->FunctionExpr = baseExpr; - context.appExpr->Type = candidate.resultType; + context.appExpr->Type = QualType(candidate.resultType); // A call may yield an l-value, and we should take a look at the candidate to be sure if(auto subscriptDeclRef = candidate.item.declRef.As<SubscriptDecl>()) @@ -3771,7 +3771,7 @@ namespace Slang { ConstraintSystem constraints; - if (!TryUnifyTypes(constraints, extDecl->targetType, type)) + if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type)) return DeclRef<Decl>().As<ExtensionDecl>(); auto constraintSubst = TrySolveConstraintSystem(&constraints, DeclRef<Decl>(extGenericDecl, nullptr).As<GenericDecl>()); @@ -4291,7 +4291,7 @@ namespace Slang { // Nothing at all was found that we could even consider invoking getSink()->diagnose(expr->FunctionExpr, Diagnostics::expectedFunction); - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); return expr; } } @@ -4562,7 +4562,7 @@ namespace Slang if (expr->declRef) return expr; - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); auto lookupResult = LookUp(this, expr->name, expr->scope); if (lookupResult.isValid()) @@ -4587,7 +4587,7 @@ namespace Slang if (expr->Expression->Type->Equals(ExpressionType::Error.Ptr())) { // If the expression being casted has an error type, then just silently succeed - expr->Type = targetType; + expr->Type = targetType.Ptr(); return expr; } else if (auto targetArithType = targetType->AsArithmeticType()) @@ -4604,7 +4604,7 @@ namespace Slang // TODO(tfoley): this checking is incomplete here, and could // lead to downstream compilation failures - expr->Type = targetType; + expr->Type = targetType.Ptr(); return expr; } } @@ -4612,7 +4612,7 @@ namespace Slang fail: // Default: in no other case succeds, then the cast failed and we emit a diagnostic. getSink()->diagnose(expr, Diagnostics::invalidTypeCast, expr->Expression->Type, targetType->ToString()); - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); return expr; } #if TIMREMOVED @@ -4656,11 +4656,11 @@ namespace Slang auto& type = expr->Type; if (auto pointerLikeType = type->As<PointerLikeType>()) { - type = pointerLikeType->elementType; + type = QualType(pointerLikeType->elementType); auto derefExpr = new DerefExpr(); derefExpr->base = expr; - derefExpr->Type = pointerLikeType->elementType; + derefExpr->Type = QualType(pointerLikeType->elementType); // TODO(tfoley): deal with l-value-ness here @@ -4691,7 +4691,7 @@ namespace Slang bool anyDuplicates = false; bool anyError = false; - for (int i = 0; i < memberRefExpr->name.Length(); i++) + for (UInt i = 0; i < memberRefExpr->name.Length(); i++) { auto ch = memberRefExpr->name[i]; int elementIndex = -1; @@ -4738,7 +4738,7 @@ namespace Slang if (anyError) { - swizExpr->Type = ExpressionType::Error; + swizExpr->Type = QualType(ExpressionType::Error); } else if (elementCount == 1) { @@ -4747,15 +4747,15 @@ namespace Slang // Note(tfoley): the official HLSL rules seem to be that it produces // a one-component vector, which is then implicitly convertible to // a scalar, but that seems like it just adds complexity. - swizExpr->Type = baseElementType; + swizExpr->Type = QualType(baseElementType); } else { // TODO(tfoley): would be nice to "re-sugar" type // here if the input type had a sugared name... - swizExpr->Type = createVectorType( + swizExpr->Type = QualType(createVectorType( baseElementType, - new ConstantIntVal(elementCount)); + new ConstantIntVal(elementCount))); } // A swizzle can be used as an l-value as long as there @@ -4861,14 +4861,14 @@ namespace Slang // catch-all fail: getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType); - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); return expr; } // All remaining cases assume we have a `BasicType` else if (!baseType->AsBasicType()) - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); else - expr->Type = ExpressionType::Error; + expr->Type = QualType(ExpressionType::Error); if (!baseType->Equals(ExpressionType::Error.Ptr()) && expr->Type->Equals(ExpressionType::Error.Ptr())) { @@ -5023,7 +5023,7 @@ namespace Slang { sink->diagnose(declRef, Diagnostics::unimplemented, "cannot form reference to this kind of declaration"); } - return ExpressionType::Error; + return QualType(ExpressionType::Error); } QualType getTypeForDeclRef( diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp index 786376baf..2d75e1900 100644 --- a/source/slang/lexer.cpp +++ b/source/slang/lexer.cpp @@ -415,7 +415,7 @@ namespace Slang return tokenType; } - static bool isNumberExponent(char c, int base) + static bool isNumberExponent(int c, int base) { switch( c ) { @@ -497,7 +497,6 @@ namespace Slang for(;;) { - int digitVal = 0; int c = *cursor; switch(c) { diff --git a/source/slang/options.cpp b/source/slang/options.cpp index 62b45e025..cced0f0ff 100644 --- a/source/slang/options.cpp +++ b/source/slang/options.cpp @@ -238,7 +238,7 @@ struct OptionsParser } else { - fprintf(stderr, "unknown code generation target '%S'\n", name.ToWString()); + fprintf(stderr, "unknown code generation target '%S'\n", name.ToWString().begin()); exit(1); } @@ -302,7 +302,7 @@ struct OptionsParser else if (name == "glslang") { passThrough = SLANG_PASS_THROUGH_GLSLANG; } else { - fprintf(stderr, "unknown pass-through target '%S'\n", name.ToWString()); + fprintf(stderr, "unknown pass-through target '%S'\n", name.ToWString().begin()); exit(1); } @@ -387,7 +387,7 @@ struct OptionsParser } else { - fprintf(stderr, "unknown command-line option '%S'\n", argStr.ToWString()); + fprintf(stderr, "unknown command-line option '%S'\n", argStr.ToWString().begin()); // TODO: print a usage message exit(1); } diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 01b047c2c..2a0c64892 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -211,8 +211,8 @@ LayoutSemanticInfo ExtractLayoutSemanticInfo( // TODO: need to parse and handle `space` binding int space = 0; - int index = 0; - for (int ii = 1; ii < registerName.Length(); ++ii) + UInt index = 0; + for (UInt ii = 1; ii < registerName.Length(); ++ii) { int c = registerName[ii]; if (c >= '0' && c <= '9') diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index cd839415f..4f622ada6 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -3277,7 +3277,7 @@ namespace Slang constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; constExpr->integerValue = value; - constExpr->Type = suffixType; + constExpr->Type = QualType(suffixType); return constExpr; } @@ -3346,7 +3346,7 @@ namespace Slang constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; constExpr->floatingPointValue = value; - constExpr->Type = suffixType; + constExpr->Type = QualType(suffixType); return constExpr; } diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 7643b3b85..b43387ddd 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1975,7 +1975,7 @@ sb << TEXT; void SlangStdLib::Finalize() { - code = nullptr; + code = String(); stdlibPath = String(); glslLibraryCode = String(); } 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<ExpressionType> type) - : type(type) - , IsLeftValue(false) - {} - QualType(ExpressionType* type) : type(type) , IsLeftValue(false) {} - void operator=(RefPtr<ExpressionType> t) - { - *this = QualType(t); - } - - void operator=(ExpressionType* t) - { - *this = QualType(t); - } - ExpressionType* Ptr() { return type.Ptr(); } operator RefPtr<ExpressionType>() { return type; } @@ -1444,7 +1429,7 @@ namespace Slang return type->Equals(other.Ptr()); } ExpressionType* Ptr() { return type.Ptr(); } - operator RefPtr<ExpressionType>() + operator ExpressionType*() { return type; } @@ -1473,7 +1458,7 @@ namespace Slang inline RefPtr<ExpressionType> GetType(DeclRef<VarDeclBase> const& declRef) { - return declRef.Substitute(declRef.getDecl()->Type); + return declRef.Substitute(declRef.getDecl()->Type.Ptr()); } inline RefPtr<ExpressionSyntaxNode> getInitExpr(DeclRef<VarDeclBase> const& declRef) @@ -1519,7 +1504,7 @@ namespace Slang inline RefPtr<ExpressionType> GetTargetType(DeclRef<ExtensionDecl> 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<ExpressionType> GetType(DeclRef<TypeDefDecl> 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<ExpressionType> GetSub(DeclRef<GenericTypeConstraintDecl> const& declRef) { - return declRef.Substitute(declRef.getDecl()->sub); + return declRef.Substitute(declRef.getDecl()->sub.Ptr()); } inline RefPtr<ExpressionType> GetSup(DeclRef<GenericTypeConstraintDecl> 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; |
