Inheritance: NodeExpr
Esempio n. 1
0
 public void Visit(NodeStr s)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
 public void Visit(NodeStr s)
 {
     log.Error(s.Span, "A string literal is not valid in this placement. Perhaps you meant to put it in a function?");
 }
Esempio n. 3
0
 public void Visit(NodeStr s)
 {
     Push(new PointerTyRef(TyInt.Int8Ty, false));
 }
Esempio n. 4
0
 public void Visit(NodeStr s)
 {
     var value = s.Value;
     var constCStr = BuildGlobalStringPtr(builder, value, "");
     Push(s.Span, new PointerTyRef(TyInt.Int8Ty, false), constCStr);
 }
Esempio n. 5
0
 public void Visit(NodeStr s)
 {
 }
Esempio n. 6
0
 public void Visit(NodeStr s)
 {
     Write("{0}{1}\"{2}\"", s.Token.StrC ? "c" : "", s.Token.StrVerbatim ? "v" : "", s.Value);
 }
Esempio n. 7
0
        private NodeExpr ParsePrimaryExpr(bool isEnclosed, bool doError = true)
        {
            if (!HasCurrent)
            {
                log.Error(GetLastSpan(), "Expected a primary expression, got end of file.");
                return null;
            }

            NodeExpr result;
            switch (Current.type)
            {
                case IF:
                {
                    var @if = new NodeIf();
                    while (Check(IF))
                    {
                        Advance();
                        @if.conditions.Add(new NodeIf.IfBlock(ParseExpr(), ParseBlock()));
                        if (Check(EL))
                        {
                            if (!Check(IF))
                            {
                                @if.fail = ParseBlock();
                                break;
                            }
                            else Advance();
                        }
                    }
                    result = @if;
                } break;
                case LPAREN:
                    var lparen = Current;
                    Advance();
                    if (Check(RPAREN))
                    {
                        result = new NodeTuple(lparen, Current, new List<NodeExpr>());
                        Advance();
                        break;
                    }
                    bool trailingComma;
                    var exprs = ParseCommaList(out trailingComma);
                    if (exprs.Count == 1 && !trailingComma)
                    {
                        Expect(RPAREN, "Expected ')' to match opening '('.");
                        result = new NodeEnclosed(lparen, Last, exprs[0]);
                    }
                    else
                    {
                        Expect(RPAREN, "Expected ')' to close tuple.");
                        result = new NodeTuple(lparen, Last, exprs);
                    }
                    break;
                case TRUE: case FALSE:
                {
                    result = new NodeBool(Current);
                    Advance();
                } break;
                case INT:
                {
                    result = new NodeInt(Current);
                    Advance();
                } break;
                case STR:
                {
                    result = new NodeStr(Current);
                    Advance();
                } break;
                case IDENT:
                {
                    result = new NodeId(Current);
                    Advance();
                } break;
                default:
                    if (doError)
                    {
                        log.Error(GetLastSpan(), "Unexpected token '{0}' when parsing primary expression.", Current);
                        Advance();
                    }
                    return null;
            }

            // TODO(kai): check field index.
            while (Check(DOT))
            {
                var dot = Current;
                Advance();
                result = new NodeIndex(result, dot, new NodeId(ExpectIdent("Identifier expected for type index.")));
            }

            return ParseInvoke(result, isEnclosed);
        }