Exemplo n.º 1
0
        public int getIndex(Ident ident)
        {
            var refObj = ident.ReferencedObject;

            if (refObj is Function || refObj is Variable)
            {
                var obj = (Interfaces.iName)refObj;
                for (int i = 0; i < this.AllObjects.Count; i++)
                {
                    var it = this.AllObjects[i];
                    if (it is Interfaces.iName && ((Interfaces.iName)it).Name.OriginalValue == obj.Name.OriginalValue)
                    {
                        if (it is Function && obj is Function && HelperClasses.ArgList.matchesArglist(((Function)it).ArgList, ((Function)obj).ArgList))
                        {
                            return(i);
                        }
                        else if (it is Variable)
                        {
                            return(i);
                        }
                    }
                }
            }
            throw new Exception();
        }
Exemplo n.º 2
0
 public SupportInfoObject(string command, Ident type, bool hasR = false, bool hasL = false)
 {
     this.SqfCommand = command;
     this.outType    = new VarTypeObject(type);
     this.hasL       = hasL;
     this.hasR       = hasR;
 }
Exemplo n.º 3
0
        public int getIndex(Ident ident)
        {
            int index  = 0;
            var refObj = ident.ReferencedObject;

            if (refObj is VirtualFunction)
            {
                var obj = (Interfaces.iName)refObj;
                for (int i = 0; i < this.children.Count; i++)
                {
                    var it = this.children[i];
                    if (it is Interfaces.iName && ((Interfaces.iName)it).Name.OriginalValue == obj.Name.OriginalValue)
                    {
                        if (it is VirtualFunction && obj is VirtualFunction && HelperClasses.ArgList.matchesArglist(((VirtualFunction)it).ArgList, ((VirtualFunction)obj).ArgList))
                        {
                            return(index);
                        }
                    }
                    if (it is VirtualFunction && ((VirtualFunction)it).IsVirtual)
                    {
                        index++;
                    }
                }
            }
            throw new Exception();
        }
Exemplo n.º 4
0
 public VarTypeObject(VarType v)
 {
     this.ident = null;
     this.varType = v;
     if (v == VarType.ObjectStrict || v == VarType.Object)
         throw new Exception("TODO: Allow anonymous objects");
     template = null;
     //TODO: Allow anonymous objects
 }
Exemplo n.º 5
0
        public Deref(pBaseLangObject parent, int line, int pos, string file) : base(parent)
        {
            Ident ident = new Ident(null, "string", line, pos, file);

            this.ReferencedType = new VarTypeObject(ident);
            this.Line           = line;
            this.Pos            = pos;
            this.File           = file;
        }
Exemplo n.º 6
0
        public VarTypeObject(Ident i, bool isStrict = false, Template template = null)
        {
            this.ident = i;
            this.varType = isStrict ? VarType.ObjectStrict : VarType.Object;
            this.template = template;

            if(this.template == null && (this.ident.ReferencedObject is Interfaces.iTemplate))
            {
                this.template = ((Interfaces.iTemplate)this.ident.ReferencedObject).TemplateObject;
            }
        }
Exemplo n.º 7
0
        public VarTypeObject(Ident i, Template template = null)
        {
            this.ident    = i;
            this.varType  = VarType.Object;
            this.template = template;

            if (this.template == null && (this.ident.ReferencedObject is Interfaces.iTemplate))
            {
                this.template = ((Interfaces.iTemplate) this.ident.ReferencedObject).TemplateObject;
            }
        }
Exemplo n.º 8
0
 public NativeAssign(pBaseLangObject parent, int line, int pos, string file) : base(parent, line, pos, file)
 {
     if (parent is Native)
     {
         this.name = ((Native)parent).Name;
         this.VTO  = new VarTypeObject(this.name);
     }
     else
     {
         throw new Exception("Never NEVER ever this should happen! If it does, report to dev.");
     }
 }
 public NativeAssign(pBaseLangObject parent, int line, int pos)
     : base(parent, line, pos)
 {
     if (parent is Native)
     {
         this.name = ((Native)parent).Name;
         this.VTO = new VarTypeObject(this.name);
     }
     else
     {
         throw new Exception("Never NEVER ever this should happen! If it does, report to dev.");
     }
 }
