Exemple #1
0
 public CodeScope(TextSpan loc)
 {
     innerScopes = new List<CodeScope>();
     scopeVars = new Dictionary<string, VarDecl>();
     scopeLocation = loc;
     outer = null;
 }
 public void PrepareParse(TextSpan programLoc)
 {
     programScope = new CodeScope(programLoc);
     methods = new List<HLSLFunction>();
     structDecls = new Dictionary<string, StructMembers>();
     typedefTypes = new List<HLSLDeclaration>();
     identNamesLocs = new Dictionary<TextSpan, string>();
     funcNamesLocs = new Dictionary<TextSpan, string>();
     structVars = new Dictionary<TextSpan, LexValue>();
     includeFiles = new List<string>();
 }
        public void GatherVariables(CodeScope cs, Dictionary<string, Babel.Parser.VarDecl> vars)
        {
            HLSLScopeUtils.GetVarDecls(cs, vars);

            foreach (KeyValuePair<string, HLSLSource> kv in allIncludes)
            {
                foreach (KeyValuePair<string, VarDecl> decls in kv.Value.programScope.scopeVars)
                {
                    if (!vars.ContainsKey(decls.Key))
                    {
                        vars.Add(decls.Key, decls.Value);
                    }
                }
            }
        }
Exemple #4
0
        public void PrepareParse(TextSpan programLoc, Source source)
        {
            _source = (HLSLSource)source;
            _source.PrepareParse(programLoc);
            tempCurScope = _source.programScope;

            tempMembers = new List<HLSLDeclaration>();
            tempFunctionVars = new Dictionary<string, VarDecl>();
            forLoopVars = new Dictionary<TextSpan, KeyValuePair<TextSpan, LexValue>>();

            //programScope = new CodeScope(programLoc);
            //tempCurScope = programScope;
        }
Exemple #5
0
        public void EndScope(LexLocation loc)
        {
            tempCurScope.scopeLocation = TextSpanHelper.Merge(tempCurScope.scopeLocation, MkTSpan(loc));

            Dictionary<TextSpan, KeyValuePair<TextSpan, LexValue>> deferred = new Dictionary<TextSpan, KeyValuePair<TextSpan, LexValue>>();
            foreach (KeyValuePair<TextSpan, KeyValuePair<TextSpan, LexValue>> kv in forLoopVars)
            {
                //If the for loop isn't embedded in this scope, then continue to defer it
                if (TextSpanHelper.IsEmbedded(TextSpanHelper.Merge(kv.Value.Key, kv.Key), tempCurScope.scopeLocation))
                    CheckForLoopScope(kv.Value.Value, kv.Value.Key, kv.Key);
                else
                    deferred.Add(kv.Key, new KeyValuePair<TextSpan, LexValue>(kv.Value.Key, kv.Value.Value));
            }
            forLoopVars.Clear();
            forLoopVars = new Dictionary<TextSpan, KeyValuePair<TextSpan, LexValue>>(deferred);

            tempLastScope = tempCurScope;
            tempCurScope = tempCurScope.outer;
        }
Exemple #6
0
        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);
                        }
                    }
                }
            }
        }
Exemple #7
0
 public void BeginScope(LexLocation loc)
 {
     CodeScope scope = new CodeScope(MkTSpan(loc));
     scope.outer = tempCurScope;
     tempCurScope.innerScopes.Add(scope);
     tempCurScope = scope;
 }