コード例 #1
0
        public override object VisitStructDeclaration([NotNull] CMinusParser.StructDeclarationContext context)
        {
            string structType = context.ID().GetText();

            bool typeSuccess = this.symbolTable.AddSymbolType(structType);

            if (!typeSuccess)
            {
                this.EmitSemanticErrorMessage($"Struct type {structType} already declared", context);
            }

            List <SymbolTable.Symbol> members = (List <SymbolTable.Symbol>) this.Visit(context.structDeclarationList());

            uint membersSize = (uint)members.Sum(member => member.size);

            SymbolTable.Symbol structSymbol = new SymbolTable.Symbol(
                id: structType,
                type: structType,
                construct: SymbolTable.Symbol.Construct.STRUCT,
                scope: 0,
                size: membersSize,
                pointerCount: 0
                );

            bool symbolSuccess = this.symbolTable.AddSymbol(structSymbol);

            if (!symbolSuccess)
            {
                this.EmitSemanticErrorMessage($"Symbol {structType} already in symbol table as a {this.symbolTable.GetSymbol(structType).construct}", context);
            }

            return(null);
        }
コード例 #2
0
 // TODO
 public override object VisitStructDeclaration([NotNull] CMinusParser.StructDeclarationContext context)
 {
     return(base.VisitStructDeclaration(context));
 }