Exemplo n.º 10
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            //ToDo: do the actual casting stuff
            string tab = this.Parent is Interfaces.iCodeBlock ? new string('\t', this.getAllParentsOf <Interfaces.iCodeBlock>().Count) : "";

            if (this.children.Count != 1 || !(this.children[0] is Ident))
            {
                throw new Exception();
            }
            Ident ident = (Ident)this.children[0];

            switch (ident.LastIdent.ReferencedType.varType)
            {
            case VarType.Object:
                ident.writeOut(sw, cfg);
                break;

            case VarType.Bool:
                switch (this.ReferencedType.varType)
                {
                case VarType.Scalar:
                    sw.Write("parseNumber ");
                    ident.writeOut(sw, cfg);
                    break;

                default:
                    ident.writeOut(sw, cfg);
                    break;
                }
                break;

            case VarType.Scalar:
                switch (this.ReferencedType.varType)
                {
                case VarType.Bool:
                    sw.Write("if(");
                    ident.writeOut(sw, cfg);
                    sw.Write(" > 0) then {true} else {false}");
                    break;

                default:
                    ident.writeOut(sw, cfg);
                    break;
                }
                break;

            default:
                throw new Exception();
            }
        }
 public Tuple<int, int> getVariableIndex(Ident ident)
 {
     Tuple<int, int> tuple = null;
     for (int i = 0; i < this.children.Count; i++)
     {
         var it = this.children[i];
         if (it is Variable)
         {
             if (((Variable)it).Name.FullyQualifiedName.Equals(ident.FullyQualifiedName))
             {
                 tuple = new Tuple<int, int>(0, i);
                 break;
             }
         }
     }
     return tuple == null ? new Tuple<int, int>(-1, -1) : tuple;
 }
Exemplo n.º 12
0
        public override int doFinalize()
        {
            int errCount = 0;

            foreach (var it in this.children)
            {
                if (it is Ident)
                {
                    Ident ident  = (Ident)it;
                    var   refObj = ident.LastIdent.ReferencedObject;
                    if (refObj is Function)
                    {
                        Function fnc = (Function)refObj;
                        if (fnc.IsVirtual)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0053, this.Line, this.Pos, this.File));
                            errCount++;
                        }
                    }
                    else if (refObj is Variable)
                    {
                        Variable obj = (Variable)refObj;
                        if (obj.encapsulation != Encapsulation.Static)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0054, this.Line, this.Pos, this.File));
                            errCount++;
                        }
                    }
                    else
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0052, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
                else
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                    errCount++;
                }
            }
            return(errCount);
        }
Exemplo n.º 13
0
 public void addParentClass(Ident blo)
 {
     this.children.Add(blo);
 }
Exemplo n.º 14
0
 public void addParent(Ident ident)
 {
     this.parentIdents.Add(ident);
 }
