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}") });
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); }
public CapabilityTypeSyntax( ReferenceCapability referenceCapability, ITypeSyntax referentType, TextSpan span) : base(span) { ReferentType = referentType; Capability = referenceCapability; }
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); }
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; }
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); }
public DefaultTypeValueSyntax(ISyntaxNode parent, JurParser.DefaultValueContext context) : base(parent, context, context.DEFAULT_VALUE()) { Type = ToType(context.type()); ImmediateChildren = ImmutableArray.Create <ITreeNode>().Add(Type); }
public bool AlreadyBound(ITypeSyntax syntax) => TypesBindings.ContainsKey(syntax);
public IType GetBindingFor(ITypeSyntax syntax) => TypesBindings[syntax];
public IType BindType(ITypeSyntax syntax) { return(symbols.AlreadyBound(syntax) ? symbols.GetBindingFor(syntax) : symbols.MakeBindingFor(syntax, BindTypeCore(syntax))); }