internal static IEnumerable <IVbField> GetFields(TokenStreamReader reader) { /* TODO: Field declarations á la "Var1, Var2, Var3 As Integer" are not supported right now. */ while (!reader.IsEOF) { List <IToken> tokens = reader.GetUntilEOL().ToList(); if (tokens.Count < 2) { continue; } IVbField field = null; if (TryParseFieldDeclaration(tokens, out field)) { yield return(field); } } }
private static bool TryParseFieldDeclaration(IReadOnlyList<IToken> tokens, out IVbField field) { field = null; MemberVisibility vis = MemberVisibility.Default; bool isConst = false; bool isStatic = false; bool hasVisibility = TryGetMemberVisibility(tokens.First(), out vis); var tConst = tokens.Find(AnalyzerConstants.Constant); var tShared = tokens.Find(AnalyzerConstants.Shared); var tAs = tokens.Find("As"); var tAssign = tokens.Find("="); var tIsWithEvents = tokens.Find("WithEvents"); /* Check whether the line qualifies as a field declaration. */ if (tokens.ContainsAny(AnalyzerConstants.Method_Function, AnalyzerConstants.Method_Property, AnalyzerConstants.Method_Sub)) { return false; } if (!hasVisibility) { if (tConst == null) { return false; } } if (tAs != null) { if (tokens[tAs.Item1 - 1].Type != TokenType.Word) { return false; } } IList<IToken> copy = tokens.ToList(); if (tConst != null) { isConst = true; copy.RemoveAt(0); } if (tShared != null) { isStatic = true; copy.RemoveAt(0); } if (tIsWithEvents != null) { // TODO: Actually make use of that keyword! copy.RemoveAt(0); } if (hasVisibility) { copy.RemoveAt(0); } // Consume name, which is the next. string name = copy.First().Content; copy.RemoveAt(0); // TODO: Parse the rest. field = new VbField() { IsConstant = isConst, IsStatic = isStatic, Name = name, Location = tokens.First().Location, Visibility = vis, Type = VbTypes.Variant, }; return true; }
private static bool TryParseFieldDeclaration(IReadOnlyList <IToken> tokens, out IVbField field) { field = null; MemberVisibility vis = MemberVisibility.Default; bool isConst = false; bool isStatic = false; bool hasVisibility = TryGetMemberVisibility(tokens.First(), out vis); var tConst = tokens.Find(AnalyzerConstants.Constant); var tShared = tokens.Find(AnalyzerConstants.Shared); var tAs = tokens.Find("As"); var tAssign = tokens.Find("="); var tIsWithEvents = tokens.Find("WithEvents"); /* Check whether the line qualifies as a field declaration. */ if (tokens.ContainsAny(AnalyzerConstants.Method_Function, AnalyzerConstants.Method_Property, AnalyzerConstants.Method_Sub)) { return(false); } if (!hasVisibility) { if (tConst == null) { return(false); } } if (tAs != null) { if (tokens[tAs.Item1 - 1].Type != TokenType.Word) { return(false); } } IList <IToken> copy = tokens.ToList(); if (tConst != null) { isConst = true; copy.RemoveAt(0); } if (tShared != null) { isStatic = true; copy.RemoveAt(0); } if (tIsWithEvents != null) { // TODO: Actually make use of that keyword! copy.RemoveAt(0); } if (hasVisibility) { copy.RemoveAt(0); } // Consume name, which is the next. string name = copy.First().Content; copy.RemoveAt(0); // TODO: Parse the rest. field = new VbField() { IsConstant = isConst, IsStatic = isStatic, Name = name, Location = tokens.First().Location, Visibility = vis, Type = VbTypes.Variant, }; return(true); }
internal VB6UnresolvedField(IVbField field, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition) : base(field, file, typeReference, typeDefinition) { this.IsConst = field.IsConstant; }