Exemplo n.º 15
0
        public override int doFinalize()
        {
            int   errCount    = 0;
            Ident parentIdent = (this.Parent is Ident ? (Ident)this.Parent : default(Ident));

            //Check what we have here (possible outcomes: variableacces, arrayaccess, functioncall, namespaceaccess)
            #region typeDetection
            type = IdenType.NamespaceAccess;
            var fncCalls  = this.getAllChildrenOf <FunctionCall>();
            var arrAccess = this.getAllChildrenOf <ArrayAccess>();
            if (this.Parent is Template && !(this.Parent.Parent is Ident))
            {
                type = IdenType.TemplateVar;
            }
            else if (this.Parent is SqfCall && ((SqfCall)this.Parent).Name == this)
            {
                type = IdenType.SqfCommandName;
            }
            else if (this.IsSelfReference)
            {
                type = IdenType.ThisVar;
            }
            else if (fncCalls.Count > 0)
            {
                type = IdenType.FunctionCall;
            }
            else if (arrAccess.Count > 0)
            {
                type = IdenType.ArrayAccess;
            }
            else if (IsNamespaceAccess())
            {
                type = IdenType.NamespaceAccess;
            }
            else if (parentIdent == null && this.Access == AccessType.NA)
            {
                if (this.Parent is Interfaces.iClass || (this.Parent is Interfaces.iFunction && ((Interfaces.iFunction) this.Parent).ReturnType.ident == this) || this.Parent is Value || this.Parent is Variable)
                {
                    type = IdenType.NamespaceAccess;
                }
                else
                {
                    type = IdenType.VariableAccess;
                }
            }
            else if (parentIdent != null && (
                         (parentIdent.Access == AccessType.Namespace && this.Access == AccessType.NA) ||
                         this.Access == AccessType.Instance ||
                         (parentIdent.Access == AccessType.Instance && this.Access == AccessType.NA)
                         ))
            {
                var ntr = HelperClasses.NamespaceResolver.createNSR(this);
                if (ntr == null)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0012, this.Line, this.Pos, this.File));
                    errCount++;
                    return(errCount);
                }
                if (ntr.Reference is Interfaces.iClass)
                {
                    type = IdenType.NamespaceAccess;
                }
                else
                {
                    type = IdenType.VariableAccess;
                }
            }
            else if (this.Access == AccessType.Namespace)
            {
                type = IdenType.NamespaceAccess;
            }
            else if (this.Access == AccessType.Instance && parentIdent == null)
            {
                type = IdenType.VariableAccess;
            }
            else
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                errCount++;
            }
            #endregion
            //And process it then ((unless its a simple ident, then we do not want to process ... here any further))
            if (
                this.IsSimpleIdentifier &&
                (
                    (this.Parent is Interfaces.iName && ((Interfaces.iName) this.Parent).Name == this) ||
                    (this.Parent is Interfaces.iHasType && !(this.Parent is Expression) && ((Interfaces.iHasType) this.Parent).ReferencedType.ident == this)
                ) &&
                !(this.Parent is AssignContainer) &&
                !(this.Parent is NewInstance) &&
                !(this.Parent is Interfaces.iHasType && ((Interfaces.iHasType) this.Parent).ReferencedType.ident == this)
                )
            {
                this.ReferencedObject = this.Parent;
                if (this.Parent is Interfaces.iHasType)
                {
                    this.ReferencedType = ((Interfaces.iHasType) this.Parent).ReferencedType;
                }
                else //todo: try to replace with proper refObject type
                {
                    this.ReferencedType = new VarTypeObject(this, (this.Parent is Interfaces.iTemplate ? ((Interfaces.iTemplate) this.Parent).TemplateObject : null));
                }
            }
            else
            {
                switch (type)
                {
                    #region ThisVar
                case IdenType.ThisVar:
                {
                    Interfaces.iClass curObject = this.getFirstOf <Interfaces.iClass>();
                    this.ReferencedObject = (pBaseLangObject)curObject;
                    this.ReferencedType   = curObject.VTO;
                    var fnc = this.getFirstOf <Interfaces.iFunction>();
                    if (fnc.FunctionEncapsulation == Encapsulation.Static)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0055, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
                break;

                    #endregion
                    #region TemplateVar
                case IdenType.TemplateVar:
                {
                    this.ReferencedObject = (pBaseLangObject)this.getFirstOf <Interfaces.iClass>();
                    this.ReferencedType   = ((Interfaces.iClass) this.ReferencedObject).VTO;
                }
                break;

                    #endregion
                    #region SqfCommandName
                case IdenType.SqfCommandName:
                {
                    this.ReferencedObject = this.Parent;
                    this.ReferencedType   = ((SqfCall)this.Parent).ReferencedType;
                }
                break;

                    #endregion
                    #region VariableAccess & ArrayAccess
                case IdenType.VariableAccess:
                case IdenType.ArrayAccess:
                {
                    var nsr = HelperClasses.NamespaceResolver.createNSR(this);
                    if (nsr != null && nsr.IsValid && (nsr.Reference is oosEnum.EnumEntry || nsr.Reference is oosEnum))
                    {
                        if (nsr.Reference is oosEnum.EnumEntry)
                        {
                            var entry = (oosEnum.EnumEntry)nsr.Reference;
                            this.ReferencedObject = entry;
                            this.ReferencedType   = ((oosEnum)entry.Parent).ReferencedType;
                            break;
                        }
                        else if (nsr.Reference is oosEnum)
                        {
                            var e = (oosEnum)nsr.Reference;
                            this.ReferencedObject = e;
                            this.ReferencedType   = e.ReferencedType;
                            break;
                        }
                    }
                    var variable = HelperClasses.NamespaceResolver.getVariableReferenceOfFQN(HelperClasses.NamespaceResolver.createNSR(this, true), true, this);
                    if (variable == null)
                    {
                        variable = HelperClasses.NamespaceResolver.getVariableReferenceOfFQN(this, false, this);
                    }
                    if (variable == null)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0012, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                    else
                    {
                        this.ReferencedObject = variable;
                        //Set type to variable type
                        this.ReferencedType = variable.varType;

                        if (type == IdenType.ArrayAccess)
                        {
                            if (variable.ReferencedType.IsObject)
                            {
                                //Check if given object is implementing the ArrayAccess operator
                                if (variable.ReferencedType.ident.LastIdent.ReferencedObject is Interfaces.iClass)
                                {
                                    Interfaces.iClass            classRef = (Interfaces.iClass)variable.ReferencedType.ident.LastIdent.ReferencedObject;
                                    Interfaces.iOperatorFunction opFnc    = classRef.getOperatorFunction(OverridableOperator.ArrayAccess);
                                    if (opFnc == null)
                                    {
                                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0005, this.Line, this.Pos, this.File));
                                        errCount++;
                                    }
                                    else
                                    {
                                        this.ReferencedType = opFnc.ReturnType;
                                        if (variable.TemplateObject != null)
                                        {
                                            var templateList = ((pBaseLangObject)opFnc).getAllParentsOf <Interfaces.iTemplate>();
                                            foreach (var it in templateList)
                                            {
                                                var tmp = HelperClasses.ArgList.resolveVarTypeObject(opFnc.ReturnType, it.TemplateObject, variable.TemplateObject);
                                                if (tmp != opFnc.ReturnType)
                                                {
                                                    this.ReferencedType = tmp;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                                    errCount++;
                                }
                            }
                            else
                            {
                                //just check if this is an array type
                                switch (this.ReferencedType.varType)
                                {
                                case VarType.BoolArray:
                                    this.ReferencedType         = new VarTypeObject(this.ReferencedType);
                                    this.ReferencedType.varType = VarType.Bool;
                                    break;

                                case VarType.ScalarArray:
                                    this.ReferencedType         = new VarTypeObject(this.ReferencedType);
                                    this.ReferencedType.varType = VarType.Scalar;
                                    break;

                                default:
                                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0006, this.Line, this.Pos, this.File));
                                    errCount++;
                                    break;
                                }
                            }
                        }
                    }
                }
                break;

                    #endregion
                    #region FunctionCall
                case IdenType.FunctionCall:
                {
                    List <Interfaces.iFunction> fncList;
                    var fncCall     = fncCalls[0];
                    var newInstance = this.getFirstOf <NewInstance>(true, typeof(Ident));
                    var fqn         = this.FullyQualifiedName;
                    if (parentIdent != null && parentIdent.ReferencedObject is Variable)
                    {
                        //if (((Variable)parentIdent.ReferencedObject).ReferencedType.IsObject)
                        //    fqn = ((Interfaces.iClass)((Variable)parentIdent.ReferencedObject).ReferencedType.ident.LastIdent.ReferencedObject).Name.LastIdent.FullyQualifiedName + "." + this.originalValue;
                        //else
                        parentIdent.ReferencedObject.finalize();
                        fqn = parentIdent.ReferencedType.ident.LastIdent.ReferencedType.ident.LastIdent.FullyQualifiedName + "." + this.originalValue;
                    }
                    if (newInstance == null)
                    {
                        fncList = HelperClasses.NamespaceResolver.getFunctionReferenceOfFQN(HelperClasses.NamespaceResolver.createNSR(fqn));
                    }
                    else
                    {
                        fncList = HelperClasses.NamespaceResolver.getFunctionReferenceOfFQN(HelperClasses.NamespaceResolver.createNSR(fqn + "." + this.originalValue));
                    }
                    if (fncList.Count == 0)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0001, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                    else
                    {
                        //Search the correct function in the possible matches
                        Interfaces.iFunction fnc = null;
                        foreach (var it in fncList)
                        {
                            if (HelperClasses.ArgList.matchesArglist(it.ArgList, fncCall.ArgList, (parentIdent != null && parentIdent.ReferencedObject is Variable ? (Variable)parentIdent.ReferencedObject : null)))
                            {
                                fnc = it;
                                break;
                            }
                        }
                        //Raise new linker issue if we could not locate a matching function
                        if (fnc == null)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0002, this.Line, this.Pos, this.File));
                            errCount++;
                        }
                        else
                        {
                            if (fnc is Function && ((Function)fnc).IsConstructor && this.getFirstOf <NewInstance>() == null)
                            {
                                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0026, this.Line, this.Pos, this.File));
                                errCount++;
                            }
                            //Ref the object to the function
                            this.ReferencedObject = (pBaseLangObject)fnc;
                            //Ref the type to the return type
                            this.ReferencedType = fnc.ReturnType;

                            //As last step make sure we got the correct encapsulation here
                            var enc = fnc.FunctionEncapsulation;
                            if (enc != Encapsulation.Static && enc != Encapsulation.Public)
                            {
                                var parentClass = this.getFirstOf <Interfaces.iClass>();
                                HelperClasses.NamespaceResolver fncNsr = fnc.Name;
                                if (enc == Encapsulation.Private)
                                {
                                    //Private encapsulation just requires checking the current class we are operating in
                                    if (!fncNsr.isInNamespace(parentClass == null ? null : parentClass.Name))
                                    {
                                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0003, this.Line, this.Pos, this.File));
                                        errCount++;
                                    }
                                }
                                else
                                {
                                    //Protected we need to check ALL extended classes ...
                                    var  classes = parentClass.ExtendedClasses;
                                    bool flag    = false;
                                    foreach (var it in classes)
                                    {
                                        if (fncNsr.isInNamespace(it))
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (!flag)
                                    {
                                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0004, this.Line, this.Pos, this.File));
                                        errCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                break;

                    #endregion
                    #region NamespaceAccess
                case IdenType.NamespaceAccess:
                {
                    if (this.IsAnonymousIdent)
                    {
                        this.ReferencedObject = getClassTemplate();
                        this.ReferencedObject = null;
                    }
                    else
                    {
                        var nsr = HelperClasses.NamespaceResolver.createNSR(this);
                        if (nsr == null)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0046, this.Line, this.Pos, this.File));
                            errCount++;
                        }
                        else
                        {
                            var reference = nsr.Reference;
                            this.ReferencedObject = reference;
                            if (reference is Interfaces.iClass)
                            {
                                this.ReferencedType = ((Interfaces.iClass)reference).VTO;
                            }
                            else if (reference is Interfaces.iFunction)
                            {
                                this.ReferencedType = ((Interfaces.iFunction)reference).ReturnType;
                            }
                            else
                            {
                                this.ReferencedType = null;
                            }
                        }
                    }
                }
                break;
                    #endregion
                }
            }


            return(errCount);
        }
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            if (this.Parent is Ident || this.Parent is AssignContainer)
            {
                Ident  parent  = this.Parent is AssignContainer ? ((AssignContainer)this.Parent).Name.NextWorkerIdent : (Ident)this.Parent;
                string varName = '(' + parent.WriteOutValue + ')';
                switch (this.Operation)
                {
                case AssignmentCharacters.PlusOne:
                    sw.Write(varName + " + 1");
                    break;

                case AssignmentCharacters.MinusOne:
                    sw.Write(varName + " - 1");
                    break;

                case AssignmentCharacters.AdditionAssign:
                    sw.Write(varName + " + (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.SubstractionAssign:
                    sw.Write(varName + " - (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.MultiplicationAssign:
                    sw.Write(varName + " * (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                case AssignmentCharacters.DivisionAssign:
                    sw.Write(varName + " / (");
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    sw.Write(")");
                    break;

                default:
                    foreach (var it in this.children)
                    {
                        it.writeOut(sw, cfg);
                    }
                    break;
                }
            }
            else if (this.Parent is Variable)
            {
                foreach (var it in this.children)
                {
                    it.writeOut(sw, cfg);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 17
0
 public VarTypeObject(VarTypeObject vto)
 {
     this.ident = vto.ident;
     this.varType = vto.varType;
     template = vto.template;
 }
Exemplo n.º 18
0
 public void addParentClass(Ident blo)
 {
     this.children.Add(blo);
 }
Exemplo n.º 19
0
 public Tuple<int, int> getVariableIndex(Ident ident, bool allowDeepSearch)
 {
     Tuple<int, int> tuple = null;
     for (int i = 0; i < this.children.Count; i++)
     {
         var it = this.children[i];
         if (it is Variable)
         {
             if (((Variable)it).Name.FullyQualifiedName.Equals(ident.LastIdent.FullyQualifiedName))
             {
                 tuple = new Tuple<int, int>(this.parentClasses.Count + this.parentInterfaces.Count, i);
                 break;
             }
         }
     }
     if (allowDeepSearch && tuple == null)
     {
         for (int i = 0; i < this.parentClasses.Count; i++)
         {
             var it = this.parentClasses[i];
             tuple = it.getVariableIndex(ident, false);
             if (tuple.Item1 != -1)
             {
                 tuple = new Tuple<int, int>(i, tuple.Item2);
                 break;
             }
             else
             {
                 tuple = null;
             }
         }
         for (int i = 0; i < this.parentInterfaces.Count; i++)
         {
             var it = this.parentInterfaces[i];
             tuple = it.getVariableIndex(ident);
             if (tuple.Item1 != -1)
             {
                 tuple = new Tuple<int, int>(this.parentClasses.Count + i, tuple.Item2);
                 break;
             }
             else
             {
                 tuple = null;
             }
         }
     }
     return tuple == null ? new Tuple<int, int>(-1, -1) : tuple;
 }
Exemplo n.º 20
0
 public Tuple<int, int> getVariableIndex(Ident ident)
 {
     return this.getVariableIndex(ident, true);
 }
Exemplo n.º 21
0
 public Tuple<int, int> getFunctionIndex(Ident ident)
 {
     return this.getFunctionIndex(ident, true);
 }
Exemplo n.º 22
0
 public int getClassIndex(Ident otherClassIdent)
 {
     var classIdents = this.ParentClassesIdents;
     classIdents.Add(this.Name);
     for(int i = 0; i < classIdents.Count; i++)
     {
         if (((Ident)classIdents[i]).ReferencedType.ident.LastIdent.FullyQualifiedName.Equals(otherClassIdent.LastIdent.FullyQualifiedName))
             return i;
     }
     return -1;
 }
Exemplo n.º 23
0
        public override void writeOut(System.IO.StreamWriter sw, SqfConfigObjects.SqfConfigFile cfg)
        {
            string variableName = this.Name.WriteOutValue;

            if (this.ReferencedObject is Interfaces.iFunction)
            {
                Interfaces.iFunction fnc = (Interfaces.iFunction) this.ReferencedObject;
                bool flag = false;
                if (fnc is NativeInstruction)
                {
                    var           nIns       = (NativeInstruction)fnc;
                    List <string> stringList = new List <string>();
                    if (!string.IsNullOrEmpty(variableName))
                    {
                        stringList.Add(variableName);
                    }
                    foreach (var it in this.children)
                    {
                        using (MemoryStream memStream = new MemoryStream())
                        {
                            StreamWriter memStreamWriter = new StreamWriter(memStream);
                            it.writeOut(memStreamWriter, cfg);
                            memStreamWriter.Flush();
                            memStream.Seek(0, SeekOrigin.Begin);
                            stringList.Add(new StreamReader(memStream).ReadToEnd());
                        }
                    }
                    sw.Write(nIns.getCode(stringList.ToArray()));
                }
                else
                {
                    if (fnc.FunctionEncapsulation == Encapsulation.Static || fnc.IsConstructor)
                    {
                        sw.Write('[');
                    }
                    else
                    {
                        sw.Write('[' + variableName);
                        flag = true;
                    }
                    foreach (var it in this.children)
                    {
                        if (flag)
                        {
                            sw.Write(", ");
                        }
                        else
                        {
                            flag = true;
                        }
                        it.writeOut(sw, cfg);
                    }
                    if (fnc is Function)
                    {
                        if (fnc.IsVirtual)
                        {
                            sw.Write(']' + (!fnc.IsAsync ? " call (" : " spawn (") + '(' + variableName + ')' + ((Function)fnc).SqfVariableName + ')');
                        }
                        else
                        {
                            sw.Write(']' + (!fnc.IsAsync ? " call " : " spawn ") + ((Function)fnc).SqfVariableName);
                        }
                        if (((Function)fnc).IsThrowing && this.getFirstOf <TryCatch>() == null)
                        {
                            Ident ident = this.getFirstOf <Ident>();
                            Logger.Instance.log(Logger.LogLevel.WARNING, "Function '" + fnc.Name.FullyQualifiedName + "' is throwing but not catched. line " + ident.Line + ", pos " + ident.Pos + ", file '" + ident.File + '\'');
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            else
            {
                throw new Exception();
            }
        }
Exemplo n.º 24
0
        public static void readSupportInfoList()
        {
            if (supportInfoList != null)
            {
                throw new Exception("SupportInfoList cannot be read twice!");
            }
            supportInfoList = new List <SupportInfoObject>();
            using (var reader = new StringReader(Compiler.Properties.Resources.SQF_SupportInfo))
            {
                string line      = "";
                int    lineIndex = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    lineIndex++;
                    string[] splitString = line.Split('#');
                    string   command     = "";
                    if (splitString[0] == "t")
                    {
                        continue;
                    }
                    if (splitString[0] == "u")
                    {
                        command = splitString[2].Split(' ')[0];
                    }
                    else if (splitString[0] == "b")
                    {
                        command = splitString[2].Split(' ')[1];
                    }
                    else
                    {
                        command = splitString[2];
                    }
                    command = command.ToLower();
                    if (splitString[1].StartsWith("::"))
                    {
                        var   anotherSplit = splitString[1].Split(new char[] { ':' });
                        Ident ident        = null;
                        foreach (var s in anotherSplit)
                        {
                            if (!string.IsNullOrEmpty(s))
                            {
                                Ident tmpIdent = new Ident(ident, s, -1, -1, "");
                                tmpIdent.Access = Ident.AccessType.Namespace;
                                if (ident != null)
                                {
                                    ident.addChild(tmpIdent);
                                    ident = tmpIdent;
                                }
                                else
                                {
                                    tmpIdent.IsGlobalIdentifier = true;
                                    ident = tmpIdent;
                                }
                            }
                        }
                        ident.Access = Ident.AccessType.NA;
                        supportInfoList.Add(new SupportInfoObject(command, ident.getLastOf <Ident>(), splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                    }
                    else
                    {
                        switch (splitString[1].ToLower())
                        {
                        default:
                            throw new Exception("Unknown returnType encountered while parsing SupportInfo.txt, Line: " + lineIndex);

                        case "nil":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.Void, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;

                        case "bool":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.Bool, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;

                        case "bool[]":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.BoolArray, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;

                        case "scalar":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.Scalar, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;

                        case "scalar[]":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.ScalarArray, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;

                        case "other":
                            supportInfoList.Add(new SupportInfoObject(command, VarType.Other, splitString[0] == "u" || splitString[0] == "b", splitString[0] == "b"));
                            break;
                        }
                    }
                }
            }
        }