public void MarkIdentifierAsFunction(LexValue identifier, LexLocation idenLoc) { //if(identNamesLocs.ContainsKey(MkTSpan(idenLoc))) // identNamesLocs.Remove(MkTSpan(idenLoc)); if (_source.identNamesLocs.ContainsKey(MkTSpan(idenLoc))) _source.identNamesLocs.Remove(MkTSpan(idenLoc)); //funcNamesLocs.Add(MkTSpan(idenLoc), identifier.str); _source.funcNamesLocs.Add(MkTSpan(idenLoc), identifier.str); }
//Need to defer the checking of the for loop scope until the scope it is in finishes parsing public void DeferCheckForLoopScope(LexValue assignVal, LexLocation forHeader, LexLocation forBody) { forLoopVars.Add(MkTSpan(forBody), new KeyValuePair<TextSpan, LexValue>(MkTSpan(forHeader), assignVal)); }
//Used by the parser to combine multiple tokens' string values into a single token public LexValue Lexify(string strToLex) { LexValue val = new LexValue(); val.str = strToLex; return val; }
//Records a variable declaration that will later get added to a scope public void AddVariable(LexValue varName, LexValue type, LexLocation loc) { if (!shouldAddDeclarations()) { return; } if (varName.str != null) { HLSLDeclaration newDecl = new Babel.HLSLDeclaration(type.str, varName.str, GLYPHVARIABLE, varName.str); tempCurScope.scopeVars.Add(varName.str, new VarDecl(newDecl, MkTSpan(loc))); } }
public void CheckForLoopScope(LexValue assignVal, TextSpan forHeader, TextSpan forBody) { if (assignVal.str != null) { if (!(assignVal.str.Equals(string.Empty))) { CodeScope forscope; string[] typeAndName = assignVal.str.Split(' '); //if (HLSLScopeUtils.HasScopeForSpan(forBody, programScope, out forscope)) if (HLSLScopeUtils.HasScopeForSpan(forBody, _source.programScope, out forscope)) { forscope.scopeVars.Add(typeAndName[1], new VarDecl(new HLSLDeclaration(typeAndName[0], typeAndName[1], GLYPHVARIABLE, typeAndName[1]), forBody)); forscope.scopeLocation = TextSpanHelper.Merge(forHeader, forBody); } else { TextSpan forScopeLocation = TextSpanHelper.Merge(forHeader, forBody); CodeScope forCs = new CodeScope(new Dictionary<string, VarDecl>(), forScopeLocation); forCs.outer = forscope; forCs.scopeVars.Add(typeAndName[1], new VarDecl(new HLSLDeclaration(typeAndName[0], typeAndName[1], GLYPHVARIABLE, typeAndName[1]), forBody)); if (forscope.innerScopes.Count == 0) { forscope.innerScopes.Add(forCs); } else { bool inserted = false; for (int i = 0; i < forscope.innerScopes.Count; i++) { if (TextSpanHelper.EndsBeforeStartOf(forScopeLocation, forscope.innerScopes[i].scopeLocation)) { forscope.innerScopes.Insert(i, forCs); inserted = true; break; } } if (!inserted) forscope.innerScopes.Add(forCs); } } } } }
//Used for locating the struct var that precedes the dot that triggered a MemberSelect operation public void AddStructVarForCompletion(LexValue varName, LexLocation loc) { //structVars.Add(MkTSpan(loc), varName); _source.structVars.Add(MkTSpan(loc), varName); }
//Adds a typedef'ed type public void AddTypedefType(LexValue type, LexValue newType) { if (!shouldAddDeclarations()) { return; } //typedefTypes.Add(new HLSLDeclaration(type.str, newType.str, GLYPHTYPEDEF, newType.str)); _source.typedefTypes.Add(new HLSLDeclaration(type.str, newType.str, GLYPHTYPEDEF, newType.str)); }
//Adds a struct type and its members public void AddStructType(LexValue loc) { if (!shouldAddDeclarations()) { return; } HLSLDeclaration structDecl = new HLSLDeclaration("struct", loc.str, GLYPHSTRUCT, loc.str); // structDecls.Add(structDecl); //Need to keep this static member for the initial lex since the source hasn't been created yet, //but really only need it for the names, the sources still keep their own struct decls if(!structDecls.ContainsKey(loc.str)) structDecls.Add(loc.str, new StructMembers(loc.str, tempMembers, structDecl)); _source.structDecls.Add(loc.str, new StructMembers(loc.str, tempMembers, structDecl)); tempMembers.Clear(); }
//Creates a list of member variables that are within a struct public void AddStructMember(LexValue type, LexValue identifier) { tempMembers.Add(new HLSLDeclaration(type.str, identifier.str, GLYPHVARIABLE, identifier.str)); }
public void AddIdentifierToCheck(LexValue identifier, LexLocation idenLoc) { //identNamesLocs.Add(MkTSpan(idenLoc), identifier.str); _source.identNamesLocs.Add(MkTSpan(idenLoc), identifier.str); }
public void AddFunctionParamVar(LexValue varName, LexValue type, LexLocation loc) { if (!shouldAddDeclarations()) { return; } HLSLDeclaration newDecl = new HLSLDeclaration(type.str, varName.str, GLYPHVARIABLE, varName.str); tempFunctionVars.Add(varName.str, new VarDecl(newDecl, MkTSpan(loc))); }
// Add function to list of autocompletions, eventually method completion also public void AddFunction(LexValue type, LexValue name, LexValue parameters) { if (!shouldAddDeclarations() || parameters.str == null) { return; } HLSLFunction method = new HLSLFunction(); method.Name = name.str; method.Type = type.str; method.Parameters = new List<HLSLParameter>(); if (parameters.str != "") { string[] splitParams = parameters.str.Split(','); foreach (string param in splitParams) { HLSLParameter parameter = new HLSLParameter(); parameter.Description = param; parameter.Name = param; parameter.Display = param; method.Parameters.Add(parameter); } } //methods.Add(method); _source.methods.Add(method); foreach (KeyValuePair<string, VarDecl> kv in tempFunctionVars) tempLastScope.scopeVars.Add(kv.Key, kv.Value); tempFunctionVars.Clear(); }