Пример #1
0
        public override int doFinalize()
        {
            int errCount = 0;
            var fnc      = this.getFirstOf <Function>();

            if (this.children.Count > 0)
            {
                var returnExpression = (Expression)this.children[0];
                if (fnc.IsAsync)
                {
                    if (!returnExpression.ReferencedType.Equals(new VarTypeObject(VarType.Void)))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0022, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
                else
                {
                    if (!returnExpression.ReferencedType.Equals(fnc.varType))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0022, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
            }
            else if (fnc.varType.varType != VarType.Void)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0023, this.Line, this.Pos, this.File));
                errCount++;
            }
            return(errCount);
        }
Пример #2
0
        public override int doFinalize()
        {
            int errCount = 0;

            if (LIdent is Cast)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0030, ((Ident)((Cast)LIdent).children[0]).Line, ((Ident)((Cast)LIdent).children[0]).Pos));
                errCount++;
            }
            else if (LIdent is Ident)
            {
                var varType = ((Ident)LIdent).LastIdent.ReferencedType;
                if (!varType.IsObject)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0028, ((Ident)LIdent).Line, ((Ident)LIdent).Pos));
                    errCount++;
                }
            }
            else
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, RIdent.Line, RIdent.Pos));
                errCount++;
            }
            var refObject = RIdent.LastIdent.ReferencedObject;

            if (!(refObject is oosClass || refObject is oosInterface))
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0029, RIdent.Line, RIdent.Pos));
                errCount++;
            }
            return(errCount);
        }
Пример #3
0
        public override int doFinalize()
        {
            int  errCount = 0;
            var  caseList = this.getAllChildrenOf <Case>();
            bool flag     = false;

            foreach (var it in caseList)
            {
                if (it.Cases.Count == 0)
                {
                    if (flag)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0020, it.Line, it.Pos));
                        errCount++;
                    }
                    else
                    {
                        flag             = true;
                        this.DefaultCase = it;
                    }
                }
            }
            //ToDo: Check for duplicated case
            return(errCount);
        }
Пример #4
0
        public override int doFinalize()
        {
            int errCount = 0;

            if (this.varType.ident != null)
            {
                errCount += this.varType.ident.doFinalize();
            }
            var childType = ((Ident)this.children[0]).LastIdent.ReferencedType;

            if (this.varType.varType == VarType.Object && childType.varType != VarType.Object)
            {//Non-Object to object
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0031, ((Ident)this.children[0]).Line, ((Ident)this.children[0]).Pos));
                errCount++;
            }
            if (this.varType.varType != VarType.Object && childType.varType == VarType.Object)
            {//Object to non-object
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0033, ((Ident)this.children[0]).Line, ((Ident)this.children[0]).Pos));
                errCount++;
            }
            if (this.varType.Equals(childType))
            {//Same type
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0034, ((Ident)this.children[0]).Line, ((Ident)this.children[0]).Pos));
                errCount++;
            }
            return(errCount);
        }
Пример #5
0
 public override int doFinalize()
 {
     if (!((Variable)variable).ReferencedType.IsKindOf(Wrapper.Compiler.InternalObjectVarTypes.VT_Exception))
     {
         Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0056, ((Variable)variable).Line, ((Variable)variable).Pos));
         return(1);
     }
     return(0);
 }
Пример #6
0
        public override int doFinalize()
        {
            int           errCount   = 0;
            var           list       = this.getAllChildrenOf <EnumEntry>();
            VarTypeObject vto        = null;
            int           offset     = 0;
            List <string> usedValues = new List <string>();

            for (int i = 0; i < list.Count; i++)
            {
                var it = list[i];
                if (it.Value == null)
                {
                    Value val = new Value(it);
                    val.value = (i + offset).ToString();
                    it.Value  = val;
                    it.Value.varType.varType = VarType.Scalar;
                }
                else
                {
                    if (it.Value.varType.varType == VarType.Scalar)
                    {
                        offset = int.Parse(it.Value.value) - i;
                    }
                }
                if (usedValues.Contains(it.Value.value))
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0048, it.Name.Line, it.Name.Pos, it.Name.File));
                    errCount++;
                }
                usedValues.Add(it.Value.value);
                if (vto == null)
                {
                    vto = it.Value.varType;
                }
                else if (!vto.Equals(it.Value.varType))
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0047, it.Name.Line, it.Name.Pos, it.Name.File));
                    errCount++;
                }
            }
            this.ReferencedType.ident          = vto.ident;
            this.ReferencedType.varType        = vto.varType;
            this.ReferencedType.TemplateObject = vto.TemplateObject;


            if (list.Count == 1)
            {
                Logger.Instance.log(Logger.LogLevel.WARNING, "Enum '" + this.Name.OriginalValue + "' only has a single value assigned to it");
            }

            return(errCount);
        }
