diff options
| author | Tim Foley <tim.foley.is@gmail.com> | 2017-08-09 11:20:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-09 11:20:09 -0700 |
| commit | 6e4830f4d74adef0a47c6503d84dc114240fafa3 (patch) | |
| tree | 4f549da8c05be186f12442565389d9f3df44c6d7 | |
| parent | 8e4c0c35d6c2d0fd754b713441c2eee8f13f87b2 (diff) | |
| parent | 695c2700de54a5fec72ce7214c137a1dc3a02d7b (diff) | |
Merge pull request #155 from tfoleyNV/renaming
Major naming overhaul:
31 files changed, 1202 insertions, 1482 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 4c73894c5..23394e107 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -44,7 +44,7 @@ namespace Slang } struct SemanticsVisitor - : ExprVisitor<SemanticsVisitor, RefPtr<ExpressionSyntaxNode>> + : ExprVisitor<SemanticsVisitor, RefPtr<Expr>> , StmtVisitor<SemanticsVisitor> , DeclVisitor<SemanticsVisitor> { @@ -54,8 +54,8 @@ namespace Slang return sink; } -// ProgramSyntaxNode * program = nullptr; - FunctionSyntaxNode * function = nullptr; +// ModuleDecl * program = nullptr; + FuncDecl * function = nullptr; CompileRequest* request = nullptr; TranslationUnitRequest* translationUnit = nullptr; @@ -66,14 +66,14 @@ namespace Slang } // lexical outer statements - List<StatementSyntaxNode*> outerStmts; + List<Stmt*> outerStmts; // We need to track what has been `import`ed, // to avoid importing the same thing more than once // // TODO: a smarter approach might be to filter // out duplicate references during lookup. - HashSet<ProgramSyntaxNode*> importedModules; + HashSet<ModuleDecl*> importedModules; public: SemanticsVisitor( @@ -95,8 +95,8 @@ namespace Slang public: // Translate Types - RefPtr<ExpressionType> typeResult; - RefPtr<ExpressionSyntaxNode> TranslateTypeNodeImpl(const RefPtr<ExpressionSyntaxNode> & node) + RefPtr<Type> typeResult; + RefPtr<Expr> TranslateTypeNodeImpl(const RefPtr<Expr> & node) { if (!node) return nullptr; @@ -104,16 +104,16 @@ namespace Slang expr = ExpectATypeRepr(expr); return expr; } - RefPtr<ExpressionType> ExtractTypeFromTypeRepr(const RefPtr<ExpressionSyntaxNode>& typeRepr) + RefPtr<Type> ExtractTypeFromTypeRepr(const RefPtr<Expr>& typeRepr) { if (!typeRepr) return nullptr; - if (auto typeType = typeRepr->Type->As<TypeType>()) + if (auto typeType = typeRepr->type->As<TypeType>()) { return typeType->type; } return getSession()->getErrorType(); } - RefPtr<ExpressionType> TranslateTypeNode(const RefPtr<ExpressionSyntaxNode> & node) + RefPtr<Type> TranslateTypeNode(const RefPtr<Expr> & node) { if (!node) return nullptr; auto typeRepr = TranslateTypeNodeImpl(node); @@ -139,53 +139,53 @@ namespace Slang return result; } - RefPtr<ExpressionSyntaxNode> ConstructDeclRefExpr( + RefPtr<Expr> ConstructDeclRefExpr( DeclRef<Decl> declRef, - RefPtr<ExpressionSyntaxNode> baseExpr, - RefPtr<ExpressionSyntaxNode> originalExpr) + RefPtr<Expr> baseExpr, + RefPtr<Expr> originalExpr) { if (baseExpr) { - auto expr = new MemberExpressionSyntaxNode(); + auto expr = new MemberExpr(); expr->Position = originalExpr->Position; expr->BaseExpression = baseExpr; expr->name = declRef.GetName(); - expr->Type = GetTypeForDeclRef(declRef); + expr->type = GetTypeForDeclRef(declRef); expr->declRef = declRef; return expr; } else { - auto expr = new VarExpressionSyntaxNode(); + auto expr = new VarExpr(); expr->Position = originalExpr->Position; expr->name = declRef.GetName(); - expr->Type = GetTypeForDeclRef(declRef); + expr->type = GetTypeForDeclRef(declRef); expr->declRef = declRef; return expr; } } - RefPtr<ExpressionSyntaxNode> ConstructDerefExpr( - RefPtr<ExpressionSyntaxNode> base, - RefPtr<ExpressionSyntaxNode> originalExpr) + RefPtr<Expr> ConstructDerefExpr( + RefPtr<Expr> base, + RefPtr<Expr> originalExpr) { - auto ptrLikeType = base->Type->As<PointerLikeType>(); + auto ptrLikeType = base->type->As<PointerLikeType>(); SLANG_ASSERT(ptrLikeType); auto derefExpr = new DerefExpr(); derefExpr->Position = originalExpr->Position; derefExpr->base = base; - derefExpr->Type = QualType(ptrLikeType->elementType); + derefExpr->type = QualType(ptrLikeType->elementType); // TODO(tfoley): handle l-value status here return derefExpr; } - RefPtr<ExpressionSyntaxNode> ConstructLookupResultExpr( + RefPtr<Expr> ConstructLookupResultExpr( LookupResultItem const& item, - RefPtr<ExpressionSyntaxNode> baseExpr, - RefPtr<ExpressionSyntaxNode> originalExpr) + RefPtr<Expr> baseExpr, + RefPtr<Expr> originalExpr) { // If we collected any breadcrumbs, then these represent // additional segments of the lookup path that we need @@ -209,16 +209,16 @@ namespace Slang return ConstructDeclRefExpr(item.declRef, bb, originalExpr); } - RefPtr<ExpressionSyntaxNode> createLookupResultExpr( + RefPtr<Expr> createLookupResultExpr( LookupResult const& lookupResult, - RefPtr<ExpressionSyntaxNode> baseExpr, - RefPtr<ExpressionSyntaxNode> originalExpr) + RefPtr<Expr> baseExpr, + RefPtr<Expr> originalExpr) { if (lookupResult.isOverloaded()) { auto overloadedExpr = new OverloadedExpr(); overloadedExpr->Position = originalExpr->Position; - overloadedExpr->Type = QualType( + overloadedExpr->type = QualType( getSession()->getOverloadedType()); overloadedExpr->base = baseExpr; overloadedExpr->lookupResult2 = lookupResult; @@ -230,7 +230,7 @@ namespace Slang } } - RefPtr<ExpressionSyntaxNode> ResolveOverloadedExpr(RefPtr<OverloadedExpr> overloadedExpr, LookupMask mask) + RefPtr<Expr> ResolveOverloadedExpr(RefPtr<OverloadedExpr> overloadedExpr, LookupMask mask) { auto lookupResult = overloadedExpr->lookupResult2; SLANG_RELEASE_ASSERT(lookupResult.isValid() && lookupResult.isOverloaded()); @@ -267,18 +267,18 @@ namespace Slang return ConstructLookupResultExpr(lookupResult.item, overloadedExpr->base, overloadedExpr); } - RefPtr<ExpressionSyntaxNode> ExpectATypeRepr(RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> ExpectATypeRepr(RefPtr<Expr> expr) { if (auto overloadedExpr = expr.As<OverloadedExpr>()) { - expr = ResolveOverloadedExpr(overloadedExpr, LookupMask::Type); + expr = ResolveOverloadedExpr(overloadedExpr, LookupMask::type); } - if (auto typeType = expr->Type.type->As<TypeType>()) + if (auto typeType = expr->type.type->As<TypeType>()) { return expr; } - else if (auto errorType = expr->Type.type->As<ErrorType>()) + else if (auto errorType = expr->type.type->As<ErrorType>()) { return expr; } @@ -290,41 +290,41 @@ namespace Slang return CreateErrorExpr(expr); } - RefPtr<ExpressionType> ExpectAType(RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Type> ExpectAType(RefPtr<Expr> expr) { auto typeRepr = ExpectATypeRepr(expr); - if (auto typeType = typeRepr->Type->As<TypeType>()) + if (auto typeType = typeRepr->type->As<TypeType>()) { return typeType->type; } return getSession()->getErrorType(); } - RefPtr<ExpressionType> ExtractGenericArgType(RefPtr<ExpressionSyntaxNode> exp) + RefPtr<Type> ExtractGenericArgType(RefPtr<Expr> exp) { return ExpectAType(exp); } - RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<ExpressionSyntaxNode> exp) + RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<Expr> exp) { return CheckIntegerConstantExpression(exp.Ptr()); } - RefPtr<Val> ExtractGenericArgVal(RefPtr<ExpressionSyntaxNode> exp) + RefPtr<Val> ExtractGenericArgVal(RefPtr<Expr> exp) { if (auto overloadedExpr = exp.As<OverloadedExpr>()) { // assume that if it is overloaded, we want a type - exp = ResolveOverloadedExpr(overloadedExpr, LookupMask::Type); + exp = ResolveOverloadedExpr(overloadedExpr, LookupMask::type); } - if (auto typeType = exp->Type->As<TypeType>()) + if (auto typeType = exp->type->As<TypeType>()) { return typeType->type; } - else if (auto errorType = exp->Type->As<ErrorType>()) + else if (auto errorType = exp->type->As<ErrorType>()) { - return exp->Type.type; + return exp->type.type; } else { @@ -336,9 +336,9 @@ namespace Slang // the given generic declaration for the given arguments. // The arguments should already be checked against // the declaration. - RefPtr<ExpressionType> InstantiateGenericType( + RefPtr<Type> InstantiateGenericType( DeclRef<GenericDecl> genericDeclRef, - List<RefPtr<ExpressionSyntaxNode>> const& args) + List<RefPtr<Expr>> const& args) { RefPtr<Substitutions> subst = new Substitutions(); subst->genericDecl = genericDeclRef.getDecl(); @@ -411,9 +411,9 @@ namespace Slang // the name of a non-proper type, and then have the compiler fill // in the default values for its type arguments (e.g., a variable // given type `Texture2D` will actually have type `Texture2D<float4>`). - bool CoerceToProperTypeImpl(TypeExp const& typeExp, RefPtr<ExpressionType>* outProperType) + bool CoerceToProperTypeImpl(TypeExp const& typeExp, RefPtr<Type>* outProperType) { - ExpressionType* type = typeExp.type.Ptr(); + Type* type = typeExp.type.Ptr(); if (auto genericDeclRefType = type->As<GenericDeclRefType>()) { // We are using a reference to a generic declaration as a concrete @@ -426,7 +426,7 @@ namespace Slang auto genericDeclRef = genericDeclRefType->GetDeclRef(); EnsureDecl(genericDeclRef.decl); - List<RefPtr<ExpressionSyntaxNode>> args; + List<RefPtr<Expr>> args; for (RefPtr<Decl> member : genericDeclRef.getDecl()->Members) { if (auto typeParam = member.As<GenericTypeParamDecl>()) @@ -450,7 +450,7 @@ namespace Slang } else if (auto valParam = member.As<GenericValueParamDecl>()) { - if (!valParam->Expr) + if (!valParam->initExpr) { if (outProperType) { @@ -465,7 +465,7 @@ namespace Slang // TODO: this is one place where syntax should get cloned! if(outProperType) - args.Add(valParam->Expr); + args.Add(valParam->initExpr); } else { @@ -521,7 +521,7 @@ namespace Slang TypeExp CoerceToUsableType(TypeExp const& typeExp) { TypeExp result = CoerceToProperType(typeExp); - ExpressionType* type = result.type.Ptr(); + Type* type = result.type.Ptr(); if (auto basicType = type->As<BasicExpressionType>()) { // TODO: `void` shouldn't be a basic type, to make this easier to avoid @@ -545,32 +545,32 @@ namespace Slang return CoerceToUsableType(TranslateTypeNode(typeExp)); } - RefPtr<ExpressionSyntaxNode> CheckTerm(RefPtr<ExpressionSyntaxNode> term) + RefPtr<Expr> CheckTerm(RefPtr<Expr> term) { if (!term) return nullptr; return ExprVisitor::dispatch(term); } - RefPtr<ExpressionSyntaxNode> CreateErrorExpr(ExpressionSyntaxNode* expr) + RefPtr<Expr> CreateErrorExpr(Expr* expr) { - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); return expr; } - bool IsErrorExpr(RefPtr<ExpressionSyntaxNode> expr) + bool IsErrorExpr(RefPtr<Expr> expr) { // TODO: we may want other cases here... - if (auto errorType = expr->Type->As<ErrorType>()) + if (auto errorType = expr->type->As<ErrorType>()) return true; return false; } // Capture the "base" expression in case this is a member reference - RefPtr<ExpressionSyntaxNode> GetBaseExpr(RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> GetBaseExpr(RefPtr<Expr> expr) { - if (auto memberExpr = expr.As<MemberExpressionSyntaxNode>()) + if (auto memberExpr = expr.As<MemberExpr>()) { return memberExpr->BaseExpression; } @@ -694,10 +694,10 @@ namespace Slang // Central engine for implementing implicit coercion logic bool TryCoerceImpl( - RefPtr<ExpressionType> toType, // the target type for conversion - RefPtr<ExpressionSyntaxNode>* outToExpr, // (optional) a place to stuff the target expression - RefPtr<ExpressionType> fromType, // the source type for the conversion - RefPtr<ExpressionSyntaxNode> fromExpr, // the source expression + RefPtr<Type> toType, // the target type for conversion + RefPtr<Expr>* outToExpr, // (optional) a place to stuff the target expression + RefPtr<Type> fromType, // the source type for the conversion + RefPtr<Expr> fromExpr, // the source expression ConversionCost* outCost) // (optional) a place to stuff the conversion cost { // Easy case: the types are equal @@ -727,12 +727,12 @@ namespace Slang // In the case where we need to build a reuslt expression, // we will collect the new arguments here - List<RefPtr<ExpressionSyntaxNode>> coercedArgs; + List<RefPtr<Expr>> coercedArgs; if(auto toDeclRefType = toType->As<DeclRefType>()) { auto toTypeDeclRef = toDeclRefType->declRef; - if(auto toStructDeclRef = toTypeDeclRef.As<StructSyntaxNode>()) + if(auto toStructDeclRef = toTypeDeclRef.As<StructDecl>()) { // Trying to initialize a `struct` type given an initializer list. // We will go through the fields in order and try to match them @@ -751,13 +751,13 @@ namespace Slang auto arg = fromInitializerListExpr->args[argIndex++]; // - RefPtr<ExpressionSyntaxNode> coercedArg; + RefPtr<Expr> coercedArg; ConversionCost argCost; bool argResult = TryCoerceImpl( GetType(fieldDeclRef), outToExpr ? &coercedArg : nullptr, - arg->Type, + arg->type, arg, outCost ? &argCost : nullptr); @@ -785,13 +785,13 @@ namespace Slang for(auto& arg : fromInitializerListExpr->args) { - RefPtr<ExpressionSyntaxNode> coercedArg; + RefPtr<Expr> coercedArg; ConversionCost argCost; bool argResult = TryCoerceImpl( toElementType, outToExpr ? &coercedArg : nullptr, - arg->Type, + arg->type, arg, outCost ? &argCost : nullptr); @@ -824,7 +824,7 @@ namespace Slang { auto toInitializerListExpr = new InitializerListExpr(); toInitializerListExpr->Position = fromInitializerListExpr->Position; - toInitializerListExpr->Type = QualType(toType); + toInitializerListExpr->type = QualType(toType); toInitializerListExpr->args = coercedArgs; @@ -978,8 +978,8 @@ namespace Slang // Check whether a type coercion is possible bool CanCoerce( - RefPtr<ExpressionType> toType, // the target type for conversion - RefPtr<ExpressionType> fromType, // the source type for the conversion + RefPtr<Type> toType, // the target type for conversion + RefPtr<Type> fromType, // the source type for the conversion ConversionCost* outCost = 0) // (optional) a place to stuff the conversion cost { return TryCoerceImpl( @@ -990,14 +990,14 @@ namespace Slang outCost); } - RefPtr<ExpressionSyntaxNode> CreateImplicitCastExpr( - RefPtr<ExpressionType> toType, - RefPtr<ExpressionSyntaxNode> fromExpr) + RefPtr<Expr> CreateImplicitCastExpr( + RefPtr<Type> toType, + RefPtr<Expr> fromExpr) { // In "rewrite" mode, we will generate a different syntax node // to indicate that this type-cast was implicitly generated // by the compiler, and shouldn't appear in the output code. - RefPtr<TypeCastExpressionSyntaxNode> castExpr; + RefPtr<TypeCastExpr> castExpr; if (isRewriteMode()) { castExpr = new HiddenImplicitCastExpr(); @@ -1009,7 +1009,7 @@ namespace Slang castExpr->Position = fromExpr->Position; castExpr->TargetType.type = toType; - castExpr->Type = QualType(toType); + castExpr->type = QualType(toType); castExpr->Expression = fromExpr; return castExpr; } @@ -1020,29 +1020,29 @@ namespace Slang } // Perform type coercion, and emit errors if it isn't possible - RefPtr<ExpressionSyntaxNode> Coerce( - RefPtr<ExpressionType> toType, - RefPtr<ExpressionSyntaxNode> fromExpr) + RefPtr<Expr> Coerce( + RefPtr<Type> toType, + RefPtr<Expr> fromExpr) { // If semantic checking is being suppressed, then we might see // expressions without a type, and we need to ignore them. - if( !fromExpr->Type.type ) + if( !fromExpr->type.type ) { if(isRewriteMode()) return fromExpr; } - RefPtr<ExpressionSyntaxNode> expr; + RefPtr<Expr> expr; if (!TryCoerceImpl( toType, &expr, - fromExpr->Type.Ptr(), + fromExpr->type.Ptr(), fromExpr.Ptr(), nullptr)) { if(!isRewriteMode()) { - getSink()->diagnose(fromExpr->Position, Diagnostics::typeMismatch, toType, fromExpr->Type); + getSink()->diagnose(fromExpr->Position, Diagnostics::typeMismatch, toType, fromExpr->type); } // Note(tfoley): We don't call `CreateErrorExpr` here, because that would @@ -1059,7 +1059,7 @@ namespace Slang void CheckVarDeclCommon(RefPtr<VarDeclBase> varDecl) { // Check the type, if one was given - TypeExp type = CheckUsableType(varDecl->Type); + TypeExp type = CheckUsableType(varDecl->type); // TODO: Additional validation rules on types should go here, // but we need to deal with the fact that some cases might be @@ -1067,7 +1067,7 @@ namespace Slang // but not in othters (e.g., an unsized array field in a struct). // Check the initializers, if one was given - RefPtr<ExpressionSyntaxNode> initExpr = CheckTerm(varDecl->Expr); + RefPtr<Expr> initExpr = CheckTerm(varDecl->initExpr); // If a type was given, ... if (type.Ptr()) @@ -1098,8 +1098,8 @@ namespace Slang } } - varDecl->Type = type; - varDecl->Expr = initExpr; + varDecl->type = type; + varDecl->initExpr = initExpr; } void CheckGenericConstraintDecl(GenericTypeConstraintDecl* decl) @@ -1176,7 +1176,7 @@ namespace Slang } RefPtr<ConstantIntVal> checkConstantIntVal( - RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> expr) { // First type-check the expression as normal expr = CheckExpr(expr); @@ -1323,7 +1323,7 @@ namespace Slang decl->modifiers.first = resultModifiers; } - void visitProgramSyntaxNode(ProgramSyntaxNode* programNode) + void visitModuleDecl(ModuleDecl* programNode) { // Try to register all the builtin decls for (auto decl : programNode->Members) @@ -1355,11 +1355,11 @@ namespace Slang for (auto & s : programNode->getMembersOfType<TypeDefDecl>()) checkDecl(s.Ptr()); - for (auto & s : programNode->getMembersOfType<StructSyntaxNode>()) + for (auto & s : programNode->getMembersOfType<StructDecl>()) { checkDecl(s.Ptr()); } - for (auto & s : programNode->getMembersOfType<ClassSyntaxNode>()) + for (auto & s : programNode->getMembersOfType<ClassDecl>()) { checkDecl(s.Ptr()); } @@ -1370,14 +1370,14 @@ namespace Slang checkDecl(g.Ptr()); } - for (auto & func : programNode->getMembersOfType<FunctionSyntaxNode>()) + for (auto & func : programNode->getMembersOfType<FuncDecl>()) { if (!func->IsChecked(DeclCheckState::Checked)) { VisitFunctionDeclaration(func.Ptr()); } } - for (auto & func : programNode->getMembersOfType<FunctionSyntaxNode>()) + for (auto & func : programNode->getMembersOfType<FuncDecl>()) { EnsureDecl(func); } @@ -1400,7 +1400,7 @@ namespace Slang } } - void visitClassSyntaxNode(ClassSyntaxNode * classNode) + void visitClassDecl(ClassDecl * classNode) { if (classNode->IsChecked(DeclCheckState::Checked)) return; @@ -1408,7 +1408,7 @@ namespace Slang for (auto field : classNode->GetFields()) { - field->Type = CheckUsableType(field->Type); + field->type = CheckUsableType(field->type); field->SetCheckState(DeclCheckState::Checked); } } @@ -1417,11 +1417,11 @@ namespace Slang { // TODO: bottleneck through general-case variable checking - field->Type = CheckUsableType(field->Type); + field->type = CheckUsableType(field->type); field->SetCheckState(DeclCheckState::Checked); } - void visitStructSyntaxNode(StructSyntaxNode * structNode) + void visitStructDecl(StructDecl * structNode) { if (structNode->IsChecked(DeclCheckState::Checked)) return; @@ -1446,17 +1446,17 @@ namespace Slang if (decl->IsChecked(DeclCheckState::Checked)) return; decl->SetCheckState(DeclCheckState::CheckingHeader); - decl->Type = CheckProperType(decl->Type); + decl->type = CheckProperType(decl->type); decl->SetCheckState(DeclCheckState::Checked); } - void checkStmt(StatementSyntaxNode* stmt) + void checkStmt(Stmt* stmt) { if (!stmt) return; StmtVisitor::dispatch(stmt); } - void visitFunctionSyntaxNode(FunctionSyntaxNode *functionNode) + void visitFuncDecl(FuncDecl *functionNode) { if (functionNode->IsChecked(DeclCheckState::Checked)) return; @@ -1478,8 +1478,8 @@ namespace Slang // Check if two functions have the same signature for the purposes // of overload resolution. bool DoFunctionSignaturesMatch( - FunctionSyntaxNode* fst, - FunctionSyntaxNode* snd) + FuncDecl* fst, + FuncDecl* snd) { // TODO(tfoley): This function won't do anything sensible for generics, // so we need to figure out a plan for that... @@ -1501,7 +1501,7 @@ namespace Slang auto sndParam = sndParams[ii]; // If a given parameter type doesn't match, then signatures don't match - if (!fstParam->Type.Equals(sndParam->Type)) + if (!fstParam->type.Equals(sndParam->type)) return false; // If one parameter is `out` and the other isn't, then they don't match @@ -1518,7 +1518,7 @@ namespace Slang return true; } - void ValidateFunctionRedeclaration(FunctionSyntaxNode* funcDecl) + void ValidateFunctionRedeclaration(FuncDecl* funcDecl) { auto parentDecl = funcDecl->ParentDecl; SLANG_RELEASE_ASSERT(parentDecl); @@ -1538,7 +1538,7 @@ namespace Slang // We only care about previously-declared functions // Note(tfoley): although we should really error out if the // name is already in use for something else, like a variable... - auto prevFuncDecl = dynamic_cast<FunctionSyntaxNode*>(prevDecl); + auto prevFuncDecl = dynamic_cast<FuncDecl*>(prevDecl); if (!prevFuncDecl) continue; @@ -1592,12 +1592,12 @@ namespace Slang // Nothing to do } - void visitParameterSyntaxNode(ParameterSyntaxNode* para) + void visitParamDecl(ParamDecl* para) { // TODO: This needs to bottleneck through the common variable checks - para->Type = CheckUsableType(para->Type); - if (para->Type.Equals(getSession()->getVoidType())) + para->type = CheckUsableType(para->type); + if (para->type.Equals(getSession()->getVoidType())) { if (!isRewriteMode()) { @@ -1606,7 +1606,7 @@ namespace Slang } } - void VisitFunctionDeclaration(FunctionSyntaxNode *functionNode) + void VisitFunctionDeclaration(FuncDecl *functionNode) { if (functionNode->IsChecked(DeclCheckState::CheckedHeader)) return; functionNode->SetCheckState(DeclCheckState::CheckingHeader); @@ -1636,7 +1636,7 @@ namespace Slang ValidateFunctionRedeclaration(functionNode); } - void visitVarDeclrStatementSyntaxNode(VarDeclrStatementSyntaxNode* stmt) + void visitDeclStmt(DeclStmt* stmt) { // We directly dispatch here instead of using `EnsureDecl()` for two // reasons: @@ -1677,7 +1677,7 @@ namespace Slang return nullptr; } - void visitBreakStatementSyntaxNode(BreakStatementSyntaxNode *stmt) + void visitBreakStmt(BreakStmt *stmt) { auto outer = FindOuterStmt<BreakableStmt>(); if (!outer) @@ -1689,7 +1689,7 @@ namespace Slang } stmt->parentStmt = outer; } - void visitContinueStatementSyntaxNode(ContinueStatementSyntaxNode *stmt) + void visitContinueStmt(ContinueStmt *stmt) { auto outer = FindOuterStmt<LoopStmt>(); if (!outer) @@ -1702,25 +1702,25 @@ namespace Slang stmt->parentStmt = outer; } - void PushOuterStmt(StatementSyntaxNode* stmt) + void PushOuterStmt(Stmt* stmt) { outerStmts.Add(stmt); } - void PopOuterStmt(StatementSyntaxNode* /*stmt*/) + void PopOuterStmt(Stmt* /*stmt*/) { outerStmts.RemoveAt(outerStmts.Count() - 1); } - RefPtr<ExpressionSyntaxNode> checkPredicateExpr(ExpressionSyntaxNode* expr) + RefPtr<Expr> checkPredicateExpr(Expr* expr) { - RefPtr<ExpressionSyntaxNode> e = expr; + RefPtr<Expr> e = expr; e = CheckTerm(e); e = Coerce(getSession()->getBoolType(), e); return e; } - void visitDoWhileStatementSyntaxNode(DoWhileStatementSyntaxNode *stmt) + void visitDoWhileStmt(DoWhileStmt *stmt) { PushOuterStmt(stmt); stmt->Predicate = checkPredicateExpr(stmt->Predicate); @@ -1728,7 +1728,7 @@ namespace Slang PopOuterStmt(stmt); } - void visitForStatementSyntaxNode(ForStatementSyntaxNode *stmt) + void visitForStmt(ForStmt *stmt) { PushOuterStmt(stmt); checkStmt(stmt->InitialStatement); @@ -1745,7 +1745,7 @@ namespace Slang PopOuterStmt(stmt); } - RefPtr<ExpressionSyntaxNode> checkExpressionAndExpectIntegerConstant(RefPtr<ExpressionSyntaxNode> expr, RefPtr<IntVal>* outIntVal) + RefPtr<Expr> checkExpressionAndExpectIntegerConstant(RefPtr<Expr> expr, RefPtr<IntVal>* outIntVal) { expr = CheckExpr(expr); auto intVal = CheckIntegerConstantExpression(expr); @@ -1758,7 +1758,7 @@ namespace Slang { PushOuterStmt(stmt); - stmt->varDecl->Type.type = getSession()->getIntType(); + stmt->varDecl->type.type = getSession()->getIntType(); addModifier(stmt->varDecl, new ConstModifier()); RefPtr<IntVal> rangeBeginVal; @@ -1834,7 +1834,7 @@ namespace Slang } stmt->parentStmt = switchStmt; } - void visitIfStatementSyntaxNode(IfStatementSyntaxNode *stmt) + void visitIfStmt(IfStmt *stmt) { stmt->Predicate = checkPredicateExpr(stmt->Predicate); checkStmt(stmt->PositiveStatement); @@ -1846,17 +1846,17 @@ namespace Slang // Nothing to do } - void visitEmptyStatementSyntaxNode(EmptyStatementSyntaxNode*) + void visitEmptyStmt(EmptyStmt*) { // Nothing to do } - void visitDiscardStatementSyntaxNode(DiscardStatementSyntaxNode*) + void visitDiscardStmt(DiscardStmt*) { // Nothing to do } - void visitReturnStatementSyntaxNode(ReturnStatementSyntaxNode *stmt) + void visitReturnStmt(ReturnStmt *stmt) { if (!stmt->Expression) { @@ -1871,7 +1871,7 @@ namespace Slang else { stmt->Expression = CheckTerm(stmt->Expression); - if (!stmt->Expression->Type->Equals(getSession()->getErrorType())) + if (!stmt->Expression->type->Equals(getSession()->getErrorType())) { if (function) { @@ -1901,7 +1901,7 @@ namespace Slang void maybeInferArraySizeForVariable(Variable* varDecl) { // Not an array? - auto arrayType = varDecl->Type->AsArrayType(); + auto arrayType = varDecl->type->AsArrayType(); if (!arrayType) return; // Explicit element count given? @@ -1909,7 +1909,7 @@ namespace Slang if (elementCount) return; // No initializer? - auto initExpr = varDecl->Expr; + auto initExpr = varDecl->initExpr; if(!initExpr) return; // Is the initializer an initializer list? @@ -1919,7 +1919,7 @@ namespace Slang elementCount = new ConstantIntVal(argCount); } // Is the type of the initializer an array type? - else if(auto arrayInitType = initExpr->Type->As<ArrayExpressionType>()) + else if(auto arrayInitType = initExpr->type->As<ArrayExpressionType>()) { elementCount = arrayInitType->ArrayLength; } @@ -1931,14 +1931,14 @@ namespace Slang // Create a new array type based on the size we found, // and install it into our type. - varDecl->Type.type = getArrayType( + varDecl->type.type = getArrayType( arrayType->BaseType, elementCount); } void ValidateArraySizeForVariable(Variable* varDecl) { - auto arrayType = varDecl->Type->AsArrayType(); + auto arrayType = varDecl->type->AsArrayType(); if (!arrayType) return; auto elementCount = arrayType->ArrayLength; @@ -1966,7 +1966,7 @@ namespace Slang void visitVariable(Variable* varDecl) { - TypeExp typeExp = CheckUsableType(varDecl->Type); + TypeExp typeExp = CheckUsableType(varDecl->type); #if 0 if (typeExp.type->GetBindableResourceType() != BindableResourceType::NonBindable) { @@ -1974,12 +1974,12 @@ namespace Slang auto parentDecl = varDecl->ParentDecl; if (auto parentScopeDecl = dynamic_cast<ScopeDecl*>(parentDecl)) { - getSink()->diagnose(varDecl->Type, Diagnostics::invalidTypeForLocalVariable); + getSink()->diagnose(varDecl->type, Diagnostics::invalidTypeForLocalVariable); } } #endif - varDecl->Type = typeExp; - if (varDecl->Type.Equals(getSession()->getVoidType())) + varDecl->type = typeExp; + if (varDecl->type.Equals(getSession()->getVoidType())) { if (!isRewriteMode()) { @@ -1987,10 +1987,10 @@ namespace Slang } } - if(auto initExpr = varDecl->Expr) + if(auto initExpr = varDecl->initExpr) { initExpr = CheckTerm(initExpr); - varDecl->Expr = initExpr; + varDecl->initExpr = initExpr; } // If this is an array variable, then we first want to give @@ -2007,63 +2007,63 @@ namespace Slang ValidateArraySizeForVariable(varDecl); - if(auto initExpr = varDecl->Expr) + if(auto initExpr = varDecl->initExpr) { // TODO(tfoley): should coercion of initializer lists be special-cased // here, or handled as a general case for coercion? - initExpr = Coerce(varDecl->Type.Ptr(), initExpr); - varDecl->Expr = initExpr; + initExpr = Coerce(varDecl->type.Ptr(), initExpr); + varDecl->initExpr = initExpr; } varDecl->SetCheckState(DeclCheckState::Checked); } - void visitWhileStatementSyntaxNode(WhileStatementSyntaxNode *stmt) + void visitWhileStmt(WhileStmt *stmt) { PushOuterStmt(stmt); stmt->Predicate = checkPredicateExpr(stmt->Predicate); checkStmt(stmt->Statement); PopOuterStmt(stmt); } - void visitExpressionStatementSyntaxNode(ExpressionStatementSyntaxNode *stmt) + void visitExpressionStmt(ExpressionStmt *stmt) { stmt->Expression = CheckExpr(stmt->Expression); } - RefPtr<ExpressionSyntaxNode> visitConstantExpressionSyntaxNode(ConstantExpressionSyntaxNode *expr) + RefPtr<Expr> visitConstantExpr(ConstantExpr *expr) { // The expression might already have a type, determined by its suffix - if(expr->Type.type) + if(expr->type.type) return expr; switch (expr->ConstType) { - case ConstantExpressionSyntaxNode::ConstantType::Int: - expr->Type = getSession()->getIntType(); + case ConstantExpr::ConstantType::Int: + expr->type = getSession()->getIntType(); break; - case ConstantExpressionSyntaxNode::ConstantType::Bool: - expr->Type = getSession()->getBoolType(); + case ConstantExpr::ConstantType::Bool: + expr->type = getSession()->getBoolType(); break; - case ConstantExpressionSyntaxNode::ConstantType::Float: - expr->Type = getSession()->getFloatType(); + case ConstantExpr::ConstantType::Float: + expr->type = getSession()->getFloatType(); break; default: - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); throw "Invalid constant type."; break; } return expr; } - IntVal* GetIntVal(ConstantExpressionSyntaxNode* expr) + IntVal* GetIntVal(ConstantExpr* expr) { // TODO(tfoley): don't keep allocating here! return new ConstantIntVal(expr->integerValue); } RefPtr<IntVal> TryConstantFoldExpr( - InvokeExpressionSyntaxNode* invokeExpr) + InvokeExpr* invokeExpr) { // We need all the operands to the expression @@ -2174,7 +2174,7 @@ namespace Slang } RefPtr<IntVal> TryConstantFoldExpr( - ExpressionSyntaxNode* expr) + Expr* expr) { // Unwrap any "identity" expressions while (auto parenExpr = dynamic_cast<ParenExpr*>(expr)) @@ -2183,7 +2183,7 @@ namespace Slang } // TODO(tfoley): more serious constant folding here - if (auto constExp = dynamic_cast<ConstantExpressionSyntaxNode*>(expr)) + if (auto constExp = dynamic_cast<ConstantExpr*>(expr)) { return GetIntVal(constExp); } @@ -2259,13 +2259,13 @@ namespace Slang } } - if (auto invokeExpr = dynamic_cast<InvokeExpressionSyntaxNode*>(expr)) + if (auto invokeExpr = dynamic_cast<InvokeExpr*>(expr)) { auto val = TryConstantFoldExpr(invokeExpr); if (val) return val; } - else if(auto castExpr = dynamic_cast<TypeCastExpressionSyntaxNode*>(expr)) + else if(auto castExpr = dynamic_cast<TypeCastExpr*>(expr)) { auto val = TryConstantFoldExpr(castExpr->Expression.Ptr()); if(val) @@ -2277,9 +2277,9 @@ namespace Slang // Try to check an integer constant expression, either returning the value, // or NULL if the expression isn't recognized as a constant. - RefPtr<IntVal> TryCheckIntegerConstantExpression(ExpressionSyntaxNode* exp) + RefPtr<IntVal> TryCheckIntegerConstantExpression(Expr* exp) { - if (!exp->Type.type->Equals(getSession()->getIntType())) + if (!exp->type.type->Equals(getSession()->getIntType())) { return nullptr; } @@ -2291,7 +2291,7 @@ namespace Slang } // Enforce that an expression resolves to an integer constant, and get its value - RefPtr<IntVal> CheckIntegerConstantExpression(ExpressionSyntaxNode* inExpr) + RefPtr<IntVal> CheckIntegerConstantExpression(Expr* inExpr) { // First coerce the expression to the expected type auto expr = Coerce(getSession()->getIntType(),inExpr); @@ -2308,15 +2308,15 @@ namespace Slang - RefPtr<ExpressionSyntaxNode> CheckSimpleSubscriptExpr( - RefPtr<IndexExpressionSyntaxNode> subscriptExpr, - RefPtr<ExpressionType> elementType) + RefPtr<Expr> CheckSimpleSubscriptExpr( + RefPtr<IndexExpr> subscriptExpr, + RefPtr<Type> elementType) { auto baseExpr = subscriptExpr->BaseExpression; auto indexExpr = subscriptExpr->IndexExpression; - if (!indexExpr->Type->Equals(getSession()->getIntType()) && - !indexExpr->Type->Equals(getSession()->getUIntType())) + if (!indexExpr->type->Equals(getSession()->getIntType()) && + !indexExpr->type->Equals(getSession()->getUIntType())) { if (!isRewriteMode()) { @@ -2325,10 +2325,10 @@ namespace Slang return CreateErrorExpr(subscriptExpr.Ptr()); } - subscriptExpr->Type = QualType(elementType); + subscriptExpr->type = QualType(elementType); // TODO(tfoley): need to be more careful about this stuff - subscriptExpr->Type.IsLeftValue = baseExpr->Type.IsLeftValue; + subscriptExpr->type.IsLeftValue = baseExpr->type.IsLeftValue; return subscriptExpr; } @@ -2344,7 +2344,7 @@ namespace Slang // programmatically, so that it will work just like a type of // that form constructed by the user. RefPtr<VectorExpressionType> createVectorType( - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, RefPtr<IntVal> elementCount) { auto session = getSession(); @@ -2364,12 +2364,12 @@ namespace Slang declRef)->As<VectorExpressionType>(); } - RefPtr<ExpressionSyntaxNode> visitIndexExpressionSyntaxNode(IndexExpressionSyntaxNode* subscriptExpr) + RefPtr<Expr> visitIndexExpr(IndexExpr* subscriptExpr) { auto baseExpr = subscriptExpr->BaseExpression; baseExpr = CheckExpr(baseExpr); - RefPtr<ExpressionSyntaxNode> indexExpr = subscriptExpr->IndexExpression; + RefPtr<Expr> indexExpr = subscriptExpr->IndexExpression; if (indexExpr) { indexExpr = CheckExpr(indexExpr); @@ -2385,7 +2385,7 @@ namespace Slang // Otherwise, we need to look at the type of the base expression, // to figure out how subscripting should work. - auto baseType = baseExpr->Type.Ptr(); + auto baseType = baseExpr->type.Ptr(); if (auto baseTypeType = baseType->As<TypeType>()) { // We are trying to "index" into a type, so we have an expression like `float[2]` @@ -2403,7 +2403,7 @@ namespace Slang elementCount); typeResult = arrayType; - subscriptExpr->Type = QualType(getTypeType(arrayType)); + subscriptExpr->type = QualType(getTypeType(arrayType)); return subscriptExpr; } else if (auto baseArrayType = baseType->As<ArrayExpressionType>()) @@ -2451,13 +2451,13 @@ namespace Slang goto fail; } - RefPtr<ExpressionSyntaxNode> subscriptFuncExpr = createLookupResultExpr( + RefPtr<Expr> subscriptFuncExpr = createLookupResultExpr( lookupResult, subscriptExpr->BaseExpression, subscriptExpr); // Now that we know there is at least one subscript member, // we will construct a reference to it and try to call it - RefPtr<InvokeExpressionSyntaxNode> subscriptCallExpr = new InvokeExpressionSyntaxNode(); + RefPtr<InvokeExpr> subscriptCallExpr = new InvokeExpr(); subscriptCallExpr->Position = subscriptExpr->Position; subscriptCallExpr->FunctionExpr = subscriptFuncExpr; @@ -2478,14 +2478,14 @@ namespace Slang } } - bool MatchArguments(FunctionSyntaxNode * functionNode, List <RefPtr<ExpressionSyntaxNode>> &args) + bool MatchArguments(FuncDecl * functionNode, List <RefPtr<Expr>> &args) { if (functionNode->GetParameters().Count() != args.Count()) return false; int i = 0; for (auto param : functionNode->GetParameters()) { - if (!param->Type.Equals(args[i]->Type.Ptr())) + if (!param->type.Equals(args[i]->type.Ptr())) return false; i++; } @@ -2493,31 +2493,31 @@ namespace Slang } // Coerce an expression to a specific type that it is expected to have in context - RefPtr<ExpressionSyntaxNode> CoerceExprToType( - RefPtr<ExpressionSyntaxNode> expr, - RefPtr<ExpressionType> type) + RefPtr<Expr> CoerceExprToType( + RefPtr<Expr> expr, + RefPtr<Type> type) { // TODO(tfoley): clean this up so there is only one version... return Coerce(type, expr); } - RefPtr<ExpressionSyntaxNode> visitParenExpr(ParenExpr* expr) + RefPtr<Expr> visitParenExpr(ParenExpr* expr) { auto base = expr->base; base = CheckTerm(base); expr->base = base; - expr->Type = base->Type; + expr->type = base->type; return expr; } // - RefPtr<ExpressionSyntaxNode> visitAssignExpr(AssignExpr* expr) + RefPtr<Expr> visitAssignExpr(AssignExpr* expr) { expr->left = CheckExpr(expr->left); - auto type = expr->left->Type; + auto type = expr->left->type; expr->right = Coerce(type, CheckTerm(expr->right)); @@ -2532,7 +2532,7 @@ namespace Slang getSink()->diagnose(expr, Diagnostics::assignNonLValue); } } - expr->Type = type; + expr->type = type; return expr; } @@ -2595,7 +2595,7 @@ namespace Slang for (auto& paramDecl : decl->GetParameters()) { - paramDecl->Type = CheckUsableType(paramDecl->Type); + paramDecl->type = CheckUsableType(paramDecl->type); } decl->SetCheckState(DeclCheckState::CheckedHeader); @@ -2611,7 +2611,7 @@ namespace Slang for (auto& paramDecl : decl->GetParameters()) { - paramDecl->Type = CheckUsableType(paramDecl->Type); + paramDecl->type = CheckUsableType(paramDecl->type); } decl->ReturnType = CheckUsableType(decl->ReturnType); @@ -2645,7 +2645,7 @@ namespace Slang List<Constraint> constraints; }; - RefPtr<ExpressionType> TryJoinVectorAndScalarType( + RefPtr<Type> TryJoinVectorAndScalarType( RefPtr<VectorExpressionType> vectorType, RefPtr<BasicExpressionType> scalarType) { @@ -2665,7 +2665,7 @@ namespace Slang } bool DoesTypeConformToInterface( - RefPtr<ExpressionType> type, + RefPtr<Type> type, DeclRef<InterfaceDecl> interfaceDeclRef) { // for now look up a conformance member... @@ -2691,8 +2691,8 @@ namespace Slang return false; } - RefPtr<ExpressionType> TryJoinTypeWithInterface( - RefPtr<ExpressionType> type, + RefPtr<Type> TryJoinTypeWithInterface( + RefPtr<Type> type, DeclRef<InterfaceDecl> interfaceDeclRef) { // The most basic test here should be: does the type declare conformance to the trait. @@ -2710,9 +2710,9 @@ namespace Slang } // Try to compute the "join" between two types - RefPtr<ExpressionType> TryJoinTypes( - RefPtr<ExpressionType> left, - RefPtr<ExpressionType> right) + RefPtr<Type> TryJoinTypes( + RefPtr<Type> left, + RefPtr<Type> right) { // Easy case: they are the same type! if (left->Equals(right)) @@ -2828,13 +2828,13 @@ namespace Slang { if (auto typeParam = m.As<GenericTypeParamDecl>()) { - RefPtr<ExpressionType> type = nullptr; + RefPtr<Type> type = nullptr; for (auto& c : system->constraints) { if (c.decl != typeParam.getDecl()) continue; - auto cType = c.val.As<ExpressionType>(); + auto cType = c.val.As<Type>(); SLANG_RELEASE_ASSERT(cType.Ptr()); if (!type) @@ -2952,7 +2952,7 @@ namespace Slang LookupResultItem item; // The type of the result expression if this candidate is selected - RefPtr<ExpressionType> resultType; + RefPtr<Type> resultType; // A system for tracking constraints introduced on generic parameters ConstraintSystem constraintSystem; @@ -2978,7 +2978,7 @@ namespace Slang }; RefPtr<AppExprBase> appExpr; - RefPtr<ExpressionSyntaxNode> baseExpr; + RefPtr<Expr> baseExpr; // Are we still trying out candidates, or are we // checking the chosen one for real? @@ -3000,7 +3000,7 @@ namespace Slang }; // count the number of parameters required/allowed for a callable - ParamCounts CountParameters(FilteredMemberRefList<ParameterSyntaxNode> params) + ParamCounts CountParameters(FilteredMemberRefList<ParamDecl> params) { ParamCounts counts = { 0, 0 }; for (auto param : params) @@ -3017,7 +3017,7 @@ namespace Slang // 2. We are not handling the possibility of multiple declarations for // a single function, where we'd need to merge default parameters across // all the declarations. - if (!param.getDecl()->Expr) + if (!param.getDecl()->initExpr) { counts.required++; } @@ -3042,7 +3042,7 @@ namespace Slang else if (auto valParam = m.As<GenericValueParamDecl>()) { counts.allowed++; - if (!valParam->Expr) + if (!valParam->initExpr) { counts.required++; } @@ -3180,7 +3180,7 @@ namespace Slang if (context.mode == OverloadResolveContext::Mode::JustTrying) { ConversionCost cost = kConversionCost_None; - if (!CanCoerce(GetType(valParamRef), arg->Type, &cost)) + if (!CanCoerce(GetType(valParamRef), arg->type, &cost)) { return false; } @@ -3208,7 +3208,7 @@ namespace Slang auto& args = context.appExpr->Arguments; UInt argCount = args.Count(); - List<DeclRef<ParameterSyntaxNode>> params; + List<DeclRef<ParamDecl>> params; switch (candidate.flavor) { case OverloadCandidate::Flavor::Func: @@ -3235,7 +3235,7 @@ namespace Slang if (context.mode == OverloadResolveContext::Mode::JustTrying) { ConversionCost cost = kConversionCost_None; - if (!CanCoerce(GetType(param), arg->Type, &cost)) + if (!CanCoerce(GetType(param), arg->type, &cost)) { return false; } @@ -3282,8 +3282,8 @@ namespace Slang } // Create the representation of a given generic applied to some arguments - RefPtr<ExpressionSyntaxNode> CreateGenericDeclRef( - RefPtr<ExpressionSyntaxNode> baseExpr, + RefPtr<Expr> CreateGenericDeclRef( + RefPtr<Expr> baseExpr, RefPtr<AppExprBase> appExpr) { auto baseDeclRefExpr = baseExpr.As<DeclRefExpr>(); @@ -3322,7 +3322,7 @@ namespace Slang // // If the candidate isn't actually applicable, this is // where we'd start reporting the issue(s). - RefPtr<ExpressionSyntaxNode> CompleteOverloadCandidate( + RefPtr<Expr> CompleteOverloadCandidate( OverloadResolveContext& context, OverloadCandidate& candidate) { @@ -3344,7 +3344,7 @@ namespace Slang } context.mode = OverloadResolveContext::Mode::ForReal; - context.appExpr->Type = QualType(getSession()->getErrorType()); + context.appExpr->type = QualType(getSession()->getErrorType()); if (!TryCheckOverloadCandidateArity(context, candidate)) goto error; @@ -3366,14 +3366,14 @@ namespace Slang { case OverloadCandidate::Flavor::Func: context.appExpr->FunctionExpr = baseExpr; - context.appExpr->Type = QualType(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>()) { for(auto setter : subscriptDeclRef.getDecl()->getMembersOfType<SetterDecl>()) { - context.appExpr->Type.IsLeftValue = true; + context.appExpr->type.IsLeftValue = true; } } @@ -3550,7 +3550,7 @@ namespace Slang void AddCtorOverloadCandidate( LookupResultItem typeItem, - RefPtr<ExpressionType> type, + RefPtr<Type> type, DeclRef<ConstructorDecl> ctorDeclRef, OverloadResolveContext& context) { @@ -3590,9 +3590,9 @@ namespace Slang RefPtr<Val> snd) { // if both values are types, then unify types - if (auto fstType = fst.As<ExpressionType>()) + if (auto fstType = fst.As<Type>()) { - if (auto sndType = snd.As<ExpressionType>()) + if (auto sndType = snd.As<Type>()) { return TryUnifyTypes(constraints, fstType, sndType); } @@ -3663,7 +3663,7 @@ namespace Slang bool TryUnifyTypeParam( ConstraintSystem& constraints, RefPtr<GenericTypeParamDecl> typeParamDecl, - RefPtr<ExpressionType> type) + RefPtr<Type> type) { // We want to constrain the given type parameter // to equal the given type. @@ -3708,8 +3708,8 @@ namespace Slang bool TryUnifyTypesByStructuralMatch( ConstraintSystem& constraints, - RefPtr<ExpressionType> fst, - RefPtr<ExpressionType> snd) + RefPtr<Type> fst, + RefPtr<Type> snd) { if (auto fstDeclRefType = fst->As<DeclRefType>()) { @@ -3747,8 +3747,8 @@ namespace Slang bool TryUnifyTypes( ConstraintSystem& constraints, - RefPtr<ExpressionType> fst, - RefPtr<ExpressionType> snd) + RefPtr<Type> fst, + RefPtr<Type> snd) { if (fst->Equals(snd)) return true; @@ -3819,7 +3819,7 @@ namespace Slang // Is the candidate extension declaration actually applicable to the given type DeclRef<ExtensionDecl> ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr<ExpressionType> type) + RefPtr<Type> type) { if (auto extGenericDecl = GetOuterGeneric(extDecl)) { @@ -3856,13 +3856,13 @@ namespace Slang bool TryUnifyArgAndParamTypes( ConstraintSystem& system, - RefPtr<ExpressionSyntaxNode> argExpr, - DeclRef<ParameterSyntaxNode> paramDeclRef) + RefPtr<Expr> argExpr, + DeclRef<ParamDecl> paramDeclRef) { // TODO(tfoley): potentially need a bit more // nuance in case where argument might be // an overload group... - return TryUnifyTypes(system, argExpr->Type, GetType(paramDeclRef)); + return TryUnifyTypes(system, argExpr->type, GetType(paramDeclRef)); } // Take a generic declaration and try to specialize its parameters @@ -3945,7 +3945,7 @@ namespace Slang void AddAggTypeOverloadCandidates( LookupResultItem typeItem, - RefPtr<ExpressionType> type, + RefPtr<Type> type, DeclRef<AggTypeDecl> aggTypeDeclRef, OverloadResolveContext& context) { @@ -3990,7 +3990,7 @@ namespace Slang } void AddTypeOverloadCandidates( - RefPtr<ExpressionType> type, + RefPtr<Type> type, OverloadResolveContext& context) { if (auto declRefType = type->As<DeclRefType>()) @@ -4059,10 +4059,10 @@ namespace Slang } void AddOverloadCandidates( - RefPtr<ExpressionSyntaxNode> funcExpr, + RefPtr<Expr> funcExpr, OverloadResolveContext& context) { - auto funcExprType = funcExpr->Type; + auto funcExprType = funcExpr->type; if (auto funcDeclRefExpr = funcExpr.As<DeclRefExpr>()) { @@ -4096,7 +4096,7 @@ namespace Slang } } - void formatType(StringBuilder& sb, RefPtr<ExpressionType> type) + void formatType(StringBuilder& sb, RefPtr<Type> type) { sb << type->ToString(); } @@ -4228,7 +4228,7 @@ namespace Slang for (auto a : expr->Arguments) { if (!first) argsListBuilder << ", "; - argsListBuilder << a->Type->ToString(); + argsListBuilder << a->type->ToString(); first = false; } argsListBuilder << ")"; @@ -4236,11 +4236,11 @@ namespace Slang } - RefPtr<ExpressionSyntaxNode> ResolveInvoke(InvokeExpressionSyntaxNode * expr) + RefPtr<Expr> ResolveInvoke(InvokeExpr * expr) { // Look at the base expression for the call, and figure out how to invoke it. auto funcExpr = expr->FunctionExpr; - auto funcExprType = funcExpr->Type; + auto funcExprType = funcExpr->type; // If we are trying to apply an erroroneous expression, then just bail out now. if(IsErrorExpr(funcExpr)) @@ -4258,7 +4258,7 @@ namespace Slang OverloadResolveContext context; context.appExpr = expr; - if (auto funcMemberExpr = funcExpr.As<MemberExpressionSyntaxNode>()) + if (auto funcMemberExpr = funcExpr.As<MemberExpr>()) { context.baseExpr = funcMemberExpr->BaseExpression; } @@ -4287,9 +4287,9 @@ namespace Slang } String funcName; - if (auto baseVar = funcExpr.As<VarExpressionSyntaxNode>()) + if (auto baseVar = funcExpr.As<VarExpr>()) funcName = baseVar->name; - else if(auto baseMemberRef = funcExpr.As<MemberExpressionSyntaxNode>()) + else if(auto baseMemberRef = funcExpr.As<MemberExpr>()) funcName = baseMemberRef->name; String argsList = GetCallSignatureString(expr); @@ -4373,7 +4373,7 @@ namespace Slang { getSink()->diagnose(expr->FunctionExpr, Diagnostics::expectedFunction); } - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); return expr; } } @@ -4396,7 +4396,7 @@ namespace Slang } void AddGenericOverloadCandidates( - RefPtr<ExpressionSyntaxNode> baseExpr, + RefPtr<Expr> baseExpr, OverloadResolveContext& context) { if(auto baseDeclRefExpr = baseExpr.As<DeclRefExpr>()) @@ -4419,7 +4419,7 @@ namespace Slang } } - RefPtr<ExpressionSyntaxNode> visitGenericAppExpr(GenericAppExpr * genericAppExpr) + RefPtr<Expr> visitGenericAppExpr(GenericAppExpr * genericAppExpr) { // We are applying a generic to arguments, but there might be multiple generic // declarations with the same name, so this becomes a specialized case of @@ -4509,12 +4509,12 @@ namespace Slang } } - RefPtr<ExpressionSyntaxNode> visitSharedTypeExpr(SharedTypeExpr* expr) + RefPtr<Expr> visitSharedTypeExpr(SharedTypeExpr* expr) { - if (!expr->Type.Ptr()) + if (!expr->type.Ptr()) { expr->base = CheckProperType(expr->base); - expr->Type = expr->base.exp->Type; + expr->type = expr->base.exp->type; } return expr; } @@ -4522,7 +4522,7 @@ namespace Slang - RefPtr<ExpressionSyntaxNode> CheckExpr(RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> CheckExpr(RefPtr<Expr> expr) { auto term = CheckTerm(expr); @@ -4532,17 +4532,17 @@ namespace Slang return term; } - RefPtr<ExpressionSyntaxNode> CheckInvokeExprWithCheckedOperands(InvokeExpressionSyntaxNode *expr) + RefPtr<Expr> CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) { auto rs = ResolveInvoke(expr); - if (auto invoke = dynamic_cast<InvokeExpressionSyntaxNode*>(rs.Ptr())) + if (auto invoke = dynamic_cast<InvokeExpr*>(rs.Ptr())) { // if this is still an invoke expression, test arguments passed to inout/out parameter are LValues - if(auto funcType = invoke->FunctionExpr->Type->As<FuncType>()) + if(auto funcType = invoke->FunctionExpr->type->As<FuncType>()) { - List<RefPtr<ParameterSyntaxNode>> paramsStorage; - List<RefPtr<ParameterSyntaxNode>> * params = nullptr; + List<RefPtr<ParamDecl>> paramsStorage; + List<RefPtr<ParamDecl>> * params = nullptr; if (auto func = funcType->declRef.getDecl()) { paramsStorage = func->GetParameters().ToArray(); @@ -4554,8 +4554,8 @@ namespace Slang { if ((*params)[i]->HasModifier<OutModifier>()) { - if (i < expr->Arguments.Count() && expr->Arguments[i]->Type->AsBasicType() && - !expr->Arguments[i]->Type.IsLeftValue) + if (i < expr->Arguments.Count() && expr->Arguments[i]->type->AsBasicType() && + !expr->Arguments[i]->type.IsLeftValue) { if (!isRewriteMode()) { @@ -4570,7 +4570,7 @@ namespace Slang return rs; } - RefPtr<ExpressionSyntaxNode> visitInvokeExpressionSyntaxNode(InvokeExpressionSyntaxNode *expr) + RefPtr<Expr> visitInvokeExpr(InvokeExpr *expr) { // check the base expression first expr->FunctionExpr = CheckExpr(expr->FunctionExpr); @@ -4585,13 +4585,13 @@ namespace Slang } - RefPtr<ExpressionSyntaxNode> visitVarExpressionSyntaxNode(VarExpressionSyntaxNode *expr) + RefPtr<Expr> visitVarExpr(VarExpr *expr) { // If we've already resolved this expression, don't try again. if (expr->declRef) return expr; - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); auto lookupResult = LookUp( getSession(), @@ -4612,22 +4612,22 @@ namespace Slang return expr; } - RefPtr<ExpressionSyntaxNode> visitTypeCastExpressionSyntaxNode(TypeCastExpressionSyntaxNode * expr) + RefPtr<Expr> visitTypeCastExpr(TypeCastExpr * expr) { expr->Expression = CheckTerm(expr->Expression); auto targetType = CheckProperType(expr->TargetType); expr->TargetType = targetType; // The way to perform casting depends on the types involved - if (expr->Expression->Type->Equals(getSession()->getErrorType())) + if (expr->Expression->type->Equals(getSession()->getErrorType())) { // If the expression being casted has an error type, then just silently succeed - expr->Type = targetType.Ptr(); + expr->type = targetType.Ptr(); return expr; } else if (auto targetArithType = targetType->AsArithmeticType()) { - if (auto exprArithType = expr->Expression->Type->AsArithmeticType()) + if (auto exprArithType = expr->Expression->type->AsArithmeticType()) { // Both source and destination types are arithmetic, so we might // have a valid cast @@ -4639,7 +4639,7 @@ namespace Slang // TODO(tfoley): this checking is incomplete here, and could // lead to downstream compilation failures - expr->Type = targetType.Ptr(); + expr->type = targetType.Ptr(); return expr; } } @@ -4650,9 +4650,9 @@ namespace Slang // Default: in no other case succeds, then the cast failed and we emit a diagnostic. if (!isRewriteMode()) { - getSink()->diagnose(expr, Diagnostics::invalidTypeCast, expr->Expression->Type, targetType->ToString()); + getSink()->diagnose(expr, Diagnostics::invalidTypeCast, expr->Expression->type, targetType->ToString()); } - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); return expr; } @@ -4673,25 +4673,25 @@ namespace Slang // deal with this cases here, even if they are no-ops. // - RefPtr<ExpressionSyntaxNode> visitDerefExpr(DerefExpr* expr) + RefPtr<Expr> visitDerefExpr(DerefExpr* expr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), expr, "should not appear in input syntax"); return expr; } - RefPtr<ExpressionSyntaxNode> visitSwizzleExpr(SwizzleExpr* expr) + RefPtr<Expr> visitSwizzleExpr(SwizzleExpr* expr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), expr, "should not appear in input syntax"); return expr; } - RefPtr<ExpressionSyntaxNode> visitOverloadedExpr(OverloadedExpr* expr) + RefPtr<Expr> visitOverloadedExpr(OverloadedExpr* expr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), expr, "should not appear in input syntax"); return expr; } - RefPtr<ExpressionSyntaxNode> visitAggTypeCtorExpr(AggTypeCtorExpr* expr) + RefPtr<Expr> visitAggTypeCtorExpr(AggTypeCtorExpr* expr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), expr, "should not appear in input syntax"); return expr; @@ -4701,19 +4701,19 @@ namespace Slang // // - RefPtr<ExpressionSyntaxNode> MaybeDereference(RefPtr<ExpressionSyntaxNode> inExpr) + RefPtr<Expr> MaybeDereference(RefPtr<Expr> inExpr) { - RefPtr<ExpressionSyntaxNode> expr = inExpr; + RefPtr<Expr> expr = inExpr; for (;;) { - auto& type = expr->Type; + auto& type = expr->type; if (auto pointerLikeType = type->As<PointerLikeType>()) { type = QualType(pointerLikeType->elementType); auto derefExpr = new DerefExpr(); derefExpr->base = expr; - derefExpr->Type = QualType(pointerLikeType->elementType); + derefExpr->type = QualType(pointerLikeType->elementType); // TODO(tfoley): deal with l-value-ness here @@ -4726,9 +4726,9 @@ namespace Slang } } - RefPtr<ExpressionSyntaxNode> CheckSwizzleExpr( - MemberExpressionSyntaxNode* memberRefExpr, - RefPtr<ExpressionType> baseElementType, + RefPtr<Expr> CheckSwizzleExpr( + MemberExpr* memberRefExpr, + RefPtr<Type> baseElementType, IntegerLiteralValue baseElementCount) { RefPtr<SwizzleExpr> swizExpr = new SwizzleExpr(); @@ -4806,27 +4806,27 @@ 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 = QualType(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 = QualType(createVectorType( + swizExpr->type = QualType(createVectorType( baseElementType, new ConstantIntVal(elementCount))); } // A swizzle can be used as an l-value as long as there // were no duplicates in the list of components - swizExpr->Type.IsLeftValue = !anyDuplicates; + swizExpr->type.IsLeftValue = !anyDuplicates; return swizExpr; } - RefPtr<ExpressionSyntaxNode> CheckSwizzleExpr( - MemberExpressionSyntaxNode* memberRefExpr, - RefPtr<ExpressionType> baseElementType, + RefPtr<Expr> CheckSwizzleExpr( + MemberExpr* memberRefExpr, + RefPtr<Type> baseElementType, RefPtr<IntVal> baseElementCount) { if (auto constantElementCount = baseElementCount.As<ConstantIntVal>()) @@ -4844,13 +4844,13 @@ namespace Slang } - RefPtr<ExpressionSyntaxNode> visitMemberExpressionSyntaxNode(MemberExpressionSyntaxNode * expr) + RefPtr<Expr> visitMemberExpr(MemberExpr * expr) { expr->BaseExpression = CheckExpr(expr->BaseExpression); expr->BaseExpression = MaybeDereference(expr->BaseExpression); - auto & baseType = expr->BaseExpression->Type; + auto & baseType = expr->BaseExpression->type; // Note: Checking for vector types before declaration-reference types, // because vectors are also declaration reference types... @@ -4930,16 +4930,16 @@ namespace Slang { getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType); } - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); return expr; } // All remaining cases assume we have a `BasicType` else if (!baseType->AsBasicType()) - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); else - expr->Type = QualType(getSession()->getErrorType()); + expr->type = QualType(getSession()->getErrorType()); if (!baseType->Equals(getSession()->getErrorType()) && - expr->Type->Equals(getSession()->getErrorType())) + expr->type->Equals(getSession()->getErrorType())) { if (!isRewriteMode()) { @@ -4953,7 +4953,7 @@ namespace Slang // - RefPtr<ExpressionSyntaxNode> visitInitializerListExpr(InitializerListExpr* expr) + RefPtr<Expr> visitInitializerListExpr(InitializerListExpr* expr) { // When faced with an initializer list, we first just check the sub-expressions blindly. // Actually making them conform to a desired type will wait for when we know the desired @@ -4964,12 +4964,12 @@ namespace Slang arg = CheckTerm(arg); } - expr->Type = getSession()->getInitializerListType(); + expr->type = getSession()->getInitializerListType(); return expr; } - void importModuleIntoScope(Scope* scope, ProgramSyntaxNode* moduleDecl) + void importModuleIntoScope(Scope* scope, ModuleDecl* moduleDecl) { // If we've imported this one already, then // skip the step where we modify the current scope. @@ -5053,7 +5053,7 @@ namespace Slang SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef<Decl> declRef, - RefPtr<ExpressionType>* outTypeResult) + RefPtr<Type>* outTypeResult) { if( sema ) { @@ -5110,14 +5110,14 @@ namespace Slang Session* session, DeclRef<Decl> declRef) { - RefPtr<ExpressionType> typeResult; + RefPtr<Type> typeResult; return getTypeForDeclRef(session, nullptr, nullptr, declRef, &typeResult); } DeclRef<ExtensionDecl> ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr<ExpressionType> type) + RefPtr<Type> type) { if(!semantics) return DeclRef<ExtensionDecl>(); diff --git a/source/slang/compiler.h b/source/slang/compiler.h index 8fcbd444d..fd40a62f6 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -162,7 +162,7 @@ namespace Slang SlangCompileFlags compileFlags = 0; // The parsed syntax for the translation unit - RefPtr<ProgramSyntaxNode> SyntaxNode; + RefPtr<ModuleDecl> SyntaxNode; // The resulting output for the translation unit // @@ -241,13 +241,13 @@ namespace Slang // Modules that have been dynamically loaded via `import` // // This is a list of unique modules loaded, in the order they were encountered. - List<RefPtr<ProgramSyntaxNode> > loadedModulesList; + List<RefPtr<ModuleDecl> > loadedModulesList; // Map from the logical name of a module to its definition - Dictionary<String, RefPtr<ProgramSyntaxNode>> mapPathToLoadedModule; + Dictionary<String, RefPtr<ModuleDecl>> mapPathToLoadedModule; // Map from the path of a module file to its definition - Dictionary<String, RefPtr<ProgramSyntaxNode>> mapNameToLoadedModules; + Dictionary<String, RefPtr<ModuleDecl>> mapNameToLoadedModules; CompileRequest(Session* session) @@ -281,7 +281,7 @@ namespace Slang String const& name, Profile profile); - RefPtr<ProgramSyntaxNode> loadModule( + RefPtr<ModuleDecl> loadModule( String const& name, String const& path, String const& source, @@ -291,7 +291,7 @@ namespace Slang String const& path, TokenList const& tokens); - RefPtr<ProgramSyntaxNode> findOrImportModule( + RefPtr<ModuleDecl> findOrImportModule( String const& name, CodePosition const& loc); }; @@ -322,7 +322,7 @@ namespace Slang RefPtr<Scope> slangLanguageScope; RefPtr<Scope> glslLanguageScope; - List<RefPtr<ProgramSyntaxNode>> loadedModuleCode; + List<RefPtr<ModuleDecl>> loadedModuleCode; // @@ -340,27 +340,27 @@ namespace Slang String getGLSLLibraryCode(); // Basic types that we don't want to re-create all the time - RefPtr<ExpressionType> errorType; - RefPtr<ExpressionType> initializerListType; - RefPtr<ExpressionType> overloadedType; + RefPtr<Type> errorType; + RefPtr<Type> initializerListType; + RefPtr<Type> overloadedType; - Dictionary<int, RefPtr<ExpressionType>> builtinTypes; + Dictionary<int, RefPtr<Type>> builtinTypes; Dictionary<String, Decl*> magicDecls; - List<RefPtr<ExpressionType>> canonicalTypes; + List<RefPtr<Type>> canonicalTypes; void initializeTypes(); - ExpressionType* getBoolType(); - ExpressionType* getFloatType(); - ExpressionType* getDoubleType(); - ExpressionType* getIntType(); - ExpressionType* getUIntType(); - ExpressionType* getVoidType(); - ExpressionType* getBuiltinType(BaseType flavor); - - ExpressionType* getInitializerListType(); - ExpressionType* getOverloadedType(); - ExpressionType* getErrorType(); + Type* getBoolType(); + Type* getFloatType(); + Type* getDoubleType(); + Type* getIntType(); + Type* getUIntType(); + Type* getVoidType(); + Type* getBuiltinType(BaseType flavor); + + Type* getInitializerListType(); + Type* getOverloadedType(); + Type* getErrorType(); // diff --git a/source/slang/decl-defs.h b/source/slang/decl-defs.h index f2405b0f0..4f219e63c 100644 --- a/source/slang/decl-defs.h +++ b/source/slang/decl-defs.h @@ -36,15 +36,15 @@ END_SYNTAX_CLASS() // Base class for all variable-like declarations ABSTRACT_SYNTAX_CLASS(VarDeclBase, Decl) - // Type of the variable - SYNTAX_FIELD(TypeExp, Type) + // type of the variable + SYNTAX_FIELD(TypeExp, type) RAW( - ExpressionType* getType() { return Type.type.Ptr(); } + Type* getType() { return type.type.Ptr(); } ) // Initializer expression (optional) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Expr) + SYNTAX_FIELD(RefPtr<Expr>, initExpr) END_SYNTAX_CLASS() @@ -103,9 +103,9 @@ RAW( ) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(StructSyntaxNode, AggTypeDecl) +SIMPLE_SYNTAX_CLASS(StructDecl, AggTypeDecl) -SIMPLE_SYNTAX_CLASS(ClassSyntaxNode, AggTypeDecl) +SIMPLE_SYNTAX_CLASS(ClassDecl, AggTypeDecl) // An interface which other types can conform to SIMPLE_SYNTAX_CLASS(InterfaceDecl, AggTypeDecl) @@ -130,20 +130,20 @@ END_SYNTAX_CLASS() // A `typedef` declaration SYNTAX_CLASS(TypeDefDecl, SimpleTypeDecl) - SYNTAX_FIELD(TypeExp, Type) + SYNTAX_FIELD(TypeExp, type) END_SYNTAX_CLASS() // A scope for local declarations (e.g., as part of a statement) SIMPLE_SYNTAX_CLASS(ScopeDecl, ContainerDecl) -SIMPLE_SYNTAX_CLASS(ParameterSyntaxNode, VarDeclBase) +SIMPLE_SYNTAX_CLASS(ParamDecl, VarDeclBase) // Base class for things that have parameter lists and can thus be applied to arguments ("called") ABSTRACT_SYNTAX_CLASS(CallableDecl, ContainerDecl) RAW( - FilteredMemberList<ParameterSyntaxNode> GetParameters() + FilteredMemberList<ParamDecl> GetParameters() { - return getMembersOfType<ParameterSyntaxNode>(); + return getMembersOfType<ParamDecl>(); }) SYNTAX_FIELD(TypeExp, ReturnType) @@ -151,7 +151,7 @@ END_SYNTAX_CLASS() // Base class for callable things that may also have a body that is evaluated to produce their result ABSTRACT_SYNTAX_CLASS(FunctionDeclBase, CallableDecl) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, Body) + SYNTAX_FIELD(RefPtr<Stmt>, Body) END_SYNTAX_CLASS() // A constructor/initializer to create instances of a type @@ -166,13 +166,13 @@ SIMPLE_SYNTAX_CLASS(AccessorDecl, FunctionDeclBase) SIMPLE_SYNTAX_CLASS(GetterDecl, AccessorDecl) SIMPLE_SYNTAX_CLASS(SetterDecl, AccessorDecl) -SIMPLE_SYNTAX_CLASS(FunctionSyntaxNode, FunctionDeclBase) +SIMPLE_SYNTAX_CLASS(FuncDecl, FunctionDeclBase) SIMPLE_SYNTAX_CLASS(Variable, VarDeclBase); // A "module" of code (essentiately, a single translation unit) // that provides a scope for some number of declarations. -SIMPLE_SYNTAX_CLASS(ProgramSyntaxNode, ContainerDecl) +SIMPLE_SYNTAX_CLASS(ModuleDecl, ContainerDecl) SYNTAX_CLASS(ImportDecl, Decl) // The name of the module we are trying to import @@ -182,7 +182,7 @@ SYNTAX_CLASS(ImportDecl, Decl) FIELD(RefPtr<Scope>, scope) // The module that actually got imported - DECL_FIELD(RefPtr<ProgramSyntaxNode>, importedModuleDecl) + DECL_FIELD(RefPtr<ModuleDecl>, importedModuleDecl) END_SYNTAX_CLASS() // A generic declaration, parameterized on types/values diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index d23f2bd16..e0b959a81 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -42,7 +42,7 @@ void printDiagnosticArg(StringBuilder& sb, Decl* decl) sb << decl->Name.Content; } -void printDiagnosticArg(StringBuilder& sb, ExpressionType* type) +void printDiagnosticArg(StringBuilder& sb, Type* type) { sb << type->ToString(); } diff --git a/source/slang/diagnostics.h b/source/slang/diagnostics.h index f88bf460e..6ea677b38 100644 --- a/source/slang/diagnostics.h +++ b/source/slang/diagnostics.h @@ -68,8 +68,8 @@ namespace Slang }; class Decl; + class type; class Type; - class ExpressionType; class ILType; class StageAttribute; struct TypeExp; @@ -80,8 +80,8 @@ namespace Slang void printDiagnosticArg(StringBuilder& sb, UInt val); void printDiagnosticArg(StringBuilder& sb, Slang::String const& str); void printDiagnosticArg(StringBuilder& sb, Decl* decl); + void printDiagnosticArg(StringBuilder& sb, type* type); void printDiagnosticArg(StringBuilder& sb, Type* type); - void printDiagnosticArg(StringBuilder& sb, ExpressionType* type); void printDiagnosticArg(StringBuilder& sb, TypeExp const& type); void printDiagnosticArg(StringBuilder& sb, QualType const& type); void printDiagnosticArg(StringBuilder& sb, TokenType tokenType); diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index d2f932ebf..72632260f 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -71,7 +71,7 @@ struct SharedEmitContext // We only want to emit each `import`ed module one time, so // we maintain a set of already-emitted modules. - HashSet<ProgramSyntaxNode*> modulesAlreadyEmitted; + HashSet<ModuleDecl*> modulesAlreadyEmitted; // We track the original global-scope layout so that we can // find layout information for `import`ed parameters. @@ -82,7 +82,7 @@ struct SharedEmitContext ProgramLayout* programLayout; - ProgramSyntaxNode* program; + ModuleDecl* program; bool needHackSamplerForTexelFetch = false; @@ -124,7 +124,7 @@ void requireGLSLVersion( static String getStringOrIdentifierTokenValue( Token const& token) { - switch(token.Type) + switch(token.type) { default: SLANG_UNEXPECTED("needed an identifier or string literal"); @@ -793,7 +793,7 @@ struct EmitVisitor } void emitGLSLTypePrefix( - RefPtr<ExpressionType> type) + RefPtr<Type> type) { if(auto basicElementType = type->As<BasicExpressionType>()) { @@ -980,7 +980,7 @@ struct EmitVisitor } } - void emitTypeImpl(RefPtr<ExpressionType> type, EDeclarator* declarator) + void emitTypeImpl(RefPtr<Type> type, EDeclarator* declarator) { TypeEmitArg arg; arg.declarator = declarator; @@ -1186,7 +1186,7 @@ struct EmitVisitor } void EmitType( - RefPtr<ExpressionType> type, + RefPtr<Type> type, CodePosition const& typeLoc, String const& name, CodePosition const& nameLoc) @@ -1201,19 +1201,19 @@ struct EmitVisitor } - void EmitType(RefPtr<ExpressionType> type, Token const& nameToken) + void EmitType(RefPtr<Type> type, Token const& nameToken) { EmitType(type, CodePosition(), nameToken.Content, nameToken.Position); } - void EmitType(RefPtr<ExpressionType> type) + void EmitType(RefPtr<Type> type) { emitTypeImpl(type, nullptr); } - void emitTypeBasedOnExpr(ExpressionSyntaxNode* expr, EDeclarator* declarator) + void emitTypeBasedOnExpr(Expr* expr, EDeclarator* declarator) { - if (auto subscriptExpr = dynamic_cast<IndexExpressionSyntaxNode*>(expr)) + if (auto subscriptExpr = dynamic_cast<IndexExpr*>(expr)) { // Looks like an array emitTypeBasedOnExpr(subscriptExpr->BaseExpression, declarator); @@ -1278,13 +1278,13 @@ struct EmitVisitor // Determine if an expression should not be emitted when it is the base of // a member reference expression. - bool IsBaseExpressionImplicit(RefPtr<ExpressionSyntaxNode> expr) + bool IsBaseExpressionImplicit(RefPtr<Expr> expr) { // HACK(tfoley): For now, anything with a constant-buffer type should be // left implicit. // Look through any dereferencing that took place - RefPtr<ExpressionSyntaxNode> e = expr; + RefPtr<Expr> e = expr; while (auto derefExpr = e.As<DerefExpr>()) { e = derefExpr->base; @@ -1298,7 +1298,7 @@ struct EmitVisitor } // Is the expression referencing a constant buffer? - if (auto cbufferType = e->Type->As<ConstantBufferType>()) + if (auto cbufferType = e->type->As<ConstantBufferType>()) { return true; } @@ -1307,13 +1307,13 @@ struct EmitVisitor } #if 0 - void EmitPostfixExpr(RefPtr<ExpressionSyntaxNode> expr) + void EmitPostfixExpr(RefPtr<Expr> expr) { EmitExprWithPrecedence(expr, kEOp_Postfix); } #endif - void EmitExpr(RefPtr<ExpressionSyntaxNode> expr) + void EmitExpr(RefPtr<Expr> expr) { EmitExprWithPrecedence(expr, kEOp_General); } @@ -1336,12 +1336,12 @@ struct EmitVisitor // we may need to ignore certain constructs that the type-checker // might have introduced, but which interfere with our ability // to use it effectively in the target language - RefPtr<ExpressionSyntaxNode> prepareLValueExpr( - RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> prepareLValueExpr( + RefPtr<Expr> expr) { for(;;) { - if(auto typeCastExpr = expr.As<TypeCastExpressionSyntaxNode>()) + if(auto typeCastExpr = expr.As<TypeCastExpr>()) { expr = typeCastExpr->Expression; } @@ -1358,7 +1358,7 @@ struct EmitVisitor EOpInfo outerPrec, EOpInfo prec, char const* op, - RefPtr<InvokeExpressionSyntaxNode> binExpr, + RefPtr<InvokeExpr> binExpr, bool isAssign) { bool needsClose = MaybeEmitParens(outerPrec, prec); @@ -1380,12 +1380,12 @@ struct EmitVisitor } } - void EmitBinExpr(EOpInfo outerPrec, EOpInfo prec, char const* op, RefPtr<InvokeExpressionSyntaxNode> binExpr) + void EmitBinExpr(EOpInfo outerPrec, EOpInfo prec, char const* op, RefPtr<InvokeExpr> binExpr) { emitInfixExprImpl(outerPrec, prec, op, binExpr, false); } - void EmitBinAssignExpr(EOpInfo outerPrec, EOpInfo prec, char const* op, RefPtr<InvokeExpressionSyntaxNode> binExpr) + void EmitBinAssignExpr(EOpInfo outerPrec, EOpInfo prec, char const* op, RefPtr<InvokeExpr> binExpr) { emitInfixExprImpl(outerPrec, prec, op, binExpr, true); } @@ -1395,7 +1395,7 @@ struct EmitVisitor EOpInfo prec, char const* preOp, char const* postOp, - RefPtr<InvokeExpressionSyntaxNode> expr, + RefPtr<InvokeExpr> expr, bool isAssign) { bool needsClose = MaybeEmitParens(outerPrec, prec); @@ -1429,7 +1429,7 @@ struct EmitVisitor EOpInfo prec, char const* preOp, char const* postOp, - RefPtr<InvokeExpressionSyntaxNode> expr) + RefPtr<InvokeExpr> expr) { emitUnaryExprImpl(outerPrec, prec, preOp, postOp, expr, false); } @@ -1439,7 +1439,7 @@ struct EmitVisitor EOpInfo prec, char const* preOp, char const* postOp, - RefPtr<InvokeExpressionSyntaxNode> expr) + RefPtr<InvokeExpr> expr) { emitUnaryExprImpl(outerPrec, prec, preOp, postOp, expr, true); } @@ -1453,7 +1453,7 @@ struct EmitVisitor // If no target name was specified, then the modifier implicitly // applies to all targets. - if(targetToken.Type == TokenType::Unknown) + if(targetToken.type == TokenType::Unknown) return true; // Otherwise, we need to check if the target name matches what @@ -1486,7 +1486,7 @@ struct EmitVisitor // For now "better"-ness is defined as: a modifier // with a specified target is better than one without // (it is more specific) - if(!bestModifier || bestModifier->targetToken.Type == TokenType::Unknown) + if(!bestModifier || bestModifier->targetToken.type == TokenType::Unknown) { bestModifier = m; } @@ -1498,7 +1498,7 @@ struct EmitVisitor // Emit a call expression that doesn't involve any special cases, // just an expression of the form `f(a0, a1, ...)` void emitSimpleCallExpr( - RefPtr<InvokeExpressionSyntaxNode> callExpr, + RefPtr<InvokeExpr> callExpr, EOpInfo outerPrec) { auto prec = kEOp_Postfix; @@ -1511,7 +1511,7 @@ struct EmitVisitor if (auto ctorDeclRef = declRef.As<ConstructorDecl>()) { // We really want to emit a reference to the type begin constructed - EmitType(callExpr->Type); + EmitType(callExpr->type); } else { @@ -1583,7 +1583,7 @@ struct EmitVisitor return result; } - void EmitExprWithPrecedence(RefPtr<ExpressionSyntaxNode> expr, EOpInfo outerPrec) + void EmitExprWithPrecedence(RefPtr<Expr> expr, EOpInfo outerPrec) { ExprEmitArg arg; arg.outerPrec = outerPrec; @@ -1591,7 +1591,7 @@ struct EmitVisitor ExprVisitorWithArg::dispatch(expr, arg); } - void EmitExprWithPrecedence(RefPtr<ExpressionSyntaxNode> expr, EPrecedence leftPrec, EPrecedence rightPrec) + void EmitExprWithPrecedence(RefPtr<Expr> expr, EPrecedence leftPrec, EPrecedence rightPrec) { EOpInfo outerPrec; outerPrec.leftPrecedence = leftPrec; @@ -1626,7 +1626,7 @@ struct EmitVisitor emitTypeExp(expr->base); } - void visitSelectExpressionSyntaxNode(SelectExpressionSyntaxNode* selectExpr, ExprEmitArg const& arg) + void visitSelectExpr(SelectExpr* selectExpr, ExprEmitArg const& arg) { auto prec = kEOp_Conditional; auto outerPrec = arg.outerPrec; @@ -1662,7 +1662,7 @@ struct EmitVisitor } void emitUncheckedCallExpr( - RefPtr<InvokeExpressionSyntaxNode> callExpr, + RefPtr<InvokeExpr> callExpr, String const& funcName, ExprEmitArg const& arg) { @@ -1765,8 +1765,8 @@ struct EmitVisitor } } - void visitInvokeExpressionSyntaxNode( - RefPtr<InvokeExpressionSyntaxNode> callExpr, + void visitInvokeExpr( + RefPtr<InvokeExpr> callExpr, ExprEmitArg const& arg) { auto outerPrec = arg.outerPrec; @@ -1896,7 +1896,7 @@ struct EmitVisitor } - if(targetIntrinsicModifier->definitionToken.Type != TokenType::Unknown) + if(targetIntrinsicModifier->definitionToken.type != TokenType::Unknown) { auto name = getStringOrIdentifierTokenValue(targetIntrinsicModifier->definitionToken); @@ -1958,7 +1958,7 @@ struct EmitVisitor case 'o': // For a call using object-oriented syntax, this // expands to the "base" object used for the call - if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpressionSyntaxNode>()) + if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpr>()) { Emit("("); EmitExpr(memberExpr->BaseExpression); @@ -1975,14 +1975,14 @@ struct EmitVisitor // then this form will pair up the t and s arguments as needed for a GLSL // texturing operation. SLANG_RELEASE_ASSERT(argCount > 0); - if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpressionSyntaxNode>()) + if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpr>()) { auto base = memberExpr->BaseExpression; - if (auto baseTextureType = base->Type->As<TextureType>()) + if (auto baseTextureType = base->type->As<TextureType>()) { emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); - if (auto samplerType = callExpr->Arguments[0]->Type.type->As<SamplerStateType>()) + if (auto samplerType = callExpr->Arguments[0]->type.type->As<SamplerStateType>()) { if (samplerType->flavor == SamplerStateType::Flavor::SamplerComparisonState) { @@ -2027,7 +2027,7 @@ struct EmitVisitor { if (auto varDecl = dd.As<VarDeclBase>()) { - if (auto samplerType = varDecl->Type.type->As<SamplerStateType>()) + if (auto samplerType = varDecl->type.type->As<SamplerStateType>()) { samplerVar = varDecl; break; @@ -2035,10 +2035,10 @@ struct EmitVisitor } } - if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpressionSyntaxNode>()) + if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpr>()) { auto base = memberExpr->BaseExpression; - if (auto baseTextureType = base->Type->As<TextureType>()) + if (auto baseTextureType = base->type->As<TextureType>()) { emitGLSLTextureOrTextureSamplerType(baseTextureType, "sampler"); Emit("("); @@ -2074,10 +2074,10 @@ struct EmitVisitor // properly swizzle the output of the equivalent GLSL call into the right // shape. SLANG_RELEASE_ASSERT(argCount > 0); - if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpressionSyntaxNode>()) + if (auto memberExpr = callExpr->FunctionExpr.As<MemberExpr>()) { auto base = memberExpr->BaseExpression; - if (auto baseTextureType = base->Type->As<TextureType>()) + if (auto baseTextureType = base->type->As<TextureType>()) { auto elementType = baseTextureType->elementType; if (auto basicType = elementType->As<BasicExpressionType>()) @@ -2134,7 +2134,7 @@ struct EmitVisitor { // We expect any subscript operation to be invoked as a member, // so the function expression had better be in the correct form. - if(auto memberExpr = funcExpr.As<MemberExpressionSyntaxNode>()) + if(auto memberExpr = funcExpr.As<MemberExpr>()) { Emit("("); @@ -2182,7 +2182,7 @@ struct EmitVisitor if(needClose) Emit(")"); } - void visitMemberExpressionSyntaxNode(MemberExpressionSyntaxNode* memberExpr, ExprEmitArg const& arg) + void visitMemberExpr(MemberExpr* memberExpr, ExprEmitArg const& arg) { auto prec = kEOp_Postfix; auto outerPrec = arg.outerPrec; @@ -2238,7 +2238,7 @@ struct EmitVisitor if(needClose) Emit(")"); } - void visitIndexExpressionSyntaxNode(IndexExpressionSyntaxNode* subscriptExpr, ExprEmitArg const& arg) + void visitIndexExpr(IndexExpr* subscriptExpr, ExprEmitArg const& arg) { auto prec = kEOp_Postfix; auto outerPrec = arg.outerPrec; @@ -2260,7 +2260,7 @@ struct EmitVisitor emitName(expr->lookupResult2.getName()); } - void visitVarExpressionSyntaxNode(VarExpressionSyntaxNode* varExpr, ExprEmitArg const& arg) + void visitVarExpr(VarExpr* varExpr, ExprEmitArg const& arg) { auto prec = kEOp_Atomic; auto outerPrec = arg.outerPrec; @@ -2297,16 +2297,16 @@ struct EmitVisitor ExprVisitorWithArg::dispatch(derefExpr->base, arg); } - void visitConstantExpressionSyntaxNode(ConstantExpressionSyntaxNode* litExpr, ExprEmitArg const& arg) + void visitConstantExpr(ConstantExpr* litExpr, ExprEmitArg const& arg) { auto outerPrec = arg.outerPrec; bool needClose = MaybeEmitParens(outerPrec, kEOp_Atomic); char const* suffix = ""; - auto type = litExpr->Type.type; + auto type = litExpr->type.type; switch (litExpr->ConstType) { - case ConstantExpressionSyntaxNode::ConstantType::Int: + case ConstantExpr::ConstantType::Int: if(!type) { // Special case for "rewrite" mode @@ -2328,7 +2328,7 @@ struct EmitVisitor break; - case ConstantExpressionSyntaxNode::ConstantType::Float: + case ConstantExpr::ConstantType::Float: if(!type) { // Special case for "rewrite" mode @@ -2349,10 +2349,10 @@ struct EmitVisitor Emit(suffix); break; - case ConstantExpressionSyntaxNode::ConstantType::Bool: + case ConstantExpr::ConstantType::Bool: Emit(litExpr->integerValue ? "true" : "false"); break; - case ConstantExpressionSyntaxNode::ConstantType::String: + case ConstantExpr::ConstantType::String: emitStringLiteral(litExpr->stringValue); break; default: @@ -2369,14 +2369,14 @@ struct EmitVisitor ExprVisitorWithArg::dispatch(castExpr->Expression, arg); } - void visitTypeCastExpressionSyntaxNode(TypeCastExpressionSyntaxNode* castExpr, ExprEmitArg const& arg) + void visitTypeCastExpr(TypeCastExpr* castExpr, ExprEmitArg const& arg) { bool needClose = false; switch(context->shared->target) { case CodeGenTarget::GLSL: // GLSL requires constructor syntax for all conversions - EmitType(castExpr->Type); + EmitType(castExpr->type); Emit("("); EmitExpr(castExpr->Expression); Emit(")"); @@ -2391,7 +2391,7 @@ struct EmitVisitor needClose = MaybeEmitParens(outerPrec, prec); Emit("("); - EmitType(castExpr->Type); + EmitType(castExpr->type); Emit(")("); EmitExpr(castExpr->Expression); Emit(")"); @@ -2418,7 +2418,7 @@ struct EmitVisitor // Emit a statement as a `{}`-enclosed block statement, but avoid adding redundant // curly braces if the statement is itself a block statement. - void EmitBlockStmt(RefPtr<StatementSyntaxNode> stmt) + void EmitBlockStmt(RefPtr<Stmt> stmt) { // TODO(tfoley): support indenting Emit("{\n"); @@ -2433,7 +2433,7 @@ struct EmitVisitor Emit("}\n"); } - void EmitLoopAttributes(RefPtr<StatementSyntaxNode> decl) + void EmitLoopAttributes(RefPtr<Stmt> decl) { // Don't emit these attributes for GLSL, because it doesn't understand them if (context->shared->target == CodeGenTarget::GLSL) @@ -2467,7 +2467,7 @@ struct EmitVisitor Emit("}\n"); } - void EmitStmt(RefPtr<StatementSyntaxNode> stmt) + void EmitStmt(RefPtr<Stmt> stmt) { // TODO(tfoley): this shouldn't occur, but sometimes // lowering will get confused by an empty function body... @@ -2495,13 +2495,13 @@ struct EmitVisitor EmitUnparsedStmt(unparsedStmt); return; } - else if (auto exprStmt = stmt.As<ExpressionStatementSyntaxNode>()) + else if (auto exprStmt = stmt.As<ExpressionStmt>()) { EmitExpr(exprStmt->Expression); Emit(";\n"); return; } - else if (auto returnStmt = stmt.As<ReturnStatementSyntaxNode>()) + else if (auto returnStmt = stmt.As<ReturnStmt>()) { Emit("return"); if (auto expr = returnStmt->Expression) @@ -2512,12 +2512,12 @@ struct EmitVisitor Emit(";\n"); return; } - else if (auto declStmt = stmt.As<VarDeclrStatementSyntaxNode>()) + else if (auto declStmt = stmt.As<DeclStmt>()) { EmitDecl(declStmt->decl); return; } - else if (auto ifStmt = stmt.As<IfStatementSyntaxNode>()) + else if (auto ifStmt = stmt.As<IfStmt>()) { Emit("if("); EmitExpr(ifStmt->Predicate); @@ -2530,7 +2530,7 @@ struct EmitVisitor } return; } - else if (auto forStmt = stmt.As<ForStatementSyntaxNode>()) + else if (auto forStmt = stmt.As<ForStmt>()) { // We are going to always take a `for` loop like: // @@ -2587,7 +2587,7 @@ struct EmitVisitor return; } - else if (auto whileStmt = stmt.As<WhileStatementSyntaxNode>()) + else if (auto whileStmt = stmt.As<WhileStmt>()) { EmitLoopAttributes(whileStmt); @@ -2597,7 +2597,7 @@ struct EmitVisitor EmitBlockStmt(whileStmt->Statement); return; } - else if (auto doWhileStmt = stmt.As<DoWhileStatementSyntaxNode>()) + else if (auto doWhileStmt = stmt.As<DoWhileStmt>()) { EmitLoopAttributes(doWhileStmt); @@ -2608,12 +2608,12 @@ struct EmitVisitor Emit(")\n"); return; } - else if (auto discardStmt = stmt.As<DiscardStatementSyntaxNode>()) + else if (auto discardStmt = stmt.As<DiscardStmt>()) { Emit("discard;\n"); return; } - else if (auto emptyStmt = stmt.As<EmptyStatementSyntaxNode>()) + else if (auto emptyStmt = stmt.As<EmptyStmt>()) { return; } @@ -2637,12 +2637,12 @@ struct EmitVisitor Emit("default:{}\n"); return; } - else if (auto breakStmt = stmt.As<BreakStatementSyntaxNode>()) + else if (auto breakStmt = stmt.As<BreakStmt>()) { Emit("break;\n"); return; } - else if (auto continueStmt = stmt.As<ContinueStatementSyntaxNode>()) + else if (auto continueStmt = stmt.As<ContinueStmt>()) { Emit("continue;\n"); return; @@ -2659,7 +2659,7 @@ struct EmitVisitor void EmitVal(RefPtr<Val> val) { - if (auto type = val.As<ExpressionType>()) + if (auto type = val.As<Type>()) { EmitType(type); } @@ -2745,7 +2745,7 @@ struct EmitVisitor IGNORED(GenericTypeParamDecl) // Not epected to appear (probably dead code) - IGNORED(ClassSyntaxNode) + IGNORED(ClassDecl) // Not semantically meaningful for emit, or expected // to be lowered out of existence before we get here @@ -2759,7 +2759,7 @@ struct EmitVisitor IGNORED(AggTypeDeclBase) // Should not appear nested inside other decls - IGNORED(ProgramSyntaxNode) + IGNORED(ModuleDecl) #undef IGNORED @@ -2778,7 +2778,7 @@ struct EmitVisitor SLANG_RELEASE_ASSERT(context->shared->target != CodeGenTarget::GLSL); Emit("typedef "); - EmitType(decl->Type, decl->Name.Content); + EmitType(decl->type, decl->Name.Content); Emit(";\n"); } @@ -2863,7 +2863,7 @@ struct EmitVisitor } emit(mod->nameToken.Content); - if(mod->valToken.Type != TokenType::Unknown) + if(mod->valToken.type != TokenType::Unknown) { Emit(" = "); emit(mod->valToken.Content); @@ -3000,7 +3000,7 @@ struct EmitVisitor #if 0 Emit(": register("); Emit(registerSemantic->registerName.Content); - if(registerSemantic->componentMask.Type != TokenType::Unknown) + if(registerSemantic->componentMask.type != TokenType::Unknown) { Emit("."); Emit(registerSemantic->componentMask.Content); @@ -3017,7 +3017,7 @@ struct EmitVisitor Emit(": packoffset("); Emit(packOffsetSemantic->registerName.Content); - if(packOffsetSemantic->componentMask.Type != TokenType::Unknown) + if(packOffsetSemantic->componentMask.type != TokenType::Unknown) { Emit("."); Emit(packOffsetSemantic->componentMask.Content); @@ -3081,7 +3081,7 @@ struct EmitVisitor } } - void visitStructSyntaxNode(RefPtr<StructSyntaxNode> decl, DeclEmitArg const&) + void visitStructDecl(RefPtr<StructDecl> decl, DeclEmitArg const&) { // Don't emit a declaration that was only generated implicitly, for // the purposes of semantic checking. @@ -3106,7 +3106,7 @@ struct EmitVisitor auto type = GetType(declRef); if (!type || type->As<ErrorType>()) { - EmitType(declRef.getDecl()->Type, declRef.getDecl()->getNameToken()); + EmitType(declRef.getDecl()->type, declRef.getDecl()->getNameToken()); } else { @@ -3116,9 +3116,9 @@ struct EmitVisitor EmitSemantics(declRef.getDecl()); // TODO(tfoley): technically have to apply substitution here too... - if (auto initExpr = declRef.getDecl()->Expr) + if (auto initExpr = declRef.getDecl()->initExpr) { - if (declRef.As<ParameterSyntaxNode>() + if (declRef.As<ParamDecl>() && context->shared->target == CodeGenTarget::GLSL) { // Don't emit default parameter values when lowering to GLSL @@ -3263,7 +3263,7 @@ struct EmitVisitor RefPtr<VarLayout> layout) { // The data type that describes where stuff in the constant buffer should go - RefPtr<ExpressionType> dataType = parameterBlockType->elementType; + RefPtr<Type> dataType = parameterBlockType->elementType; // We expect/require the data type to be a user-defined `struct` type auto declRefType = dataType->As<DeclRefType>(); @@ -3302,7 +3302,7 @@ struct EmitVisitor emitHLSLRegisterSemantic(*info); Emit("\n{\n"); - if (auto structRef = declRefType->declRef.As<StructSyntaxNode>()) + if (auto structRef = declRefType->declRef.As<StructDecl>()) { int fieldCounter = 0; @@ -3427,7 +3427,7 @@ struct EmitVisitor RefPtr<VarLayout> layout) { // The data type that describes where stuff in the constant buffer should go - RefPtr<ExpressionType> dataType = parameterBlockType->elementType; + RefPtr<Type> dataType = parameterBlockType->elementType; // We expect/require the data type to be a user-defined `struct` type auto declRefType = dataType->As<DeclRefType>(); @@ -3483,7 +3483,7 @@ struct EmitVisitor } Emit("\n{\n"); - if (auto structRef = declRefType->declRef.As<StructSyntaxNode>()) + if (auto structRef = declRefType->declRef.As<StructDecl>()) { for (auto field : getMembersOfType<StructField>(structRef)) { @@ -3505,7 +3505,7 @@ struct EmitVisitor } Emit("}"); - if( varDecl->Name.Type != TokenType::Unknown ) + if( varDecl->Name.type != TokenType::Unknown ) { Emit(" "); emitName(varDecl->Name); @@ -3559,7 +3559,7 @@ struct EmitVisitor // // TODO(tfoley): there might be a better way to detect this, e.g., // with an attribute that gets attached to the variable declaration. - if (auto parameterBlockType = decl->Type->As<ParameterBlockType>()) + if (auto parameterBlockType = decl->type->As<ParameterBlockType>()) { emitParameterBlockDecl(decl, parameterBlockType, layout); return; @@ -3600,12 +3600,12 @@ struct EmitVisitor Emit(";\n"); } - void EmitParamDecl(RefPtr<ParameterSyntaxNode> decl) + void EmitParamDecl(RefPtr<ParamDecl> decl) { EmitVarDeclCommon(decl); } - void visitFunctionSyntaxNode(RefPtr<FunctionSyntaxNode> decl, DeclEmitArg const&) + void visitFuncDecl(RefPtr<FuncDecl> decl, DeclEmitArg const&) { EmitModifiers(decl); @@ -3617,7 +3617,7 @@ struct EmitVisitor Emit("("); bool first = true; - for (auto paramDecl : decl->getMembersOfType<ParameterSyntaxNode>()) + for (auto paramDecl : decl->getMembersOfType<ParamDecl>()) { if (!first) Emit(", "); EmitParamDecl(paramDecl); @@ -3638,7 +3638,7 @@ struct EmitVisitor } void emitGLSLVersionDirective( - ProgramSyntaxNode* program) + ModuleDecl* program) { // Did the user provide an explicit `#version` directive in their code? if( auto versionDirective = program->FindModifier<GLSLVersionDirective>() ) @@ -3647,7 +3647,7 @@ struct EmitVisitor Emit("#version "); emit(versionDirective->versionNumberToken.Content); - if(versionDirective->glslProfileToken.Type != TokenType::Unknown) + if(versionDirective->glslProfileToken.type != TokenType::Unknown) { Emit(" "); emit(versionDirective->glslProfileToken.Content); @@ -3700,7 +3700,7 @@ struct EmitVisitor } void emitGLSLPreprocessorDirectives( - RefPtr<ProgramSyntaxNode> program) + RefPtr<ModuleDecl> program) { switch(context->shared->target) { diff --git a/source/slang/expr-defs.h b/source/slang/expr-defs.h index dc93407e0..1860f8a72 100644 --- a/source/slang/expr-defs.h +++ b/source/slang/expr-defs.h @@ -4,7 +4,7 @@ // Base class for expressions that will reference declarations -ABSTRACT_SYNTAX_CLASS(DeclRefExpr, ExpressionSyntaxNode) +ABSTRACT_SYNTAX_CLASS(DeclRefExpr, Expr) // The scope in which to perform lookup FIELD(RefPtr<Scope>, scope) @@ -16,21 +16,21 @@ ABSTRACT_SYNTAX_CLASS(DeclRefExpr, ExpressionSyntaxNode) FIELD(String, name) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(VarExpressionSyntaxNode, DeclRefExpr) +SIMPLE_SYNTAX_CLASS(VarExpr, DeclRefExpr) // An expression that references an overloaded set of declarations // having the same name. -SYNTAX_CLASS(OverloadedExpr, ExpressionSyntaxNode) +SYNTAX_CLASS(OverloadedExpr, Expr) // Optional: the base expression is this overloaded result // arose from a member-reference expression. - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, base) + SYNTAX_FIELD(RefPtr<Expr>, base) // The lookup result that was ambiguous FIELD(LookupResult, lookupResult2) END_SYNTAX_CLASS() -SYNTAX_CLASS(ConstantExpressionSyntaxNode, ExpressionSyntaxNode) +SYNTAX_CLASS(ConstantExpr, Expr) FIELD(Token, token) RAW( @@ -52,13 +52,13 @@ SYNTAX_CLASS(ConstantExpressionSyntaxNode, ExpressionSyntaxNode) END_SYNTAX_CLASS() // An initializer list, e.g. `{ 1, 2, 3 }` -SYNTAX_CLASS(InitializerListExpr, ExpressionSyntaxNode) - SYNTAX_FIELD(List<RefPtr<ExpressionSyntaxNode>>, args) +SYNTAX_CLASS(InitializerListExpr, Expr) + SYNTAX_FIELD(List<RefPtr<Expr>>, args) END_SYNTAX_CLASS() // A base class for expressions with arguments -ABSTRACT_SYNTAX_CLASS(ExprWithArgsBase, ExpressionSyntaxNode) - SYNTAX_FIELD(List<RefPtr<ExpressionSyntaxNode>>, Arguments) +ABSTRACT_SYNTAX_CLASS(ExprWithArgsBase, Expr) + SYNTAX_FIELD(List<RefPtr<Expr>>, Arguments) END_SYNTAX_CLASS() // An aggregate type constructor @@ -70,49 +70,49 @@ END_SYNTAX_CLASS() // A base expression being applied to arguments: covers // both ordinary `()` function calls and `<>` generic application ABSTRACT_SYNTAX_CLASS(AppExprBase, ExprWithArgsBase) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, FunctionExpr) + SYNTAX_FIELD(RefPtr<Expr>, FunctionExpr) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(InvokeExpressionSyntaxNode, AppExprBase) +SIMPLE_SYNTAX_CLASS(InvokeExpr, AppExprBase) -SIMPLE_SYNTAX_CLASS(OperatorExpressionSyntaxNode, InvokeExpressionSyntaxNode) +SIMPLE_SYNTAX_CLASS(OperatorExpr, InvokeExpr) -SIMPLE_SYNTAX_CLASS(InfixExpr , OperatorExpressionSyntaxNode) -SIMPLE_SYNTAX_CLASS(PrefixExpr , OperatorExpressionSyntaxNode) -SIMPLE_SYNTAX_CLASS(PostfixExpr, OperatorExpressionSyntaxNode) +SIMPLE_SYNTAX_CLASS(InfixExpr , OperatorExpr) +SIMPLE_SYNTAX_CLASS(PrefixExpr , OperatorExpr) +SIMPLE_SYNTAX_CLASS(PostfixExpr, OperatorExpr) -SYNTAX_CLASS(IndexExpressionSyntaxNode, ExpressionSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, BaseExpression) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, IndexExpression) +SYNTAX_CLASS(IndexExpr, Expr) + SYNTAX_FIELD(RefPtr<Expr>, BaseExpression) + SYNTAX_FIELD(RefPtr<Expr>, IndexExpression) END_SYNTAX_CLASS() -SYNTAX_CLASS(MemberExpressionSyntaxNode, DeclRefExpr) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, BaseExpression) +SYNTAX_CLASS(MemberExpr, DeclRefExpr) + SYNTAX_FIELD(RefPtr<Expr>, BaseExpression) END_SYNTAX_CLASS() -SYNTAX_CLASS(SwizzleExpr, ExpressionSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, base) +SYNTAX_CLASS(SwizzleExpr, Expr) + SYNTAX_FIELD(RefPtr<Expr>, base) FIELD(int, elementCount) FIELD(int, elementIndices[4]) END_SYNTAX_CLASS() // A dereference of a pointer or pointer-like type -SYNTAX_CLASS(DerefExpr, ExpressionSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, base) +SYNTAX_CLASS(DerefExpr, Expr) + SYNTAX_FIELD(RefPtr<Expr>, base) END_SYNTAX_CLASS() // Any operation that performs type-casting -SYNTAX_CLASS(TypeCastExpressionSyntaxNode, ExpressionSyntaxNode) +SYNTAX_CLASS(TypeCastExpr, Expr) SYNTAX_FIELD(TypeExp, TargetType) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Expression) + SYNTAX_FIELD(RefPtr<Expr>, Expression) END_SYNTAX_CLASS() -// An explicit type-cast that appear in the user's code with `(Type) expr` syntax -SYNTAX_CLASS(ExplicitCastExpr, TypeCastExpressionSyntaxNode) +// An explicit type-cast that appear in the user's code with `(type) expr` syntax +SYNTAX_CLASS(ExplicitCastExpr, TypeCastExpr) END_SYNTAX_CLASS() // An implicit type-cast inserted during semantic checking -SYNTAX_CLASS(ImplicitCastExpr, TypeCastExpressionSyntaxNode) +SYNTAX_CLASS(ImplicitCastExpr, TypeCastExpr) END_SYNTAX_CLASS() // An implicit type-cast that should also be hidden on output, @@ -120,26 +120,26 @@ END_SYNTAX_CLASS() SYNTAX_CLASS(HiddenImplicitCastExpr, ImplicitCastExpr) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(SelectExpressionSyntaxNode, OperatorExpressionSyntaxNode) +SIMPLE_SYNTAX_CLASS(SelectExpr, OperatorExpr) SIMPLE_SYNTAX_CLASS(GenericAppExpr, AppExprBase) // An expression representing re-use of the syntax for a type in more // than once conceptually-distinct declaration -SYNTAX_CLASS(SharedTypeExpr, ExpressionSyntaxNode) +SYNTAX_CLASS(SharedTypeExpr, Expr) // The underlying type expression that we want to share SYNTAX_FIELD(TypeExp, base) END_SYNTAX_CLASS() -SYNTAX_CLASS(AssignExpr, ExpressionSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, left); - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, right); +SYNTAX_CLASS(AssignExpr, Expr) + SYNTAX_FIELD(RefPtr<Expr>, left); + SYNTAX_FIELD(RefPtr<Expr>, right); END_SYNTAX_CLASS() // Just an expression inside parentheses `(exp)` // // We keep this around explicitly to be sure we don't lose any structure // when we do rewriter stuff. -SYNTAX_CLASS(ParenExpr, ExpressionSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, base); +SYNTAX_CLASS(ParenExpr, Expr) + SYNTAX_FIELD(RefPtr<Expr>, base); END_SYNTAX_CLASS() diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp index 49856c1c9..84b34c9a9 100644 --- a/source/slang/lexer.cpp +++ b/source/slang/lexer.cpp @@ -18,7 +18,7 @@ namespace Slang Token* TokenList::end() const { SLANG_ASSERT(mTokens.Count()); - SLANG_ASSERT(mTokens[mTokens.Count()-1].Type == TokenType::EndOfFile); + SLANG_ASSERT(mTokens[mTokens.Count()-1].type == TokenType::EndOfFile); return &mTokens[mTokens.Count() - 1]; } @@ -40,7 +40,7 @@ namespace Slang Token token = *mCursor; if (mCursor == mEnd) - token.Type = TokenType::EndOfFile; + token.type = TokenType::EndOfFile; return token; } @@ -49,7 +49,7 @@ namespace Slang if (mCursor == mEnd) return TokenType::EndOfFile; SLANG_ASSERT(mCursor); - return mCursor->Type; + return mCursor->type; } CodePosition TokenReader::PeekLoc() const @@ -67,7 +67,7 @@ namespace Slang Token token = *mCursor; if (mCursor == mEnd) - token.Type = TokenType::EndOfFile; + token.type = TokenType::EndOfFile; else mCursor++; return token; @@ -774,8 +774,8 @@ namespace Slang String getStringLiteralTokenValue(Token const& token) { - SLANG_ASSERT(token.Type == TokenType::StringLiteral - || token.Type == TokenType::CharLiteral); + SLANG_ASSERT(token.type == TokenType::StringLiteral + || token.type == TokenType::CharLiteral); char const* cursor = token.Content.begin(); char const* end = token.Content.end(); @@ -1244,7 +1244,7 @@ namespace Slang break; } - token.Type = tokenType; + token.type = tokenType; char const* textEnd = cursor; @@ -1303,7 +1303,7 @@ namespace Slang Token token = lexToken(); tokenList.mTokens.Add(token); - if(token.Type == TokenType::EndOfFile) + if(token.type == TokenType::EndOfFile) return tokenList; } } diff --git a/source/slang/lookup.cpp b/source/slang/lookup.cpp index b0e9ce971..3370b369b 100644 --- a/source/slang/lookup.cpp +++ b/source/slang/lookup.cpp @@ -8,7 +8,7 @@ namespace Slang { DeclRef<ExtensionDecl> ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr<ExpressionType> type); + RefPtr<Type> type); // @@ -74,11 +74,11 @@ bool DeclPassesLookupMask(Decl* decl, LookupMask mask) // type declarations if(auto aggTypeDecl = dynamic_cast<AggTypeDecl*>(decl)) { - return int(mask) & int(LookupMask::Type); + return int(mask) & int(LookupMask::type); } else if(auto simpleTypeDecl = dynamic_cast<SimpleTypeDecl*>(decl)) { - return int(mask) & int(LookupMask::Type); + return int(mask) & int(LookupMask::type); } // function declarations else if(auto funcDecl = dynamic_cast<FunctionDeclBase*>(decl)) @@ -154,7 +154,7 @@ LookupResultItem CreateLookupResultItem( void DoMemberLookupImpl( Session* session, String const& name, - RefPtr<ExpressionType> baseType, + RefPtr<Type> baseType, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* breadcrumbs) @@ -270,7 +270,7 @@ void DoLocalLookupImpl( // Consider lookup via extension if( auto aggTypeDeclRef = containerDeclRef.As<AggTypeDecl>() ) { - RefPtr<ExpressionType> type = DeclRefType::Create( + RefPtr<Type> type = DeclRefType::Create( session, aggTypeDeclRef); diff --git a/source/slang/lookup.h b/source/slang/lookup.h index 35f378948..8710ac54f 100644 --- a/source/slang/lookup.h +++ b/source/slang/lookup.h @@ -38,7 +38,7 @@ QualType getTypeForDeclRef( SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef<Decl> declRef, - RefPtr<ExpressionType>* outTypeResult); + RefPtr<Type>* outTypeResult); QualType getTypeForDeclRef( Session* session, diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index e8aa06f03..611180415 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -28,7 +28,7 @@ struct StructuralTransformVisitorBase { V* visitor; - RefPtr<StatementSyntaxNode> transformDeclField(StatementSyntaxNode* stmt) + RefPtr<Stmt> transformDeclField(Stmt* stmt) { return visitor->translateStmtRef(stmt); } @@ -58,12 +58,12 @@ struct StructuralTransformVisitorBase return result; } - RefPtr<ExpressionSyntaxNode> transformSyntaxField(ExpressionSyntaxNode* expr) + RefPtr<Expr> transformSyntaxField(Expr* expr) { return visitor->transformSyntaxField(expr); } - RefPtr<StatementSyntaxNode> transformSyntaxField(StatementSyntaxNode* stmt) + RefPtr<Stmt> transformSyntaxField(Stmt* stmt) { return visitor->transformSyntaxField(stmt); } @@ -92,8 +92,8 @@ struct StructuralTransformVisitorBase }; template<typename V> -RefPtr<StatementSyntaxNode> structuralTransform( - StatementSyntaxNode* stmt, +RefPtr<Stmt> structuralTransform( + Stmt* stmt, V* visitor) { StructuralTransformStmtVisitor<V> transformer; @@ -104,16 +104,16 @@ RefPtr<StatementSyntaxNode> structuralTransform( template<typename V> struct StructuralTransformExprVisitor : StructuralTransformVisitorBase<V> - , ExprVisitor<StructuralTransformExprVisitor<V>, RefPtr<ExpressionSyntaxNode>> + , ExprVisitor<StructuralTransformExprVisitor<V>, RefPtr<Expr>> { - void transformFields(ExpressionSyntaxNode* result, ExpressionSyntaxNode* obj) + void transformFields(Expr* result, Expr* obj) { - result->Type = transformSyntaxField(obj->Type); + result->type = transformSyntaxField(obj->type); } #define SYNTAX_CLASS(NAME, BASE, ...) \ - RefPtr<ExpressionSyntaxNode> visit##NAME(NAME* obj) { \ + RefPtr<Expr> visit##NAME(NAME* obj) { \ RefPtr<NAME> result = new NAME(*obj); \ transformFields(result, obj); \ return result; \ @@ -136,8 +136,8 @@ struct StructuralTransformExprVisitor template<typename V> -RefPtr<ExpressionSyntaxNode> structuralTransform( - ExpressionSyntaxNode* expr, +RefPtr<Expr> structuralTransform( + Expr* expr, V* visitor) { StructuralTransformExprVisitor<V> transformer; @@ -257,7 +257,7 @@ struct LoweredExpr : flavor(Flavor::Expr) {} - LoweredExpr(ExpressionSyntaxNode* expr) + LoweredExpr(Expr* expr) : value(expr) , flavor(Flavor::Expr) {} @@ -274,10 +274,10 @@ struct LoweredExpr Flavor getFlavor() const { return flavor; } - ExpressionSyntaxNode* getExpr() const + Expr* getExpr() const { assert(getFlavor() == Flavor::Expr); - return (ExpressionSyntaxNode*)value.Ptr(); + return (Expr*)value.Ptr(); } TupleExpr* getTupleExpr() const @@ -293,7 +293,7 @@ struct LoweredExpr return (VaryingTupleExpr*)value.Ptr(); } - ExpressionSyntaxNode* asExpr() const + Expr* asExpr() const { return (getFlavor() == Flavor::Expr) ? getExpr() : nullptr; } @@ -319,7 +319,7 @@ class PseudoVarDecl : public RefObject public: Token Name; CodePosition Position; - TypeExp Type; + TypeExp type; }; class TupleVarDecl : public PseudoVarDecl @@ -340,7 +340,7 @@ class PseudoExpr : public RefObject { public: CodePosition Position; - QualType Type; + QualType type; }; // Pseudo-syntax used during lowering: @@ -356,7 +356,7 @@ public: // Optional reference to the "primary" value of the tuple, // in the case of a tuple type with "orinary" fields - RefPtr<ExpressionSyntaxNode> primaryExpr; + RefPtr<Expr> primaryExpr; // Additional fields to store values for any non-ordinary fields // (or fields that aren't exclusively orginary) @@ -418,14 +418,14 @@ struct SharedLoweringContext Dictionary<String, String> reservedWords; - RefPtr<ProgramSyntaxNode> loweredProgram; + RefPtr<ModuleDecl> loweredProgram; Dictionary<Decl*, LoweredDecl> loweredDecls; Dictionary<RefObject*, Decl*> mapLoweredDeclToOriginal; // Work to be done at the very start and end of the entry point - RefPtr<StatementSyntaxNode> entryPointInitializeStmt; - RefPtr<StatementSyntaxNode> entryPointFinalizeStmt; + RefPtr<Stmt> entryPointInitializeStmt; + RefPtr<Stmt> entryPointFinalizeStmt; // Counter used for generating unique temporary names int nameCounter = 0; @@ -452,14 +452,14 @@ struct LoweringVisitor : ExprVisitor<LoweringVisitor, LoweredExpr> , StmtVisitor<LoweringVisitor, void> , DeclVisitor<LoweringVisitor, LoweredDecl> - , ValVisitor<LoweringVisitor, RefPtr<Val>, RefPtr<ExpressionType>> + , ValVisitor<LoweringVisitor, RefPtr<Val>, RefPtr<Type>> { // SharedLoweringContext* shared; RefPtr<Substitutions> substitutions; bool isBuildingStmt = false; - RefPtr<StatementSyntaxNode> stmtBeingBuilt; + RefPtr<Stmt> stmtBeingBuilt; // If we *aren't* building a statement, then this // is the container we should be adding declarations to @@ -660,8 +660,8 @@ struct LoweringVisitor // Types // - RefPtr<ExpressionType> lowerType( - ExpressionType* type) + RefPtr<Type> lowerType( + Type* type) { if (!type) return nullptr; return TypeVisitor::dispatch(type); @@ -676,29 +676,29 @@ struct LoweringVisitor return result; } - RefPtr<ExpressionType> visitErrorType(ErrorType* type) + RefPtr<Type> visitErrorType(ErrorType* type) { return type; } - RefPtr<ExpressionType> visitOverloadGroupType(OverloadGroupType* type) + RefPtr<Type> visitOverloadGroupType(OverloadGroupType* type) { return type; } - RefPtr<ExpressionType> visitInitializerListType(InitializerListType* type) + RefPtr<Type> visitInitializerListType(InitializerListType* type) { return type; } - RefPtr<ExpressionType> visitGenericDeclRefType(GenericDeclRefType* type) + RefPtr<Type> visitGenericDeclRefType(GenericDeclRefType* type) { return getGenericDeclRefType( type->getSession(), translateDeclRef(DeclRef<Decl>(type->declRef)).As<GenericDecl>()); } - RefPtr<ExpressionType> visitFuncType(FuncType* type) + RefPtr<Type> visitFuncType(FuncType* type) { RefPtr<FuncType> loweredType = getFuncType( getSession(), @@ -706,7 +706,7 @@ struct LoweringVisitor return loweredType; } - RefPtr<ExpressionType> visitDeclRefType(DeclRefType* type) + RefPtr<Type> visitDeclRefType(DeclRefType* type) { auto loweredDeclRef = translateDeclRef(type->declRef); return DeclRefType::Create( @@ -714,7 +714,7 @@ struct LoweringVisitor loweredDeclRef.As<Decl>()); } - RefPtr<ExpressionType> visitNamedExpressionType(NamedExpressionType* type) + RefPtr<Type> visitNamedExpressionType(NamedExpressionType* type) { if (shared->target == CodeGenTarget::GLSL) { @@ -727,12 +727,12 @@ struct LoweringVisitor translateDeclRef(DeclRef<Decl>(type->declRef)).As<TypeDefDecl>()); } - RefPtr<ExpressionType> visitTypeType(TypeType* type) + RefPtr<Type> visitTypeType(TypeType* type) { return getTypeType(lowerType(type->type)); } - RefPtr<ExpressionType> visitArrayExpressionType(ArrayExpressionType* type) + RefPtr<Type> visitArrayExpressionType(ArrayExpressionType* type) { RefPtr<ArrayExpressionType> loweredType = Slang::getArrayType( lowerType(type->BaseType), @@ -740,7 +740,7 @@ struct LoweringVisitor return loweredType; } - RefPtr<ExpressionType> transformSyntaxField(ExpressionType* type) + RefPtr<Type> transformSyntaxField(Type* type) { return lowerType(type); } @@ -750,14 +750,14 @@ struct LoweringVisitor // LoweredExpr lowerExprOrTuple( - ExpressionSyntaxNode* expr) + Expr* expr) { if (!expr) return LoweredExpr(); return ExprVisitor::dispatch(expr); } - RefPtr<ExpressionSyntaxNode> lowerExpr( - ExpressionSyntaxNode* expr) + RefPtr<Expr> lowerExpr( + Expr* expr) { if (!expr) return nullptr; @@ -766,28 +766,28 @@ struct LoweringVisitor } // catch-all - RefPtr<ExpressionSyntaxNode> visitExpressionSyntaxNode( - ExpressionSyntaxNode* expr) + LoweredExpr visitExpr( + Expr* expr) { - return structuralTransform(expr, this); + return LoweredExpr(structuralTransform(expr, this)); } - RefPtr<ExpressionSyntaxNode> transformSyntaxField(ExpressionSyntaxNode* expr) + RefPtr<Expr> transformSyntaxField(Expr* expr) { return lowerExpr(expr); } void lowerExprCommon( - ExpressionSyntaxNode* loweredExpr, - ExpressionSyntaxNode* expr) + Expr* loweredExpr, + Expr* expr) { loweredExpr->Position = expr->Position; - loweredExpr->Type.type = lowerType(expr->Type.type); + loweredExpr->type.type = lowerType(expr->type.type); } void lowerExprCommon( LoweredExpr const& loweredExpr, - ExpressionSyntaxNode* expr) + Expr* expr) { if (auto simpleExpr = loweredExpr.asExpr()) { @@ -795,21 +795,21 @@ struct LoweringVisitor } } - RefPtr<ExpressionSyntaxNode> createUncheckedVarRef( + RefPtr<Expr> createUncheckedVarRef( char const* name) { - RefPtr<VarExpressionSyntaxNode> result = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> result = new VarExpr(); result->name = name; return result; } - RefPtr<ExpressionSyntaxNode> createSimpleVarRef( + RefPtr<Expr> createSimpleVarRef( CodePosition const& loc, VarDeclBase* decl) { - RefPtr<VarExpressionSyntaxNode> result = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> result = new VarExpr(); result->Position = loc; - result->Type.type = decl->Type.type; + result->type.type = decl->type.type; result->declRef = makeDeclRef(decl); result->name = decl->getName(); return result; @@ -843,7 +843,7 @@ struct LoweringVisitor { RefPtr<TupleExpr> result = new TupleExpr(); result->Position = loc; - result->Type.type = decl->Type.type; + result->type.type = decl->type.type; if (auto primaryDecl = decl->primaryDecl) { @@ -874,8 +874,8 @@ struct LoweringVisitor return decl->expr; } - LoweredExpr visitVarExpressionSyntaxNode( - VarExpressionSyntaxNode* expr) + LoweredExpr visitVarExpr( + VarExpr* expr) { doSampleRateInputCheck(expr->name); @@ -898,7 +898,7 @@ struct LoweringVisitor return createVaryingTupleRef(expr->Position, varyingTupleVarDecl); } - RefPtr<VarExpressionSyntaxNode> loweredExpr = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> loweredExpr = new VarExpr(); lowerExprCommon(loweredExpr, expr); loweredExpr->declRef = loweredDeclRef.As<Decl>(); loweredExpr->name = expr->name; @@ -915,12 +915,12 @@ struct LoweringVisitor return result; } - RefPtr<ExpressionSyntaxNode> moveTemp(RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> moveTemp(RefPtr<Expr> expr) { RefPtr<Variable> varDecl = new Variable(); varDecl->Name.Content = generateName(); - varDecl->Type.type = expr->Type.type; - varDecl->Expr = expr; + varDecl->type.type = expr->type.type; + varDecl->initExpr = expr; addDecl(varDecl); @@ -931,16 +931,16 @@ struct LoweringVisitor // use/evaluate more than once, and if needed replace it with a // reference to a temporary (initialized with the expr) so that it // can safely be re-evaluated. - RefPtr<ExpressionSyntaxNode> maybeMoveTemp( - ExpressionSyntaxNode* expr) + RefPtr<Expr> maybeMoveTemp( + Expr* expr) { // TODO: actually implement this properly! // Certain expressions are already in a form we can directly re-use, // so there is no reason to move them. - if (dynamic_cast<VarExpressionSyntaxNode*>(expr)) + if (dynamic_cast<VarExpr*>(expr)) return expr; - if (dynamic_cast<ConstantExpressionSyntaxNode*>(expr)) + if (dynamic_cast<ConstantExpr*>(expr)) return expr; // In the general case, though, we need to introduce a temporary @@ -954,7 +954,7 @@ struct LoweringVisitor { RefPtr<TupleExpr> resultExpr = new TupleExpr(); resultExpr->Position = tupleExpr->Position; - resultExpr->Type = tupleExpr->Type; + resultExpr->type = tupleExpr->type; if (tupleExpr->primaryExpr) { resultExpr->primaryExpr = maybeMoveTemp(tupleExpr->primaryExpr); @@ -974,7 +974,7 @@ struct LoweringVisitor { RefPtr<VaryingTupleExpr> resultExpr = new VaryingTupleExpr(); resultExpr->Position = varyingTupleExpr->Position; - resultExpr->Type = varyingTupleExpr->Type; + resultExpr->type = varyingTupleExpr->type; for (auto ee : varyingTupleExpr->elements) { VaryingTupleExpr::Element elem; @@ -995,8 +995,8 @@ struct LoweringVisitor // Similar to the above, this ensures that an l-value expression // is safe to re-evaluate, by recursively moving things off // to temporaries where needed. - RefPtr<ExpressionSyntaxNode> ensureSimpleLValue( - ExpressionSyntaxNode* expr) + RefPtr<Expr> ensureSimpleLValue( + Expr* expr) { // TODO: actually implement this properly! @@ -1021,22 +1021,22 @@ struct LoweringVisitor WithFixups, }; - RefPtr<ExpressionSyntaxNode> createSimpleAssignExpr( - RefPtr<ExpressionSyntaxNode> leftExpr, - RefPtr<ExpressionSyntaxNode> rightExpr) + RefPtr<Expr> createSimpleAssignExpr( + RefPtr<Expr> leftExpr, + RefPtr<Expr> rightExpr) { RefPtr<AssignExpr> loweredExpr = new AssignExpr(); - loweredExpr->Type = leftExpr->Type; + loweredExpr->type = leftExpr->type; loweredExpr->left = leftExpr; loweredExpr->right = rightExpr; return loweredExpr; } - RefPtr<ExpressionSyntaxNode> convertExprForAssignmentWithFixups( - RefPtr<ExpressionType> leftType, - RefPtr<ExpressionSyntaxNode> rightExpr) + RefPtr<Expr> convertExprForAssignmentWithFixups( + RefPtr<Type> leftType, + RefPtr<Expr> rightExpr) { - auto rightType = rightExpr->Type.type; + auto rightType = rightExpr->type.type; if (auto leftArrayType = leftType->As<ArrayExpressionType>()) { // LHS type was an array @@ -1058,7 +1058,7 @@ struct LoweringVisitor RefPtr<AggTypeCtorExpr> ctorExpr = new AggTypeCtorExpr(); ctorExpr->Position = rightExpr->Position; - ctorExpr->Type.type = leftType; + ctorExpr->type.type = leftType; ctorExpr->base.type = leftType; int elementCount = (int) GetIntVal(rightVecType->elementCount); @@ -1066,7 +1066,7 @@ struct LoweringVisitor { RefPtr<SwizzleExpr> swizzleExpr = new SwizzleExpr(); swizzleExpr->Position = rightExpr->Position; - swizzleExpr->Type.type = rightVecType->elementType; + swizzleExpr->type.type = rightVecType->elementType; swizzleExpr->base = rightExpr; swizzleExpr->elementCount = 1; swizzleExpr->elementIndices[0] = ee; @@ -1089,42 +1089,42 @@ struct LoweringVisitor } - RefPtr<ExpressionSyntaxNode> createConstIntExpr(IntegerLiteralValue value) + RefPtr<Expr> createConstIntExpr(IntegerLiteralValue value) { - RefPtr<ConstantExpressionSyntaxNode> expr = new ConstantExpressionSyntaxNode(); - expr->Type.type = getIntType(); - expr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + RefPtr<ConstantExpr> expr = new ConstantExpr(); + expr->type.type = getIntType(); + expr->ConstType = ConstantExpr::ConstantType::Int; expr->integerValue = value; return expr; } struct SeqExprBuilder { - RefPtr<ExpressionSyntaxNode> expr; - RefPtr<ExpressionSyntaxNode>* link = nullptr; + RefPtr<Expr> expr; + RefPtr<Expr>* link = nullptr; }; - RefPtr<ExpressionSyntaxNode> createSimpleVarExpr(char const* name) + RefPtr<Expr> createSimpleVarExpr(char const* name) { - RefPtr<VarExpressionSyntaxNode> varExpr = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> varExpr = new VarExpr(); varExpr->name = name; return varExpr; } - RefPtr<InvokeExpressionSyntaxNode> createSeqExpr( - RefPtr<ExpressionSyntaxNode> left, - RefPtr<ExpressionSyntaxNode> right) + RefPtr<InvokeExpr> createSeqExpr( + RefPtr<Expr> left, + RefPtr<Expr> right) { RefPtr<InfixExpr> seqExpr = new InfixExpr(); seqExpr->Position = left->Position; - seqExpr->Type = right->Type; + seqExpr->type = right->type; seqExpr->FunctionExpr = createSimpleVarExpr(","); seqExpr->Arguments.Add(left); seqExpr->Arguments.Add(right); return seqExpr; } - void addExpr(SeqExprBuilder* builder, RefPtr<ExpressionSyntaxNode> expr) + void addExpr(SeqExprBuilder* builder, RefPtr<Expr> expr) { // No expression to add? Do nothing. if (!expr) return; @@ -1159,12 +1159,12 @@ struct LoweringVisitor builder->link = &seqExpr->Arguments[1]; } - RefPtr<ExpressionSyntaxNode> createSimpleAssignExprWithFixups( - RefPtr<ExpressionSyntaxNode> leftExpr, - RefPtr<ExpressionSyntaxNode> rightExpr) + RefPtr<Expr> createSimpleAssignExprWithFixups( + RefPtr<Expr> leftExpr, + RefPtr<Expr> rightExpr) { - auto leftType = leftExpr->Type.type; - auto rightType = rightExpr->Type.type; + auto leftType = leftExpr->type.type; + auto rightType = rightExpr->type.type; // If types are unknown, or match, then just do // things the ordinary way. @@ -1206,16 +1206,16 @@ struct LoweringVisitor for (int ee = 0; ee < elementCount; ++ee) { // LHS array element - RefPtr<IndexExpressionSyntaxNode> arrayElemExpr = new IndexExpressionSyntaxNode(); + RefPtr<IndexExpr> arrayElemExpr = new IndexExpr(); arrayElemExpr->Position = leftExpr->Position; - arrayElemExpr->Type.type = leftArrayType->BaseType; + arrayElemExpr->type.type = leftArrayType->BaseType; arrayElemExpr->BaseExpression = leftExpr; arrayElemExpr->IndexExpression = createConstIntExpr(ee); // RHS swizzle RefPtr<SwizzleExpr> swizzleExpr = new SwizzleExpr(); swizzleExpr->Position = rightExpr->Position; - swizzleExpr->Type.type = rightVecType->elementType; + swizzleExpr->type.type = rightVecType->elementType; swizzleExpr->base = rightExpr; swizzleExpr->elementCount = 1; swizzleExpr->elementIndices[0] = ee; @@ -1243,9 +1243,9 @@ struct LoweringVisitor return createSimpleAssignExpr(leftExpr, convertedRightExpr); } - RefPtr<ExpressionSyntaxNode> createSimpleAssignExpr( - ExpressionSyntaxNode* leftExpr, - ExpressionSyntaxNode* rightExpr, + RefPtr<Expr> createSimpleAssignExpr( + Expr* leftExpr, + Expr* rightExpr, AssignMode mode) { switch (mode) @@ -1268,7 +1268,7 @@ struct LoweringVisitor if (leftTuple && rightTuple) { RefPtr<TupleExpr> resultTuple = new TupleExpr(); - resultTuple->Type = leftTuple->Type; + resultTuple->type = leftTuple->type; if (leftTuple->primaryExpr) { @@ -1308,16 +1308,16 @@ struct LoweringVisitor auto leftVaryingTuple = leftExpr.asVaryingTuple(); auto rightVaryingTuple = rightExpr.asVaryingTuple(); - RefPtr<ExpressionSyntaxNode> leftSimpleExpr = leftExpr.asExpr(); - RefPtr<ExpressionSyntaxNode> rightSimpleExpr = rightExpr.asExpr(); + RefPtr<Expr> leftSimpleExpr = leftExpr.asExpr(); + RefPtr<Expr> rightSimpleExpr = rightExpr.asExpr(); if (leftVaryingTuple && rightVaryingTuple) { RefPtr<VaryingTupleExpr> resultTuple = new VaryingTupleExpr(); - resultTuple->Type.type = leftVaryingTuple->Type.type; + resultTuple->type.type = leftVaryingTuple->type.type; resultTuple->Position = leftVaryingTuple->Position; - SLANG_RELEASE_ASSERT(resultTuple->Type.type); + SLANG_RELEASE_ASSERT(resultTuple->type.type); UInt elementCount = leftVaryingTuple->elements.Count(); SLANG_RELEASE_ASSERT(elementCount == rightVaryingTuple->elements.Count()); @@ -1343,10 +1343,10 @@ struct LoweringVisitor // This will naturally yield a tuple expression. RefPtr<VaryingTupleExpr> resultTuple = new VaryingTupleExpr(); - resultTuple->Type.type = leftVaryingTuple->Type.type; + resultTuple->type.type = leftVaryingTuple->type.type; resultTuple->Position = leftVaryingTuple->Position; - SLANG_RELEASE_ASSERT(resultTuple->Type.type); + SLANG_RELEASE_ASSERT(resultTuple->type.type); UInt elementCount = leftVaryingTuple->elements.Count(); @@ -1365,9 +1365,9 @@ struct LoweringVisitor auto leftElem = leftVaryingTuple->elements[ee]; - RefPtr<MemberExpressionSyntaxNode> rightElemExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> rightElemExpr = new MemberExpr(); rightElemExpr->Position = rightSimpleExpr->Position; - rightElemExpr->Type.type = GetType(leftElem.originalFieldDeclRef); + rightElemExpr->type.type = GetType(leftElem.originalFieldDeclRef); rightElemExpr->declRef = leftElem.originalFieldDeclRef; rightElemExpr->name = leftElem.originalFieldDeclRef.GetName(); rightElemExpr->BaseExpression = rightSimpleExpr; @@ -1391,10 +1391,10 @@ struct LoweringVisitor RefPtr<VaryingTupleExpr> resultTuple = new VaryingTupleExpr(); - resultTuple->Type.type = leftSimpleExpr->Type.type; + resultTuple->type.type = leftSimpleExpr->type.type; resultTuple->Position = leftSimpleExpr->Position; - SLANG_RELEASE_ASSERT(resultTuple->Type.type); + SLANG_RELEASE_ASSERT(resultTuple->type.type); UInt elementCount = rightVaryingTuple->elements.Count(); @@ -1412,9 +1412,9 @@ struct LoweringVisitor auto rightElem = rightVaryingTuple->elements[ee]; - RefPtr<MemberExpressionSyntaxNode> leftElemExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> leftElemExpr = new MemberExpr(); leftElemExpr->Position = leftSimpleExpr->Position; - leftElemExpr->Type.type = GetType(rightElem.originalFieldDeclRef); + leftElemExpr->type.type = GetType(rightElem.originalFieldDeclRef); leftElemExpr->declRef = rightElem.originalFieldDeclRef; leftElemExpr->name = rightElem.originalFieldDeclRef.GetName(); leftElemExpr->BaseExpression = leftSimpleExpr; @@ -1455,8 +1455,8 @@ struct LoweringVisitor return loweredExpr; } - RefPtr<ExpressionType> getSubscripResultType( - RefPtr<ExpressionType> type) + RefPtr<Type> getSubscripResultType( + RefPtr<Type> type) { if (auto arrayType = type->As<ArrayExpressionType>()) { @@ -1465,14 +1465,14 @@ struct LoweringVisitor return nullptr; } - RefPtr<ExpressionSyntaxNode> createSimpleSubscriptExpr( - RefPtr<ExpressionSyntaxNode> baseExpr, - RefPtr<ExpressionSyntaxNode> indexExpr) + RefPtr<Expr> createSimpleSubscriptExpr( + RefPtr<Expr> baseExpr, + RefPtr<Expr> indexExpr) { // Default case: just reconstrut a subscript expr - auto loweredExpr = new IndexExpressionSyntaxNode(); + auto loweredExpr = new IndexExpr(); - loweredExpr->Type.type = getSubscripResultType(baseExpr->Type.type); + loweredExpr->type.type = getSubscripResultType(baseExpr->type.type); loweredExpr->BaseExpression = baseExpr; loweredExpr->IndexExpression = indexExpr; @@ -1481,7 +1481,7 @@ struct LoweringVisitor LoweredExpr createSubscriptExpr( LoweredExpr baseExpr, - RefPtr<ExpressionSyntaxNode> indexExpr) + RefPtr<Expr> indexExpr) { // TODO: This logic ends up duplicating the `indexExpr` // that was given, without worrying about any side @@ -1492,7 +1492,7 @@ struct LoweringVisitor indexExpr = maybeMoveTemp(indexExpr); auto loweredExpr = new TupleExpr(); - loweredExpr->Type.type = getSubscripResultType(baseTuple->Type.type); + loweredExpr->type.type = getSubscripResultType(baseTuple->type.type); if (auto basePrimary = baseTuple->primaryExpr) { @@ -1518,9 +1518,9 @@ struct LoweringVisitor indexExpr = maybeMoveTemp(indexExpr); auto loweredExpr = new VaryingTupleExpr(); - loweredExpr->Type.type = getSubscripResultType(baseVaryingTuple->Type.type); + loweredExpr->type.type = getSubscripResultType(baseVaryingTuple->type.type); - SLANG_RELEASE_ASSERT(loweredExpr->Type.type); + SLANG_RELEASE_ASSERT(loweredExpr->type.type); for (auto elem : baseVaryingTuple->elements) { @@ -1541,8 +1541,8 @@ struct LoweringVisitor } } - LoweredExpr visitIndexExpressionSyntaxNode( - IndexExpressionSyntaxNode* subscriptExpr) + LoweredExpr visitIndexExpr( + IndexExpr* subscriptExpr) { auto baseExpr = lowerExprOrTuple(subscriptExpr->BaseExpression); auto indexExpr = lowerExpr(subscriptExpr->IndexExpression); @@ -1560,7 +1560,7 @@ struct LoweringVisitor else { // Default case: just reconstrut a subscript expr - RefPtr<IndexExpressionSyntaxNode> loweredExpr = new IndexExpressionSyntaxNode(); + RefPtr<IndexExpr> loweredExpr = new IndexExpr(); lowerExprCommon(loweredExpr, subscriptExpr); loweredExpr->BaseExpression = baseExpr.getExpr(); loweredExpr->IndexExpression = indexExpr; @@ -1568,7 +1568,7 @@ struct LoweringVisitor } } - RefPtr<ExpressionSyntaxNode> maybeReifyTuple( + RefPtr<Expr> maybeReifyTuple( LoweredExpr expr) { if (auto tupleExpr = expr.asTuple()) @@ -1586,9 +1586,9 @@ struct LoweringVisitor // to handle that case... RefPtr<AggTypeCtorExpr> resultExpr = new AggTypeCtorExpr(); - resultExpr->Type = varyingTupleExpr->Type; - resultExpr->base.type = varyingTupleExpr->Type.type; - SLANG_RELEASE_ASSERT(resultExpr->Type.type); + resultExpr->type = varyingTupleExpr->type; + resultExpr->base.type = varyingTupleExpr->type.type; + SLANG_RELEASE_ASSERT(resultExpr->type.type); for (auto elem : varyingTupleExpr->elements) { @@ -1603,7 +1603,7 @@ struct LoweringVisitor } bool needGlslangBug988Workaround( - RefPtr<ExpressionSyntaxNode> inExpr) + RefPtr<Expr> inExpr) { switch (getTarget()) { @@ -1622,7 +1622,7 @@ struct LoweringVisitor // Issue (1): is the type of the expression something that needs the WAR? - auto exprType = inExpr->Type.type; + auto exprType = inExpr->type.type; exprType = unwrapArray(exprType); if (!isStructType(exprType)) @@ -1634,7 +1634,7 @@ struct LoweringVisitor auto expr = inExpr; for (;;) { - if (auto memberRefExpr = expr.As<MemberExpressionSyntaxNode>()) + if (auto memberRefExpr = expr.As<MemberExpr>()) { expr = memberRefExpr->BaseExpression; continue; @@ -1646,7 +1646,7 @@ struct LoweringVisitor continue; } - if (auto subscriptExpr = expr.As<IndexExpressionSyntaxNode>()) + if (auto subscriptExpr = expr.As<IndexExpr>()) { expr = subscriptExpr->BaseExpression; continue; @@ -1655,7 +1655,7 @@ struct LoweringVisitor break; } - if (auto varExpr = expr.As<VarExpressionSyntaxNode>()) + if (auto varExpr = expr.As<VarExpr>()) { auto declRef = varExpr->declRef; if (!declRef) @@ -1682,7 +1682,7 @@ struct LoweringVisitor void addArg( ExprWithArgsBase* callExpr, - RefPtr<ExpressionSyntaxNode> argExpr) + RefPtr<Expr> argExpr) { // This should be the default case where we have a perfectly // ordinary expression, but we need to work around a glslang @@ -1726,9 +1726,9 @@ struct LoweringVisitor } } - RefPtr<ExpressionSyntaxNode> lowerCallExpr( - RefPtr<InvokeExpressionSyntaxNode> loweredExpr, - InvokeExpressionSyntaxNode* expr) + RefPtr<Expr> lowerCallExpr( + RefPtr<InvokeExpr> loweredExpr, + InvokeExpr* expr) { lowerExprCommon(loweredExpr, expr); @@ -1743,10 +1743,10 @@ struct LoweringVisitor return loweredExpr; } - LoweredExpr visitInvokeExpressionSyntaxNode( - InvokeExpressionSyntaxNode* expr) + LoweredExpr visitInvokeExpr( + InvokeExpr* expr) { - return LoweredExpr(lowerCallExpr(new InvokeExpressionSyntaxNode(), expr)); + return LoweredExpr(lowerCallExpr(new InvokeExpr(), expr)); } LoweredExpr visitInfixExpr( @@ -1761,12 +1761,12 @@ struct LoweringVisitor return LoweredExpr(lowerCallExpr(new PrefixExpr(), expr)); } - LoweredExpr visitSelectExpressionSyntaxNode( - SelectExpressionSyntaxNode* expr) + LoweredExpr visitSelectExpr( + SelectExpr* expr) { // TODO: A tuple needs to be special-cased here - return LoweredExpr(lowerCallExpr(new SelectExpressionSyntaxNode(), expr)); + return LoweredExpr(lowerCallExpr(new SelectExpr(), expr)); } LoweredExpr visitPostfixExpr( @@ -1827,8 +1827,8 @@ struct LoweringVisitor return &shared->compileRequest->mSink; } - LoweredExpr visitMemberExpressionSyntaxNode( - MemberExpressionSyntaxNode* expr) + LoweredExpr visitMemberExpr( + MemberExpr* expr) { auto loweredBase = lowerExprOrTuple(expr->BaseExpression); @@ -1862,7 +1862,7 @@ struct LoweringVisitor SLANG_RELEASE_ASSERT(!tupleFieldTupleExpr->primaryExpr); - RefPtr<MemberExpressionSyntaxNode> loweredPrimaryExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> loweredPrimaryExpr = new MemberExpr(); lowerExprCommon(loweredPrimaryExpr, expr); loweredPrimaryExpr->BaseExpression = baseTuple->primaryExpr; loweredPrimaryExpr->declRef = loweredDeclRef.As<Decl>(); @@ -1893,7 +1893,7 @@ struct LoweringVisitor // Default handling: - RefPtr<MemberExpressionSyntaxNode> loweredExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> loweredExpr = new MemberExpr(); lowerExprCommon(loweredExpr, expr); loweredExpr->BaseExpression = loweredBase.getExpr(); loweredExpr->declRef = loweredDeclRef.As<Decl>(); @@ -1911,8 +1911,8 @@ struct LoweringVisitor // (or event to none), and in such a case this function wraps // the result up as a `SeqStmt` or `EmptyStmt` as appropriate. // - RefPtr<StatementSyntaxNode> lowerStmt( - StatementSyntaxNode* stmt) + RefPtr<Stmt> lowerStmt( + Stmt* stmt) { if (!stmt) return nullptr; @@ -1924,7 +1924,7 @@ struct LoweringVisitor if (!subVisitor.stmtBeingBuilt) { - return new EmptyStatementSyntaxNode(); + return new EmptyStmt(); } else { @@ -1940,14 +1940,14 @@ struct LoweringVisitor StmtLoweringState* parent = nullptr; // The outer statement (both lowered and original) - StatementSyntaxNode* loweredStmt = nullptr; - StatementSyntaxNode* originalStmt = nullptr; + Stmt* loweredStmt = nullptr; + Stmt* originalStmt = nullptr; }; StmtLoweringState stmtLoweringState; // Translate a reference from one statement to an outer statement - StatementSyntaxNode* translateStmtRef( - StatementSyntaxNode* originalStmt) + Stmt* translateStmtRef( + Stmt* originalStmt) { if (!originalStmt) return nullptr; @@ -1964,7 +1964,7 @@ struct LoweringVisitor // Expand a statement to be lowered into one or more statements void lowerStmtImpl( - StatementSyntaxNode* stmt) + Stmt* stmt) { StmtVisitor::dispatch(stmt); } @@ -1993,8 +1993,8 @@ struct LoweringVisitor } void addStmtImpl( - RefPtr<StatementSyntaxNode>& dest, - StatementSyntaxNode* stmt) + RefPtr<Stmt>& dest, + Stmt* stmt) { // add a statement to the code we are building... if (!dest) @@ -2026,17 +2026,17 @@ struct LoweringVisitor } void addStmt( - StatementSyntaxNode* stmt) + Stmt* stmt) { addStmtImpl(stmtBeingBuilt, stmt); } void addSimpleExprStmt( - RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> expr) { if (auto infixExpr = expr.As<InfixExpr>()) { - if (auto varExpr = infixExpr->FunctionExpr.As<VarExpressionSyntaxNode>()) + if (auto varExpr = infixExpr->FunctionExpr.As<VarExpr>()) { if (varExpr->name == ",") { @@ -2049,13 +2049,13 @@ struct LoweringVisitor } } } - else if (auto varExpr = expr.As<VarExpressionSyntaxNode>()) + else if (auto varExpr = expr.As<VarExpr>()) { // Skip an expression that is just a reference to a single variable return; } - RefPtr<ExpressionStatementSyntaxNode> stmt = new ExpressionStatementSyntaxNode(); + RefPtr<ExpressionStmt> stmt = new ExpressionStmt(); stmt->Expression = expr; addStmt(stmt); } @@ -2110,19 +2110,19 @@ struct LoweringVisitor } } - void visitExpressionStatementSyntaxNode(ExpressionStatementSyntaxNode* stmt) + void visitExpressionStmt(ExpressionStmt* stmt) { addExprStmt(lowerExprOrTuple(stmt->Expression)); } - void visitVarDeclrStatementSyntaxNode(VarDeclrStatementSyntaxNode* stmt) + void visitDeclStmt(DeclStmt* stmt) { DeclVisitor::dispatch(stmt->decl); } void lowerStmtFields( - StatementSyntaxNode* loweredStmt, - StatementSyntaxNode* originalStmt) + Stmt* loweredStmt, + Stmt* originalStmt) { loweredStmt->Position = originalStmt->Position; loweredStmt->modifiers = originalStmt->modifiers; @@ -2147,16 +2147,16 @@ struct LoweringVisitor loweredStmt->parentStmt = translateStmtRef(originalStmt->parentStmt); } - void visitContinueStatementSyntaxNode(ContinueStatementSyntaxNode* stmt) + void visitContinueStmt(ContinueStmt* stmt) { - RefPtr<ContinueStatementSyntaxNode> loweredStmt = new ContinueStatementSyntaxNode(); + RefPtr<ContinueStmt> loweredStmt = new ContinueStmt(); lowerChildStmtFields(loweredStmt, stmt); addStmt(loweredStmt); } - void visitBreakStatementSyntaxNode(BreakStatementSyntaxNode* stmt) + void visitBreakStmt(BreakStmt* stmt) { - RefPtr<BreakStatementSyntaxNode> loweredStmt = new BreakStatementSyntaxNode(); + RefPtr<BreakStmt> loweredStmt = new BreakStmt(); lowerChildStmtFields(loweredStmt, stmt); addStmt(loweredStmt); } @@ -2168,16 +2168,16 @@ struct LoweringVisitor addStmt(loweredStmt); } - void visitDiscardStatementSyntaxNode(DiscardStatementSyntaxNode* stmt) + void visitDiscardStmt(DiscardStmt* stmt) { - RefPtr<DiscardStatementSyntaxNode> loweredStmt = new DiscardStatementSyntaxNode(); + RefPtr<DiscardStmt> loweredStmt = new DiscardStmt(); lowerStmtFields(loweredStmt, stmt); addStmt(loweredStmt); } - void visitEmptyStatementSyntaxNode(EmptyStatementSyntaxNode* stmt) + void visitEmptyStmt(EmptyStmt* stmt) { - RefPtr<EmptyStatementSyntaxNode> loweredStmt = new EmptyStatementSyntaxNode(); + RefPtr<EmptyStmt> loweredStmt = new EmptyStmt(); lowerStmtFields(loweredStmt, stmt); addStmt(loweredStmt); } @@ -2189,7 +2189,7 @@ struct LoweringVisitor for (auto token : stmt->tokens) { - if (token.Type == TokenType::Identifier) + if (token.type == TokenType::Identifier) doSampleRateInputCheck(token.Content); } @@ -2208,9 +2208,9 @@ struct LoweringVisitor addStmt(loweredStmt); } - void visitIfStatementSyntaxNode(IfStatementSyntaxNode* stmt) + void visitIfStmt(IfStmt* stmt) { - RefPtr<IfStatementSyntaxNode> loweredStmt = new IfStatementSyntaxNode(); + RefPtr<IfStmt> loweredStmt = new IfStmt(); lowerStmtFields(loweredStmt, stmt); loweredStmt->Predicate = lowerExpr(stmt->Predicate); @@ -2234,8 +2234,8 @@ struct LoweringVisitor } void lowerForStmtCommon( - RefPtr<ForStatementSyntaxNode> loweredStmt, - ForStatementSyntaxNode* stmt) + RefPtr<ForStmt> loweredStmt, + ForStmt* stmt) { lowerScopeStmtFields(loweredStmt, stmt); @@ -2249,9 +2249,9 @@ struct LoweringVisitor addStmt(loweredStmt); } - void visitForStatementSyntaxNode(ForStatementSyntaxNode* stmt) + void visitForStmt(ForStmt* stmt) { - lowerForStmtCommon(new ForStatementSyntaxNode(), stmt); + lowerForStmtCommon(new ForStmt(), stmt); } void visitUnscopedForStmt(UnscopedForStmt* stmt) @@ -2274,18 +2274,18 @@ struct LoweringVisitor auto varDecl = stmt->varDecl; - auto varType = lowerType(varDecl->Type); + auto varType = lowerType(varDecl->type); for (IntegerLiteralValue ii = rangeBeginVal; ii < rangeEndVal; ++ii) { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); - constExpr->Type.type = varType.type; - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); + constExpr->type.type = varType.type; + constExpr->ConstType = ConstantExpr::ConstantType::Int; constExpr->integerValue = ii; RefPtr<VaryingTupleVarDecl> loweredVarDecl = new VaryingTupleVarDecl(); loweredVarDecl->Position = varDecl->Position; - loweredVarDecl->Type = varType; + loweredVarDecl->type = varType; loweredVarDecl->expr = LoweredExpr(constExpr); shared->loweredDecls[varDecl] = LoweredDecl(loweredVarDecl); @@ -2294,9 +2294,9 @@ struct LoweringVisitor } } - void visitWhileStatementSyntaxNode(WhileStatementSyntaxNode* stmt) + void visitWhileStmt(WhileStmt* stmt) { - RefPtr<WhileStatementSyntaxNode> loweredStmt = new WhileStatementSyntaxNode(); + RefPtr<WhileStmt> loweredStmt = new WhileStmt(); lowerScopeStmtFields(loweredStmt, stmt); LoweringVisitor subVisitor = pushScope(loweredStmt, stmt); @@ -2307,9 +2307,9 @@ struct LoweringVisitor addStmt(loweredStmt); } - void visitDoWhileStatementSyntaxNode(DoWhileStatementSyntaxNode* stmt) + void visitDoWhileStmt(DoWhileStmt* stmt) { - RefPtr<DoWhileStatementSyntaxNode> loweredStmt = new DoWhileStatementSyntaxNode(); + RefPtr<DoWhileStmt> loweredStmt = new DoWhileStmt(); lowerScopeStmtFields(loweredStmt, stmt); LoweringVisitor subVisitor = pushScope(loweredStmt, stmt); @@ -2320,12 +2320,12 @@ struct LoweringVisitor addStmt(loweredStmt); } - RefPtr<StatementSyntaxNode> transformSyntaxField(StatementSyntaxNode* stmt) + RefPtr<Stmt> transformSyntaxField(Stmt* stmt) { return lowerStmt(stmt); } - void lowerStmtCommon(StatementSyntaxNode* loweredStmt, StatementSyntaxNode* stmt) + void lowerStmtCommon(Stmt* loweredStmt, Stmt* stmt) { loweredStmt->modifiers = stmt->modifiers; } @@ -2349,13 +2349,13 @@ struct LoweringVisitor assign(expr, LoweredExpr(createVarRef(getPosition(expr), varDecl))); } - RefPtr<ExpressionSyntaxNode> createCastExpr( - RefPtr<ExpressionType> type, - RefPtr<ExpressionSyntaxNode> expr) + RefPtr<Expr> createCastExpr( + RefPtr<Type> type, + RefPtr<Expr> expr) { RefPtr<ExplicitCastExpr> castExpr = new ExplicitCastExpr(); castExpr->Position = expr->Position; - castExpr->Type.type = type; + castExpr->type.type = type; castExpr->TargetType.type = type; castExpr->Expression = expr; return castExpr; @@ -2381,9 +2381,9 @@ struct LoweringVisitor assignWithFixups(expr, LoweredExpr(createVarRef(getPosition(expr), varDecl))); } - void visitReturnStatementSyntaxNode(ReturnStatementSyntaxNode* stmt) + void visitReturnStmt(ReturnStmt* stmt) { - auto loweredStmt = new ReturnStatementSyntaxNode(); + auto loweredStmt = new ReturnStmt(); lowerStmtCommon(loweredStmt, stmt); if (stmt->Expression) @@ -2409,7 +2409,7 @@ struct LoweringVisitor RefPtr<Val> translateVal(Val* val) { - if (auto type = dynamic_cast<ExpressionType*>(val)) + if (auto type = dynamic_cast<Type*>(val)) return lowerType(type); if (auto litVal = dynamic_cast<ConstantIntVal*>(val)) @@ -2520,7 +2520,7 @@ struct LoweringVisitor if (isBuildingStmt) { - RefPtr<VarDeclrStatementSyntaxNode> declStmt = new VarDeclrStatementSyntaxNode(); + RefPtr<DeclStmt> declStmt = new DeclStmt(); declStmt->Position = decl->Position; declStmt->decl = decl; addStmt(declStmt); @@ -2659,7 +2659,7 @@ struct LoweringVisitor SLANG_UNEXPECTED("generics should be lowered to specialized decls"); } - LoweredDecl visitProgramSyntaxNode(ProgramSyntaxNode*) + LoweredDecl visitModuleDecl(ModuleDecl*) { SLANG_UNEXPECTED("module decls should be lowered explicitly"); } @@ -2696,7 +2696,7 @@ struct LoweringVisitor RefPtr<TypeDefDecl> loweredDecl = new TypeDefDecl(); lowerDeclCommon(loweredDecl, decl); - loweredDecl->Type = lowerType(decl->Type); + loweredDecl->type = lowerType(decl->type); addMember(shared->loweredProgram, loweredDecl); return LoweredDecl(loweredDecl); @@ -2741,7 +2741,7 @@ struct LoweringVisitor return LoweredDecl(loweredDecl); } - TupleTypeModifier* isTupleType(ExpressionType* type) + TupleTypeModifier* isTupleType(Type* type) { if (auto declRefType = type->As<DeclRefType>()) { @@ -2754,7 +2754,7 @@ struct LoweringVisitor return nullptr; } - ExpressionType* unwrapArray(ExpressionType* inType) + Type* unwrapArray(Type* inType) { auto type = inType; while (auto arrayType = type->As<ArrayExpressionType>()) @@ -2764,12 +2764,12 @@ struct LoweringVisitor return type; } - TupleTypeModifier* isTupleTypeOrArrayOfTupleType(ExpressionType* type) + TupleTypeModifier* isTupleTypeOrArrayOfTupleType(Type* type) { return isTupleType(unwrapArray(type)); } - bool isResourceType(ExpressionType* type) + bool isResourceType(Type* type) { while (auto arrayType = type->As<ArrayExpressionType>()) { @@ -2790,7 +2790,7 @@ struct LoweringVisitor return false; } - RefPtr<Decl> visitAggTypeDecl(AggTypeDecl* decl) + LoweredDecl visitAggTypeDecl(AggTypeDecl* decl) { // We want to lower any aggregate type declaration // to just a `struct` type that contains its fields. @@ -2798,7 +2798,7 @@ struct LoweringVisitor // Any non-field members (e.g., methods) will be // lowered separately. - RefPtr<StructSyntaxNode> loweredDecl = new StructSyntaxNode(); + RefPtr<StructDecl> loweredDecl = new StructDecl(); lowerDeclCommon(loweredDecl, decl); // We need to be ready to turn this type into a "tuple" type, @@ -2842,7 +2842,7 @@ struct LoweringVisitor // If the field is of a type that requires special handling, // we need to make a note of it. - auto loweredFieldType = loweredField->Type.type; + auto loweredFieldType = loweredField->type.type; bool isTupleField = false; bool fieldHasAnyNonTupleFields = false; bool fieldHasTupleType = false; @@ -2911,7 +2911,7 @@ struct LoweringVisitor } - return loweredDecl; + return LoweredDecl(loweredDecl); } RefPtr<VarDeclBase> lowerSimpleVarDeclCommon( @@ -2921,8 +2921,8 @@ struct LoweringVisitor { lowerDeclCommon(loweredDecl, decl); - loweredDecl->Type = loweredType; - loweredDecl->Expr = lowerExpr(decl->Expr); + loweredDecl->type = loweredType; + loweredDecl->initExpr = lowerExpr(decl->initExpr); return loweredDecl; } @@ -2931,7 +2931,7 @@ struct LoweringVisitor RefPtr<VarDeclBase> loweredDecl, VarDeclBase* decl) { - auto loweredType = lowerType(decl->Type); + auto loweredType = lowerType(decl->type); return lowerSimpleVarDeclCommon(loweredDecl, decl, loweredType); } @@ -2953,13 +2953,13 @@ struct LoweringVisitor String name; // The parent tuple type (or array thereof) we are scalarizing - RefPtr<ExpressionType> tupleType; + RefPtr<Type> tupleType; // The actual declaration of the tuple type (which will give us the fields) DeclRef<AggTypeDecl> tupleTypeDecl; // An initializer expression to use for the tuple members - RefPtr<ExpressionSyntaxNode> initExpr; + RefPtr<Expr> initExpr; // The original layout given to the top-level variable RefPtr<VarLayout> primaryVarLayout; @@ -2999,7 +2999,7 @@ struct LoweringVisitor // TODO: need to extract the initializer for this field SLANG_RELEASE_ASSERT(!info.initExpr); - RefPtr<ExpressionSyntaxNode> fieldInitExpr; + RefPtr<Expr> fieldInitExpr; String fieldName = info.name + "_" + dd.GetName(); @@ -3092,7 +3092,7 @@ struct LoweringVisitor { // Otherwise the field has a simple type, and we just need to declare the variable here - RefPtr<ExpressionType> fieldVarType = fieldType; + RefPtr<Type> fieldVarType = fieldType; for (auto aa = info.arraySpecs; aa; aa = aa->next) { RefPtr<ArrayExpressionType> arrayType = Slang::getArrayType( @@ -3104,7 +3104,7 @@ struct LoweringVisitor RefPtr<VarDeclBase> fieldVarDecl = info.varDeclClass.createInstance(); fieldVarDecl->Name.Content = fieldName; - fieldVarDecl->Type.type = fieldVarType; + fieldVarDecl->type.type = fieldVarType; addDecl(fieldVarDecl); @@ -3133,10 +3133,10 @@ struct LoweringVisitor SyntaxClass<VarDeclBase> varDeclClass, RefPtr<VarDeclBase> originalVarDecl, String const& name, - RefPtr<ExpressionType> tupleType, + RefPtr<Type> tupleType, DeclRef<AggTypeDecl> tupleTypeDecl, TupleTypeModifier* tupleTypeMod, - RefPtr<ExpressionSyntaxNode> initExpr, + RefPtr<Expr> initExpr, RefPtr<VarLayout> primaryVarLayout, RefPtr<StructTypeLayout> tupleTypeLayout) { @@ -3153,7 +3153,7 @@ struct LoweringVisitor { RefPtr<VarDeclBase> primaryVarDecl = varDeclClass.createInstance(); primaryVarDecl->Name.Content = name; - primaryVarDecl->Type.type = tupleType; + primaryVarDecl->type.type = tupleType; primaryVarDecl->modifiers = originalVarDecl->modifiers; @@ -3211,9 +3211,9 @@ struct LoweringVisitor SyntaxClass<VarDeclBase> varDeclClass, RefPtr<VarDeclBase> originalVarDecl, String const& name, - RefPtr<ExpressionType> tupleType, + RefPtr<Type> tupleType, TupleTypeModifier* tupleTypeMod, - RefPtr<ExpressionSyntaxNode> initExpr, + RefPtr<Expr> initExpr, RefPtr<VarLayout> primaryVarLayout) { RefPtr<StructTypeLayout> tupleTypeLayout; @@ -3239,7 +3239,7 @@ struct LoweringVisitor VarDeclBase* decl, SyntaxClass<VarDeclBase> loweredDeclClass) { - auto loweredType = lowerType(decl->Type); + auto loweredType = lowerType(decl->type); if (auto tupleTypeMod = isTupleTypeOrArrayOfTupleType(loweredType)) { @@ -3251,7 +3251,7 @@ struct LoweringVisitor // If the variable had an initializer, we expect it // to resolve to a tuple *value* - auto loweredInit = lowerExpr(decl->Expr); + auto loweredInit = lowerExpr(decl->initExpr); // TODO: need to extract layout here and propagate it down! @@ -3311,7 +3311,7 @@ struct LoweringVisitor // If this is a global variable (program scope), then add it // to the global scope. RefPtr<ContainerDecl> pp = decl->ParentDecl; - if (auto parentModuleDecl = pp.As<ProgramSyntaxNode>()) + if (auto parentModuleDecl = pp.As<ModuleDecl>()) { LoweringVisitor subVisitor = *this; subVisitor.parentDecl = translateDeclRef(parentModuleDecl); @@ -3328,7 +3328,7 @@ struct LoweringVisitor } } - SourceLanguage getSourceLanguage(ProgramSyntaxNode* moduleDecl) + SourceLanguage getSourceLanguage(ModuleDecl* moduleDecl) { for (auto translationUnit : shared->compileRequest->translationUnits) { @@ -3366,7 +3366,7 @@ struct LoweringVisitor } } - AggTypeDecl* isStructType(RefPtr<ExpressionType> type) + AggTypeDecl* isStructType(RefPtr<Type> type) { if (type->As<BasicExpressionType>()) return nullptr; else if (type->As<VectorExpressionType>()) return nullptr; @@ -3384,7 +3384,7 @@ struct LoweringVisitor return nullptr; } - bool isImportedStructType(RefPtr<ExpressionType> type) + bool isImportedStructType(RefPtr<Type> type) { // TODO: make this use `isStructType` above @@ -3416,7 +3416,7 @@ struct LoweringVisitor Variable* decl) { // Global variable? Check if it is a sample-rate input. - if (dynamic_cast<ProgramSyntaxNode*>(decl->ParentDecl)) + if (dynamic_cast<ModuleDecl*>(decl->ParentDecl)) { if (decl->HasModifier<InModifier>()) { @@ -3429,7 +3429,7 @@ struct LoweringVisitor auto inRes = varLayout->FindResourceInfo(LayoutResourceKind::VertexInput); auto outRes = varLayout->FindResourceInfo(LayoutResourceKind::FragmentOutput); - if( (inRes || outRes) && isImportedStructType(decl->Type.type)) + if( (inRes || outRes) && isImportedStructType(decl->type.type)) { // We are seemingly looking at a GLSL global-scope varying // of an aggregate type which was imported from library @@ -3480,10 +3480,10 @@ struct LoweringVisitor return LoweredDecl(lowerSimpleVarDeclCommon(new StructField(), decl)); } - LoweredDecl visitParameterSyntaxNode( - ParameterSyntaxNode* decl) + LoweredDecl visitParamDecl( + ParamDecl* decl) { - auto loweredDecl = lowerVarDeclCommon(decl, getClass<ParameterSyntaxNode>()); + auto loweredDecl = lowerVarDeclCommon(decl, getClass<ParamDecl>()); return loweredDecl; } @@ -3508,7 +3508,7 @@ struct LoweringVisitor { // TODO: need to generate a name - RefPtr<FunctionSyntaxNode> loweredDecl = new FunctionSyntaxNode(); + RefPtr<FuncDecl> loweredDecl = new FuncDecl(); lowerDeclCommon(loweredDecl, decl); // TODO: push scope for parent decl here... @@ -3612,18 +3612,18 @@ struct LoweringVisitor VaryingParameterVarChain* varChain = nullptr; }; - RefPtr<ExpressionSyntaxNode> createGLSLBuiltinRef( + RefPtr<Expr> createGLSLBuiltinRef( char const* name, - RefPtr<ExpressionType> type) + RefPtr<Type> type) { - RefPtr<VarExpressionSyntaxNode> globalVarRef = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> globalVarRef = new VarExpr(); globalVarRef->name = name; - globalVarRef->Type.type = type; + globalVarRef->type.type = type; return globalVarRef; } bool isIntegralType( - ExpressionType* type) + Type* type) { if (auto baseType = type->As<BasicExpressionType>()) { @@ -3659,28 +3659,28 @@ struct LoweringVisitor Slang::requireGLSLVersion(entryPoint, version); } - RefPtr<ExpressionType> getFloatType() + RefPtr<Type> getFloatType() { return getSession()->getFloatType(); } - RefPtr<ExpressionType> getIntType() + RefPtr<Type> getIntType() { return getSession()->getIntType(); } - RefPtr<ExpressionType> getUIntType() + RefPtr<Type> getUIntType() { return getSession()->getUIntType(); } - RefPtr<ExpressionType> getBoolType() + RefPtr<Type> getBoolType() { return getSession()->getBoolType(); } RefPtr<VectorExpressionType> getVectorType( - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, RefPtr<IntVal> elementCount) { auto session = getSession(); @@ -3709,21 +3709,21 @@ struct LoweringVisitor } RefPtr<VectorExpressionType> getVectorType( - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, int elementCount) { return getVectorType(elementType, getConstantIntVal(elementCount)); } RefPtr<ArrayExpressionType> getUnsizedArrayType( - RefPtr<ExpressionType> elementType) + RefPtr<Type> elementType) { RefPtr<ArrayExpressionType> arrayType = Slang::getArrayType(elementType); return arrayType; } RefPtr<ArrayExpressionType> getArrayType( - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, IntegerLiteralValue elementCount) { return Slang::getArrayType(elementType, getConstantIntVal(elementCount)); @@ -3731,10 +3731,10 @@ struct LoweringVisitor LoweredExpr lowerSimpleShaderParameterToGLSLGlobal( VaryingParameterInfo const& info, - RefPtr<ExpressionType> varType, + RefPtr<Type> varType, RefPtr<VarLayout> varLayout) { - RefPtr<ExpressionType> type = varType; + RefPtr<Type> type = varType; for (auto aa = info.arraySpecs; aa; aa = aa->next) { @@ -3750,7 +3750,7 @@ struct LoweringVisitor // We need to create a reference to the global-scope declaration // of the proper GLSL input/output variable. This might // be a user-defined input/output, or a system-defined `gl_` one. - RefPtr<ExpressionSyntaxNode> globalVarExpr; + RefPtr<Expr> globalVarExpr; // Handle system-value inputs/outputs SLANG_RELEASE_ASSERT(varLayout); @@ -3941,7 +3941,7 @@ struct LoweringVisitor { RefPtr<Variable> globalVarDecl = new Variable(); globalVarDecl->Name.Content = info.name; - globalVarDecl->Type.type = type; + globalVarDecl->type.type = type; ensureDeclHasAValidName(globalVarDecl); @@ -3998,9 +3998,9 @@ struct LoweringVisitor } - RefPtr<VarExpressionSyntaxNode> globalVarRef = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> globalVarRef = new VarExpr(); globalVarRef->Position = globalVarDecl->Position; - globalVarRef->Type.type = globalVarDecl->Type.type; + globalVarRef->type.type = globalVarDecl->type.type; globalVarRef->declRef = makeDeclRef(globalVarDecl.Ptr()); globalVarRef->name = globalVarDecl->getName(); @@ -4012,7 +4012,7 @@ struct LoweringVisitor LoweredExpr lowerShaderParameterToGLSLGLobalsRec( VaryingParameterInfo const& info, - RefPtr<ExpressionType> varType, + RefPtr<Type> varType, RefPtr<VarLayout> varLayout) { SLANG_RELEASE_ASSERT(varLayout); @@ -4063,9 +4063,9 @@ struct LoweringVisitor // to destructure it into its constituent fields RefPtr<VaryingTupleExpr> tupleExpr = new VaryingTupleExpr(); - tupleExpr->Type.type = varType; + tupleExpr->type.type = varType; - SLANG_RELEASE_ASSERT(tupleExpr->Type.type); + SLANG_RELEASE_ASSERT(tupleExpr->type.type); for (auto fieldDeclRef : getMembersOfType<VarDeclBase>(aggTypeDeclRef)) { @@ -4143,7 +4143,7 @@ struct LoweringVisitor break; } - auto loweredType = lowerType(originalVarDecl->Type); + auto loweredType = lowerType(originalVarDecl->type); auto loweredExpr = lowerShaderParameterToGLSLGLobalsRec( info, @@ -4170,7 +4170,7 @@ struct LoweringVisitor { RefPtr<VaryingTupleVarDecl> loweredDecl = new VaryingTupleVarDecl(); loweredDecl->Name = originalVarDecl->Name; - loweredDecl->Type = loweredType; + loweredDecl->type = loweredType; loweredDecl->expr = loweredExpr; return loweredDecl; @@ -4180,26 +4180,26 @@ struct LoweringVisitor RefPtr<VarDeclBase> originalVarDecl, LoweredExpr loweredExpr) { - auto loweredType = lowerType(originalVarDecl->Type); + auto loweredType = lowerType(originalVarDecl->type); return createVaryingTupleVarDecl(originalVarDecl, loweredType, loweredExpr); } struct EntryPointParamPair { - RefPtr<ParameterSyntaxNode> original; + RefPtr<ParamDecl> original; RefPtr<VarLayout> layout; RefPtr<Variable> lowered; }; - RefPtr<FunctionSyntaxNode> lowerEntryPointToGLSL( - FunctionSyntaxNode* entryPointDecl, + RefPtr<FuncDecl> lowerEntryPointToGLSL( + FuncDecl* entryPointDecl, RefPtr<EntryPointLayout> entryPointLayout) { // First, loer the entry-point function as an ordinary function: auto loweredEntryPointFunc = visitFunctionDeclBase(entryPointDecl).getDecl()->As<FunctionDeclBase>(); // Now we will generate a `void main() { ... }` function to call the lowered code. - RefPtr<FunctionSyntaxNode> mainDecl = new FunctionSyntaxNode(); + RefPtr<FuncDecl> mainDecl = new FuncDecl(); mainDecl->ReturnType.type = getSession()->getVoidType(); mainDecl->Name.Content = "main"; @@ -4232,7 +4232,7 @@ struct LoweringVisitor RefPtr<Variable> localVarDecl = new Variable(); localVarDecl->Position = paramDecl->Position; localVarDecl->Name.Content = paramDecl->getName(); - localVarDecl->Type = lowerType(paramDecl->Type); + localVarDecl->type = lowerType(paramDecl->type); ensureDeclHasAValidName(localVarDecl); @@ -4270,7 +4270,7 @@ struct LoweringVisitor resultVarDecl = new Variable(); resultVarDecl->Position = loweredEntryPointFunc->Position; resultVarDecl->Name.Content = "main_result"; - resultVarDecl->Type = TypeExp(loweredEntryPointFunc->ReturnType); + resultVarDecl->type = TypeExp(loweredEntryPointFunc->ReturnType); ensureDeclHasAValidName(resultVarDecl); @@ -4284,24 +4284,24 @@ struct LoweringVisitor getSession(), entryPointDeclRef); - RefPtr<VarExpressionSyntaxNode> entryPointRef = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> entryPointRef = new VarExpr(); entryPointRef->name = loweredEntryPointFunc->getName(); entryPointRef->declRef = entryPointDeclRef; - entryPointRef->Type = QualType(entryPointType); + entryPointRef->type = QualType(entryPointType); - RefPtr<InvokeExpressionSyntaxNode> callExpr = new InvokeExpressionSyntaxNode(); + RefPtr<InvokeExpr> callExpr = new InvokeExpr(); callExpr->FunctionExpr = entryPointRef; - callExpr->Type = QualType(loweredEntryPointFunc->ReturnType); + callExpr->type = QualType(loweredEntryPointFunc->ReturnType); // for (auto paramPair : params) { auto localVarDecl = paramPair.lowered; - RefPtr<VarExpressionSyntaxNode> varRef = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> varRef = new VarExpr(); varRef->name = localVarDecl->getName(); varRef->declRef = makeDeclRef(localVarDecl.Ptr()); - varRef->Type = QualType(localVarDecl->getType()); + varRef->type = QualType(localVarDecl->getType()); callExpr->Arguments.Add(varRef); } @@ -4342,7 +4342,7 @@ struct LoweringVisitor auto loweredExpr = lowerShaderParameterToGLSLGLobalsRec( info, - resultVarDecl->Type.type, + resultVarDecl->type.type, entryPointLayout->resultLayout); subVisitor.assignWithFixups(loweredExpr, resultVarDecl); @@ -4364,7 +4364,7 @@ struct LoweringVisitor return mainDecl; #if 0 - RefPtr<FunctionSyntaxNode> loweredDecl = new FunctionSyntaxNode(); + RefPtr<FuncDecl> loweredDecl = new FuncDecl(); lowerDeclCommon(loweredDecl, entryPointDecl); // We create a sub-context appropriate for lowering the function body @@ -4389,7 +4389,7 @@ struct LoweringVisitor resultGlobal = new Variable(); // TODO: need a scheme for generating unique names resultGlobal->Name.Content = "_main_result"; - resultGlobal->Type = loweredReturnType; + resultGlobal->type = loweredReturnType; addMember(shared->loweredProgram, resultGlobal); } @@ -4414,15 +4414,15 @@ struct LoweringVisitor #endif } - RefPtr<FunctionSyntaxNode> lowerEntryPoint( - FunctionSyntaxNode* entryPointDecl, + RefPtr<FuncDecl> lowerEntryPoint( + FuncDecl* entryPointDecl, RefPtr<EntryPointLayout> entryPointLayout) { switch( getTarget() ) { // Default case: lower an entry point just like any other function default: - return visitFunctionDeclBase(entryPointDecl).getDecl()->As<FunctionSyntaxNode>(); + return visitFunctionDeclBase(entryPointDecl).getDecl()->As<FuncDecl>(); // For Slang->GLSL translation, we need to lower things from HLSL-style // declarations over to GLSL conventions @@ -4431,7 +4431,7 @@ struct LoweringVisitor } } - RefPtr<FunctionSyntaxNode> lowerEntryPoint( + RefPtr<FuncDecl> lowerEntryPoint( EntryPointRequest* entryPointRequest) { auto entryPointLayout = findEntryPointLayout(entryPointRequest); @@ -4533,7 +4533,7 @@ LoweredEntryPoint lowerEntryPoint( // Create a single module/program to hold all the lowered code // (with the exception of instrinsic/stdlib declarations, which // will be remain where they are) - RefPtr<ProgramSyntaxNode> loweredProgram = new ProgramSyntaxNode(); + RefPtr<ModuleDecl> loweredProgram = new ModuleDecl(); sharedContext.loweredProgram = loweredProgram; LoweringVisitor visitor; diff --git a/source/slang/lower.h b/source/slang/lower.h index 688c1df8f..919260af3 100644 --- a/source/slang/lower.h +++ b/source/slang/lower.h @@ -22,12 +22,12 @@ namespace Slang struct LoweredEntryPoint { // The actual lowered entry point - RefPtr<FunctionSyntaxNode> entryPoint; + RefPtr<FuncDecl> entryPoint; // The generated program AST that // contains the entry point and any // other declarations it uses - RefPtr<ProgramSyntaxNode> program; + RefPtr<ModuleDecl> program; }; // Emit code for a single entry point, based on diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index 89f2096e4..5bab29aba 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -265,7 +265,7 @@ SIMPLE_SYNTAX_CLASS(HLSLVolatileModifier, Modifier) // An HLSL `[name(arg0, ...)]` style attribute. SYNTAX_CLASS(HLSLAttribute, Modifier) FIELD(Token, nameToken) - SYNTAX_FIELD(List<RefPtr<ExpressionSyntaxNode>>, args) + SYNTAX_FIELD(List<RefPtr<Expr>>, args) END_SYNTAX_CLASS() // An HLSL `[name(...)]` attribute that hasn't undergone diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 9b1036d02..eeaa04a3f 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -390,7 +390,7 @@ static bool isGLSLBuiltinName(VarDeclBase* varDecl) return getReflectionName(varDecl).StartsWith("gl_"); } -RefPtr<ExpressionType> tryGetEffectiveTypeForGLSLVaryingInput( +RefPtr<Type> tryGetEffectiveTypeForGLSLVaryingInput( ParameterBindingContext* context, VarDeclBase* varDecl) { @@ -428,7 +428,7 @@ RefPtr<ExpressionType> tryGetEffectiveTypeForGLSLVaryingInput( return nullptr; } -RefPtr<ExpressionType> tryGetEffectiveTypeForGLSLVaryingOutput( +RefPtr<Type> tryGetEffectiveTypeForGLSLVaryingOutput( ParameterBindingContext* context, VarDeclBase* varDecl) { @@ -592,14 +592,14 @@ struct EntryPointParameterState static RefPtr<TypeLayout> processEntryPointParameter( ParameterBindingContext* context, - RefPtr<ExpressionType> type, + RefPtr<Type> type, EntryPointParameterState const& state, RefPtr<VarLayout> varLayout); static void collectGlobalScopeGLSLVaryingParameter( ParameterBindingContext* context, RefPtr<VarDeclBase> varDecl, - RefPtr<ExpressionType> effectiveType, + RefPtr<Type> effectiveType, EntryPointParameterDirection direction) { int defaultSemanticIndex = 0; @@ -994,7 +994,7 @@ static void completeBindingsForParameter( static void collectGlobalScopeParameters( ParameterBindingContext* context, - ProgramSyntaxNode* program) + ModuleDecl* program) { // First enumerate parameters at global scope for( auto decl : program->Members ) @@ -1066,7 +1066,7 @@ SimpleSemanticInfo decomposeSimpleSemantic( static RefPtr<TypeLayout> processSimpleEntryPointParameter( ParameterBindingContext* context, - RefPtr<ExpressionType> type, + RefPtr<Type> type, EntryPointParameterState const& inState, RefPtr<VarLayout> varLayout, int semanticSlotCount = 1) @@ -1147,7 +1147,7 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( static RefPtr<TypeLayout> processEntryPointParameterWithPossibleSemantic( ParameterBindingContext* context, Decl* declForSemantic, - RefPtr<ExpressionType> type, + RefPtr<Type> type, EntryPointParameterState const& state, RefPtr<VarLayout> varLayout) { @@ -1178,7 +1178,7 @@ static RefPtr<TypeLayout> processEntryPointParameterWithPossibleSemantic( static RefPtr<TypeLayout> processEntryPointParameter( ParameterBindingContext* context, - RefPtr<ExpressionType> type, + RefPtr<Type> type, EntryPointParameterState const& state, RefPtr<VarLayout> varLayout) { @@ -1235,7 +1235,7 @@ static RefPtr<TypeLayout> processEntryPointParameter( { auto declRef = declRefType->declRef; - if (auto structDeclRef = declRef.As<StructSyntaxNode>()) + if (auto structDeclRef = declRef.As<StructDecl>()) { RefPtr<StructTypeLayout> structLayout = new StructTypeLayout(); structLayout->type = type; @@ -1288,7 +1288,7 @@ static RefPtr<TypeLayout> processEntryPointParameter( static void collectEntryPointParameters( ParameterBindingContext* context, EntryPointRequest* entryPoint, - ProgramSyntaxNode* translationUnitSyntax) + ModuleDecl* translationUnitSyntax) { // First, look for the entry point with the specified name @@ -1307,7 +1307,7 @@ static void collectEntryPointParameters( return; } - FunctionSyntaxNode* entryPointFuncDecl = dynamic_cast<FunctionSyntaxNode*>(entryPointDecl); + FuncDecl* entryPointFuncDecl = dynamic_cast<FuncDecl*>(entryPointDecl); if( !entryPointFuncDecl ) { // Not a function! @@ -1368,7 +1368,7 @@ static void collectEntryPointParameters( auto paramTypeLayout = processEntryPointParameterWithPossibleSemantic( context, paramDecl.Ptr(), - paramDecl->Type.type, + paramDecl->type.type, state, paramVarLayout); @@ -1443,7 +1443,7 @@ inferStageForTranslationUnit( static void collectModuleParameters( ParameterBindingContext* inContext, - ProgramSyntaxNode* module) + ModuleDecl* module) { // Each loaded module provides a separate (logical) namespace for // parameters, so that two parameters with the same name, in @@ -1689,10 +1689,10 @@ void generateParameterBindings( RefPtr<Variable> var = new Variable(); var->Name.Content = "SLANG_hack_samplerForTexelFetch"; - var->Type.type = getSamplerStateType(request->mSession); + var->type.type = getSamplerStateType(request->mSession); auto typeLayout = new TypeLayout(); - typeLayout->type = var->Type.type; + typeLayout->type = var->type.type; typeLayout->addResourceUsage(LayoutResourceKind::DescriptorTableSlot, 1); auto varLayout = new VarLayout(); diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index c36b2f477..41a4411d2 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -86,37 +86,37 @@ namespace Slang return translationUnit->compileRequest->mSession; } - RefPtr<ProgramSyntaxNode> Parse(); + RefPtr<ModuleDecl> Parse(); Token ReadToken(); Token ReadToken(TokenType type); Token ReadToken(const char * string); bool LookAheadToken(TokenType type, int offset = 0); bool LookAheadToken(const char * string, int offset = 0); - void parseSourceFile(ProgramSyntaxNode* program); - RefPtr<ProgramSyntaxNode> ParseProgram(); - RefPtr<StructSyntaxNode> ParseStruct(); - RefPtr<ClassSyntaxNode> ParseClass(); - RefPtr<StatementSyntaxNode> ParseStatement(); - RefPtr<StatementSyntaxNode> ParseBlockStatement(); - RefPtr<VarDeclrStatementSyntaxNode> ParseVarDeclrStatement(Modifiers modifiers); - RefPtr<IfStatementSyntaxNode> ParseIfStatement(); - RefPtr<ForStatementSyntaxNode> ParseForStatement(); - RefPtr<WhileStatementSyntaxNode> ParseWhileStatement(); - RefPtr<DoWhileStatementSyntaxNode> ParseDoWhileStatement(); - RefPtr<BreakStatementSyntaxNode> ParseBreakStatement(); - RefPtr<ContinueStatementSyntaxNode> ParseContinueStatement(); - RefPtr<ReturnStatementSyntaxNode> ParseReturnStatement(); - RefPtr<ExpressionStatementSyntaxNode> ParseExpressionStatement(); - RefPtr<ExpressionSyntaxNode> ParseExpression(Precedence level = Precedence::Comma); + void parseSourceFile(ModuleDecl* program); + RefPtr<ModuleDecl> ParseProgram(); + RefPtr<StructDecl> ParseStruct(); + RefPtr<ClassDecl> ParseClass(); + RefPtr<Stmt> ParseStatement(); + RefPtr<Stmt> ParseBlockStatement(); + RefPtr<DeclStmt> ParseVarDeclrStatement(Modifiers modifiers); + RefPtr<IfStmt> ParseIfStatement(); + RefPtr<ForStmt> ParseForStatement(); + RefPtr<WhileStmt> ParseWhileStatement(); + RefPtr<DoWhileStmt> ParseDoWhileStatement(); + RefPtr<BreakStmt> ParseBreakStatement(); + RefPtr<ContinueStmt> ParseContinueStatement(); + RefPtr<ReturnStmt> ParseReturnStatement(); + RefPtr<ExpressionStmt> ParseExpressionStatement(); + RefPtr<Expr> ParseExpression(Precedence level = Precedence::Comma); // Parse an expression that might be used in an initializer or argument context, so we should avoid operator-comma - inline RefPtr<ExpressionSyntaxNode> ParseInitExpr() { return ParseExpression(Precedence::Assignment); } - inline RefPtr<ExpressionSyntaxNode> ParseArgExpr() { return ParseExpression(Precedence::Assignment); } + inline RefPtr<Expr> ParseInitExpr() { return ParseExpression(Precedence::Assignment); } + inline RefPtr<Expr> ParseArgExpr() { return ParseExpression(Precedence::Assignment); } - RefPtr<ExpressionSyntaxNode> ParseLeafExpression(); - RefPtr<ParameterSyntaxNode> ParseParameter(); - RefPtr<ExpressionSyntaxNode> ParseType(); + RefPtr<Expr> ParseLeafExpression(); + RefPtr<ParamDecl> ParseParameter(); + RefPtr<Expr> ParseType(); TypeExp ParseTypeExp(); Parser & operator = (const Parser &) = delete; @@ -204,7 +204,7 @@ namespace Slang static TokenType SkipBalancedToken( TokenReader* reader) { - TokenType tokenType = reader->AdvanceToken().Type; + TokenType tokenType = reader->AdvanceToken().type; switch (tokenType) { default: @@ -526,7 +526,7 @@ namespace Slang return false; } - RefPtr<ProgramSyntaxNode> Parser::Parse() + RefPtr<ModuleDecl> Parser::Parse() { return ParseProgram(); } @@ -545,7 +545,7 @@ namespace Slang auto nameToken = parser->ReadToken(TokenType::Identifier); typeDefDecl->Name = nameToken; - typeDefDecl->Type = type; + typeDefDecl->type = type; return typeDefDecl; } @@ -937,7 +937,7 @@ namespace Slang if (AdvanceIf(parser, "operator")) { name = parser->ReadToken(); - switch (name.Type) + switch (name.type) { case TokenType::OpAdd: case TokenType::OpSub: case TokenType::OpMul: case TokenType::OpDiv: case TokenType::OpMod: case TokenType::OpNot: case TokenType::OpBitNot: case TokenType::OpLsh: case TokenType::OpRsh: @@ -1017,16 +1017,16 @@ namespace Slang CodePosition openBracketLoc; // The expression that yields the element count, or NULL - RefPtr<ExpressionSyntaxNode> elementCountExpr; + RefPtr<Expr> elementCountExpr; }; // "Unwrapped" information about a declarator struct DeclaratorInfo { - RefPtr<ExpressionSyntaxNode> typeSpec; + RefPtr<Expr> typeSpec; Token nameToken; RefPtr<Modifier> semantics; - RefPtr<ExpressionSyntaxNode> initializer; + RefPtr<Expr> initializer; }; // Add a member declaration to its container, and ensure that its @@ -1081,7 +1081,7 @@ namespace Slang static void ParseFuncDeclHeader( Parser* parser, DeclaratorInfo const& declaratorInfo, - RefPtr<FunctionSyntaxNode> decl) + RefPtr<FuncDecl> decl) { parser->PushScope(decl.Ptr()); @@ -1099,7 +1099,7 @@ namespace Slang ContainerDecl* /*containerDecl*/, DeclaratorInfo const& declaratorInfo) { - RefPtr<FunctionSyntaxNode> decl = new FunctionSyntaxNode(); + RefPtr<FuncDecl> decl = new FuncDecl(); ParseFuncDeclHeader(parser, declaratorInfo, decl); if (AdvanceIf(parser, TokenType::Semicolon)) @@ -1118,13 +1118,13 @@ namespace Slang static RefPtr<VarDeclBase> CreateVarDeclForContext( ContainerDecl* containerDecl ) { - if (dynamic_cast<StructSyntaxNode*>(containerDecl) || dynamic_cast<ClassSyntaxNode*>(containerDecl)) + if (dynamic_cast<StructDecl*>(containerDecl) || dynamic_cast<ClassDecl*>(containerDecl)) { return new StructField(); } else if (dynamic_cast<CallableDecl*>(containerDecl)) { - return new ParameterSyntaxNode(); + return new ParamDecl(); } else { @@ -1167,7 +1167,7 @@ namespace Slang { parser->FillPosition(decl.Ptr()); - if( declaratorInfo.nameToken.Type == TokenType::Unknown ) + if( declaratorInfo.nameToken.type == TokenType::Unknown ) { // HACK(tfoley): we always give a name, even if the declarator didn't include one... :( decl->Name.Content = generateName(parser); @@ -1177,11 +1177,11 @@ namespace Slang decl->Position = declaratorInfo.nameToken.Position; decl->Name = declaratorInfo.nameToken; } - decl->Type = TypeExp(declaratorInfo.typeSpec); + decl->type = TypeExp(declaratorInfo.typeSpec); AddModifiers(decl.Ptr(), declaratorInfo.semantics); - decl->Expr = declaratorInfo.initializer; + decl->initExpr = declaratorInfo.initializer; } static RefPtr<Declarator> ParseDeclarator(Parser* parser); @@ -1291,7 +1291,7 @@ namespace Slang { RefPtr<Declarator> declarator; RefPtr<Modifier> semantics; - RefPtr<ExpressionSyntaxNode> initializer; + RefPtr<Expr> initializer; }; // Parse a declarator plus optional semantics @@ -1348,7 +1348,7 @@ namespace Slang // TODO(tfoley): we don't support pointers for now auto arrayDeclarator = (ArrayDeclarator*) declarator.Ptr(); - auto arrayTypeExpr = new IndexExpressionSyntaxNode(); + auto arrayTypeExpr = new IndexExpr(); arrayTypeExpr->Position = arrayDeclarator->openBracketLoc; arrayTypeExpr->BaseExpression = ioInfo->typeSpec; arrayTypeExpr->IndexExpression = arrayDeclarator->elementCountExpr; @@ -1413,13 +1413,13 @@ namespace Slang }; // Pares an argument to an application of a generic - RefPtr<ExpressionSyntaxNode> ParseGenericArg(Parser* parser) + RefPtr<Expr> ParseGenericArg(Parser* parser) { return parser->ParseArgExpr(); } // Create a type expression that will refer to the given declaration - static RefPtr<ExpressionSyntaxNode> + static RefPtr<Expr> createDeclRefType(Parser* parser, RefPtr<Decl> decl) { // For now we just construct an expression that @@ -1427,7 +1427,7 @@ namespace Slang // // TODO: do this better, e.g. by filling in the `declRef` field directly - auto expr = new VarExpressionSyntaxNode(); + auto expr = new VarExpr(); expr->scope = parser->currentScope.Ptr(); expr->Position = decl->getNameToken().Position; expr->name = decl->getName(); @@ -1442,12 +1442,12 @@ namespace Slang RefPtr<Decl> decl; // Put the resulting expression (which should evaluate to a type) here - RefPtr<ExpressionSyntaxNode> expr; + RefPtr<Expr> expr; }; - static RefPtr<ExpressionSyntaxNode> parseGenericApp( + static RefPtr<Expr> parseGenericApp( Parser* parser, - RefPtr<ExpressionSyntaxNode> base) + RefPtr<Expr> base) { RefPtr<GenericAppExpr> genericApp = new GenericAppExpr(); @@ -1472,14 +1472,14 @@ namespace Slang } // Parse option `[]` braces after a type expression, that indicate an array type - static RefPtr<ExpressionSyntaxNode> parsePostfixTypeSuffix( + static RefPtr<Expr> parsePostfixTypeSuffix( Parser* parser, - RefPtr<ExpressionSyntaxNode> inTypeExpr) + RefPtr<Expr> inTypeExpr) { auto typeExpr = inTypeExpr; while (parser->LookAheadToken(TokenType::LBracket)) { - RefPtr<IndexExpressionSyntaxNode> arrType = new IndexExpressionSyntaxNode(); + RefPtr<IndexExpr> arrType = new IndexExpr(); arrType->Position = typeExpr->Position; arrType->BaseExpression = typeExpr; parser->ReadToken(TokenType::LBracket); @@ -1520,12 +1520,12 @@ namespace Slang Token typeName = parser->ReadToken(TokenType::Identifier); - auto basicType = new VarExpressionSyntaxNode(); + auto basicType = new VarExpr(); basicType->scope = parser->currentScope.Ptr(); basicType->Position = typeName.Position; basicType->name = typeName.Content; - RefPtr<ExpressionSyntaxNode> typeExpr = basicType; + RefPtr<Expr> typeExpr = basicType; if (parser->LookAheadToken(TokenType::OpLess)) { @@ -1797,7 +1797,7 @@ namespace Slang // We are going to represent each buffer as a pair of declarations. // The first is a type declaration that holds all the members, while // the second is a variable declaration that uses the buffer type. - RefPtr<StructSyntaxNode> bufferDataTypeDecl = new StructSyntaxNode(); + RefPtr<StructDecl> bufferDataTypeDecl = new StructDecl(); RefPtr<Variable> bufferVarDecl = new Variable(); // Both declarations will have a location that points to the name @@ -1824,13 +1824,13 @@ namespace Slang // these constructs directly into the AST and *then* desugar them. // Construct a type expression to reference the buffer data type - auto bufferDataTypeExpr = new VarExpressionSyntaxNode(); + auto bufferDataTypeExpr = new VarExpr(); bufferDataTypeExpr->Position = bufferDataTypeDecl->Position; bufferDataTypeExpr->name = bufferDataTypeDecl->Name.Content; bufferDataTypeExpr->scope = parser->currentScope.Ptr(); // Construct a type exrpession to reference the type constructor - auto bufferWrapperTypeExpr = new VarExpressionSyntaxNode(); + auto bufferWrapperTypeExpr = new VarExpr(); bufferWrapperTypeExpr->Position = bufferWrapperTypeNamePos; bufferWrapperTypeExpr->name = bufferWrapperTypeName; @@ -1845,7 +1845,7 @@ namespace Slang bufferVarTypeExpr->FunctionExpr = bufferWrapperTypeExpr; bufferVarTypeExpr->Arguments.Add(bufferDataTypeExpr); - bufferVarDecl->Type.exp = bufferVarTypeExpr; + bufferVarDecl->type.exp = bufferVarTypeExpr; // Any semantics applied to the bufer declaration are taken as applying // to the variable instead. @@ -1953,7 +1953,7 @@ namespace Slang // We are going to represent each buffer as a pair of declarations. // The first is a type declaration that holds all the members, while // the second is a variable declaration that uses the buffer type. - RefPtr<StructSyntaxNode> blockDataTypeDecl = new StructSyntaxNode(); + RefPtr<StructDecl> blockDataTypeDecl = new StructDecl(); RefPtr<Variable> blockVarDecl = new Variable(); addModifier(blockDataTypeDecl, new ImplicitParameterBlockElementTypeModifier()); @@ -1977,13 +1977,13 @@ namespace Slang // these constructs directly into the AST and *then* desugar them. // Construct a type expression to reference the buffer data type - auto blockDataTypeExpr = new VarExpressionSyntaxNode(); + auto blockDataTypeExpr = new VarExpr(); blockDataTypeExpr->Position = blockDataTypeDecl->Position; blockDataTypeExpr->name = blockDataTypeDecl->Name.Content; blockDataTypeExpr->scope = parser->currentScope.Ptr(); // Construct a type exrpession to reference the type constructor - auto blockWrapperTypeExpr = new VarExpressionSyntaxNode(); + auto blockWrapperTypeExpr = new VarExpr(); blockWrapperTypeExpr->Position = pos; blockWrapperTypeExpr->name = blockWrapperTypeName; // Always need to look this up in the outer scope, @@ -1997,7 +1997,7 @@ namespace Slang blockVarTypeExpr->FunctionExpr = blockWrapperTypeExpr; blockVarTypeExpr->Arguments.Add(blockDataTypeExpr); - blockVarDecl->Type.exp = blockVarTypeExpr; + blockVarDecl->type.exp = blockVarTypeExpr; // The declarations in the body belong to the data type. parseAggTypeDeclBody(parser, blockDataTypeDecl.Ptr()); @@ -2056,11 +2056,11 @@ namespace Slang paramDecl->Name = parser->ReadToken(TokenType::Identifier); if (AdvanceIf(parser, TokenType::Colon)) { - paramDecl->Type = parser->ParseTypeExp(); + paramDecl->type = parser->ParseTypeExp(); } if (AdvanceIf(parser, TokenType::OpAssign)) { - paramDecl->Expr = parser->ParseInitExpr(); + paramDecl->initExpr = parser->ParseInitExpr(); } return paramDecl; } @@ -2084,7 +2084,7 @@ namespace Slang auto paramTypeExpr = new SharedTypeExpr(); paramTypeExpr->Position = paramDecl->Position; paramTypeExpr->base.type = paramType; - paramTypeExpr->Type = QualType(getTypeType(paramType)); + paramTypeExpr->type = QualType(getTypeType(paramType)); paramConstraint->sub = TypeExp(paramTypeExpr); paramConstraint->sup = parser->ParseTypeExp(); @@ -2438,7 +2438,7 @@ namespace Slang } - void Parser::parseSourceFile(ProgramSyntaxNode* program) + void Parser::parseSourceFile(ModuleDecl* program) { if (outerScope) { @@ -2454,18 +2454,18 @@ namespace Slang currentScope = nullptr; } - RefPtr<ProgramSyntaxNode> Parser::ParseProgram() + RefPtr<ModuleDecl> Parser::ParseProgram() { - RefPtr<ProgramSyntaxNode> program = new ProgramSyntaxNode(); + RefPtr<ModuleDecl> program = new ModuleDecl(); parseSourceFile(program.Ptr()); return program; } - RefPtr<StructSyntaxNode> Parser::ParseStruct() + RefPtr<StructDecl> Parser::ParseStruct() { - RefPtr<StructSyntaxNode> rs = new StructSyntaxNode(); + RefPtr<StructDecl> rs = new StructDecl(); FillPosition(rs.Ptr()); ReadToken("struct"); @@ -2481,9 +2481,9 @@ namespace Slang return rs; } - RefPtr<ClassSyntaxNode> Parser::ParseClass() + RefPtr<ClassDecl> Parser::ParseClass() { - RefPtr<ClassSyntaxNode> rs = new ClassSyntaxNode(); + RefPtr<ClassDecl> rs = new ClassDecl(); FillPosition(rs.Ptr()); ReadToken("class"); rs->Name = ReadToken(TokenType::Identifier); @@ -2493,7 +2493,7 @@ namespace Slang return rs; } - static RefPtr<StatementSyntaxNode> ParseSwitchStmt(Parser* parser) + static RefPtr<Stmt> ParseSwitchStmt(Parser* parser) { RefPtr<SwitchStmt> stmt = new SwitchStmt(); parser->FillPosition(stmt.Ptr()); @@ -2505,7 +2505,7 @@ namespace Slang return stmt; } - static RefPtr<StatementSyntaxNode> ParseCaseStmt(Parser* parser) + static RefPtr<Stmt> ParseCaseStmt(Parser* parser) { RefPtr<CaseStmt> stmt = new CaseStmt(); parser->FillPosition(stmt.Ptr()); @@ -2515,7 +2515,7 @@ namespace Slang return stmt; } - static RefPtr<StatementSyntaxNode> ParseDefaultStmt(Parser* parser) + static RefPtr<Stmt> ParseDefaultStmt(Parser* parser) { RefPtr<DefaultStmt> stmt = new DefaultStmt(); parser->FillPosition(stmt.Ptr()); @@ -2580,7 +2580,7 @@ namespace Slang return isTypeName(parser, name); } - RefPtr<StatementSyntaxNode> parseCompileTimeForStmt( + RefPtr<Stmt> parseCompileTimeForStmt( Parser* parser) { RefPtr<ScopeDecl> scopeDecl = new ScopeDecl(); @@ -2602,8 +2602,8 @@ namespace Slang parser->ReadToken("Range"); parser->ReadToken(TokenType::LParent); - RefPtr<ExpressionSyntaxNode> rangeBeginExpr; - RefPtr<ExpressionSyntaxNode> rangeEndExpr = parser->ParseArgExpr(); + RefPtr<Expr> rangeBeginExpr; + RefPtr<Expr> rangeEndExpr = parser->ParseArgExpr(); if (AdvanceIf(parser, TokenType::Comma)) { rangeBeginExpr = rangeEndExpr; @@ -2626,7 +2626,7 @@ namespace Slang return stmt; } - RefPtr<StatementSyntaxNode> parseCompileTimeStmt( + RefPtr<Stmt> parseCompileTimeStmt( Parser* parser) { parser->ReadToken(TokenType::Dollar); @@ -2641,11 +2641,11 @@ namespace Slang } } - RefPtr<StatementSyntaxNode> Parser::ParseStatement() + RefPtr<Stmt> Parser::ParseStatement() { auto modifiers = ParseModifiers(this); - RefPtr<StatementSyntaxNode> statement; + RefPtr<Stmt> statement; if (LookAheadToken(TokenType::LBrace)) statement = ParseBlockStatement(); else if (peekTypeName(this)) @@ -2666,7 +2666,7 @@ namespace Slang statement = ParseReturnStatement(); else if (LookAheadToken("discard")) { - statement = new DiscardStatementSyntaxNode(); + statement = new DiscardStmt(); FillPosition(statement.Ptr()); ReadToken("discard"); ReadToken(TokenType::Semicolon); @@ -2693,7 +2693,7 @@ namespace Slang // Try to parse a type (knowing that the type grammar is // a subset of the expression grammar, and so this should // always succeed). - RefPtr<ExpressionSyntaxNode> type = ParseType(); + RefPtr<Expr> type = ParseType(); // We don't actually care about the type, though, so // don't retain it type = nullptr; @@ -2721,7 +2721,7 @@ namespace Slang } else if (LookAheadToken(TokenType::Semicolon)) { - statement = new EmptyStatementSyntaxNode(); + statement = new EmptyStmt(); FillPosition(statement.Ptr()); ReadToken(TokenType::Semicolon); } @@ -2744,7 +2744,7 @@ namespace Slang return statement; } - RefPtr<StatementSyntaxNode> Parser::ParseBlockStatement() + RefPtr<Stmt> Parser::ParseBlockStatement() { // If we are being asked not to check things *and* we haven't // seen any `import` declarations yet, then we can safely assume @@ -2799,7 +2799,7 @@ namespace Slang PushScope(scopeDecl.Ptr()); ReadToken(TokenType::LBrace); - RefPtr<StatementSyntaxNode> body; + RefPtr<Stmt> body; if(!tokenReader.IsAtEnd()) { @@ -2836,10 +2836,10 @@ namespace Slang return blockStatement; } - RefPtr<VarDeclrStatementSyntaxNode> Parser::ParseVarDeclrStatement( + RefPtr<DeclStmt> Parser::ParseVarDeclrStatement( Modifiers modifiers) { - RefPtr<VarDeclrStatementSyntaxNode>varDeclrStatement = new VarDeclrStatementSyntaxNode(); + RefPtr<DeclStmt>varDeclrStatement = new DeclStmt(); FillPosition(varDeclrStatement.Ptr()); auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers); @@ -2847,9 +2847,9 @@ namespace Slang return varDeclrStatement; } - RefPtr<IfStatementSyntaxNode> Parser::ParseIfStatement() + RefPtr<IfStmt> Parser::ParseIfStatement() { - RefPtr<IfStatementSyntaxNode> ifStatement = new IfStatementSyntaxNode(); + RefPtr<IfStmt> ifStatement = new IfStmt(); FillPosition(ifStatement.Ptr()); ReadToken("if"); ReadToken(TokenType::LParent); @@ -2864,7 +2864,7 @@ namespace Slang return ifStatement; } - RefPtr<ForStatementSyntaxNode> Parser::ParseForStatement() + RefPtr<ForStmt> Parser::ParseForStatement() { RefPtr<ScopeDecl> scopeDecl = new ScopeDecl(); @@ -2879,14 +2879,14 @@ namespace Slang // case, just so that we can correctly handle it in downstream // logic. // - RefPtr<ForStatementSyntaxNode> stmt; + RefPtr<ForStmt> stmt; if (brokenScoping) { stmt = new UnscopedForStmt(); } else { - stmt = new ForStatementSyntaxNode(); + stmt = new ForStmt(); } stmt->scopeDecl = scopeDecl; @@ -2925,9 +2925,9 @@ namespace Slang return stmt; } - RefPtr<WhileStatementSyntaxNode> Parser::ParseWhileStatement() + RefPtr<WhileStmt> Parser::ParseWhileStatement() { - RefPtr<WhileStatementSyntaxNode> whileStatement = new WhileStatementSyntaxNode(); + RefPtr<WhileStmt> whileStatement = new WhileStmt(); FillPosition(whileStatement.Ptr()); ReadToken("while"); ReadToken(TokenType::LParent); @@ -2937,9 +2937,9 @@ namespace Slang return whileStatement; } - RefPtr<DoWhileStatementSyntaxNode> Parser::ParseDoWhileStatement() + RefPtr<DoWhileStmt> Parser::ParseDoWhileStatement() { - RefPtr<DoWhileStatementSyntaxNode> doWhileStatement = new DoWhileStatementSyntaxNode(); + RefPtr<DoWhileStmt> doWhileStatement = new DoWhileStmt(); FillPosition(doWhileStatement.Ptr()); ReadToken("do"); doWhileStatement->Statement = ParseStatement(); @@ -2951,27 +2951,27 @@ namespace Slang return doWhileStatement; } - RefPtr<BreakStatementSyntaxNode> Parser::ParseBreakStatement() + RefPtr<BreakStmt> Parser::ParseBreakStatement() { - RefPtr<BreakStatementSyntaxNode> breakStatement = new BreakStatementSyntaxNode(); + RefPtr<BreakStmt> breakStatement = new BreakStmt(); FillPosition(breakStatement.Ptr()); ReadToken("break"); ReadToken(TokenType::Semicolon); return breakStatement; } - RefPtr<ContinueStatementSyntaxNode> Parser::ParseContinueStatement() + RefPtr<ContinueStmt> Parser::ParseContinueStatement() { - RefPtr<ContinueStatementSyntaxNode> continueStatement = new ContinueStatementSyntaxNode(); + RefPtr<ContinueStmt> continueStatement = new ContinueStmt(); FillPosition(continueStatement.Ptr()); ReadToken("continue"); ReadToken(TokenType::Semicolon); return continueStatement; } - RefPtr<ReturnStatementSyntaxNode> Parser::ParseReturnStatement() + RefPtr<ReturnStmt> Parser::ParseReturnStatement() { - RefPtr<ReturnStatementSyntaxNode> returnStatement = new ReturnStatementSyntaxNode(); + RefPtr<ReturnStmt> returnStatement = new ReturnStmt(); FillPosition(returnStatement.Ptr()); ReadToken("return"); if (!LookAheadToken(TokenType::Semicolon)) @@ -2980,9 +2980,9 @@ namespace Slang return returnStatement; } - RefPtr<ExpressionStatementSyntaxNode> Parser::ParseExpressionStatement() + RefPtr<ExpressionStmt> Parser::ParseExpressionStatement() { - RefPtr<ExpressionStatementSyntaxNode> statement = new ExpressionStatementSyntaxNode(); + RefPtr<ExpressionStmt> statement = new ExpressionStmt(); FillPosition(statement.Ptr()); statement->Expression = ParseExpression(); @@ -2991,9 +2991,9 @@ namespace Slang return statement; } - RefPtr<ParameterSyntaxNode> Parser::ParseParameter() + RefPtr<ParamDecl> Parser::ParseParameter() { - RefPtr<ParameterSyntaxNode> parameter = new ParameterSyntaxNode(); + RefPtr<ParamDecl> parameter = new ParamDecl(); parameter->modifiers = ParseModifiers(this); DeclaratorInfo declaratorInfo; @@ -3007,7 +3007,7 @@ namespace Slang return parameter; } - RefPtr<ExpressionSyntaxNode> Parser::ParseType() + RefPtr<Expr> Parser::ParseType() { auto typeSpec = parseTypeSpec(this); if( typeSpec.decl ) @@ -3103,7 +3103,7 @@ namespace Slang } } - static RefPtr<ExpressionSyntaxNode> parseOperator(Parser* parser) + static RefPtr<Expr> parseOperator(Parser* parser) { Token opToken; switch(parser->tokenReader.PeekTokenType()) @@ -3118,7 +3118,7 @@ namespace Slang break; } - auto opExpr = new VarExpressionSyntaxNode(); + auto opExpr = new VarExpr(); opExpr->name = opToken.Content; opExpr->scope = parser->currentScope; opExpr->Position = opToken.Position; @@ -3127,11 +3127,11 @@ namespace Slang } - static RefPtr<ExpressionSyntaxNode> createInfixExpr( + static RefPtr<Expr> createInfixExpr( Parser* /*parser*/, - RefPtr<ExpressionSyntaxNode> left, - RefPtr<ExpressionSyntaxNode> op, - RefPtr<ExpressionSyntaxNode> right) + RefPtr<Expr> left, + RefPtr<Expr> op, + RefPtr<Expr> right) { RefPtr<InfixExpr> expr = new InfixExpr(); expr->Position = op->Position; @@ -3141,9 +3141,9 @@ namespace Slang return expr; } - static RefPtr<ExpressionSyntaxNode> parseInfixExprWithPrecedence( + static RefPtr<Expr> parseInfixExprWithPrecedence( Parser* parser, - RefPtr<ExpressionSyntaxNode> inExpr, + RefPtr<Expr> inExpr, Precedence prec) { auto expr = inExpr; @@ -3160,7 +3160,7 @@ namespace Slang // one non-binary case we need to deal with. if(opTokenType == TokenType::QuestionMark) { - RefPtr<SelectExpressionSyntaxNode> select = new SelectExpressionSyntaxNode(); + RefPtr<SelectExpr> select = new SelectExpr(); select->Position = op->Position; select->FunctionExpr = op; @@ -3203,7 +3203,7 @@ namespace Slang return expr; } - RefPtr<ExpressionSyntaxNode> Parser::ParseExpression(Precedence level) + RefPtr<Expr> Parser::ParseExpression(Precedence level) { auto expr = ParseLeafExpression(); return parseInfixExprWithPrecedence(this, expr, level); @@ -3218,7 +3218,7 @@ namespace Slang auto condition = ParseExpression(Precedence(level + 1)); if (LookAheadToken(TokenType::QuestionMark)) { - RefPtr<SelectExpressionSyntaxNode> select = new SelectExpressionSyntaxNode(); + RefPtr<SelectExpr> select = new SelectExpr(); FillPosition(select.Ptr()); select->Arguments.Add(condition); @@ -3240,7 +3240,7 @@ namespace Slang auto left = ParseExpression(Precedence(level + 1)); while (GetOpLevel(this, tokenReader.PeekTokenType()) == level) { - RefPtr<OperatorExpressionSyntaxNode> tmp = new InfixExpr(); + RefPtr<OperatorExpr> tmp = new InfixExpr(); tmp->FunctionExpr = parseOperator(this); tmp->Arguments.Add(left); @@ -3255,7 +3255,7 @@ namespace Slang auto left = ParseExpression(Precedence(level + 1)); if (GetOpLevel(this, tokenReader.PeekTokenType()) == level) { - RefPtr<OperatorExpressionSyntaxNode> tmp = new InfixExpr(); + RefPtr<OperatorExpr> tmp = new InfixExpr(); tmp->Arguments.Add(left); FillPosition(tmp.Ptr()); tmp->FunctionExpr = parseOperator(this); @@ -3270,11 +3270,11 @@ namespace Slang // We *might* be looking at an application of a generic to arguments, // but we need to disambiguate to make sure. - static RefPtr<ExpressionSyntaxNode> maybeParseGenericApp( + static RefPtr<Expr> maybeParseGenericApp( Parser* parser, // TODO: need to support more general expressions here - RefPtr<VarExpressionSyntaxNode> base) + RefPtr<VarExpr> base) { if(peekTokenType(parser) != TokenType::OpLess) return base; @@ -3287,7 +3287,7 @@ namespace Slang return parseGenericApp(parser, base); } - static RefPtr<ExpressionSyntaxNode> parseAtomicExpr(Parser* parser) + static RefPtr<Expr> parseAtomicExpr(Parser* parser) { switch( peekTokenType(parser) ) { @@ -3309,7 +3309,7 @@ namespace Slang if (peekTypeName(parser) && parser->LookAheadToken(TokenType::RParent, 1)) { - RefPtr<TypeCastExpressionSyntaxNode> tcexpr = new ExplicitCastExpr(); + RefPtr<TypeCastExpr> tcexpr = new ExplicitCastExpr(); parser->FillPosition(tcexpr.Ptr()); tcexpr->TargetType = parser->ParseTypeExp(); parser->ReadToken(TokenType::RParent); @@ -3318,7 +3318,7 @@ namespace Slang } else { - RefPtr<ExpressionSyntaxNode> base = parser->ParseExpression(); + RefPtr<Expr> base = parser->ParseExpression(); parser->ReadToken(TokenType::RParent); RefPtr<ParenExpr> parenExpr = new ParenExpr(); @@ -3337,7 +3337,7 @@ namespace Slang // Initializer list parser->ReadToken(TokenType::LBrace); - List<RefPtr<ExpressionSyntaxNode>> exprs; + List<RefPtr<Expr>> exprs; for(;;) { @@ -3361,7 +3361,7 @@ namespace Slang case TokenType::IntegerLiteral: { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); parser->FillPosition(constExpr.Ptr()); auto token = parser->tokenReader.AdvanceToken(); @@ -3373,7 +3373,7 @@ namespace Slang // Look at any suffix on the value char const* suffixCursor = suffix.begin(); - RefPtr<ExpressionType> suffixType = nullptr; + RefPtr<Type> suffixType = nullptr; if( suffixCursor && *suffixCursor ) { int lCount = 0; @@ -3421,9 +3421,9 @@ namespace Slang } } - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + constExpr->ConstType = ConstantExpr::ConstantType::Int; constExpr->integerValue = value; - constExpr->Type = QualType(suffixType); + constExpr->type = QualType(suffixType); return constExpr; } @@ -3431,7 +3431,7 @@ namespace Slang case TokenType::FloatingPointLiteral: { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); parser->FillPosition(constExpr.Ptr()); auto token = parser->tokenReader.AdvanceToken(); @@ -3443,7 +3443,7 @@ namespace Slang // Look at any suffix on the value char const* suffixCursor = suffix.begin(); - RefPtr<ExpressionType> suffixType = nullptr; + RefPtr<Type> suffixType = nullptr; if( suffixCursor && *suffixCursor ) { int fCount = 0; @@ -3490,20 +3490,20 @@ namespace Slang } } - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; + constExpr->ConstType = ConstantExpr::ConstantType::Float; constExpr->floatingPointValue = value; - constExpr->Type = QualType(suffixType); + constExpr->type = QualType(suffixType); return constExpr; } case TokenType::StringLiteral: { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); auto token = parser->tokenReader.AdvanceToken(); constExpr->token = token; parser->FillPosition(constExpr.Ptr()); - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::String; + constExpr->ConstType = ConstantExpr::ConstantType::String; if (!parser->LookAheadToken(TokenType::StringLiteral)) { @@ -3532,18 +3532,18 @@ namespace Slang if (parser->LookAheadToken("true") || parser->LookAheadToken("false")) { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); auto token = parser->tokenReader.AdvanceToken(); constExpr->token = token; parser->FillPosition(constExpr.Ptr()); - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Bool; + constExpr->ConstType = ConstantExpr::ConstantType::Bool; constExpr->integerValue = token.Content == "true" ? 1 : 0; return constExpr; } // Default behavior is just to create a name expression - RefPtr<VarExpressionSyntaxNode> varExpr = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> varExpr = new VarExpr(); varExpr->scope = parser->currentScope.Ptr(); parser->FillPosition(varExpr.Ptr()); auto token = parser->ReadToken(TokenType::Identifier); @@ -3559,7 +3559,7 @@ namespace Slang } } - static RefPtr<ExpressionSyntaxNode> parsePostfixExpr(Parser* parser) + static RefPtr<Expr> parsePostfixExpr(Parser* parser) { auto expr = parseAtomicExpr(parser); for(;;) @@ -3573,7 +3573,7 @@ namespace Slang case TokenType::OpInc: case TokenType::OpDec: { - RefPtr<OperatorExpressionSyntaxNode> postfixExpr = new PostfixExpr(); + RefPtr<OperatorExpr> postfixExpr = new PostfixExpr(); parser->FillPosition(postfixExpr.Ptr()); postfixExpr->FunctionExpr = parseOperator(parser); postfixExpr->Arguments.Add(expr); @@ -3585,7 +3585,7 @@ namespace Slang // Subscript operation `a[i]` case TokenType::LBracket: { - RefPtr<IndexExpressionSyntaxNode> indexExpr = new IndexExpressionSyntaxNode(); + RefPtr<IndexExpr> indexExpr = new IndexExpr(); indexExpr->BaseExpression = expr; parser->FillPosition(indexExpr.Ptr()); parser->ReadToken(TokenType::LBracket); @@ -3603,7 +3603,7 @@ namespace Slang // Call oepration `f(x)` case TokenType::LParent: { - RefPtr<InvokeExpressionSyntaxNode> invokeExpr = new InvokeExpressionSyntaxNode(); + RefPtr<InvokeExpr> invokeExpr = new InvokeExpr(); invokeExpr->FunctionExpr = expr; parser->FillPosition(invokeExpr.Ptr()); parser->ReadToken(TokenType::LParent); @@ -3628,7 +3628,7 @@ namespace Slang // Member access `x.m` case TokenType::Dot: { - RefPtr<MemberExpressionSyntaxNode> memberExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> memberExpr = new MemberExpr(); // TODO(tfoley): why would a member expression need this? memberExpr->scope = parser->currentScope.Ptr(); @@ -3645,7 +3645,7 @@ namespace Slang } } - static RefPtr<ExpressionSyntaxNode> parsePrefixExpr(Parser* parser) + static RefPtr<Expr> parsePrefixExpr(Parser* parser) { switch( peekTokenType(parser) ) { @@ -3669,19 +3669,19 @@ namespace Slang } } - RefPtr<ExpressionSyntaxNode> Parser::ParseLeafExpression() + RefPtr<Expr> Parser::ParseLeafExpression() { return parsePrefixExpr(this); #if 0 - RefPtr<ExpressionSyntaxNode> rs; + RefPtr<Expr> rs; if (LookAheadToken(TokenType::OpInc) || LookAheadToken(TokenType::OpDec) || LookAheadToken(TokenType::OpNot) || LookAheadToken(TokenType::OpBitNot) || LookAheadToken(TokenType::OpSub)) { - RefPtr<OperatorExpressionSyntaxNode> unaryExpr = new PrefixExpr(); + RefPtr<OperatorExpr> unaryExpr = new PrefixExpr(); FillPosition(unaryExpr.Ptr()); unaryExpr->FunctionExpr = parseOperator(this); unaryExpr->Arguments.Add(ParseLeafExpression()); @@ -3692,10 +3692,10 @@ namespace Slang if (LookAheadToken(TokenType::LParent)) { ReadToken(TokenType::LParent); - RefPtr<ExpressionSyntaxNode> expr; + RefPtr<Expr> expr; if (peekTypeName(this) && LookAheadToken(TokenType::RParent, 1)) { - RefPtr<TypeCastExpressionSyntaxNode> tcexpr = new TypeCastExpressionSyntaxNode(); + RefPtr<TypeCastExpr> tcexpr = new TypeCastExpr(); FillPosition(tcexpr.Ptr()); tcexpr->TargetType = ParseTypeExp(); ReadToken(TokenType::RParent); @@ -3717,7 +3717,7 @@ namespace Slang // Initializer list ReadToken(TokenType::LBrace); - List<RefPtr<ExpressionSyntaxNode>> exprs; + List<RefPtr<Expr>> exprs; for(;;) { @@ -3741,33 +3741,33 @@ namespace Slang else if (LookAheadToken(TokenType::IntegerLiteral) || LookAheadToken(TokenType::FloatingPointLiteral)) { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); auto token = tokenReader.AdvanceToken(); FillPosition(constExpr.Ptr()); - if (token.Type == TokenType::IntegerLiteral) + if (token.type == TokenType::IntegerLiteral) { - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + constExpr->ConstType = ConstantExpr::ConstantType::Int; constExpr->IntValue = StringToInt(token.Content); } - else if (token.Type == TokenType::FloatingPointLiteral) + else if (token.type == TokenType::FloatingPointLiteral) { - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; + constExpr->ConstType = ConstantExpr::ConstantType::Float; constExpr->FloatValue = (FloatingPointLiteralValue) StringToDouble(token.Content); } rs = constExpr; } else if (LookAheadToken("true") || LookAheadToken("false")) { - RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + RefPtr<ConstantExpr> constExpr = new ConstantExpr(); auto token = tokenReader.AdvanceToken(); FillPosition(constExpr.Ptr()); - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Bool; + constExpr->ConstType = ConstantExpr::ConstantType::Bool; constExpr->IntValue = token.Content == "true" ? 1 : 0; rs = constExpr; } else if (LookAheadToken(TokenType::Identifier)) { - RefPtr<VarExpressionSyntaxNode> varExpr = new VarExpressionSyntaxNode(); + RefPtr<VarExpr> varExpr = new VarExpr(); varExpr->scope = currentScope.Ptr(); FillPosition(varExpr.Ptr()); auto token = ReadToken(TokenType::Identifier); @@ -3784,7 +3784,7 @@ namespace Slang { if (LookAheadToken(TokenType::OpInc)) { - RefPtr<OperatorExpressionSyntaxNode> unaryExpr = new PostfixExpr(); + RefPtr<OperatorExpr> unaryExpr = new PostfixExpr(); FillPosition(unaryExpr.Ptr()); unaryExpr->FunctionExpr = parseOperator(this); unaryExpr->Arguments.Add(rs); @@ -3792,7 +3792,7 @@ namespace Slang } else if (LookAheadToken(TokenType::OpDec)) { - RefPtr<OperatorExpressionSyntaxNode> unaryExpr = new PostfixExpr(); + RefPtr<OperatorExpr> unaryExpr = new PostfixExpr(); FillPosition(unaryExpr.Ptr()); unaryExpr->FunctionExpr = parseOperator(this); unaryExpr->Arguments.Add(rs); @@ -3800,7 +3800,7 @@ namespace Slang } else if (LookAheadToken(TokenType::LBracket)) { - RefPtr<IndexExpressionSyntaxNode> indexExpr = new IndexExpressionSyntaxNode(); + RefPtr<IndexExpr> indexExpr = new IndexExpr(); indexExpr->BaseExpression = rs; FillPosition(indexExpr.Ptr()); ReadToken(TokenType::LBracket); @@ -3810,7 +3810,7 @@ namespace Slang } else if (LookAheadToken(TokenType::LParent)) { - RefPtr<InvokeExpressionSyntaxNode> invokeExpr = new InvokeExpressionSyntaxNode(); + RefPtr<InvokeExpr> invokeExpr = new InvokeExpr(); invokeExpr->FunctionExpr = rs; FillPosition(invokeExpr.Ptr()); ReadToken(TokenType::LParent); @@ -3831,7 +3831,7 @@ namespace Slang } else if (LookAheadToken(TokenType::Dot)) { - RefPtr<MemberExpressionSyntaxNode> memberExpr = new MemberExpressionSyntaxNode(); + RefPtr<MemberExpr> memberExpr = new MemberExpr(); memberExpr->scope = currentScope.Ptr(); FillPosition(memberExpr.Ptr()); memberExpr->BaseExpression = rs; diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index ec38a7214..53f0c4774 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -175,7 +175,7 @@ struct Preprocessor return translationUnit; } - ProgramSyntaxNode* getSyntax() + ModuleDecl* getSyntax() { return getTranslationUnit()->SyntaxNode.Ptr(); } @@ -411,7 +411,7 @@ static CodePosition PeekLoc(Preprocessor* preprocessor) // Get the `TokenType` of the current (raw) token static TokenType PeekRawTokenType(Preprocessor* preprocessor) { - return PeekRawToken(preprocessor).Type; + return PeekRawToken(preprocessor).type; } // @@ -546,7 +546,7 @@ static void AddEndOfStreamToken( PreprocessorMacro* macro) { Token token = PeekRawToken(preprocessor); - token.Type = TokenType::EndOfFile; + token.type = TokenType::EndOfFile; macro->tokens.mTokens.Add(token); } @@ -564,7 +564,7 @@ static void MaybeBeginMacroExpansion( Token const& token = PeekRawToken(preprocessor); // Not an identifier? Can't be a macro. - if (token.Type != TokenType::Identifier) + if (token.type != TokenType::Identifier) return; // Look for a macro with the given name. @@ -795,7 +795,7 @@ static Token PeekToken(Preprocessor* preprocessor) // Peek the type of the next token, including macro expansion. static TokenType PeekTokenType(Preprocessor* preprocessor) { - return PeekToken(preprocessor).Type; + return PeekToken(preprocessor).type; } // @@ -865,7 +865,7 @@ static PreprocessorMacro* LookupMacro(PreprocessorDirectiveContext* context, Str // Determine if we have read everthing on the directive's line. static bool IsEndOfLine(PreprocessorDirectiveContext* context) { - return PeekRawToken(context->preprocessor).Type == TokenType::EndOfDirective; + return PeekRawToken(context->preprocessor).type == TokenType::EndOfDirective; } // Peek one raw token in a directive, without going past the end of the line. @@ -1108,7 +1108,7 @@ static PreprocessorExpressionValue ParseAndEvaluateUnaryExpression(PreprocessorD String name = nameToken.Content; // If we saw an opening `(`, then expect one to close - if (leftParen.Type != TokenType::Unknown) + if (leftParen.type != TokenType::Unknown) { if(!ExpectRaw(context, TokenType::RParent, Diagnostics::expectedTokenInDefinedExpression)) { @@ -1143,7 +1143,7 @@ static int GetInfixOpPrecedence(Token const& opToken) // otherwise we look at the token type to figure // out what precednece it should be parse with - switch (opToken.Type) + switch (opToken.type) { default: // tokens that aren't infix operators should @@ -1184,7 +1184,7 @@ static PreprocessorExpressionValue EvaluateInfixOp( PreprocessorExpressionValue left, PreprocessorExpressionValue right) { - switch (opToken.Type) + switch (opToken.type) { default: // SLANG_INTERNAL_ERROR(getSink(preprocessor), opToken); @@ -1356,7 +1356,7 @@ static void HandleElseDirective(PreprocessorDirectiveContext* context) } // if we've already seen a `#else`, then it is an error - if (conditional->elseToken.Type != TokenType::Unknown) + if (conditional->elseToken.type != TokenType::Unknown) { GetSink(context)->diagnose(GetDirectiveLoc(context), Diagnostics::directiveAfterElse, GetDirectiveName(context)); GetSink(context)->diagnose(conditional->elseToken.Position, Diagnostics::seeDirective); @@ -1410,7 +1410,7 @@ static void HandleElifDirective(PreprocessorDirectiveContext* context) } // if we've already seen a `#else`, then it is an error - if (conditional->elseToken.Type != TokenType::Unknown) + if (conditional->elseToken.type != TokenType::Unknown) { GetSink(context)->diagnose(GetDirectiveLoc(context), Diagnostics::directiveAfterElse, GetDirectiveName(context)); GetSink(context)->diagnose(conditional->elseToken.Position, Diagnostics::seeDirective); @@ -1597,11 +1597,11 @@ static void HandleDefineDirective(PreprocessorDirectiveContext* context) for(;;) { Token token = AdvanceRawToken(context); - if( token.Type == TokenType::EndOfDirective ) + if( token.type == TokenType::EndOfDirective ) { // Last token on line will be turned into a conceptual end-of-file // token for the sub-stream that the macro expands into. - token.Type = TokenType::EndOfFile; + token.type = TokenType::EndOfFile; macro->tokens.mTokens.Add(token); break; } @@ -1876,7 +1876,7 @@ static void HandleDirective(PreprocessorDirectiveContext* context) // Try to read the directive name. context->directiveToken = PeekRawToken(context); - TokenType directiveTokenType = GetDirective(context).Type; + TokenType directiveTokenType = GetDirective(context).type; // An empty directive is allowed, and ignored. if (directiveTokenType == TokenType::EndOfDirective) @@ -1920,12 +1920,12 @@ static Token ReadToken(Preprocessor* preprocessor) { // Look at the next raw token in the input. Token const& token = PeekRawToken(preprocessor); - if (token.Type == TokenType::EndOfFile) + if (token.type == TokenType::EndOfFile) return token; // If we have a directive (`#` at start of line) then handle it - if ((token.Type == TokenType::Pound) && (token.flags & TokenFlag::AtStartOfLine)) + if ((token.type == TokenType::Pound) && (token.flags & TokenFlag::AtStartOfLine)) { // Skip the `#` AdvanceRawToken(preprocessor); @@ -1960,7 +1960,7 @@ static void InitializePreprocessor( { preprocessor->sink = sink; preprocessor->includeHandler = NULL; - preprocessor->endOfFileToken.Type = TokenType::EndOfFile; + preprocessor->endOfFileToken.type = TokenType::EndOfFile; preprocessor->endOfFileToken.flags = TokenFlag::AtStartOfLine; } @@ -2032,7 +2032,7 @@ static TokenList ReadAllTokens( // Note: we include the EOF token in the list, // since that is expected by the `TokenList` type. - if (token.Type == TokenType::EndOfFile) + if (token.type == TokenType::EndOfFile) break; } return tokens; @@ -2183,14 +2183,14 @@ static void HandleImportDirective(PreprocessorDirectiveContext* context) SourceTextInputStream* inputStream = new SourceTextInputStream(); Token token; - token.Type = TokenType::PoundImport; + token.type = TokenType::PoundImport; token.Position = GetDirectiveLoc(context); token.flags = 0; token.Content = foundPath; inputStream->lexedTokens.mTokens.Add(token); - token.Type = TokenType::EndOfFile; + token.type = TokenType::EndOfFile; token.flags = TokenFlag::AfterWhitespace | TokenFlag::AtStartOfLine; inputStream->lexedTokens.mTokens.Add(token); diff --git a/source/slang/preprocessor.h b/source/slang/preprocessor.h index d23b19773..008707ffb 100644 --- a/source/slang/preprocessor.h +++ b/source/slang/preprocessor.h @@ -8,7 +8,7 @@ namespace Slang { class DiagnosticSink; -class ProgramSyntaxNode; +class ModuleDecl; class TranslationUnitRequest; enum class IncludeResult diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index 18cf58a92..13c306d56 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -19,12 +19,12 @@ using namespace Slang; // Conversion routines to help with strongly-typed reflection API -static inline ExpressionType* convert(SlangReflectionType* type) +static inline Type* convert(SlangReflectionType* type) { - return (ExpressionType*) type; + return (Type*) type; } -static inline SlangReflectionType* convert(ExpressionType* type) +static inline SlangReflectionType* convert(Type* type) { return (SlangReflectionType*) type; } @@ -80,7 +80,7 @@ static inline SlangReflection* convert(ProgramLayout* program) return (SlangReflection*) program; } -// Type Reflection +// type Reflection SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) @@ -145,7 +145,7 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) else if( auto declRefType = type->As<DeclRefType>() ) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructSyntaxNode>() ) + if( auto structDeclRef = declRef.As<StructDecl>() ) { return SLANG_TYPE_KIND_STRUCT; } @@ -170,7 +170,7 @@ SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inTyp if(auto declRefType = dynamic_cast<DeclRefType*>(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructSyntaxNode>()) + if( auto structDeclRef = declRef.As<StructDecl>()) { return GetFields(structDeclRef).Count(); } @@ -189,7 +189,7 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflect if(auto declRefType = dynamic_cast<DeclRefType*>(type)) { auto declRef = declRefType->declRef; - if( auto structDeclRef = declRef.As<StructSyntaxNode>()) + if( auto structDeclRef = declRef.As<StructDecl>()) { auto fieldDeclRef = GetFields(structDeclRef).ToArray()[index]; return (SlangReflectionVariable*) fieldDeclRef.getDecl(); @@ -424,7 +424,7 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle return nullptr; } -// Type Layout Reflection +// type Layout Reflection SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(SlangReflectionTypeLayout* inTypeLayout) { @@ -754,7 +754,7 @@ SLANG_API void spReflectionEntryPoint_getComputeThreadGroupSize( { // Fall back to the GLSL case, which requires a search over global-scope declarations // to look for anything with the `local_size_*` qualifier - auto module = dynamic_cast<ProgramSyntaxNode*>(entryPointFunc->ParentDecl); + auto module = dynamic_cast<ModuleDecl*>(entryPointFunc->ParentDecl); if (module) { for (auto dd : module->Members) diff --git a/source/slang/reflection.h b/source/slang/reflection.h index 627ca8382..3eef47c6b 100644 --- a/source/slang/reflection.h +++ b/source/slang/reflection.h @@ -24,12 +24,12 @@ String emitReflectionJSON( // -SlangTypeKind getReflectionTypeKind(ExpressionType* type); +SlangTypeKind getReflectionTypeKind(Type* type); SlangTypeKind getReflectionParameterCategory(TypeLayout* typeLayout); -UInt getReflectionFieldCount(ExpressionType* type); -UInt getReflectionFieldByIndex(ExpressionType* type, UInt index); +UInt getReflectionFieldCount(Type* type); +UInt getReflectionFieldByIndex(Type* type, UInt index); UInt getReflectionFieldByIndex(TypeLayout* typeLayout, UInt index); } diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 03bb6a09b..0dcbf44ea 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -112,7 +112,7 @@ void CompileRequest::parseTranslationUnit( for(auto& def : translationUnit->preprocessorDefinitions) combinedPreprocessorDefinitions.Add(def.Key, def.Value); - RefPtr<ProgramSyntaxNode> translationUnitSyntax = new ProgramSyntaxNode(); + RefPtr<ModuleDecl> translationUnitSyntax = new ModuleDecl(); translationUnit->SyntaxNode = translationUnitSyntax; for (auto sourceFile : translationUnit->sourceFiles) @@ -355,7 +355,7 @@ int CompileRequest::addEntryPoint( return (int) result; } -RefPtr<ProgramSyntaxNode> CompileRequest::loadModule( +RefPtr<ModuleDecl> CompileRequest::loadModule( String const& name, String const& path, String const& source, @@ -386,7 +386,7 @@ RefPtr<ProgramSyntaxNode> CompileRequest::loadModule( // - RefPtr<ProgramSyntaxNode> moduleDecl = translationUnit->SyntaxNode; + RefPtr<ModuleDecl> moduleDecl = translationUnit->SyntaxNode; mapPathToLoadedModule.Add(path, moduleDecl); mapNameToLoadedModules.Add(name, moduleDecl); @@ -406,7 +406,7 @@ void CompileRequest::handlePoundImport( // Imported code is always native Slang code RefPtr<Scope> languageScope = mSession->slangLanguageScope; - RefPtr<ProgramSyntaxNode> translationUnitSyntax = new ProgramSyntaxNode(); + RefPtr<ModuleDecl> translationUnitSyntax = new ModuleDecl(); translationUnit->SyntaxNode = translationUnitSyntax; parseSourceFile( @@ -424,7 +424,7 @@ void CompileRequest::handlePoundImport( // - RefPtr<ProgramSyntaxNode> moduleDecl = translationUnit->SyntaxNode; + RefPtr<ModuleDecl> moduleDecl = translationUnit->SyntaxNode; // TODO: It is a bit broken here that we use the module path, // as the "name" when registering things, but this saves @@ -436,13 +436,13 @@ void CompileRequest::handlePoundImport( loadedModulesList.Add(moduleDecl); } -RefPtr<ProgramSyntaxNode> CompileRequest::findOrImportModule( +RefPtr<ModuleDecl> CompileRequest::findOrImportModule( String const& name, CodePosition const& loc) { // Have we already loaded a module matching this name? // If so, return it. - RefPtr<ProgramSyntaxNode> moduleDecl; + RefPtr<ModuleDecl> moduleDecl; if (mapNameToLoadedModules.TryGetValue(name, moduleDecl)) return moduleDecl; @@ -505,7 +505,7 @@ RefPtr<ProgramSyntaxNode> CompileRequest::findOrImportModule( loc); } -RefPtr<ProgramSyntaxNode> findOrImportModule( +RefPtr<ModuleDecl> findOrImportModule( CompileRequest* request, String const& name, CodePosition const& loc) diff --git a/source/slang/slang.natvis b/source/slang/slang.natvis index 4f64baf6e..6a9f0cbbc 100644 --- a/source/slang/slang.natvis +++ b/source/slang/slang.natvis @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> - <Type Name="Slang::CFGNode"> + <type Name="Slang::CFGNode"> <DisplayString>{{CFG Basic Block}}</DisplayString> <Expand> <LinkedListItems> @@ -10,5 +10,5 @@ <ValueNode>Value</ValueNode> </LinkedListItems> </Expand> - </Type> + </type> </AutoVisualizer>
\ No newline at end of file diff --git a/source/slang/stmt-defs.h b/source/slang/stmt-defs.h index 80e3cd60d..a9877c281 100644 --- a/source/slang/stmt-defs.h +++ b/source/slang/stmt-defs.h @@ -2,39 +2,39 @@ // Syntax class definitions for statements. -ABSTRACT_SYNTAX_CLASS(ScopeStmt, StatementSyntaxNode) +ABSTRACT_SYNTAX_CLASS(ScopeStmt, Stmt) SYNTAX_FIELD(RefPtr<ScopeDecl>, scopeDecl) END_SYNTAX_CLASS() // A sequence of statements, treated as a single statement -SYNTAX_CLASS(SeqStmt, StatementSyntaxNode) - SYNTAX_FIELD(List<RefPtr<StatementSyntaxNode>>, stmts) +SYNTAX_CLASS(SeqStmt, Stmt) + SYNTAX_FIELD(List<RefPtr<Stmt>>, stmts) END_SYNTAX_CLASS() // The simplest kind of scope statement: just a `{...}` block SYNTAX_CLASS(BlockStmt, ScopeStmt) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, body); + SYNTAX_FIELD(RefPtr<Stmt>, body); END_SYNTAX_CLASS() // A statement that we aren't going to parse or check, because // we want to let a downstream compiler handle any issues -SYNTAX_CLASS(UnparsedStmt, StatementSyntaxNode) +SYNTAX_CLASS(UnparsedStmt, Stmt) // The tokens that were contained between `{` and `}` FIELD(List<Token>, tokens) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(EmptyStatementSyntaxNode, StatementSyntaxNode) +SIMPLE_SYNTAX_CLASS(EmptyStmt, Stmt) -SIMPLE_SYNTAX_CLASS(DiscardStatementSyntaxNode, StatementSyntaxNode) +SIMPLE_SYNTAX_CLASS(DiscardStmt, Stmt) -SYNTAX_CLASS(VarDeclrStatementSyntaxNode, StatementSyntaxNode) +SYNTAX_CLASS(DeclStmt, Stmt) SYNTAX_FIELD(RefPtr<DeclBase>, decl) END_SYNTAX_CLASS() -SYNTAX_CLASS(IfStatementSyntaxNode, StatementSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Predicate) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, PositiveStatement) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, NegativeStatement) +SYNTAX_CLASS(IfStmt, Stmt) + SYNTAX_FIELD(RefPtr<Expr>, Predicate) + SYNTAX_FIELD(RefPtr<Stmt>, PositiveStatement) + SYNTAX_FIELD(RefPtr<Stmt>, NegativeStatement) END_SYNTAX_CLASS() // A statement that can be escaped with a `break` @@ -42,15 +42,15 @@ ABSTRACT_SYNTAX_CLASS(BreakableStmt, ScopeStmt) END_SYNTAX_CLASS() SYNTAX_CLASS(SwitchStmt, BreakableStmt) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, condition) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, body) + SYNTAX_FIELD(RefPtr<Expr>, condition) + SYNTAX_FIELD(RefPtr<Stmt>, body) END_SYNTAX_CLASS() // A statement that is expected to appear lexically nested inside // some other construct, and thus needs to keep track of the // outer statement that it is associated with... -ABSTRACT_SYNTAX_CLASS(ChildStmt, StatementSyntaxNode) - DECL_FIELD(StatementSyntaxNode*, parentStmt RAW(= nullptr)) +ABSTRACT_SYNTAX_CLASS(ChildStmt, Stmt) + DECL_FIELD(Stmt*, parentStmt RAW(= nullptr)) END_SYNTAX_CLASS() // a `case` or `default` statement inside a `switch` @@ -63,7 +63,7 @@ END_SYNTAX_CLASS() // a `case` statement inside a `switch` SYNTAX_CLASS(CaseStmt, CaseStmtBase) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, expr) + SYNTAX_FIELD(RefPtr<Expr>, expr) END_SYNTAX_CLASS() // a `default` statement inside a `switch` @@ -74,34 +74,34 @@ ABSTRACT_SYNTAX_CLASS(LoopStmt, BreakableStmt) END_SYNTAX_CLASS() // A `for` statement -SYNTAX_CLASS(ForStatementSyntaxNode, LoopStmt) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, InitialStatement) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, SideEffectExpression) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, PredicateExpression) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, Statement) +SYNTAX_CLASS(ForStmt, LoopStmt) + SYNTAX_FIELD(RefPtr<Stmt>, InitialStatement) + SYNTAX_FIELD(RefPtr<Expr>, SideEffectExpression) + SYNTAX_FIELD(RefPtr<Expr>, PredicateExpression) + SYNTAX_FIELD(RefPtr<Stmt>, Statement) END_SYNTAX_CLASS() // A `for` statement in a language that doesn't restrict the scope // of the loop variable to the body. -SYNTAX_CLASS(UnscopedForStmt, ForStatementSyntaxNode); +SYNTAX_CLASS(UnscopedForStmt, ForStmt); END_SYNTAX_CLASS() -SYNTAX_CLASS(WhileStatementSyntaxNode, LoopStmt) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Predicate) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, Statement) +SYNTAX_CLASS(WhileStmt, LoopStmt) + SYNTAX_FIELD(RefPtr<Expr>, Predicate) + SYNTAX_FIELD(RefPtr<Stmt>, Statement) END_SYNTAX_CLASS() -SYNTAX_CLASS(DoWhileStatementSyntaxNode, LoopStmt) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, Statement) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Predicate) +SYNTAX_CLASS(DoWhileStmt, LoopStmt) + SYNTAX_FIELD(RefPtr<Stmt>, Statement) + SYNTAX_FIELD(RefPtr<Expr>, Predicate) END_SYNTAX_CLASS() // A compile-time, range-based `for` loop, which will not appear in the output code SYNTAX_CLASS(CompileTimeForStmt, ScopeStmt) SYNTAX_FIELD(RefPtr<Variable>, varDecl) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, rangeBeginExpr) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, rangeEndExpr) - SYNTAX_FIELD(RefPtr<StatementSyntaxNode>, body) + SYNTAX_FIELD(RefPtr<Expr>, rangeBeginExpr) + SYNTAX_FIELD(RefPtr<Expr>, rangeEndExpr) + SYNTAX_FIELD(RefPtr<Stmt>, body) SYNTAX_FIELD(RefPtr<IntVal>, rangeBeginVal) SYNTAX_FIELD(RefPtr<IntVal>, rangeEndVal) END_SYNTAX_CLASS() @@ -111,14 +111,14 @@ END_SYNTAX_CLASS() ABSTRACT_SYNTAX_CLASS(JumpStmt, ChildStmt) END_SYNTAX_CLASS() -SIMPLE_SYNTAX_CLASS(BreakStatementSyntaxNode, JumpStmt) +SIMPLE_SYNTAX_CLASS(BreakStmt, JumpStmt) -SIMPLE_SYNTAX_CLASS(ContinueStatementSyntaxNode, JumpStmt) +SIMPLE_SYNTAX_CLASS(ContinueStmt, JumpStmt) -SYNTAX_CLASS(ReturnStatementSyntaxNode, StatementSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Expression) +SYNTAX_CLASS(ReturnStmt, Stmt) + SYNTAX_FIELD(RefPtr<Expr>, Expression) END_SYNTAX_CLASS() -SYNTAX_CLASS(ExpressionStatementSyntaxNode, StatementSyntaxNode) - SYNTAX_FIELD(RefPtr<ExpressionSyntaxNode>, Expression) +SYNTAX_CLASS(ExpressionStmt, Stmt) + SYNTAX_FIELD(RefPtr<Expr>, Expression) END_SYNTAX_CLASS() diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h index bcb37de09..d76607106 100644 --- a/source/slang/syntax-base-defs.h +++ b/source/slang/syntax-base-defs.h @@ -2,7 +2,7 @@ // This file defines the primary base classes for the hierarchy of // AST nodes and related objects. For example, this is where the -// basic `Decl`, `Stmt`, `Expr`, `Type`, etc. definitions come from. +// basic `Decl`, `Stmt`, `Expr`, `type`, etc. definitions come from. // Base class for all nodes representing actual syntax // (thus having a location in the source code) @@ -64,7 +64,7 @@ END_SYNTAX_CLASS() // "canonical" type. The reprsentation caches a pointer to // a canonical type on every type, so we can easily // operate on the raw representation when needed. -ABSTRACT_SYNTAX_CLASS(ExpressionType, Val) +ABSTRACT_SYNTAX_CLASS(Type, Val) RAW(typedef ITypeVisitor Visitor;) RAW(virtual void accept(IValVisitor* visitor, void* extra) override;) @@ -77,8 +77,8 @@ public: virtual String ToString() = 0; - bool Equals(ExpressionType * type); - bool Equals(RefPtr<ExpressionType> type); + bool Equals(Type * type); + bool Equals(RefPtr<Type> type); bool IsVectorType() { return As<VectorExpressionType>() != nullptr; } bool IsArray() { return As<ArrayExpressionType>() != nullptr; } @@ -105,16 +105,16 @@ public: bool IsSampler() { return As<SamplerStateType>() != nullptr; } bool IsStruct(); bool IsClass(); - ExpressionType* GetCanonicalType(); + Type* GetCanonicalType(); virtual RefPtr<Val> SubstituteImpl(Substitutions* subst, int* ioDiff) override; virtual bool EqualsVal(Val* val) override; protected: - virtual bool EqualsImpl(ExpressionType * type) = 0; + virtual bool EqualsImpl(Type * type) = 0; - virtual ExpressionType* CreateCanonicalType() = 0; - ExpressionType* canonicalType = nullptr; + virtual Type* CreateCanonicalType() = 0; + Type* canonicalType = nullptr; Session* session = nullptr; ) @@ -234,16 +234,16 @@ ABSTRACT_SYNTAX_CLASS(Decl, DeclBase) ) END_SYNTAX_CLASS() -ABSTRACT_SYNTAX_CLASS(ExpressionSyntaxNode, SyntaxNode) +ABSTRACT_SYNTAX_CLASS(Expr, SyntaxNode) RAW(typedef IExprVisitor Visitor;) - FIELD(QualType, Type) + FIELD(QualType, type) RAW(virtual void accept(IExprVisitor* visitor, void* extra) = 0;) END_SYNTAX_CLASS() -ABSTRACT_SYNTAX_CLASS(StatementSyntaxNode, ModifiableSyntaxNode) +ABSTRACT_SYNTAX_CLASS(Stmt, ModifiableSyntaxNode) RAW(typedef IStmtVisitor Visitor;) RAW(virtual void accept(IStmtVisitor* visitor, void* extra) = 0;) diff --git a/source/slang/syntax-visitors.h b/source/slang/syntax-visitors.h index 4ccc7fa0b..f2c080a57 100644 --- a/source/slang/syntax-visitors.h +++ b/source/slang/syntax-visitors.h @@ -23,7 +23,7 @@ namespace Slang // Needed by import declaration checking. // // TODO: need a better location to declare this. - RefPtr<ProgramSyntaxNode> findOrImportModule( + RefPtr<ModuleDecl> findOrImportModule( CompileRequest* request, String const& name, CodePosition const& loc); diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index e9eeeaadc..33fa5be20 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -10,7 +10,7 @@ namespace Slang { // BasicExpressionType - bool BasicExpressionType::EqualsImpl(ExpressionType * type) + bool BasicExpressionType::EqualsImpl(Type * type) { auto basicType = dynamic_cast<const BasicExpressionType*>(type); if (basicType == nullptr) @@ -18,7 +18,7 @@ namespace Slang return basicType->BaseType == BaseType; } - ExpressionType* BasicExpressionType::CreateCanonicalType() + Type* BasicExpressionType::CreateCanonicalType() { // A basic type is already canonical, in our setup return this; @@ -76,19 +76,19 @@ namespace Slang #include "object-meta-end.h" -void ExpressionType::accept(IValVisitor* visitor, void* extra) +void Type::accept(IValVisitor* visitor, void* extra) { accept((ITypeVisitor*)visitor, extra); } // TypeExp - bool TypeExp::Equals(ExpressionType* other) + bool TypeExp::Equals(Type* other) { return type->Equals(other); } - bool TypeExp::Equals(RefPtr<ExpressionType> other) + bool TypeExp::Equals(RefPtr<Type> other) { return type->Equals(other.Ptr()); } @@ -102,29 +102,29 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) // - bool ExpressionType::Equals(ExpressionType * type) + bool Type::Equals(Type * type) { return GetCanonicalType()->EqualsImpl(type->GetCanonicalType()); } - bool ExpressionType::Equals(RefPtr<ExpressionType> type) + bool Type::Equals(RefPtr<Type> type) { return Equals(type.Ptr()); } - bool ExpressionType::EqualsVal(Val* val) + bool Type::EqualsVal(Val* val) { - if (auto type = dynamic_cast<ExpressionType*>(val)) - return const_cast<ExpressionType*>(this)->Equals(type); + if (auto type = dynamic_cast<Type*>(val)) + return const_cast<Type*>(this)->Equals(type); return false; } - NamedExpressionType* ExpressionType::AsNamedType() + NamedExpressionType* Type::AsNamedType() { return dynamic_cast<NamedExpressionType*>(this); } - RefPtr<Val> ExpressionType::SubstituteImpl(Substitutions* subst, int* ioDiff) + RefPtr<Val> Type::SubstituteImpl(Substitutions* subst, int* ioDiff) { int diff = 0; auto canSubst = GetCanonicalType()->SubstituteImpl(subst, &diff); @@ -140,10 +140,10 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) } - ExpressionType* ExpressionType::GetCanonicalType() + Type* Type::GetCanonicalType() { if (!this) return nullptr; - ExpressionType* et = const_cast<ExpressionType*>(this); + Type* et = const_cast<Type*>(this); if (!et->canonicalType) { // TODO(tfoley): worry about thread safety here? @@ -153,15 +153,15 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return et->canonicalType; } - bool ExpressionType::IsTextureOrSampler() + bool Type::IsTextureOrSampler() { return IsTexture() || IsSampler(); } - bool ExpressionType::IsStruct() + bool Type::IsStruct() { auto declRefType = AsDeclRefType(); if (!declRefType) return false; - auto structDeclRef = declRefType->declRef.As<StructSyntaxNode>(); + auto structDeclRef = declRefType->declRef.As<StructDecl>(); if (!structDeclRef) return false; return true; } @@ -178,65 +178,65 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) overloadedType->setSession(this); } - ExpressionType* Session::getBoolType() + Type* Session::getBoolType() { return getBuiltinType(BaseType::Bool); } - ExpressionType* Session::getFloatType() + Type* Session::getFloatType() { return getBuiltinType(BaseType::Float); } - ExpressionType* Session::getDoubleType() + Type* Session::getDoubleType() { return getBuiltinType(BaseType::Double); } - ExpressionType* Session::getIntType() + Type* Session::getIntType() { return getBuiltinType(BaseType::Int); } - ExpressionType* Session::getUIntType() + Type* Session::getUIntType() { return getBuiltinType(BaseType::UInt); } - ExpressionType* Session::getVoidType() + Type* Session::getVoidType() { return getBuiltinType(BaseType::Void); } - ExpressionType* Session::getBuiltinType(BaseType flavor) + Type* Session::getBuiltinType(BaseType flavor) { - return RefPtr<ExpressionType>(builtinTypes[(int)flavor]); + return RefPtr<Type>(builtinTypes[(int)flavor]); } - ExpressionType* Session::getInitializerListType() + Type* Session::getInitializerListType() { return initializerListType; } - ExpressionType* Session::getOverloadedType() + Type* Session::getOverloadedType() { return overloadedType; } - ExpressionType* Session::getErrorType() + Type* Session::getErrorType() { return errorType; } - bool ArrayExpressionType::EqualsImpl(ExpressionType * type) + bool ArrayExpressionType::EqualsImpl(Type * type) { auto arrType = type->AsArrayType(); if (!arrType) return false; return (ArrayLength == arrType->ArrayLength && BaseType->Equals(arrType->BaseType.Ptr())); } - ExpressionType* ArrayExpressionType::CreateCanonicalType() + Type* ArrayExpressionType::CreateCanonicalType() { auto canonicalElementType = BaseType->GetCanonicalType(); auto canonicalArrayType = getArrayType( @@ -272,7 +272,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return (declRef.GetHashCode() * 16777619) ^ (int)(typeid(this).hash_code()); } - bool DeclRefType::EqualsImpl(ExpressionType * type) + bool DeclRefType::EqualsImpl(Type * type) { if (auto declRefType = type->AsDeclRefType()) { @@ -281,7 +281,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return false; } - ExpressionType* DeclRefType::CreateCanonicalType() + Type* DeclRefType::CreateCanonicalType() { // A declaration reference is already canonical return this; @@ -343,9 +343,9 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return DeclRefType::Create(getSession(), substDeclRef); } - static RefPtr<ExpressionType> ExtractGenericArgType(RefPtr<Val> val) + static RefPtr<Type> ExtractGenericArgType(RefPtr<Val> val) { - auto type = val.As<ExpressionType>(); + auto type = val.As<Type>(); SLANG_RELEASE_ASSERT(type.Ptr()); return type; } @@ -512,12 +512,12 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return "overload group"; } - bool OverloadGroupType::EqualsImpl(ExpressionType * /*type*/) + bool OverloadGroupType::EqualsImpl(Type * /*type*/) { return false; } - ExpressionType* OverloadGroupType::CreateCanonicalType() + Type* OverloadGroupType::CreateCanonicalType() { return this; } @@ -534,12 +534,12 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return "initializer list"; } - bool InitializerListType::EqualsImpl(ExpressionType * /*type*/) + bool InitializerListType::EqualsImpl(Type * /*type*/) { return false; } - ExpressionType* InitializerListType::CreateCanonicalType() + Type* InitializerListType::CreateCanonicalType() { return this; } @@ -556,14 +556,14 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return "error"; } - bool ErrorType::EqualsImpl(ExpressionType* type) + bool ErrorType::EqualsImpl(Type* type) { if (auto errorType = type->As<ErrorType>()) return true; return false; } - ExpressionType* ErrorType::CreateCanonicalType() + Type* ErrorType::CreateCanonicalType() { return this; } @@ -581,13 +581,13 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return declRef.GetName(); } - bool NamedExpressionType::EqualsImpl(ExpressionType * /*type*/) + bool NamedExpressionType::EqualsImpl(Type * /*type*/) { SLANG_UNEXPECTED("unreachable"); return false; } - ExpressionType* NamedExpressionType::CreateCanonicalType() + Type* NamedExpressionType::CreateCanonicalType() { return GetType(declRef)->GetCanonicalType(); } @@ -609,7 +609,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return "/* unknown FuncType */"; } - bool FuncType::EqualsImpl(ExpressionType * type) + bool FuncType::EqualsImpl(Type * type) { if (auto funcType = type->As<FuncType>()) { @@ -618,7 +618,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return false; } - ExpressionType* FuncType::CreateCanonicalType() + Type* FuncType::CreateCanonicalType() { return this; } @@ -637,7 +637,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return sb.ProduceString(); } - bool TypeType::EqualsImpl(ExpressionType * t) + bool TypeType::EqualsImpl(Type * t) { if (auto typeType = t->As<TypeType>()) { @@ -646,7 +646,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return false; } - ExpressionType* TypeType::CreateCanonicalType() + Type* TypeType::CreateCanonicalType() { auto canType = getTypeType(type->GetCanonicalType()); session->canonicalTypes.Add(canType); @@ -667,7 +667,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return "<DeclRef<GenericDecl>>"; } - bool GenericDeclRefType::EqualsImpl(ExpressionType * type) + bool GenericDeclRefType::EqualsImpl(Type * type) { if (auto genericDeclRefType = type->As<GenericDeclRefType>()) { @@ -681,7 +681,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return declRef.GetHashCode(); } - ExpressionType* GenericDeclRefType::CreateCanonicalType() + Type* GenericDeclRefType::CreateCanonicalType() { return this; } @@ -716,9 +716,9 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return getElementType()->AsBasicType(); } - ExpressionType* MatrixExpressionType::getElementType() + Type* MatrixExpressionType::getElementType() { - return this->declRef.substitutions->args[0].As<ExpressionType>().Ptr(); + return this->declRef.substitutions->args[0].As<Type>().Ptr(); } IntVal* MatrixExpressionType::getRowCount() @@ -840,7 +840,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) // DeclRefBase - RefPtr<ExpressionType> DeclRefBase::Substitute(RefPtr<ExpressionType> type) const + RefPtr<Type> DeclRefBase::Substitute(RefPtr<Type> type) const { // No substitutions? Easy. if (!substitutions) @@ -849,7 +849,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) // Otherwise we need to recurse on the type structure // and apply substitutions where it makes sense - return type->Substitute(substitutions.Ptr()).As<ExpressionType>(); + return type->Substitute(substitutions.Ptr()).As<Type>(); } DeclRefBase DeclRefBase::Substitute(DeclRefBase declRef) const @@ -861,7 +861,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) return declRef.SubstituteImpl(substitutions.Ptr(), &diff); } - RefPtr<ExpressionSyntaxNode> DeclRefBase::Substitute(RefPtr<ExpressionSyntaxNode> expr) const + RefPtr<Expr> DeclRefBase::Substitute(RefPtr<Expr> expr) const { // No substitutions? Easy. if (!substitutions) @@ -1063,9 +1063,9 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) // HLSLPatchType - ExpressionType* HLSLPatchType::getElementType() + Type* HLSLPatchType::getElementType() { - return this->declRef.substitutions->args[0].As<ExpressionType>().Ptr(); + return this->declRef.substitutions->args[0].As<Type>().Ptr(); } IntVal* HLSLPatchType::getElementCount() @@ -1076,7 +1076,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) // Constructors for types RefPtr<ArrayExpressionType> getArrayType( - ExpressionType* elementType, + Type* elementType, IntVal* elementCount) { auto session = elementType->getSession(); @@ -1088,7 +1088,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) } RefPtr<ArrayExpressionType> getArrayType( - ExpressionType* elementType) + Type* elementType) { auto session = elementType->getSession(); auto arrayType = new ArrayExpressionType(); @@ -1107,7 +1107,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra) } RefPtr<TypeType> getTypeType( - ExpressionType* type) + Type* type) { auto session = type->getSession(); auto typeType = new TypeType(type); diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 56b5624b5..059327e6f 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -14,7 +14,7 @@ namespace Slang class Session; class Substitutions; class SyntaxVisitor; - class FunctionSyntaxNode; + class FuncDecl; class Layout; struct IExprVisitor; @@ -214,22 +214,22 @@ namespace Slang struct QualType { - RefPtr<ExpressionType> type; + RefPtr<Type> type; bool IsLeftValue; QualType() : IsLeftValue(false) {} - QualType(ExpressionType* type) + QualType(Type* type) : type(type) , IsLeftValue(false) {} - ExpressionType* Ptr() { return type.Ptr(); } + Type* Ptr() { return type.Ptr(); } - operator RefPtr<ExpressionType>() { return type; } - RefPtr<ExpressionType> operator->() { return type; } + operator RefPtr<Type>() { return type; } + RefPtr<Type> operator->() { return type; } }; // A reference to a class of syntax node, that can be @@ -314,12 +314,12 @@ namespace Slang {} // Apply substitutions to a type or ddeclaration - RefPtr<ExpressionType> Substitute(RefPtr<ExpressionType> type) const; + RefPtr<Type> Substitute(RefPtr<Type> type) const; DeclRefBase Substitute(DeclRefBase declRef) const; // Apply substitutions to an expression - RefPtr<ExpressionSyntaxNode> Substitute(RefPtr<ExpressionSyntaxNode> expr) const; + RefPtr<Expr> Substitute(RefPtr<Expr> expr) const; // Apply substitutions to this declaration reference DeclRefBase SubstituteImpl(Substitutions* subst, int* ioDiff); @@ -383,11 +383,11 @@ namespace Slang return DeclRef<T>((T*) declRef.decl, declRef.substitutions); } - RefPtr<ExpressionType> Substitute(RefPtr<ExpressionType> type) const + RefPtr<Type> Substitute(RefPtr<Type> type) const { return DeclRefBase::Substitute(type); } - RefPtr<ExpressionSyntaxNode> Substitute(RefPtr<ExpressionSyntaxNode> expr) const + RefPtr<Expr> Substitute(RefPtr<Expr> expr) const { return DeclRefBase::Substitute(expr); } @@ -590,7 +590,7 @@ namespace Slang }; // - // Type Expressions + // type Expressions // // A "type expression" is a term that we expect to resolve to a type during checking. @@ -602,35 +602,35 @@ namespace Slang : exp(other.exp) , type(other.type) {} - explicit TypeExp(RefPtr<ExpressionSyntaxNode> exp) + explicit TypeExp(RefPtr<Expr> exp) : exp(exp) {} - TypeExp(RefPtr<ExpressionSyntaxNode> exp, RefPtr<ExpressionType> type) + TypeExp(RefPtr<Expr> exp, RefPtr<Type> type) : exp(exp) , type(type) {} - RefPtr<ExpressionSyntaxNode> exp; - RefPtr<ExpressionType> type; + RefPtr<Expr> exp; + RefPtr<Type> type; - bool Equals(ExpressionType* other); + bool Equals(Type* other); #if 0 { return type->Equals(other); } #endif - bool Equals(RefPtr<ExpressionType> other); + bool Equals(RefPtr<Type> other); #if 0 { return type->Equals(other.Ptr()); } #endif - ExpressionType* Ptr() { return type.Ptr(); } - operator ExpressionType*() + Type* Ptr() { return type.Ptr(); } + operator Type*() { return type; } - ExpressionType* operator->() { return Ptr(); } + Type* operator->() { return Ptr(); } TypeExp Accept(SyntaxVisitor* visitor); }; @@ -656,11 +656,11 @@ namespace Slang // Masks to be applied when lookup up declarations enum class LookupMask : uint8_t { - Type = 0x1, + type = 0x1, Function = 0x2, Value = 0x4, - All = Type | Function | Value, + All = type | Function | Value, }; // Represents one item found during lookup @@ -780,297 +780,17 @@ namespace Slang #include "object-meta-end.h" - inline RefPtr<ExpressionType> GetSub(DeclRef<GenericTypeConstraintDecl> const& declRef) + inline RefPtr<Type> GetSub(DeclRef<GenericTypeConstraintDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->sub.Ptr()); } - inline RefPtr<ExpressionType> GetSup(DeclRef<GenericTypeConstraintDecl> const& declRef) + inline RefPtr<Type> GetSup(DeclRef<GenericTypeConstraintDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->sup.Ptr()); } - // -#if 0 - - class SyntaxVisitor : public RefObject - { - protected: - DiagnosticSink * sink = nullptr; - DiagnosticSink* getSink() { return sink; } - - SourceLanguage sourceLanguage = SourceLanguage::Unknown; - public: - void setSourceLanguage(SourceLanguage language) - { - sourceLanguage = language; - } - - SyntaxVisitor(DiagnosticSink * sink) - : sink(sink) - {} - virtual ~SyntaxVisitor() - { - } - - virtual RefPtr<ProgramSyntaxNode> VisitProgram(ProgramSyntaxNode* program) - { - for (auto & m : program->Members) - m = m->Accept(this).As<Decl>(); - return program; - } - - virtual void visitImportDecl(ImportDecl * decl) = 0; - - virtual RefPtr<FunctionSyntaxNode> VisitFunction(FunctionSyntaxNode* func) - { - func->ReturnType = func->ReturnType.Accept(this); - for (auto & member : func->Members) - member = member->Accept(this).As<Decl>(); - if (func->Body) - func->Body = func->Body->Accept(this).As<BlockStatementSyntaxNode>(); - return func; - } - virtual RefPtr<ScopeDecl> VisitScopeDecl(ScopeDecl* decl) - { - // By default don't visit children, because they will always - // be encountered in the ordinary flow of the corresponding statement. - return decl; - } - virtual RefPtr<StructSyntaxNode> VisitStruct(StructSyntaxNode * s) - { - for (auto & f : s->Members) - f = f->Accept(this).As<Decl>(); - return s; - } - virtual RefPtr<ClassSyntaxNode> VisitClass(ClassSyntaxNode * s) - { - for (auto & f : s->Members) - f = f->Accept(this).As<Decl>(); - return s; - } - virtual RefPtr<GenericDecl> VisitGenericDecl(GenericDecl * decl) - { - for (auto & m : decl->Members) - m = m->Accept(this).As<Decl>(); - decl->inner = decl->inner->Accept(this).As<Decl>(); - return decl; - } - virtual RefPtr<TypeDefDecl> VisitTypeDefDecl(TypeDefDecl* decl) - { - decl->Type = decl->Type.Accept(this); - return decl; - } - virtual RefPtr<StatementSyntaxNode> VisitDiscardStatement(DiscardStatementSyntaxNode * stmt) - { - return stmt; - } - virtual RefPtr<StructField> VisitStructField(StructField * f) - { - f->Type = f->Type.Accept(this); - return f; - } - virtual RefPtr<StatementSyntaxNode> VisitBlockStatement(BlockStatementSyntaxNode* stmt) - { - for (auto & s : stmt->Statements) - s = s->Accept(this).As<StatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitBreakStatement(BreakStatementSyntaxNode* stmt) - { - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitContinueStatement(ContinueStatementSyntaxNode* stmt) - { - return stmt; - } - - virtual RefPtr<StatementSyntaxNode> VisitDoWhileStatement(DoWhileStatementSyntaxNode* stmt) - { - if (stmt->Predicate) - stmt->Predicate = stmt->Predicate->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->Statement) - stmt->Statement = stmt->Statement->Accept(this).As<StatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitEmptyStatement(EmptyStatementSyntaxNode* stmt) - { - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitForStatement(ForStatementSyntaxNode* stmt) - { - if (stmt->InitialStatement) - stmt->InitialStatement = stmt->InitialStatement->Accept(this).As<StatementSyntaxNode>(); - if (stmt->PredicateExpression) - stmt->PredicateExpression = stmt->PredicateExpression->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->SideEffectExpression) - stmt->SideEffectExpression = stmt->SideEffectExpression->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->Statement) - stmt->Statement = stmt->Statement->Accept(this).As<StatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitIfStatement(IfStatementSyntaxNode* stmt) - { - if (stmt->Predicate) - stmt->Predicate = stmt->Predicate->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->PositiveStatement) - stmt->PositiveStatement = stmt->PositiveStatement->Accept(this).As<StatementSyntaxNode>(); - if (stmt->NegativeStatement) - stmt->NegativeStatement = stmt->NegativeStatement->Accept(this).As<StatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<SwitchStmt> VisitSwitchStmt(SwitchStmt* stmt) - { - if (stmt->condition) - stmt->condition = stmt->condition->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->body) - stmt->body = stmt->body->Accept(this).As<BlockStatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<CaseStmt> VisitCaseStmt(CaseStmt* stmt) - { - if (stmt->expr) - stmt->expr = stmt->expr->Accept(this).As<ExpressionSyntaxNode>(); - return stmt; - } - virtual RefPtr<DefaultStmt> VisitDefaultStmt(DefaultStmt* stmt) - { - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitReturnStatement(ReturnStatementSyntaxNode* stmt) - { - if (stmt->Expression) - stmt->Expression = stmt->Expression->Accept(this).As<ExpressionSyntaxNode>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitVarDeclrStatement(VarDeclrStatementSyntaxNode* stmt) - { - stmt->decl = stmt->decl->Accept(this).As<DeclBase>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitWhileStatement(WhileStatementSyntaxNode* stmt) - { - if (stmt->Predicate) - stmt->Predicate = stmt->Predicate->Accept(this).As<ExpressionSyntaxNode>(); - if (stmt->Statement) - stmt->Statement = stmt->Statement->Accept(this).As<StatementSyntaxNode>(); - return stmt; - } - virtual RefPtr<StatementSyntaxNode> VisitExpressionStatement(ExpressionStatementSyntaxNode* stmt) - { - if (stmt->Expression) - stmt->Expression = stmt->Expression->Accept(this).As<ExpressionSyntaxNode>(); - return stmt; - } - - virtual RefPtr<ExpressionSyntaxNode> VisitOperatorExpression(OperatorExpressionSyntaxNode* expr) - { - for (auto && child : expr->Arguments) - child->Accept(this); - return expr; - } - virtual RefPtr<ExpressionSyntaxNode> VisitConstantExpression(ConstantExpressionSyntaxNode* expr) - { - return expr; - } - virtual RefPtr<ExpressionSyntaxNode> VisitIndexExpression(IndexExpressionSyntaxNode* expr) - { - if (expr->BaseExpression) - expr->BaseExpression = expr->BaseExpression->Accept(this).As<ExpressionSyntaxNode>(); - if (expr->IndexExpression) - expr->IndexExpression = expr->IndexExpression->Accept(this).As<ExpressionSyntaxNode>(); - return expr; - } - virtual RefPtr<ExpressionSyntaxNode> VisitMemberExpression(MemberExpressionSyntaxNode * stmt) - { - if (stmt->BaseExpression) - stmt->BaseExpression = stmt->BaseExpression->Accept(this).As<ExpressionSyntaxNode>(); - return stmt; - } - virtual RefPtr<ExpressionSyntaxNode> VisitSwizzleExpression(SwizzleExpr * expr) - { - if (expr->base) - expr->base->Accept(this); - return expr; - } - virtual RefPtr<ExpressionSyntaxNode> VisitInvokeExpression(InvokeExpressionSyntaxNode* stmt) - { - stmt->FunctionExpr->Accept(this); - for (auto & arg : stmt->Arguments) - arg = arg->Accept(this).As<ExpressionSyntaxNode>(); - return stmt; - } - virtual RefPtr<ExpressionSyntaxNode> VisitTypeCastExpression(TypeCastExpressionSyntaxNode * stmt) - { - if (stmt->Expression) - stmt->Expression = stmt->Expression->Accept(this).As<ExpressionSyntaxNode>(); - return stmt->Expression; - } - virtual RefPtr<ExpressionSyntaxNode> VisitVarExpression(VarExpressionSyntaxNode* expr) - { - return expr; - } - - virtual RefPtr<ParameterSyntaxNode> VisitParameter(ParameterSyntaxNode* param) - { - return param; - } - virtual RefPtr<ExpressionSyntaxNode> VisitGenericApp(GenericAppExpr* type) - { - return type; - } - - virtual RefPtr<Variable> VisitDeclrVariable(Variable* dclr) - { - if (dclr->Expr) - dclr->Expr = dclr->Expr->Accept(this).As<ExpressionSyntaxNode>(); - return dclr; - } - - virtual TypeExp VisitTypeExp(TypeExp const& typeExp) - { - TypeExp result = typeExp; - result.exp = typeExp.exp->Accept(this).As<ExpressionSyntaxNode>(); - if (auto typeType = result.exp->Type.type.As<TypeType>()) - { - result.type = typeType->type; - } - return result; - } - - virtual void VisitExtensionDecl(ExtensionDecl* /*decl*/) - {} - - virtual void VisitConstructorDecl(ConstructorDecl* /*decl*/) - {} - - virtual void visitSubscriptDecl(SubscriptDecl* decl) = 0; - - virtual void visitAccessorDecl(AccessorDecl* decl) = 0; - - virtual void visitInterfaceDecl(InterfaceDecl* /*decl*/) = 0; - - virtual void visitInheritanceDecl(InheritanceDecl* /*decl*/) = 0; - - virtual RefPtr<ExpressionSyntaxNode> VisitSharedTypeExpr(SharedTypeExpr* typeExpr) - { - return typeExpr; - } - - virtual void VisitDeclGroup(DeclGroup* declGroup) - { - for (auto decl : declGroup->decls) - { - decl->Accept(this); - } - } - - virtual RefPtr<ExpressionSyntaxNode> visitInitializerListExpr(InitializerListExpr* expr) = 0; - }; - -#endif - - // Note(tfoley): These logically belong to `ExpressionType`, + // Note(tfoley): These logically belong to `Type`, // but order-of-declaration stuff makes that tricky // // TODO(tfoley): These should really belong to the compilation context! @@ -1123,17 +843,17 @@ namespace Slang return FilteredMemberRefList<T>(declRef.getDecl()->Members, declRef.substitutions); } - inline RefPtr<ExpressionType> GetType(DeclRef<VarDeclBase> const& declRef) + inline RefPtr<Type> GetType(DeclRef<VarDeclBase> const& declRef) { - return declRef.Substitute(declRef.getDecl()->Type.Ptr()); + return declRef.Substitute(declRef.getDecl()->type.Ptr()); } - inline RefPtr<ExpressionSyntaxNode> getInitExpr(DeclRef<VarDeclBase> const& declRef) + inline RefPtr<Expr> getInitExpr(DeclRef<VarDeclBase> const& declRef) { - return declRef.Substitute(declRef.getDecl()->Expr); + return declRef.Substitute(declRef.getDecl()->initExpr); } - inline RefPtr<ExpressionType> GetTargetType(DeclRef<ExtensionDecl> const& declRef) + inline RefPtr<Type> GetTargetType(DeclRef<ExtensionDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->targetType.Ptr()); } @@ -1143,29 +863,29 @@ namespace Slang return declRef.getDecl()->candidateExtensions; } - inline FilteredMemberRefList<StructField> GetFields(DeclRef<StructSyntaxNode> const& declRef) + inline FilteredMemberRefList<StructField> GetFields(DeclRef<StructDecl> const& declRef) { return getMembersOfType<StructField>(declRef); } - inline RefPtr<ExpressionType> getBaseType(DeclRef<InheritanceDecl> const& declRef) + inline RefPtr<Type> getBaseType(DeclRef<InheritanceDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->base.type); } - inline RefPtr<ExpressionType> GetType(DeclRef<TypeDefDecl> const& declRef) + inline RefPtr<Type> GetType(DeclRef<TypeDefDecl> const& declRef) { - return declRef.Substitute(declRef.getDecl()->Type.Ptr()); + return declRef.Substitute(declRef.getDecl()->type.Ptr()); } - inline RefPtr<ExpressionType> GetResultType(DeclRef<CallableDecl> const& declRef) + inline RefPtr<Type> GetResultType(DeclRef<CallableDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->ReturnType.type.Ptr()); } - inline FilteredMemberRefList<ParameterSyntaxNode> GetParameters(DeclRef<CallableDecl> const& declRef) + inline FilteredMemberRefList<ParamDecl> GetParameters(DeclRef<CallableDecl> const& declRef) { - return getMembersOfType<ParameterSyntaxNode>(declRef); + return getMembersOfType<ParamDecl>(declRef); } inline Decl* GetInner(DeclRef<GenericDecl> const& declRef) @@ -1179,18 +899,18 @@ namespace Slang // RefPtr<ArrayExpressionType> getArrayType( - ExpressionType* elementType, + Type* elementType, IntVal* elementCount); RefPtr<ArrayExpressionType> getArrayType( - ExpressionType* elementType); + Type* elementType); RefPtr<NamedExpressionType> getNamedType( Session* session, DeclRef<TypeDefDecl> const& declRef); RefPtr<TypeType> getTypeType( - ExpressionType* type); + Type* type); RefPtr<FuncType> getFuncType( Session* session, diff --git a/source/slang/token.h b/source/slang/token.h index f177eb512..f29f2b4c6 100644 --- a/source/slang/token.h +++ b/source/slang/token.h @@ -26,7 +26,7 @@ typedef unsigned int TokenFlags; class Token { public: - TokenType Type = TokenType::Unknown; + TokenType type = TokenType::Unknown; String Content; CodePosition Position; TokenFlags flags = 0; @@ -34,7 +34,7 @@ public: Token(TokenType type, const String & content, int line, int col, int pos, String fileName, TokenFlags flags = 0) : flags(flags) { - Type = type; + type = type; Content = content; Position = CodePosition(line, col, pos, fileName); } diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index c1818eae0..d556e58e4 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -3,46 +3,46 @@ // Syntax class definitions for types. // The type of a reference to an overloaded name -SYNTAX_CLASS(OverloadGroupType, ExpressionType) +SYNTAX_CLASS(OverloadGroupType, Type) RAW( public: virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() // The type of an initializer-list expression (before it has // been coerced to some other type) -SYNTAX_CLASS(InitializerListType, ExpressionType) +SYNTAX_CLASS(InitializerListType, Type) RAW( virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() // The type of an expression that was erroneous -SYNTAX_CLASS(ErrorType, ExpressionType) +SYNTAX_CLASS(ErrorType, Type) RAW( public: virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() // A type that takes the form of a reference to some declaration -SYNTAX_CLASS(DeclRefType, ExpressionType) +SYNTAX_CLASS(DeclRefType, Type) DECL_FIELD(DeclRef<Decl>, declRef) RAW( @@ -61,8 +61,8 @@ RAW( {} protected: virtual int GetHashCode() override; - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; ) END_SYNTAX_CLASS() @@ -88,8 +88,8 @@ RAW( virtual Slang::String ToString() override; protected: virtual BasicExpressionType* GetScalarType() override; - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; ) END_SYNTAX_CLASS() @@ -150,7 +150,7 @@ END_SYNTAX_CLASS() // Resources that contain "elements" that can be fetched ABSTRACT_SYNTAX_CLASS(ResourceType, ResourceTypeBase) // The type that results from fetching an element from this resource - SYNTAX_FIELD(RefPtr<ExpressionType>, elementType) + SYNTAX_FIELD(RefPtr<Type>, elementType) END_SYNTAX_CLASS() ABSTRACT_SYNTAX_CLASS(TextureTypeBase, ResourceType) @@ -159,7 +159,7 @@ RAW( {} TextureTypeBase( Flavor flavor, - RefPtr<ExpressionType> elementType) + RefPtr<Type> elementType) { this->elementType = elementType; this->flavor = flavor; @@ -173,7 +173,7 @@ RAW( {} TextureType( Flavor flavor, - RefPtr<ExpressionType> elementType) + RefPtr<Type> elementType) : TextureTypeBase(flavor, elementType) {} ) @@ -187,7 +187,7 @@ RAW( {} TextureSamplerType( Flavor flavor, - RefPtr<ExpressionType> elementType) + RefPtr<Type> elementType) : TextureTypeBase(flavor, elementType) {} ) @@ -200,7 +200,7 @@ RAW( {} GLSLImageType( Flavor flavor, - RefPtr<ExpressionType> elementType) + RefPtr<Type> elementType) : TextureTypeBase(flavor, elementType) {} ) @@ -221,7 +221,7 @@ END_SYNTAX_CLASS() // Other cases of generic types known to the compiler SYNTAX_CLASS(BuiltinGenericType, DeclRefType) - SYNTAX_FIELD(RefPtr<ExpressionType>, elementType) + SYNTAX_FIELD(RefPtr<Type>, elementType) END_SYNTAX_CLASS() // Types that behave like pointers, in that they can be @@ -243,7 +243,7 @@ SIMPLE_SYNTAX_CLASS(HLSLConsumeStructuredBufferType, BuiltinGenericType) SYNTAX_CLASS(HLSLPatchType, DeclRefType) RAW( - ExpressionType* getElementType(); + Type* getElementType(); IntVal* getElementCount(); ) END_SYNTAX_CLASS() @@ -268,30 +268,30 @@ SIMPLE_SYNTAX_CLASS(ParameterBlockType, PointerLikeType) SIMPLE_SYNTAX_CLASS(UniformParameterBlockType, ParameterBlockType) SIMPLE_SYNTAX_CLASS(VaryingParameterBlockType, ParameterBlockType) -// Type for HLSL `cbuffer` declarations, and `ConstantBuffer<T>` +// type for HLSL `cbuffer` declarations, and `ConstantBuffer<T>` // ALso used for GLSL `uniform` blocks. SIMPLE_SYNTAX_CLASS(ConstantBufferType, UniformParameterBlockType) -// Type for HLSL `tbuffer` declarations, and `TextureBuffer<T>` +// type for HLSL `tbuffer` declarations, and `TextureBuffer<T>` SIMPLE_SYNTAX_CLASS(TextureBufferType, UniformParameterBlockType) -// Type for GLSL `in` and `out` blocks +// type for GLSL `in` and `out` blocks SIMPLE_SYNTAX_CLASS(GLSLInputParameterBlockType, VaryingParameterBlockType) SIMPLE_SYNTAX_CLASS(GLSLOutputParameterBlockType, VaryingParameterBlockType) -// Type for GLLSL `buffer` blocks +// type for GLLSL `buffer` blocks SIMPLE_SYNTAX_CLASS(GLSLShaderStorageBufferType, UniformParameterBlockType) -SYNTAX_CLASS(ArrayExpressionType, ExpressionType) - SYNTAX_FIELD(RefPtr<ExpressionType>, BaseType) +SYNTAX_CLASS(ArrayExpressionType, Type) + SYNTAX_FIELD(RefPtr<Type>, BaseType) SYNTAX_FIELD(RefPtr<IntVal>, ArrayLength) RAW( virtual Slang::String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() @@ -299,23 +299,23 @@ END_SYNTAX_CLASS() // The "type" of an expression that resolves to a type. // For example, in the expression `float(2)` the sub-expression, // `float` would have the type `TypeType(float)`. -SYNTAX_CLASS(TypeType, ExpressionType) +SYNTAX_CLASS(TypeType, Type) // The type that this is the type of... - SYNTAX_FIELD(RefPtr<ExpressionType>, type) + SYNTAX_FIELD(RefPtr<Type>, type) RAW( public: TypeType() {} - TypeType(RefPtr<ExpressionType> type) + TypeType(RefPtr<Type> type) : type(type) {} virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() @@ -325,7 +325,7 @@ SYNTAX_CLASS(VectorExpressionType, ArithmeticExpressionType) // The type of vector elements. // As an invariant, this should be a basic type or an alias. - SYNTAX_FIELD(RefPtr<ExpressionType>, elementType) + SYNTAX_FIELD(RefPtr<Type>, elementType) // The number of elements SYNTAX_FIELD(RefPtr<IntVal>, elementCount) @@ -342,7 +342,7 @@ END_SYNTAX_CLASS() SYNTAX_CLASS(MatrixExpressionType, ArithmeticExpressionType) RAW( - ExpressionType* getElementType(); + Type* getElementType(); IntVal* getRowCount(); IntVal* getColumnCount(); @@ -355,7 +355,7 @@ protected: END_SYNTAX_CLASS() // A type alias of some kind (e.g., via `typedef`) -SYNTAX_CLASS(NamedExpressionType, ExpressionType) +SYNTAX_CLASS(NamedExpressionType, Type) DECL_FIELD(DeclRef<TypeDefDecl>, declRef) RAW( @@ -370,8 +370,8 @@ RAW( virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() @@ -380,7 +380,7 @@ END_SYNTAX_CLASS() // either ordinary functions, or "component functions." // We do not directly store a representation of the type, and instead // use a reference to the symbol to stand in for its logical type -SYNTAX_CLASS(FuncType, ExpressionType) +SYNTAX_CLASS(FuncType, Type) DECL_FIELD(DeclRef<CallableDecl>, declRef) RAW( @@ -389,14 +389,14 @@ RAW( virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; - virtual ExpressionType* CreateCanonicalType() override; + virtual bool EqualsImpl(Type * type) override; + virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) END_SYNTAX_CLASS() // The "type" of an expression that names a generic declaration. -SYNTAX_CLASS(GenericDeclRefType, ExpressionType) +SYNTAX_CLASS(GenericDeclRefType, Type) DECL_FIELD(DeclRef<GenericDecl>, declRef) @@ -414,9 +414,9 @@ SYNTAX_CLASS(GenericDeclRefType, ExpressionType) virtual String ToString() override; protected: - virtual bool EqualsImpl(ExpressionType * type) override; + virtual bool EqualsImpl(Type * type) override; virtual int GetHashCode() override; - virtual ExpressionType* CreateCanonicalType() override; + virtual Type* CreateCanonicalType() override; ) END_SYNTAX_CLASS() diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index 245993881..544071b84 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -624,7 +624,7 @@ bool IsResourceKind(LayoutResourceKind kind) SimpleLayoutInfo GetSimpleLayoutImpl( SimpleLayoutInfo info, - RefPtr<ExpressionType> type, + RefPtr<Type> type, LayoutRulesImpl* rules, RefPtr<TypeLayout>* outTypeLayout) { @@ -740,7 +740,7 @@ RefPtr<ParameterBlockTypeLayout> createParameterBlockTypeLayout( RefPtr<ParameterBlockType> parameterBlockType, LayoutRulesImpl* parameterBlockRules, - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, LayoutRulesImpl* elementTypeRules) { // First compute resource usage of the block itself. @@ -832,7 +832,7 @@ createParameterBlockTypeLayout( RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( ShaderParameterKind kind, - RefPtr<ExpressionType> structuredBufferType, + RefPtr<Type> structuredBufferType, RefPtr<TypeLayout> elementTypeLayout, LayoutRulesImpl* rules) { @@ -865,8 +865,8 @@ createStructuredBufferTypeLayout( RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( ShaderParameterKind kind, - RefPtr<ExpressionType> structuredBufferType, - RefPtr<ExpressionType> elementType, + RefPtr<Type> structuredBufferType, + RefPtr<Type> elementType, LayoutRulesImpl* rules) { // TODO(tfoley): need to compute the layout for the constant @@ -888,13 +888,13 @@ createStructuredBufferTypeLayout( } SimpleLayoutInfo GetLayoutImpl( - ExpressionType* type, + Type* type, LayoutRulesImpl* rules, RefPtr<TypeLayout>* outTypeLayout, SimpleLayoutInfo offset); SimpleLayoutInfo GetLayoutImpl( - ExpressionType* type, + Type* type, LayoutRulesImpl* rules, RefPtr<TypeLayout>* outTypeLayout) { @@ -902,7 +902,7 @@ SimpleLayoutInfo GetLayoutImpl( } SimpleLayoutInfo GetLayoutImpl( - ExpressionType* type, + Type* type, LayoutRulesImpl* rules, RefPtr<TypeLayout>* outTypeLayout, SimpleLayoutInfo offset) @@ -1154,7 +1154,7 @@ SimpleLayoutInfo GetLayoutImpl( { auto declRef = declRefType->declRef; - if (auto structDeclRef = declRef.As<StructSyntaxNode>()) + if (auto structDeclRef = declRef.As<StructDecl>()) { RefPtr<StructTypeLayout> typeLayout; if (outTypeLayout) @@ -1270,24 +1270,24 @@ SimpleLayoutInfo GetLayoutImpl( outTypeLayout); } -SimpleLayoutInfo GetLayout(ExpressionType* inType, LayoutRulesImpl* rules) +SimpleLayoutInfo GetLayout(Type* inType, LayoutRulesImpl* rules) { return GetLayoutImpl(inType, rules, nullptr); } -RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules, SimpleLayoutInfo offset) +RefPtr<TypeLayout> CreateTypeLayout(Type* type, LayoutRulesImpl* rules, SimpleLayoutInfo offset) { RefPtr<TypeLayout> typeLayout; GetLayoutImpl(type, rules, &typeLayout, offset); return typeLayout; } -RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules) +RefPtr<TypeLayout> CreateTypeLayout(Type* type, LayoutRulesImpl* rules) { return CreateTypeLayout(type, rules, SimpleLayoutInfo()); } -SimpleLayoutInfo GetLayout(ExpressionType* type, LayoutRule rule) +SimpleLayoutInfo GetLayout(Type* type, LayoutRule rule) { LayoutRulesImpl* rulesImpl = GetLayoutRulesImpl(rule); return GetLayout(type, rulesImpl); diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index 7be1c595f..7d037b2e7 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -16,7 +16,7 @@ typedef uintptr_t UInt; // Forward declarations enum class BaseType; -class ExpressionType; +class Type; // @@ -154,8 +154,8 @@ class TypeLayout : public Layout { public: // The type that was laid out - RefPtr<ExpressionType> type; - ExpressionType* getType() { return type.Ptr(); } + RefPtr<Type> type; + Type* getType() { return type.Ptr(); } // The layout rules that were used to produce this type LayoutRulesImpl* rules; @@ -287,14 +287,14 @@ public: } }; -// Type layout for a variable that has a constant-buffer type +// type layout for a variable that has a constant-buffer type class ParameterBlockTypeLayout : public TypeLayout { public: RefPtr<TypeLayout> elementTypeLayout; }; -// Type layout for a variable that has a constant-buffer type +// type layout for a variable that has a constant-buffer type class StructuredBufferTypeLayout : public TypeLayout { public: @@ -345,7 +345,7 @@ class EntryPointLayout : public StructTypeLayout { public: // The corresponding function declaration - RefPtr<FunctionSyntaxNode> entryPoint; + RefPtr<FuncDecl> entryPoint; // The shader profile that was used to compile the entry point Profile profile; @@ -532,12 +532,12 @@ LayoutRulesImpl* GetLayoutRulesImpl(LayoutRule rule); LayoutRulesFamilyImpl* GetLayoutRulesFamilyImpl(LayoutRulesFamily rule); LayoutRulesFamilyImpl* GetLayoutRulesFamilyImpl(CodeGenTarget target); -SimpleLayoutInfo GetLayout(ExpressionType* type, LayoutRulesImpl* rules); +SimpleLayoutInfo GetLayout(Type* type, LayoutRulesImpl* rules); -SimpleLayoutInfo GetLayout(ExpressionType* type, LayoutRule rule = LayoutRule::Std430); +SimpleLayoutInfo GetLayout(Type* type, LayoutRule rule = LayoutRule::Std430); -RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules); -RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules, SimpleLayoutInfo offset); +RefPtr<TypeLayout> CreateTypeLayout(Type* type, LayoutRulesImpl* rules); +RefPtr<TypeLayout> CreateTypeLayout(Type* type, LayoutRulesImpl* rules, SimpleLayoutInfo offset); // @@ -551,7 +551,7 @@ RefPtr<ParameterBlockTypeLayout> createParameterBlockTypeLayout( RefPtr<ParameterBlockType> parameterBlockType, LayoutRulesImpl* parameterBlockRules, - RefPtr<ExpressionType> elementType, + RefPtr<Type> elementType, LayoutRulesImpl* elementTypeRules); RefPtr<ParameterBlockTypeLayout> @@ -565,8 +565,8 @@ createParameterBlockTypeLayout( RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( ShaderParameterKind kind, - RefPtr<ExpressionType> structuredBufferType, - RefPtr<ExpressionType> elementType, + RefPtr<Type> structuredBufferType, + RefPtr<Type> elementType, LayoutRulesImpl* rules); diff --git a/source/slang/visitor.h b/source/slang/visitor.h index 7000927c7..59c5772f2 100644 --- a/source/slang/visitor.h +++ b/source/slang/visitor.h @@ -10,7 +10,7 @@ namespace Slang { // -// Type Visitors +// type Visitors // struct ITypeVisitor @@ -27,7 +27,7 @@ struct ITypeVisitor template<typename Derived, typename Result = void, typename Base = ITypeVisitor> struct TypeVisitor : Base { - Result dispatch(ExpressionType* type) + Result dispatch(Type* type) { Result result; type->accept(this, &result); @@ -56,7 +56,7 @@ struct TypeVisitor : Base template<typename Derived, typename Base> struct TypeVisitor<Derived,void,Base> : Base { - void dispatch(ExpressionType* type) + void dispatch(Type* type) { type->accept(this, 0); } @@ -83,7 +83,7 @@ struct TypeVisitor<Derived,void,Base> : Base template<typename Derived, typename Arg, typename Base = ITypeVisitor> struct TypeVisitorWithArg : Base { - void dispatch(ExpressionType* type, Arg const& arg) + void dispatch(Type* type, Arg const& arg) { type->accept(this, (void*)&arg); } @@ -125,7 +125,7 @@ struct IExprVisitor template<typename Derived, typename Result = void> struct ExprVisitor : IExprVisitor { - Result dispatch(ExpressionSyntaxNode* expr) + Result dispatch(Expr* expr) { Result result; expr->accept(this, &result); @@ -154,7 +154,7 @@ struct ExprVisitor : IExprVisitor template<typename Derived> struct ExprVisitor<Derived,void> : IExprVisitor { - void dispatch(ExpressionSyntaxNode* expr) + void dispatch(Expr* expr) { expr->accept(this, 0); } @@ -181,7 +181,7 @@ struct ExprVisitor<Derived,void> : IExprVisitor template<typename Derived, typename Arg> struct ExprVisitorWithArg : IExprVisitor { - void dispatch(ExpressionSyntaxNode* obj, Arg const& arg) + void dispatch(Expr* obj, Arg const& arg) { obj->accept(this, (void*)&arg); } @@ -223,7 +223,7 @@ struct IStmtVisitor template<typename Derived, typename Result = void> struct StmtVisitor : IStmtVisitor { - Result dispatch(StatementSyntaxNode* stmt) + Result dispatch(Stmt* stmt) { Result result; stmt->accept(this, &result); @@ -252,7 +252,7 @@ struct StmtVisitor : IStmtVisitor template<typename Derived> struct StmtVisitor<Derived,void> : IStmtVisitor { - void dispatch(StatementSyntaxNode* stmt) + void dispatch(Stmt* stmt) { stmt->accept(this, 0); } |
