public override IAstNode VisitAexprRecAccess(MicroCParser.AexprRecAccessContext context) { string recName = context.name.Text; string fieldName = context.field.Text; var recSymbol = _symbolTable.LookupSymbol(recName); var fieldSymbol = recSymbol.Children.SingleOrDefault(f => f.Name == fieldName); if (fieldSymbol == null) { throw new ArgumentException($"Record: {recName} does not include a field: {fieldName}"); } var recIdent = new Identifier(recName, recSymbol.Type, recSymbol.Id); var fieldIdent = new Identifier(fieldName, fieldSymbol.Type, fieldSymbol.Id); return(new RecordAccess(recIdent, fieldIdent)); }
/// <summary> /// Exit a parse tree produced by the <c>aexprRecAccess</c> /// labeled alternative in <see cref="MicroCParser.a_expr"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitAexprRecAccess([NotNull] MicroCParser.AexprRecAccessContext context) { }
/// <summary> /// Visit a parse tree produced by the <c>aexprRecAccess</c> /// labeled alternative in <see cref="MicroCParser.a_expr"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitAexprRecAccess([NotNull] MicroCParser.AexprRecAccessContext context) { return(VisitChildren(context)); }