Пример #7
0
        public override int doFinalize()
        {
            int errCount = 0;

            foreach (var it in this.getAllChildrenOf <Expression>())
            {
                if (it.ReferencedType.varType != VarType.Scalar)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0050, it.Line, it.Pos, it.File));
                    errCount++;
                }
            }
            return(errCount);
        }
Пример #8
0
 public override int doFinalize()
 {
     if (!((Expression)this.children[0]).ReferencedType.IsKindOf(Wrapper.Compiler.InternalObjectVarTypes.VT_Exception))
     {
         Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0057, ((Expression)this.children[0]).Line, ((Expression)this.children[0]).Pos, ((Expression)this.children[0]).File));
         return(1);
     }
     if (!this.getFirstOf <Function>().IsThrowing)
     {
         var fnc = this.getFirstOf <Function>();
         Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0059, fnc.Name.Line, fnc.Name.Pos, fnc.Name.File));
         return(1);
     }
     return(0);
 }
Пример #9
0
        public override int doFinalize()
        {
            int errCount = 0;

            errCount += this.Name.finalize();
            if (VTO.ident != null)
            {
                errCount += VTO.ident.finalize();
            }
            if (Code.Contains("_this") && !(this.Parent is Native))
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0049, this.Line, this.Pos, this.File));
                errCount++;
            }
            return(errCount);
        }
Пример #10
0
        public override int doFinalize()
        {
            int errCount = 0;
            var sio      = supportInfoList.Find(SupportInfoObject.bySqfCommand(this.Name.OriginalValue.ToLower()));

            if (sio == null)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0019, this.Name.Line, this.Name.Pos));
                return(1);
            }
            var lArgs = LArgs;
            var rArgs = RArgs;

            if (lArgs.Count == 0 && sio.hasL)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0015, this.Name.Line, this.Name.Pos));
                errCount++;
            }
            else if (lArgs.Count != 0 && !sio.hasL)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0016, this.Name.Line, this.Name.Pos));
                errCount++;
            }
            if (rArgs.Count == 0 && sio.hasR)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0017, this.Name.Line, this.Name.Pos));
                errCount++;
            }
            else if (rArgs.Count != 0 && !sio.hasR)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0018, this.Name.Line, this.Name.Pos));
                errCount++;
            }
            if (!this.HasAs)
            {
                this.ReferencedType.ident          = sio.outType.ident;
                this.ReferencedType.varType        = sio.outType.varType;
                this.ReferencedType.TemplateObject = sio.outType.TemplateObject;
                if (sio.outType.IsObject)
                {
                    return(sio.outType.ident.finalize());
                }
            }
            return(0);
        }
Пример #11
0
        public override int doFinalize()
        {
            int errCount      = 0;
            var switchElement = this.Parent.getFirstOf <Switch>();

            foreach (var expression in this.Cases)
            {
                if (expression != null)
                {
                    if (!((Expression)expression).ReferencedType.Equals(switchElement.ReferencedType) && !(switchElement.ReferencedType.IsObject && switchElement.ReferencedType.ident.ReferencedObject is oosEnum))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0024, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
            }
            return(errCount);
        }
Пример #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);
        }
