示例#1
0
        void parseStruct()
        {
            Token name = parseData.tokens[parseData.cursor += 1];

            if (name.type != TT.IDENTIFIER)
            {
                throw Jolly.unexpected(token);
            }

            Token next = parseData.tokens[parseData.cursor += 1];

            AST_Struct      structNode  = new AST_Struct(token.location);
            DataType_Struct structType  = new DataType_Struct();
            SymbolTable     structTable = new SymbolTable(scope);

            structNode.index = parseData.ast.Count;
            parseData.ast.Add(structNode);
            int startNodeCount = parseData.ast.Count;

            if (next.type == TT.LESS)
            {
                parseData.cursor += 1;
                new ExpressionParser(parseData, TT.GREATER, structTable, DefineMode.TEMPLATE, end)
                .parse(false);
                next = parseData.tokens[parseData.cursor += 1];                 // Skip greater than
            }

            if (next.type == TT.COLON)
            {
                parseData.cursor   += 1;
                structNode.inherits =
                    new ExpressionParser(parseData, TT.BRACE_OPEN, structTable, DefineMode.EXPRESSION, end)
                    .parse(false)
                    .getValue();
                next = parseData.tokens[parseData.cursor];
            }

            if (next.type != TT.BRACE_OPEN)
            {
                throw Jolly.unexpected(next);
            }

            structNode.symbol = structTable;
            structNode.text   = structType.name = name.text;
            structNode.result = structTable.declaration = new IR {
                irType = NT.STRUCT, dType = structType, dKind = ValueKind.STATIC_TYPE
            };

            scope.addChild(name.text, structTable);

            parseData.cursor += 1;
            new ScopeParser(parseData, next.partnerIndex, structTable)
            .parse(ScopeParseMethod.STRUCT);

            structNode.memberCount = parseData.ast.Count - startNodeCount;
            structType.members     = new DataType[structType.memberMap.Count];
        }
示例#2
0
        public override IR implicitCast(IR i, DataType to, IRList list)
        {
            if (!(to is DataType_Reference))
            {
                return(null);
            }
            DataType_Struct iterator = this;

            while (iterator != null)
            {
                if (iterator == to)
                {
                    return(list.Add(IR.cast <IR_Reinterpret>(i, to, null)));
                }
            }
            return(null);
        }
示例#3
0
        public override IR getMember(IR i, string name, IRList list)
        {
            int             index;
            DataType_Struct iterator = this;

            while (iterator != null)
            {
                if (iterator.memberMap.TryGetValue(name, out index))
                {
                    IR _struct = i;
                    if (iterator != this)
                    {
                        _struct = list.Add(IR.cast <IR_Reinterpret>(i, iterator, null));
                    }
                    return(list.Add(IR.getMember(_struct, iterator.members[index], index + (iterator.inherits == null ? 0 : 1))));
                }
                iterator = iterator.inherits;
            }
            return(null);
        }