public MethodExtractor(ITextView textView) { _view = textView; var snapshot = _view.TextBuffer.CurrentSnapshot; _ast = _view.GetAnalyzer().ParseSnapshot(snapshot); }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { if (Children.Count > 0) { base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); } else if (!string.IsNullOrWhiteSpace(DatabaseName) || !string.IsNullOrWhiteSpace(TableName) || !string.IsNullOrWhiteSpace(ColumnName)) { // TODO: do deferred checking of these } else if (_typeNameString != null && !_isConstrainedType) { // see if the _typeNameString is a base type var tok = Tokens.GetToken(_typeNameString); if (tok == null || !Genero4glAst.BuiltinTypes.Contains(tok.Kind)) { string resolveErrMsg; var resolvedType = GetResolvedType(ast as Genero4glAst, out resolveErrMsg); if (resolvedType == null && resolveErrMsg != null) { errorFunc(resolveErrMsg, StartIndex, EndIndex); } else { ResolvedType = resolvedType; } } } }
public override void PropagateSyntaxTree(GeneroAst ast) { // set location _location = ast.ResolveLocation(this); base.PropagateSyntaxTree(ast); }
public MemberResult(string name, string documentation, GeneroMemberType type, GeneroAst ast) { _documentation = documentation; _name = _completion = name; _type = () => type; _var = null; _ast = ast; }
public override void PropagateSyntaxTree(GeneroAst ast) { foreach (var kvp in MemberDictionary) { kvp.Value.PropagateSyntaxTree(ast); } base.PropagateSyntaxTree(ast); }
public void GetTreeAndCookie(out GeneroAst tree, out IAnalysisCookie cookie) { lock (this) { tree = _tree; cookie = _cookie; } }
public ContextPossibilityMatchContainer(ContextEntry contextEntry, GeneroAst parentTree) { _parentTree = parentTree; _matchingRound = 0; _flatMatchingSet = new Dictionary <object, List <BackwardTokenSearchItem> >(); _flatNonMatchingSet = new HashSet <object>(); _possibilitiesWithNoBackwardSearch = new List <ContextPossibility>(); InitializeQueues(contextEntry); }
public MemberResult(string name, IAnalysisResult var, GeneroMemberType type, GeneroAst ast) { _documentation = null; _name = _completion = name; _var = () => var; _type = null; _ast = ast; _type = () => type; }
internal IEnumerable <IAnalysisResult> GetAnalysisResults(GeneroAst ast) { if (MemberDictionary.Count == 0 && MimicTableName != null && ast._databaseProvider != null) { // get the table's columns return(ast._databaseProvider.GetColumns(MimicTableName.Name)); } else { return(MemberDictionary.Values); } }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { // check the variable if (Variable != null) { Variable.CheckForErrors(ast, errorFunc, deferredFunctionSearches); } // check the expression base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); }
internal ExpressionAnalysis(GeneroProjectAnalyzer analyzer, string expression, GeneroAst analysis, int index, ITrackingSpan span, ITextSnapshot snapshot, IFunctionInformationProvider functionProvider, IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider, bool isFunctionCallOrDefinition) { _expr = expression; _analysis = analysis; _index = index; _span = span; _analyzer = analyzer; _snapshot = snapshot; _functionProvider = functionProvider; _databaseProvider = databaseProvider; _programFileProvider = programFileProvider; _isFunctionCallOrDefinition = isFunctionCallOrDefinition; }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { if (MemberDictionary.Count > 0) { foreach (var recChild in MemberDictionary.Values) { recChild.Type.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); } } else { // TODO: check the database and table (deferred?) } // we don't store any children off, so this does nothing base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { if (Children.Count > 0) { base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); } else if (!string.IsNullOrWhiteSpace(DatabaseName) || !string.IsNullOrWhiteSpace(TableName) || !string.IsNullOrWhiteSpace(ColumnName)) { // TODO: do deferred checking of these } else if (_typeNameString != null && !_isConstrainedType) { // see if the _typeNameString is a base type var tok = Tokens.GetToken(_typeNameString); if (tok == null || !Genero4glAst.BuiltinTypes.Contains(tok.Kind)) { // if it's not a base type, look up the type IGeneroProject dummyProj; IProjectEntry dummyProjEntry; bool isDeferred; var res = Genero4glAst.GetValueByIndex(_typeNameString, StartIndex, ast as Genero4glAst, out dummyProj, out dummyProjEntry, out isDeferred, FunctionProviderSearchMode.NoSearch, false, true, false, false); if (res == null) { errorFunc(string.Format("Type {0} not found.", _typeNameString), StartIndex, EndIndex); } else { if (res is GeneroPackageClass || res is TypeDefinitionNode) { ResolvedType = res; } else { errorFunc(string.Format("Invalid type {0} found.", _typeNameString), StartIndex, EndIndex); } } } } }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { if (_arguments != null) { // 1) check to make sure arguments have corresponding defined variables foreach (var undefinedArg in _arguments.Where(x => x.Value == null)) { errorFunc(string.Format("No definition found for parameter {0}", undefinedArg.Key.Token.Value.ToString()), undefinedArg.Key.Span.Start, undefinedArg.Key.Span.End); } } // TODO: 2) Check to make sure the types in return statements match up across multiple return statements. if (_internalReturns != null && _internalReturns.Count > 1) { } base.CheckForErrors(ast, errorFunc, deferredFunctionSearches); }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { // This will do error checking on the type reference base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); if (VariableDefinitions != null) { if (Children.Count == 1 && Children[Children.Keys[0]] is TypeReference) { var resolvedType = (Children[Children.Keys[0]] as TypeReference).ResolvedType; if (resolvedType != null) { foreach (var vardef in VariableDefinitions) { // apply the resolved type definition to the variable vardef.ResolvedType = resolvedType; } } } } }
public void UpdateTree(GeneroAst newAst, IAnalysisCookie newCookie) { lock (this) { if (_updatesPending > 0) { _updatesPending--; } if (newAst == null) { // there was an error in parsing, just let the waiter go... if (_curWaiter != null) { _curWaiter.Set(); } _tree = null; return; } _tree = newAst; if (_cookie == null || _cookie is FileCookie || !(newCookie is FileCookie)) { _cookie = newCookie; } if (_curWaiter != null) { _curWaiter.Set(); } } var newParse = OnNewParseTree; if (newParse != null) { newParse(this, EventArgs.Empty); } }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { // 1) Check to make sure the function call is valid if (Function != null) { Function.CheckForErrors(ast, errorFunc, deferredFunctionSearches); } // 2) Check the return values if (Returns != null) { foreach (var ret in Returns) { ret.CheckForErrors(ast, errorFunc, deferredFunctionSearches); if (ret.ResolvedResult != null && !(ret.ResolvedResult is VariableDef || ret.ResolvedResult is ProgramRegister)) { errorFunc(string.Format("Return item {0} is not a variable", ret.Name), ret.StartIndex, ret.EndIndex); } } if (Function != null && Function.Function != null && Function.Function.ResolvedResult != null && Function.Function.ResolvedResult is IFunctionResult) { var numReturns = (Function.Function.ResolvedResult as IFunctionResult).Returns.Length; if (Returns.Count != numReturns) { errorFunc(string.Format("Unexpected number of return variables ({0}) found, expected {1} variables.", Returns.Count, numReturns), StartIndex, EndIndex); } } } base.CheckForErrors(ast, errorFunc, deferredFunctionSearches); }
public override string GetExpressionType(GeneroAst ast) { // need to determine the return type for the function call IGeneroProject dummyProj; IProjectEntry dummyProjEntry; bool dummy; var result = ast.GetValueByIndex(Function.Name, Function.IndexSpan.Start, ast._functionProvider, ast._databaseProvider, ast._programFileProvider, true, out dummy, out dummyProj, out dummyProjEntry, FunctionProviderSearchMode.Search); if (result != null) { return(result.Typename); } return(null); }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { // Check to see if the _firstPiece exists IGeneroProject proj; IProjectEntry projEntry; string searchStr = _firstPiece; if (searchInFunctionProvider != FunctionProviderSearchMode.NoSearch || isFunctionCallOrDefinition) { StringBuilder sb = new StringBuilder(searchStr); foreach (var child in Children.Values) { if (child is ArrayIndexFglNameExpressionPiece) { sb.Append(child.ToString()); } else if (child is MemberAccessNameExpressionPiece) { if ((child as MemberAccessNameExpressionPiece).Text != ".*") { sb.Append(child.ToString()); } else { break; } } } searchStr = sb.ToString(); } bool isDeferred; // TODO: need to defer database lookups too var res = ast.GetValueByIndex(searchStr, StartIndex, ast._functionProvider, ast._databaseProvider, ast._programFileProvider, isFunctionCallOrDefinition, out isDeferred, out proj, out projEntry, searchInFunctionProvider); if (res == null) { if (isDeferred) { if (deferredFunctionSearches.ContainsKey(searchStr)) { deferredFunctionSearches[searchStr].Add(StartIndex); } else { deferredFunctionSearches.Add(searchStr, new List <int> { StartIndex }); } } else { errorFunc(string.Format("No definition found for {0}", searchStr), StartIndex, StartIndex + searchStr.Length); } } else { if (Name.EndsWith(".*") && res is VariableDef && (res as VariableDef).ResolvedType == null) { // need to make sure that the res has a resolved type (res as VariableDef).Type.CheckForErrors(ast, errorFunc, deferredFunctionSearches); (res as VariableDef).ResolvedType = (res as VariableDef).Type.ResolvedType; } // TODO: need to check array element type ResolvedResult = res; } base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition); }
public override string GetExpressionType(GeneroAst ast) { return("[arg-list]"); }
public override string GetExpressionType(GeneroAst ast) { return(InnerExpression.GetExpressionType(ast)); }
public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false) { // 1) Check parameters for errors // - undefined identifier // - record without .* if (_skipValidationFunctionNames.Contains(Function.Name)) { return; } // Check for the function name if (Function != null) { Function.CheckForErrors(ast, errorFunc, deferredFunctionSearches, FunctionProviderSearchMode.Deferred, true); } if (Parameters != null) { if (Function != null && Function.ResolvedResult != null && (Function.ResolvedResult is IFunctionResult)) { // TODO: if a parameter is a record, then the number of required input arguments increases by the number of fields in that record. int totalRequiredParams = 0; IGeneroProject proj; IProjectEntry projEntry; bool isDeferred; foreach (var param in (Function.ResolvedResult as IFunctionResult).Parameters) { TypeReference typeRef = null; var typeName = param.Type; int index = typeName.IndexOf("record", StringComparison.OrdinalIgnoreCase); // TODO: need to look into how importable projects populate their parameter result types if (index == 0 && (typeName.Length == 6 || char.IsWhiteSpace(typeName[6]))) { if (Function.ResolvedResult is AstNode4gl && (Function.ResolvedResult as AstNode4gl).StartIndex >= 0) { var useAst = ast as Genero4glAst; if ((Function.ResolvedResult as AstNode4gl).SyntaxTree != null && (Function.ResolvedResult as AstNode4gl).SyntaxTree != ast) { useAst = (Function.ResolvedResult as AstNode4gl).SyntaxTree as Genero4glAst; } // need to retrieve the variable and then get its type var resVar = Genero4glAst.GetValueByIndex(param.Name, (Function.ResolvedResult as AstNode4gl).StartIndex, useAst, out proj, out projEntry, out isDeferred); if (resVar != null && resVar is VariableDef) { typeRef = ((resVar as VariableDef).ResolvedType as TypeReference) ?? (resVar as VariableDef).Type; } } } else { // TODO: eventually, this needs to handle system types var resType = Genero4glAst.GetValueByIndex(typeName, StartIndex, ast as Genero4glAst, out proj, out projEntry, out isDeferred); if (resType != null && resType is TypeDefinitionNode && (resType as TypeDefinitionNode).TypeRef != null) { typeRef = (resType as TypeDefinitionNode).TypeRef; } } if (typeRef != null && typeRef.IsRecord && (typeRef.Children[typeRef.Children.Keys[0]] is RecordDefinitionNode)) { int recFieldCount = (typeRef.Children[typeRef.Children.Keys[0]] as RecordDefinitionNode).GetMembers(ast as Genero4glAst, Analysis.MemberType.All, false).Count(); if (recFieldCount > 0) { totalRequiredParams += recFieldCount; } else { totalRequiredParams++; } } else { totalRequiredParams++; } } int totalParameters = 0; foreach (var param in Parameters) { // The genero compiler does not do error checking of types, so I guess anything goes... // That makes things easier... if (param is FglNameExpression) { var nameParam = param as FglNameExpression; nameParam.CheckForErrors(ast, errorFunc, deferredFunctionSearches, FunctionProviderSearchMode.Deferred); if (nameParam.ResolvedResult != null) { if (nameParam.ResolvedResult is TypeDefinitionNode) // Check for any invalid parameters TODO: others { errorFunc("Invalid parameter found.", param.StartIndex, param.EndIndex); } else { TypeReference typeRef = null; if (nameParam.ResolvedResult is VariableDef) { if ((nameParam.ResolvedResult as VariableDef).ResolvedType != null && (nameParam.ResolvedResult as VariableDef).ResolvedType is TypeDefinitionNode) { var typeDef = (nameParam.ResolvedResult as VariableDef).ResolvedType as TypeDefinitionNode; if (typeDef?.TypeRef != null) { typeRef = typeDef.TypeRef; } } else { typeRef = (nameParam.ResolvedResult as VariableDef).Type; } } if (typeRef != null && typeRef.IsRecord && (typeRef.Children[typeRef.Children.Keys[0]] is RecordDefinitionNode)) { if ((nameParam.ResolvedResult as VariableDef).Type.IsArray) { if ((param as FglNameExpression).Name.EndsWith(".*")) { // need to get the number of fields in the record, as they count toward our passed parameter total int recFieldCount = ((RecordDefinitionNode)typeRef.Children[typeRef.Children.Keys[0]]).GetMembers(ast as Genero4glAst, Analysis.MemberType.All, false).Count(); if (recFieldCount > 0) { totalParameters += (recFieldCount - 1); // minus 1 so we can do the increment below } } } else { if (!(param as FglNameExpression).Name.EndsWith(".*") && !_allowedNonStarRecordParamFunctions.Contains(Function.Name)) { errorFunc("Records must be specified with a '.*' ending when passed as a function parameter.", param.StartIndex, param.EndIndex); } else { if (!_allowedNonStarRecordParamFunctions.Contains(Function.Name)) { // need to get the number of fields in the record, as they count toward our passed parameter total int recFieldCount = ((RecordDefinitionNode)typeRef.Children[typeRef.Children.Keys[0]]).GetMembers(ast as Genero4glAst, Analysis.MemberType.All, false).Count(); if (recFieldCount > 0) { totalParameters += (recFieldCount - 1); // minus 1 so we can do the increment below } } } } } } } } param.CheckForErrors(ast, errorFunc, deferredFunctionSearches); totalParameters++; } // need to determine if any of the passed in parameters are records, and if so, adjust the passed count if (totalParameters != totalRequiredParams) { errorFunc(string.Format("Unexpected number of parameters ({0}) found, expected {1} variables.", totalParameters, totalRequiredParams), StartIndex, EndIndex); } } } // TODO: should we do something with the anything parameters base.CheckForErrors(ast, errorFunc, deferredFunctionSearches); }
private IEnumerable <ITagSpan <IOutliningRegionTag> > ProcessSuite(NormalizedSnapshotSpanCollection spans, GeneroAst ast, ModuleNode moduleNode, ITextSnapshot snapshot, bool isTopLevel) { if (moduleNode != null) { TokenWithSpan[] regionTokens = new TokenWithSpan[0]; object val; if (ast.TryGetAttribute(moduleNode, NodeAttributes.CodeRegions, out val)) { regionTokens = val as TokenWithSpan[]; } var outlinables = new List <IOutlinableResult>(); GetOutlinableResults(moduleNode, ref outlinables); if (_taggerProvider._CustomCommentOutliningProvider != null) { TokenWithSpan[] commentLines = new TokenWithSpan[0]; if (ast.TryGetAttribute(moduleNode, NodeAttributes.NonCodeRegionComments, out val)) { commentLines = val as TokenWithSpan[]; outlinables.AddRange(_taggerProvider._CustomCommentOutliningProvider.GetRegions(commentLines)); } } foreach (var child in outlinables.Union(GetRegions(regionTokens))) { SnapshotSpan?span = ShouldInclude(child, spans); if (span == null) { continue; } TagSpan tagSpan = GetOutlineSpan(snapshot, child); if (tagSpan != null) { yield return(tagSpan); } } } }
public virtual void UpdateIncludesAndImports(string filename, GeneroAst ast) { }
public override void UpdateIncludesAndImports(string filename, GeneroAst ast) { if (/*_shouldAnalyzeDir &&*/ VSGeneroPackage.Instance.ProgramFileProvider != null) { var fglAst = ast as Genero4glAst; if (fglAst != null) { // first do imports if (_lastImportedModules == null) { _lastImportedModules = new HashSet <string>(StringComparer.OrdinalIgnoreCase); } var modules = fglAst.GetImportedModules().ToList(); HashSet <string> currentlyImportedModules = new HashSet <string>(_lastImportedModules, StringComparer.OrdinalIgnoreCase); foreach (var mod in modules.Select(x => VSGeneroPackage.Instance.ProgramFileProvider.GetImportModuleFilename(x, FilePath)).Where(y => y != null)) { if (!_lastImportedModules.Contains(mod)) { var impProj = ParentProject.AddImportedModule(mod, this); if (impProj != null) { _lastImportedModules.Add(mod); try { if (!impProj.ReferencingProjectEntries.Contains(this)) { // TODO: for some reason a NRE got thrown here, but nothing was apparently wrong //if (impProj.ReferencedProjects.ContainsKey(Path.GetDirectoryName(this.FilePath))) // errorSink.Add(string.Format("Circular dependency detected between import modules {0} and {1}", impProj.Directory, this.FilePath), ast._lineLocations, 1, 2, ErrorCodes.SyntaxError, Severity.Error); //else impProj.ReferencingProjectEntries.Add(this); } } catch (Exception) { int i = 0; } } } else { currentlyImportedModules.Remove(mod); } } // delete the leftovers foreach (var mod in currentlyImportedModules) { ParentProject.RemoveImportedModule(mod); _lastImportedModules.Remove(mod); } // next do includes var includes = fglAst.GetIncludedFiles(); HashSet <string> currentlyIncludedFiles = new HashSet <string>(VSGeneroPackage.Instance.DefaultAnalyzer.GetIncludedFiles(this).Select(x => x.FilePath), StringComparer.OrdinalIgnoreCase); foreach (var incl in includes.Select(x => VSGeneroPackage.Instance.ProgramFileProvider.GetIncludeFile(x, FilePath)).Where(y => y != null)) { if (!VSGeneroPackage.Instance.DefaultAnalyzer.IsIncludeFileIncludedByProjectEntry(incl, this)) { VSGeneroPackage.Instance.DefaultAnalyzer.AddIncludedFile(incl, this); } else { currentlyIncludedFiles.Remove(incl); } } // delete the leftovers foreach (var include in currentlyIncludedFiles) { VSGeneroPackage.Instance.DefaultAnalyzer.RemoveIncludedFile(include, this); } } } }
public void PropagateSyntaxTree(GeneroAst ast) { SyntaxTree = ast; Type?.PropagateSyntaxTree(ast); }
private IEnumerable <ITagSpan <IBlockTag> > ProcessSuite(NormalizedSnapshotSpanCollection spans, GeneroAst ast, ModuleNode moduleNode, ITextSnapshot snapshot, bool isTopLevel) { if (moduleNode != null) { List <Genero4glCodeBlock> outlinables = new List <Genero4glCodeBlock>(); int level = 0; Genero4glCodeBlock block = new Genero4glCodeBlock(this, _textview, null, BlockType.Root, null, level); GetOutlinableResults(this, _textview, spans, moduleNode, block, snapshot, level, ref outlinables); foreach (var child in outlinables) { TagSpan <Genero4glCodeBlock> tagSpan = new TagSpan <Genero4glCodeBlock>(child.Span, child); if (tagSpan != null) { yield return(tagSpan); } } } }
public override string GetExpressionType(GeneroAst ast) { return(null); }