Пример #13
0
        public override int doFinalize()
        {
            int errCount = 0;

            foreach (var it in this.children)
            {
                if (it is Expression)
                {
                    Expression exp = (Expression)it;
                    if (this.ReferencedType == null)
                    {
                        this.ReferencedType = exp.ReferencedType;
                    }
                    if (!this.ReferencedType.Equals(exp.ReferencedType))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0013, exp.Line, exp.Pos));
                        errCount++;
                    }
                }
                else
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN));
                    errCount++;
                }
            }
            if (this.ReferencedType != null)
            {
                this.ReferencedType = new VarTypeObject(this.ReferencedType);
                switch (this.ReferencedType.varType)
                {
                case VarType.Bool:
                    this.ReferencedType.varType = VarType.BoolArray;
                    break;

                case VarType.Scalar:
                    this.ReferencedType.varType = VarType.ScalarArray;
                    break;
                }
            }
            return(errCount);
        }
Пример #14
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);
        }
Пример #15
0
        public override int doFinalize()
        {
            int errCount = 0;

            this.ReferencedType = new VarTypeObject(VarType.Void);
            VarTypeObject vto = this.ReferencedType;

            if (this.expressionObjects.Count == 1)
            {
                var obj = this.expressionObjects[0];
                if (obj is Interfaces.iHasType)
                {
                    if (obj is Ident)
                    {
                        vto.copyFrom(((Ident)obj).LastIdent.ReferencedType);
                    }
                    else
                    {
                        vto.copyFrom(((Interfaces.iHasType)obj).ReferencedType);
                    }
                }
                else if (obj is Value)
                {
                    vto.copyFrom(((Value)obj).varType);
                }
                else
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                    errCount++;
                }
            }
            else
            {
                int i = 0;
                foreach (var op in this.expressionOperators)
                {
                    var           lArg = this.expressionObjects[i];
                    var           rArg = this.expressionObjects[++i];
                    VarTypeObject lType;
                    VarTypeObject rType;
                    if (lArg is Interfaces.iHasType)
                    {
                        lType = ((Interfaces.iHasType)lArg).ReferencedType;
                        if (lArg is Ident)
                        {
                            lType = ((Ident)lArg).LastIdent.ReferencedType;
                        }
                    }
                    else if (lArg is Value)
                    {
                        lType = ((Value)lArg).varType;
                    }
                    else
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                        errCount++;
                        continue;
                    }
                    if (rArg is Interfaces.iHasType)
                    {
                        rType = ((Interfaces.iHasType)rArg).ReferencedType;
                        if (rArg is Ident)
                        {
                            rType = ((Ident)rArg).LastIdent.ReferencedType;
                        }
                    }
                    else if (rArg is Value)
                    {
                        rType = ((Value)rArg).varType;
                    }
                    else
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, this.Line, this.Pos, this.File));
                        errCount++;
                        continue;
                    }

                    switch (op)
                    {
                    case "&":
                    case "&&":
                    case "|":
                    case "||":
                        if (lType.varType != VarType.Bool || rType.varType != VarType.Bool)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0014, this.Line, this.Pos, this.File));
                            errCount++;
                            break;
                        }
                        vto.copyFrom(new VarTypeObject(VarType.Bool));
                        break;

                    case "==":
                        vto.copyFrom(new VarTypeObject(VarType.Bool));
                        break;

                    case "+":
                    case "-":
                    case "*":
                    case "/":
                        if (lType.varType != VarType.Scalar || rType.varType != VarType.Scalar)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0014, this.Line, this.Pos, this.File));
                            errCount++;
                            break;
                        }
                        vto.copyFrom(new VarTypeObject(VarType.Scalar));
                        break;

                    case ">":
                    case ">=":
                    case "<":
                    case "<=":
                        if (lType.varType != VarType.Scalar || rType.varType != VarType.Scalar)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0014, this.Line, this.Pos, this.File));
                            errCount++;
                            break;
                        }
                        vto.copyFrom(new VarTypeObject(VarType.Bool));
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            if (vto.IsObject)
            {
                errCount += vto.ident.finalize();
            }
            return(errCount);
        }
