Beispiel #1
0
        }                                    // set during AST construction

        #region implemented abstract members of Node

        /// <summary>
        /// Resolve type defined by this typeExpression. Type Expression must be given in reversed order.
        /// </summary>
        /// <returns>The resolved type.</returns>
        /// <param name="typeExpr">Enumerator of reversed type expresion enumeration.</param>
        public static TypeNode RecursiveResolveArrayType <TSymbol>(IEnumerator <IParseTree <TSymbol> > typeExpr) where TSymbol : ISymbol <TSymbol>
        {
            bool isMutable = ASTBuilder.EatSymbol("mutable", typeExpr);

            if (ASTBuilder.EatSymbol("]", typeExpr))   // if ] is present then create ArrayType
            {
                var resType = new ArrayTypeNode();
                resType.IsConstant  = !isMutable;
                resType.IsFixedSize = false;             // we initialize all arrays as dynamic size
                if (ASTBuilder.EatSymbol("[", typeExpr)) // opening bracket, no length expression
                {
                    resType.LengthExpression = null;
                }
                else     // length expression present
                {
                    resType.LengthExpression = ExpressionNode.GetExpressionNode(typeExpr.Current);
                    typeExpr.MoveNext();
                    Debug.Assert(ASTBuilder.EatSymbol("[", typeExpr)); // eat opening bracket
                }
                resType.ElementType = RecursiveResolveArrayType(typeExpr);
                return(resType);
            }
            else
            {
                var resType = new NamedTypeNode();
                resType.BuildNode(typeExpr.Current);
                resType.IsConstant = !isMutable;
                return(resType);
            }
        }
Beispiel #2
0
        public static ConstNode GetConstNode <TSymbol>(IParseTree <TSymbol> parseTree) where TSymbol : ISymbol <TSymbol>
        {
            // one of: DecimalNumberLiteral | CharacterLiteral | StringLiteral | BooleanLiteral
            TypeNode type;

            switch (ASTBuilder.GetName(parseTree.Symbol))
            {
            case "DecimalNumberLiteral":
                type = NamedTypeNode.IntType(true);
                break;

            case "CharacterLiteral":
                type = NamedTypeNode.CharType(true);
                break;

            case "StringLiteral":
                throw new NotImplementedException();     // TODO: strings implementation

            case "BooleanLiteral":
                type = NamedTypeNode.BoolType(true);
                break;

            default:
                throw new System.ArgumentException();
            }
            return(new AtomNode(type));
        }
Beispiel #3
0
        public static NamedTypeNode ByteType(bool isConstant = false)
        {
            NamedTypeNode node = new NamedTypeNode();

            node.Name       = "byte";
            node.IsConstant = isConstant;
            return(node);
        }
Beispiel #4
0
        public static NamedTypeNode CharType(bool isConstant = false)
        {
            NamedTypeNode node = new NamedTypeNode();

            node.Name       = "char";
            node.IsConstant = isConstant;
            return(node);
        }
Beispiel #5
0
 public static ArrayTypeNode VoidType()
 {
     return(MakeType(NamedTypeNode.VoidType()));
 }
Beispiel #6
0
 public static ArrayTypeNode IntType()
 {
     return(MakeType(NamedTypeNode.IntType()));
 }
Beispiel #7
0
 public static ArrayTypeNode CharType()
 {
     return(MakeType(NamedTypeNode.CharType()));
 }
Beispiel #8
0
 public static ArrayTypeNode ByteType()
 {
     return(MakeType(NamedTypeNode.ByteType()));
 }