public override IPStmt VisitCtorStmt(PParser.CtorStmtContext context) { string machineName = context.iden().GetText(); if (!table.Lookup(machineName, out Machine targetMachine)) { throw handler.MissingDeclaration(context.iden(), "machine", machineName); } var args = (from arg in context.rvalueList()?.rvalue() ?? Enumerable.Empty <PParser.RvalueContext>() select exprVisitor.Visit(arg)).ToList(); TypeCheckingUtils.ValidatePayloadTypes(handler, context, targetMachine.PayloadType, args); return(new CtorStmt(context, targetMachine, args)); }
public override IPExpr VisitCtorExpr(PParser.CtorExprContext context) { string machineName = context.machineName.GetText(); if (!table.Lookup(machineName, out Machine machine)) { throw handler.MissingDeclaration(context.machineName, "machine", machineName); } IPExpr[] arguments = (context.rvalueList()?.rvalue().Select(Visit) ?? Enumerable.Empty <IPExpr>()).ToArray(); TypeCheckingUtils.ValidatePayloadTypes(handler, context, machine.PayloadType, arguments); return(new CtorExpr(context, machine, arguments)); }
public override IPStmt VisitCtorStmt(PParser.CtorStmtContext context) { string interfaceName = context.iden().GetText(); if (!table.Lookup(interfaceName, out Interface targetInterface)) { throw handler.MissingDeclaration(context.iden(), "interface", interfaceName); } List <IPExpr> args = TypeCheckingUtils.VisitRvalueList(context.rvalueList(), exprVisitor).ToList(); TypeCheckingUtils.ValidatePayloadTypes(handler, context, targetInterface.PayloadType, args); return(new CtorStmt(context, targetInterface, args)); }
public override PLanguageType VisitNamedType(PParser.NamedTypeContext context) { string typeName = context.name.GetText(); if (scope.Lookup(typeName, out PEnum pEnum)) { return(new EnumType(pEnum)); } if (scope.Lookup(typeName, out TypeDef typeDef)) { if (visitedTypeDefs.Contains(typeDef)) { throw handler.CircularTypeDef(context.name, typeDef); } if (typeDef.Type == null) { visitedTypeDefs.Push(typeDef); switch (typeDef.SourceLocation) { case PParser.ForeignTypeDefContext foreignType: typeDef.Type = new ForeignType(foreignType.name.GetText()); break; case PParser.PTypeDefContext typedefDecl: typeDef.Type = Visit(typedefDecl.type()); break; case InterpreterRuleContext _: case RuleContextWithAltNum _: default: throw handler.InternalError(typeDef.SourceLocation, new ArgumentOutOfRangeException(nameof(context))); } visitedTypeDefs.Pop(); } return(new TypeDefType(typeDef)); } if (scope.Lookup(typeName, out NamedEventSet eventSet)) { return(new PermissionType(eventSet)); } if (scope.Lookup(typeName, out Interface pInterface)) { return(new PermissionType(pInterface)); } if (scope.Lookup(typeName, out Machine machine)) { return(new PermissionType(machine)); } throw handler.MissingDeclaration(context.name, "enum, typedef, event set, machine, or interface", typeName); }
public override IPExpr VisitCtorExpr(PParser.CtorExprContext context) { string interfaceName = context.interfaceName.GetText(); if (!table.Lookup(interfaceName, out Interface @interface)) { throw handler.MissingDeclaration(context.interfaceName, "interface", interfaceName); } if (method.Owner?.IsSpec == true) { throw handler.IllegalMonitorOperation(context, context.NEW().Symbol, method.Owner); } IPExpr[] arguments = TypeCheckingUtils.VisitRvalueList(context.rvalueList(), this).ToArray(); TypeCheckingUtils.ValidatePayloadTypes(handler, context, @interface.PayloadType, arguments); return(new CtorExpr(context, @interface, arguments)); }
public override IPModuleExpr VisitNamedModule([NotNull] PParser.NamedModuleContext context) { // check if the named module is declared if (!globalScope.Get(context.GetText(), out NamedModule mod)) { throw handler.MissingDeclaration(context, "module", context.GetText()); } PParser.NamedModuleDeclContext declContext = (PParser.NamedModuleDeclContext)mod.SourceLocation; return(Visit(declContext.modExpr())); }
public override PLanguageType VisitNamedType(PParser.NamedTypeContext context) { string typeName = context.name.GetText(); if (scope.Lookup(typeName, out PEnum pEnum)) { return(new EnumType(pEnum)); } if (scope.Lookup(typeName, out TypeDef typeDef)) { if (visitedTypeDefs.Contains(typeDef)) { throw handler.CircularTypeDef(context.name, typeDef); } if (typeDef.Type == null) { visitedTypeDefs.Add(typeDef); switch (typeDef.SourceLocation) { case PParser.ForeignTypeDefContext foreignType: typeDef.Type = new ForeignType(foreignType.name.GetText()); break; case PParser.PTypeDefContext typedefDecl: typeDef.Type = Visit(typedefDecl.type()); break; default: throw handler.InternalError(typeDef.SourceLocation, $"Grammar changed without updating {nameof(TypeVisitor)}"); } } return(new TypeDefType(typeDef)); } if (scope.Lookup(typeName, out NamedEventSet eventSet)) { return(new PermissionType(eventSet)); } if (scope.Lookup(typeName, out Interface pInterface)) { return(new PermissionType(pInterface)); } if (scope.Lookup(typeName, out Machine machine)) { return(new PermissionType(machine)); } throw handler.MissingDeclaration(context.name, "enum, typedef, event set, machine, or interface", typeName); }