Пример #16
0
        public void Compile(Project proj)
        {
            ProjectFile = proj;
            //Make sure the build directory exists and create it if needed
            if (!Directory.Exists(proj.Buildfolder))
            {
                Directory.CreateDirectory(proj.Buildfolder);
            }
            if (!Directory.Exists(proj.OutputFolder))
            {
                Directory.CreateDirectory(proj.OutputFolder);
            }

            //Prepare some stuff needed for preprocessing
            List <preprocessFile_IfDefModes> ifdefs  = new List <preprocessFile_IfDefModes>();
            List <PostProcessFile>           ppFiles = new List <PostProcessFile>();

            //do the preprocessing
            preprocessFile(ifdefs, proj.Mainfile, "", ppFiles);
            var ppMainFile = ppFiles[0];

            if (outputFolderCleanup)
            {
                Logger.Instance.log(Logger.LogLevel.VERBOSE, "Cleaning up output dir");
                cleanupRecursive(proj.OutputFolder);
            }

            int errCount = 0;
            //Check the syntax of all files in ppFiles
            //foreach (var it in ppFiles)
            //{
            //    //if (!noPrintOut)
            //    //{
            //    //    var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //    //    it.resetPosition();
            //    //    it.FileStream.WriteTo(stream);
            //    //    stream.Flush();
            //    //    stream.Close();
            //    //}
            //    Scanner scanner = new Scanner(it.FileStream);
            //    Base baseObject = new Base();
            //    Parser p = new Parser(scanner, it.FilePath);
            //    Parser.UsedFiles = new List<string>();
            //    p.BaseObject = baseObject;
            //    p.Parse();
            //    if (p.errors.count > 0)
            //    {
            //        errCount += p.errors.count;
            //        Logger.Instance.log(Logger.LogLevel.ERROR, "In file '" + it.Name + "'");
            //    }
            //    if (printOutMode > 0)
            //    {
            //        if (printOutMode == 1 && it == ppMainFile)
            //        {
            //            var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //            it.resetPosition();
            //            it.FileStream.WriteTo(stream);
            //            stream.Flush();
            //            stream.Close();
            //        }
            //        if (printOutMode >= 2)
            //        {
            //            var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //            it.resetPosition();
            //            it.FileStream.WriteTo(stream);
            //            stream.Flush();
            //            stream.Close();
            //        }
            //    }
            //    it.resetPosition();
            //}
            //if (errCount > 0)
            //{
            //    Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Translating!");
            //    return;
            //}

            //Read in all internal objects
            Base oosTreeBase = new Base();

            NamespaceResolver.BaseClass = oosTreeBase;
            {
                Parser p;
                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources._object)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_object.ident.finalize();
                InternalObjectVarTypes.VT_nobject.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.array)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.vec3)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_vec3.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources._string)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_string.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.script)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_script.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.functions)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.Exception)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_Exception.ident.finalize();


                if (errCount > 0)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found in ressource OOS files (" + errCount + "), cannot continue with Compiling!");
                    return;
                }
            }

            //process the actual file
            Parser parser = new Parser(new Scanner(ppMainFile.FileStream), ppMainFile.FilePath);

            Parser.UsedFiles  = new List <string>();
            parser.BaseObject = oosTreeBase;
            parser.Parse();

            errCount = parser.errors.count;
            if (errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Compiling!");
                return;
            }
            var preInitFunction = parser.BaseObject.getAllChildrenOf <Function>(true, null, -1, -1, new Type[] { typeof(Namespace), typeof(oosClass) }, (obj) => obj.Name.OriginalValue.Equals("preInit"));

            errCount = 0;
            if (preInitFunction.Count > 1)
            {
                foreach (var it in preInitFunction)
                {
                    errCount++;
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0060, it.Name.Line, it.Name.Pos, it.Name.File));
                }
            }
            else if (preInitFunction.Count == 0)
            {
                var n = new Namespace(parser.BaseObject);
                parser.BaseObject.addChild(parser.BaseObject);
                n.Name = new Ident(n, ProjectFile.Author + "ComGenPreInitNS", 0, 0, "");

                var fnc = new Function(n);
                n.addChild(fnc);
                fnc.Name = new Ident(fnc, "preInit", 0, 0, "");
                preInitFunction.Add(fnc);
            }
            int id         = 0;
            var allClasses = parser.BaseObject.getAllChildrenOf <oosClass>(true, null, -1, -1, new Type[] { typeof(Namespace) }, (obj) => { obj.ID = id++; return(true); });

            id = 0;
            var allInterfaces = parser.BaseObject.getAllChildrenOf <oosInterface>(true, null, -1, -1, new Type[] { typeof(Namespace) }, (obj) => { obj.ID = id++; return(true); });

            if (preInitFunction.Count == 1)
            {
                var template = new Template(null, -1, -1, "");
                template.vtoList.Add(Compiler.InternalObjectVarTypes.VT_object);
                var arrayVto = new VarTypeObject(new Ident(null, "array", -1, -1, ""), template);

                oosClass.GlobalClassRegisterVariable               = new Variable(preInitFunction[0].Parent, -1, -1, "");
                oosClass.GlobalClassRegisterVariable.Name          = new Ident(oosClass.GlobalClassRegisterVariable, "ClassRegisterVariable_____", -1, -1, "");
                oosClass.GlobalClassRegisterVariable.varType       = arrayVto;
                oosClass.GlobalClassRegisterVariable.encapsulation = Encapsulation.Static;

                oosInterface.GlobalInterfaceRegisterVariable               = new Variable(preInitFunction[0].Parent, -1, -1, "");
                oosInterface.GlobalInterfaceRegisterVariable.Name          = new Ident(oosInterface.GlobalInterfaceRegisterVariable, "InterfaceRegisterVariable_____", -1, -1, "");
                oosInterface.GlobalInterfaceRegisterVariable.varType       = arrayVto;
                oosInterface.GlobalInterfaceRegisterVariable.encapsulation = Encapsulation.Static;
            }
            errCount += parser.BaseObject.finalize();
            if (errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Compiling!");
                return;
            }
            SqfConfigFile configFile = new SqfConfigFile(configFileName);

            oosTreeBase.writeOut(null, configFile);
            if (addFunctionsClass)
            {
                configFile.addParentalClass("CfgFunctions");
            }
            configFile.writeOut(proj.OutputFolder);
            handleRessources();
        }
