Ejemplo n.º 1
0
 private IType BindTypeCore(ITypeSyntax syntax)
 {
     if (syntax is AnyTypeSyntax)
     {
         return(new AnyType());
     }
     if (syntax is VoidTypeSyntax)
     {
         return(new VoidType());
     }
     if (syntax is ArrayTypeSyntax arrayType)
     {
         return(new ArrayType(BindType(arrayType.ElementType)));
     }
     if (syntax is FunctionPointerTypeSyntax functionPointerType)
     {
         var returnType = BindType(functionPointerType.ReturnType);
         var parameters = functionPointerType.Parameters.Select(BindType);
         return(new FunctionPointerType(returnType, parameters));
     }
     if (syntax is PrimitiveTypeSyntax)
     {
         return(syntax.Name switch
         {
             "string" => new PrimitiveType(PrimitiveKind.STRING),
             "num" => new PrimitiveType(PrimitiveKind.NUM),
             "bool" => new PrimitiveType(PrimitiveKind.BOOL),
             "char" => new PrimitiveType(PrimitiveKind.CHAR),
             var x => throw new Exception("unsupported primitive type with name: #{x}")
         });
Ejemplo n.º 2
0
 public IType MakeBindingFor(ITypeSyntax syntax, IType value)
 {
     if (!(value is UndeclaredStructType))
     {
         TypesBindings[syntax] = value;
     }
     return(value);
 }
        public TypeParameterConstraintSyntax(ISyntaxNode parent, JurParser.ConstrainContext context) : base(parent, context)
        {
            Left  = ToType(context.type(0));
            Right = ToType(context.type(1));

            ImmediateChildren = ImmutableArray.Create <ITreeNode>()
                                .Add(Left)
                                .Add(Right);
        }
Ejemplo n.º 4
0
 public CapabilityTypeSyntax(
     ReferenceCapability referenceCapability,
     ITypeSyntax referentType,
     TextSpan span)
     : base(span)
 {
     ReferentType = referentType;
     Capability   = referenceCapability;
 }
Ejemplo n.º 5
0
 public NamedParameterSyntax(
     TextSpan span,
     bool isMutableBinding,
     Name name,
     ITypeSyntax typeSyntax,
     IExpressionSyntax?defaultValue)
     : base(span, name)
 {
     IsMutableBinding = isMutableBinding;
     Name             = name;
     Type             = typeSyntax;
     DefaultValue     = defaultValue;
     DataType         = Symbol.Select(s => s.DataType);
 }
Ejemplo n.º 6
0
 public FieldDeclarationSyntax(
     IClassDeclarationSyntax declaringClass,
     TextSpan span,
     CodeFile file,
     IAccessModifierToken?accessModifier,
     bool mutableBinding,
     TextSpan nameSpan,
     Name name,
     ITypeSyntax type,
     IExpressionSyntax?initializer)
     : base(declaringClass, span, file, accessModifier, nameSpan, name, new AcyclicPromise <FieldSymbol>())
 {
     IsMutableBinding = mutableBinding;
     Name             = name;
     Type             = type;
     this.initializer = initializer;
     Symbol           = (AcyclicPromise <FieldSymbol>)base.Symbol;
 }
 public OptionalTypeSyntax(TextSpan span, ITypeSyntax referent)
     : base(span)
 {
     Referent = referent;
 }
Ejemplo n.º 8
0
 public ArrayTypeSyntax(ISyntaxNode parent, JurParser.ArrayTypeContext context) : base(parent, context)
 {
     ElementType       = ToType(context.type());
     ImmediateChildren = ImmutableArray.Create <ITreeNode>().Add(ElementType);
 }
        public TypeExpressionSyntax(ISyntaxNode parent, JurParser.TypeExpressionContext context) : base(parent, context, context.TYPE())
        {
            Type = ToType(context.type());

            ImmediateChildren = ImmutableArray.Create <ITreeNode>().Add(Type);
        }
Ejemplo n.º 10
0
        public DefaultTypeValueSyntax(ISyntaxNode parent, JurParser.DefaultValueContext context) : base(parent, context, context.DEFAULT_VALUE())
        {
            Type = ToType(context.type());

            ImmediateChildren = ImmutableArray.Create <ITreeNode>().Add(Type);
        }
Ejemplo n.º 11
0
 public bool AlreadyBound(ITypeSyntax syntax) => TypesBindings.ContainsKey(syntax);
Ejemplo n.º 12
0
 public IType GetBindingFor(ITypeSyntax syntax) => TypesBindings[syntax];
Ejemplo n.º 13
0
 public IType BindType(ITypeSyntax syntax)
 {
     return(symbols.AlreadyBound(syntax)
                ? symbols.GetBindingFor(syntax)
                : symbols.MakeBindingFor(syntax, BindTypeCore(syntax)));
 }