Exemple #1
0
        private NamespaceResolver(string origString)
        {
            this.origString = origString;
            objectTree      = new List <pBaseLangObject>();
            var             sArr      = this.origString.Split(new char[] { ':', '.' });
            pBaseLangObject curObject = BaseClass;

            objectTree.Add(BaseClass);
            bool flag = false;

            foreach (var s in sArr)
            {
                flag = false;
                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }
                foreach (var it in curObject.getAllChildrenOf <Interfaces.iName>())
                {
                    if (it.Name != null && it.Name.OriginalValue == s)
                    {
                        objectTree.Add((pBaseLangObject)it);
                        curObject = (pBaseLangObject)it;
                        flag      = true;
                        break;
                    }
                }
                if (!flag)
                {
                    break;
                }
            }
            this.IsValid = flag;
        }
        public static void printPrivateArray(pBaseLangObject obj, string tab, System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg, int scopeIndex = -1)
        {
            var varList     = obj.getAllChildrenOf <Variable>(false, null, -1, scopeIndex);
            var forLoopList = obj.getAllChildrenOf <For>(false, null, -1, scopeIndex);

            foreach (var it in forLoopList)
            {
                if (it.forArg1 != null && it.forArg1 is Variable)
                {
                    varList.Add((Variable)it.forArg1);
                }
            }
            if (varList.Count > 0)
            {
                if (varList.Count == 1)
                {
                    sw.Write(tab + '\t' + "private ");
                }
                else
                {
                    sw.Write(tab + '\t' + "private [");
                }

                for (int i = 0; i < varList.Count; i++)
                {
                    var it = varList[i];
                    if (i != 0)
                    {
                        sw.Write(", ");
                    }
                    if (it is Variable)
                    {
                        sw.Write('"' + ((Variable)it).SqfVariableName + '"');
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                if (varList.Count > 1)
                {
                    sw.Write("]");
                }
                sw.WriteLine(";");
            }
        }
Exemple #3
0
 public static Variable getVariableReferenceOfFQN(NamespaceResolver nsr, bool localVariables = true, pBaseLangObject blo = null)
 {
     if (nsr == null)
     {
         return(null);
     }
     if (!nsr.IsValid && !localVariables)
     {
         return(null);
     }
     if (!nsr.IsValid)
     {
         if (blo == null)
         {
             return(null);
         }
         pBaseLangObject curObj         = blo;
         List <Variable> privateVarList = new List <Variable>();
         while (true)
         {
             curObj = (pBaseLangObject)curObj.getFirstOf <Interfaces.iCodeBlock>(false);
             if (curObj == null)
             {
                 break;
             }
             privateVarList.AddRange(curObj.getAllChildrenOf <Variable>());
         }
         foreach (var it in privateVarList)
         {
             if (nsr.origString.EndsWith(':' + it.Name.OriginalValue))
             {
                 return(it);
             }
         }
         return(null);
     }
     else
     {
         if (nsr.objectTree.Last() is Variable)
         {
             return((Variable)nsr.objectTree.Last());
         }
         else
         {
             return(null);
         }
     }
 }
    void NAMESPACE(out pBaseLangObject outObj, pBaseLangObject parent)
    {
        var obj = new Namespace(parent); outObj = obj; pBaseLangObject blo;
        Expect(42);
        IDENT(out blo, obj);
        obj.Name = (Ident)blo;

        var nsList = parent.getAllChildrenOf<Namespace>();
        foreach(var it in nsList)
        {
            if(it.Name.OriginalValue == ((Ident)blo).OriginalValue)
            {
                obj = it;
                outObj = obj;
                break;
            }
        }

        Expect(14);
        while (StartOf(7)) {
            if (la.kind == 42) {
                NAMESPACE(out blo, obj);
                obj.addChild(blo);
            } else if (la.kind == 53) {
                CLASS(out blo, obj);
                obj.addChild(blo);
            } else if (la.kind == 43) {
                NATIVECLASS(out blo, obj);
                obj.addChild(blo);
            } else if (la.kind == 56) {
                INTERFACE(out blo, obj);
                obj.addChild(blo);
            } else {
                Get();
                if (peekCompare(-1, -1, _T_TERMINATOR) ) {
                    NEWVARIABLE(out blo, obj, Encapsulation.Static);
                    obj.addChild(blo);
                    TERMINATOR();
                } else if (StartOf(8)) {
                    FUNCTION(out blo, obj, Encapsulation.Static);
                    obj.addChild(blo);
                } else SynErr(91);
            }
        }
        Expect(15);
    }