Пример #17
0
        public override int doFinalize()
        {
            int errCount = 0;

            if (this.IsAsync)
            {
                if (!this.varType.Equals(Wrapper.Compiler.InternalObjectVarTypes.VT_script))
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0021, this.Name.Line, this.Name.Pos, this.Name.File));
                    errCount++;
                }
            }
            else
            {
                if (this.ReturnType.varType != VarType.Void && !this.AlwaysReturns && !this.IsConstructor && !this.IsExternal)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0021, this.Name.Line, this.Name.Pos, this.Name.File));
                    errCount++;
                }
            }
            if (this.IsConstructor)
            {
                var retList = this.getAllChildrenOf <Return>(true);
                if (!retList.TrueForAll(it => it.children.Count == 0))
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0025, this.Name.Line));
                    errCount++;
                }
                foreach (var it in retList)
                {
                    var val = new Value(it);
                    val.value = Wrapper.Compiler.thisVariableName;
                    it.addChild(val);
                }
            }
            switch (this.Name.OriginalValue)
            {
            case "preInit":
            case "postInit":
            case "preStart":
                if (this.encapsulation != Encapsulation.Static)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0027, this.Name.Line));
                    errCount++;
                }
                break;
            }
            //ToDo: Find a way to reallow interfaces as arguments (then remove the following foreach
            foreach (var it in this.ArgListObjects)
            {
                if (it is Variable && ((Variable)it).ReferencedType.IsObject && ((Variable)it).ReferencedType.ident.LastIdent.ReferencedObject is oosInterface)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, "Interfaces for function arguments are temporary disabled. Line: " + this.Name.Line);
                    errCount++;
                }
            }
            //up to here)
            var fncList = this.Parent.getAllChildrenOf <Function>();
            int index   = 0;

            foreach (var it in fncList)
            {
                if (it == this)
                {
                    break;
                }
                if (it.Name.FullyQualifiedName.Equals(this.Name.FullyQualifiedName, StringComparison.OrdinalIgnoreCase) && it != this)
                {
                    index++;
                }
            }
            if (index > 0)
            {
                this.SqfSuffix = index.ToString();
            }
            return(errCount);
        }
 public LinkerException(ErrorStringResolver.LinkerErrorCode lec = ErrorStringResolver.LinkerErrorCode.UNKNOWN, int line = -1, int pos = -1)
     : base(ErrorStringResolver.resolve(lec, line, pos))
 {
     this.ErrorCode = lec;
 }
