public virtual void VisitArrayTypeNode(ArrayTypeNode node) { Visit(node.ArrayKeywordNode); Visit(node.OpenBracketNode); Visit(node.IndexListNode); Visit(node.CloseBracketNode); Visit(node.OfKeywordNode); Visit(node.TypeNode); }
public TypeSymbol ResolveType(ParseNode node, ISymbolTable symbolTable, Symbol contextSymbol) { if (node is IntrinsicTypeNode) { IntrinsicType intrinsicType = IntrinsicType.Integer; IntrinsicTypeNode intrinsicTypeNode = (IntrinsicTypeNode)node; switch (intrinsicTypeNode.Type) { case TokenType.Object: intrinsicType = IntrinsicType.Object; break; case TokenType.Bool: intrinsicType = IntrinsicType.Boolean; break; case TokenType.String: case TokenType.Char: intrinsicType = IntrinsicType.String; break; case TokenType.Int: intrinsicType = IntrinsicType.Integer; break; case TokenType.UInt: intrinsicType = IntrinsicType.UnsignedInteger; break; case TokenType.Long: intrinsicType = IntrinsicType.Long; break; case TokenType.ULong: intrinsicType = IntrinsicType.UnsignedLong; break; case TokenType.Short: intrinsicType = IntrinsicType.Short; break; case TokenType.UShort: intrinsicType = IntrinsicType.UnsignedShort; break; case TokenType.Byte: intrinsicType = IntrinsicType.Byte; break; case TokenType.SByte: intrinsicType = IntrinsicType.SignedByte; break; case TokenType.Float: intrinsicType = IntrinsicType.Single; break; case TokenType.Decimal: intrinsicType = IntrinsicType.Decimal; break; case TokenType.Double: intrinsicType = IntrinsicType.Double; break; case TokenType.Delegate: intrinsicType = IntrinsicType.Delegate; break; case TokenType.Void: intrinsicType = IntrinsicType.Void; break; } TypeSymbol typeSymbol = ResolveIntrinsicType(intrinsicType); if (intrinsicTypeNode.IsNullable) { TypeSymbol nullableType = ResolveIntrinsicType(IntrinsicType.Nullable); typeSymbol = CreateGenericTypeSymbol(nullableType, new List <TypeSymbol> { typeSymbol }); } return(typeSymbol); } if (node is ArrayTypeNode) { ArrayTypeNode arrayTypeNode = (ArrayTypeNode)node; TypeSymbol itemTypeSymbol = ResolveType(arrayTypeNode.BaseType, symbolTable, contextSymbol); Debug.Assert(itemTypeSymbol != null); return(CreateArrayTypeSymbol(itemTypeSymbol)); } if (node is AtomicNameNode atomicNameNode) { TypeSymbol typeSymbol = ResolveAtomicNameNodeType(atomicNameNode, symbolTable, contextSymbol); if (typeSymbol != null) { return(typeSymbol); } } if (node is GenericNameNode) { GenericNameNode genericNameNode = (GenericNameNode)node; string genericTypeName = genericNameNode.Name + "`" + genericNameNode.TypeArguments.Count; TypeSymbol templateType = (TypeSymbol)symbolTable.FindSymbol(genericTypeName, contextSymbol, SymbolFilter.Types); if (!templateType.IsGeneric) { //generics ignored return(templateType); } List <TypeSymbol> typeArguments = new List <TypeSymbol>(); foreach (ParseNode argNode in genericNameNode.TypeArguments) { TypeSymbol argType = ResolveType(argNode, symbolTable, contextSymbol); Debug.Assert(argType != null); typeArguments.Add(argType); } if (templateType != null) { TypeSymbol resolvedSymbol = CreateGenericTypeSymbol(templateType, typeArguments); Debug.Assert(resolvedSymbol != null); return(resolvedSymbol); } } Debug.Assert(node is NameNode); NameNode nameNode = (NameNode)node; return((TypeSymbol)symbolTable.FindSymbol(nameNode.Name, contextSymbol, SymbolFilter.Types)); }
public virtual void Visit(ArrayTypeNode node) { Visit(node as TypeNode); }
public abstract dynamic Visit(ArrayTypeNode node);
public object Visit(ArrayTypeNode n, object o) { n.Type.Accept(this, null); Append("[]"); return(null); }
private TypeInfo Visit(ArrayTypeNode node) { return(GenerateArrayType(node.TypeNode)); }
public virtual AstNode VisitArrayType(ArrayTypeNode n) { return(n); }
public override dynamic Visit(ArrayTypeNode node) { return(null); }
public override TypeNode EvaluateType(API api, TypeNode type, bool isStatic) { TypeNode tdn = null; int arraysOfarrays = 0; VariableInitializerNode previous_expr = null; foreach (VariableInitializerNode vi in arrayInitializers) { if (previous_expr != null) { validateExpressions(previous_expr, vi); } previous_expr = vi; TypeNode tdn2 = vi.EvaluateType(api, null, isStatic); if (tdn != null) { if (!tdn.Equals(tdn2)) { if ((tdn is NullTypeNode && tdn2 is PrimitiveTypeNode) || (tdn2 is NullTypeNode && tdn is PrimitiveTypeNode)) { throw new SemanticException("Cannot use 'null' and primitive values in an array initialization."); } if (!(tdn is NullTypeNode && tdn2 is NullTypeNode)) { throw new SemanticException("Values in array initialization are not equal. '" + tdn.ToString() + "' and '" + tdn2.ToString() + "'"); } } } tdn = tdn2; if ((vi is InlineExpressionNode)) { if (((InlineExpressionNode)vi).primary is ArrayInstantiationNode) { arraysOfarrays++; } } } if (tdn is ArrayTypeNode) { if (arraysOfarrays > 0) { for (int i = 0; i < arraysOfarrays - 1; i++) { ((ArrayTypeNode)tdn).multidimsArrays.Add(new MultidimensionArrayTypeNode(1, null)); } } else { ((ArrayTypeNode)tdn).multidimsArrays[0].dimensions++; } } else { var i = new MultidimensionArrayTypeNode(1, null); var l = new List <MultidimensionArrayTypeNode>(); l.Add(i); var a = new ArrayTypeNode(tdn, l, null); return(a); } return(tdn); }
public BaseNode AddArrayType(string id, string type, string size, string align) { ArrayTypeNode arrn = new ArrayTypeNode(id, type, size, align); nodemap.Add(id, arrn); return arrn; }
public override TypeNode EvaluateType(API api, TypeNode type, bool isStatic) { if (identifier.ToString() == "students") { Console.Write(""); } TypeNode arrayType = null; try{ if (type == null) { FieldNode f = api.contextManager.findVariable(identifier.ToString()); if (f != null) { arrayType = f.type; if (f.isStatic == isStatic) { api.isNextStaticContext = false; } } else { arrayType = api.getTypeForIdentifier(identifier.ToString()); if (arrayType != null) { api.isNextStaticContext = true; } } } else { bool accept = false; if (!(type is ClassTypeNode)) { type = api.getTypeForIdentifier(type.ToString()); accept = true; } Context staticContext = api.buildContextForTypeDeclaration(type); FieldNode f = staticContext.findVariable(identifier.ToString(), Utils.privateLevel, Utils.protectedLevel); bool passed = f.isStatic == isStatic; if (accept) { passed = true; } if (f != null && passed) { arrayType = f.type; } } if (arrayType == null) { Utils.ThrowError("Array variable '" + identifier.ToString() + "' could not be found in the current context. "); } var arr = arrayType as ArrayTypeNode; int arraysOfArraysCounter = 0; while (arraysOfArraysCounter < arrayAccessList.Count) { if (arraysOfArraysCounter > arr.multidimsArrays.Count) { Utils.ThrowError("Cannot apply indexing with [] to an expression of type '" + arr.DataType.ToString() + "' [" + api.currentNamespace.Identifier.Name + "]"); } if (arr.multidimsArrays[arraysOfArraysCounter].dimensions != arrayAccessList[arraysOfArraysCounter].Count) { Utils.ThrowError("Wrong number of indices inside []; expected " + arr.multidimsArrays[arraysOfArraysCounter].dimensions + " [" + api.currentNamespace.Identifier.Name + "]"); } arraysOfArraysCounter++; } if (arraysOfArraysCounter == arr.multidimsArrays.Count) { arrayType = arr.DataType; } else { var dimensions = new List <MultidimensionArrayTypeNode>(); while (arraysOfArraysCounter < arr.multidimsArrays.Count) { dimensions.Add(new MultidimensionArrayTypeNode(arr.multidimsArrays[arraysOfArraysCounter].dimensions, null)); arraysOfArraysCounter++; } arrayType = new ArrayTypeNode(arr.DataType, dimensions, null); } }catch (SemanticException ex) { Utils.ThrowError(ex.Message + token.getLine()); } return(arrayType); }