private void ResolveSymbolTypes(DogeClassDefinition @class, DogeSymbolTable symbolTable, ICollection <IList <string> > usingDefinitions, IList <string> fullName) { foreach (var field in @class.FieldDefinitions) { var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(field.Name); symbol.TypeSymbol = symbolTable.ResolveSymbol( symbol.Type !, s => s.SymbolType == DogeSymbolType.Type, s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type, usingDefinitions); } foreach (var property in @class.PropertyDefinitions) { var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(property.Name); symbol.TypeSymbol = symbolTable.ResolveSymbol( symbol.Type !, s => s.SymbolType == DogeSymbolType.Type, s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type, usingDefinitions); } foreach (var method in @class.MethodDefinitions) { var symbol = symbolTable.GetSymbolTable(fullName).GetSymbol(method.Name); if (symbol.Type == null) { continue; } symbol.TypeSymbol = symbolTable.ResolveSymbol( symbol.Type !, s => s.SymbolType == DogeSymbolType.Type, s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type, usingDefinitions); method.Method.ReturnTypeSymbol = new DogeSymbolNode(symbolTable.ResolveSymbol( method.Method.ReturnType, s => s.SymbolType == DogeSymbolType.Type, s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type, usingDefinitions), method.Method.ReturnTypeIdentifier.File, method.Method.ReturnTypeIdentifier.TokenRange); foreach (var parameter in method.Method.Parameters) { parameter.TypeSymbol = new DogeSymbolNode(symbolTable.ResolveSymbol( parameter.Type, s => s.SymbolType == DogeSymbolType.Type, s => s == DogeSymbolTableType.Namespace || s == DogeSymbolTableType.Type, usingDefinitions), parameter.TypeIdentifier.File, parameter.TypeIdentifier.TokenRange); } } }
private DogeNode ResolveExpressionSymbols(DogeNode node, DogeSymbolTable symbolTable, IDictionary <string, DogeLocalDeclarationStatement> locals, ICollection <IList <string> > usingDefinitions, IList <string> fullName) { void resolveSymbols(ref DogeNode node) => node = ResolveExpressionSymbols( node, symbolTable, locals, usingDefinitions, fullName); switch (node) { case DogeBinaryExpression binaryExpression: resolveSymbols(ref binaryExpression.LeftHandSide); resolveSymbols(ref binaryExpression.RightHandSide); break; case DogeUnaryExpression unaryExpression: resolveSymbols(ref unaryExpression.InternalExpression); break; case DogeListExpression <DogeNode> listExpression: var nodeElements = listExpression.Elements.ToArray(); for (int i = 0; i < nodeElements.Length; i++) { resolveSymbols(ref nodeElements[i]); } break; case DogeListExpression <DogeMemberAccessorExpression> listExpression: DogeSymbolTable lastType = symbolTable.GetSymbolTable(fullName); int startSkip = 1; List <DogeMemberAccessorExpression> accumulator = new List <DogeMemberAccessorExpression>(); if (!lastType.TryGetSymbol(listExpression.Elements.First().Name, out _)) { for (; startSkip <= listExpression.Elements.Count; startSkip++) { if (symbolTable.TryResolveSymbol( listExpression.Elements.Select(x => x.Name).Take(startSkip).ToList(), s => s.SymbolType == DogeSymbolType.Field || s.SymbolType == DogeSymbolType.Local || s.SymbolType == DogeSymbolType.Property || s.SymbolType == DogeSymbolType.Method, s => s == DogeSymbolTableType.Type, usingDefinitions, out var lastTypeSymbol)) { DogeMemberAccessorExpression last = listExpression.Elements.ElementAt(startSkip - 1); if (lastTypeSymbol !.SymbolType != DogeSymbolType.Method) { if (last is DogeMethodCallStatement) { throw new InvalidCastException(); } lastType = symbolTable.GetSymbolTable(lastTypeSymbol.FullName); Range <int> range = new Range <int>(listExpression.Elements.First().TokenRange.First, last.TokenRange.Last); accumulator.Add( new DogeMemberAccessorExpression( new DogeIdentifier( new DogeToken( DogeTokenType.Identifier, string.Join('.', lastTypeSymbol.FullName), range.First), DogeFile.Console), false, false, listExpression.File, range) { NameSymbol = new DogeSymbolNode(lastTypeSymbol !, listExpression.File, range) }); }