Пример #19
0
        public override int doFinalize()
        {
            int errCount   = 0;
            var assignList = this.getAllChildrenOf <VariableAssignment>();

            //Make sure that we not got an auto without an assign here
            if (this.varType.varType == VarType.Auto && assignList.Count == 0 && !(this.Parent is ForEach))
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0007, this.Line, this.Pos, this.File));
                errCount++;
            }
            //Check if we got an assign and validate the value after that
            if (assignList.Count > 0)
            {
                var assign     = assignList[0];
                var assignType = assign.ReferencedType;
                var thisType   = this.varType;

                if (thisType.varType == VarType.Auto)
                {
                    thisType.varType        = assignType.varType;
                    thisType.ident          = assignType.ident;
                    thisType.TemplateObject = assignType.TemplateObject;
                }
                else
                {
                    if (!assignType.Equals(thisType))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0008, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
            }
            else if (this.varType.varType == VarType.Auto && this.Parent is ForEach)
            {
                var obj      = (ForEach)this.Parent;
                var thisType = this.varType;
                if (obj.Variable.LastIdent.ReferencedType.Equals(HelperClasses.NamespaceResolver.createNSR("::array")))
                {
                    thisType.varType        = obj.Variable.LastIdent.ReferencedType.TemplateObject.vtoList[0].varType;
                    thisType.ident          = obj.Variable.LastIdent.ReferencedType.TemplateObject.vtoList[0].ident;
                    thisType.TemplateObject = obj.Variable.LastIdent.ReferencedType.TemplateObject.vtoList[0].TemplateObject;
                }
                else
                {
                    thisType.varType        = obj.Variable.LastIdent.ReferencedType.varType;
                    thisType.ident          = obj.Variable.LastIdent.ReferencedType.ident;
                    thisType.TemplateObject = obj.Variable.LastIdent.ReferencedType.TemplateObject;
                    Logger.Instance.log(Logger.LogLevel.ERROR, "Currently only the array object is allowed for foreach");
                    errCount++;
                }
            }
            //Check variable is not yet existing in above scopes
            switch (this.encapsulation)
            {
            case Encapsulation.NA:
            {
                var fnc = this.getFirstOf <Interfaces.iFunction>();
                if (fnc != null)
                {
                    bool flag = false;
                    foreach (var it in ((pBaseLangObject)fnc).getAllChildrenOf <Variable>(true, this))
                    {
                        if (it.Name.FullyQualifiedName == this.Name.FullyQualifiedName)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0009, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
                var cls = this.getFirstOf <Interfaces.iClass>();
                if (cls != null && (fnc == null || fnc.FunctionEncapsulation != Encapsulation.Static))
                {
                    bool flag = false;
                    foreach (var it in ((pBaseLangObject)cls).getAllChildrenOf <Variable>())
                    {
                        if (it.Name.FullyQualifiedName == this.Name.FullyQualifiedName)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0051, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
            }
            break;

            default:
            {
                var classRef = this.getFirstOf <Interfaces.iClass>();
                if (classRef != null)
                {
                    if (!((pBaseLangObject)classRef).getAllChildrenOf <Variable>(true, this).TrueForAll(it => it.Name.FullyQualifiedName != this.Name.FullyQualifiedName))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0010, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
                else
                {
                    var topObject = this.getFirstOf <Base>();
                    if (!topObject.getAllChildrenOf <Variable>(true, this).TrueForAll(it => it.Name.FullyQualifiedName != this.Name.FullyQualifiedName))
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0011, this.Line, this.Pos, this.File));
                        errCount++;
                    }
                }
            }
            break;
            }
            return(errCount);
        }
Пример #20
0
        public override int doFinalize()
        {
            int errCount = 0;

            for (int i = 0; i < ParentClassesIdents.Count; i++)
            {
                var it = ParentClassesIdents[i];
                if (!(it is Ident))
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, Name.Line, Name.Pos));
                    errCount++;
                    continue;
                }
                if (((Ident)it).ReferencedObject is oosClass)
                {
                    if (i >= this.endMarkerParents)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0037, Name.Line, Name.Pos));
                        errCount++;
                    }
                    var parentClass = (oosClass)((Ident)it).ReferencedObject;
                    this.parentClasses.AddRange(parentClass.parentClasses);
                    this.parentClasses.Add(parentClass);
                }
                else if (((Ident)it).ReferencedObject is oosInterface)
                {
                    if (i < this.endMarkerParents)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0038, Name.Line, Name.Pos));
                        errCount++;
                    }
                    this.parentInterfaces.Add((oosInterface)((Ident)it).ReferencedObject);
                }
                else
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.UNKNOWN, Name.Line, Name.Pos));
                    errCount++;
                }
            }
            var functionNameList = new List <string>();

            this.AllObjects = new List <pBaseLangObject>();
            var allFunctions         = new List <Function>();
            var inheritanceFunctions = new List <Function>();
            var allVariables         = new List <Variable>();
            var classes = new List <oosClass>(this.parentClasses);

            classes.Add(this);
            foreach (var classObj in classes)
            {
                foreach (var classChild in classObj.children)
                {
                    if (classChild is Function || classChild is Variable)
                    {
                        bool flag = true;
                        if (classChild is Function && ((Function)classChild).IsVirtual)
                        {
                            inheritanceFunctions.Add((Function)classChild);
                            for (int i = 0; i < this.AllObjects.Count; i++)
                            {
                                var it = this.AllObjects[i];
                                if (it is Function && ((Function)it).Name.OriginalValue.Equals(((Function)classChild).Name.OriginalValue) && HelperClasses.ArgList.matchesArglist(((Function)it).ArgList, ((Function)classChild).ArgList))
                                {
                                    if (!((Function)classChild).IsVirtual)
                                    {
                                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0039, ((Function)classChild).Name.Line));
                                        errCount++;
                                    }
                                    this.AllObjects[i] = classChild;
                                    flag = false;
                                }
                            }
                        }

                        if (flag)
                        {
                            if (classChild is Function)
                            {
                                if (!((Function)classChild).IsConstructor || ((Function)classChild).Parent == this)
                                {
                                    this.AllObjects.Add(classChild);
                                    allFunctions.Add((Function)classChild);
                                }
                            }
                            else if (classChild is Variable)
                            {
                                this.AllObjects.Add(classChild);
                                allVariables.Add((Variable)classChild);
                            }
                        }
                    }
                }
            }



            foreach (var it in allFunctions)
            {
                var origVal = it.Name.OriginalValue;
                if (it.IsConstructor)
                {
                    continue;
                }
                if (functionNameList.FirstOrDefault(checkString => checkString.Equals(origVal)) != null)
                {
                    var parentFnc = inheritanceFunctions.FirstOrDefault(checkValue => checkValue.Name.OriginalValue == origVal);
                    if (parentFnc == null)
                    {
                        Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0039, it.Name.Line, it.Name.Pos, it.Name.File));
                        errCount++;
                    }
                    else
                    {
                        if (!it.IsVirtual)
                        {
                            Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0040, it.Name.Line, it.Name.Pos, it.Name.File));
                            errCount++;
                        }
                        else
                        {
                            var argList   = parentFnc.ArgList;
                            var itArgList = it.ArgList;
                            if (argList.Count != itArgList.Count)
                            {
                                if (argList.Count > itArgList.Count)
                                {
                                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0041, it.Name.Line, it.Name.Pos, it.Name.File));
                                    errCount++;
                                }
                                else
                                {
                                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0042, it.Name.Line, it.Name.Pos, it.Name.File));
                                    errCount++;
                                }
                            }
                            for (var i = 0; i < argList.Count; i++)
                            {
                                if (i > argList.Count || i > itArgList.Count)
                                {
                                    break;
                                }
                                var v = argList[i];
                                var e = itArgList[i];
                                if (!v.Equals(e))
                                {
                                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0043));
                                    errCount++;
                                }
                            }
                            if (!it.varType.Equals(parentFnc.varType))
                            {
                                Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0044, it.Name.Line, it.Name.Pos, it.Name.File));
                                errCount++;
                            }
                        }
                    }
                }
                functionNameList.Add(it.Name.OriginalValue);
            }
            //ToDo: Check interface functions are implemented
            return(errCount);
        }