Exemplo n.º 1
0
        public DMProc GetProc()
        {
            if (!DMObjectTree.TryGetGlobalProc(_name, out DMProc globalProc))
            {
                throw new CompileErrorException(Location, $"No proc named \"{_name}\"");
            }

            return(globalProc);
        }
Exemplo n.º 2
0
        public override (DMReference Reference, bool Conditional) EmitReference(DMObject dmObject, DMProc proc)
        {
            if (!DMObjectTree.TryGetGlobalProc(_name, out _))
            {
                throw new CompileErrorException(Location, $"There is no global proc named \"{_name}\"");
            }

            return(DMReference.CreateGlobalProc(_name), false);
        }
Exemplo n.º 3
0
        public override (DMReference Reference, bool Conditional) EmitReference(DMObject dmObject, DMProc proc)
        {
            if (dmObject.HasProc(_identifier))
            {
                return(DMReference.CreateSrcProc(_identifier), false);
            }
            else if (DMObjectTree.TryGetGlobalProc(_identifier, out _))
            {
                return(DMReference.CreateGlobalProc(_identifier), false);
            }

            throw new CompileErrorException(Location, $"Type {dmObject.Path} does not have a proc named \"{_identifier}\"");
        }
Exemplo n.º 4
0
 public void VisitCallableProcIdentifier(DMASTCallableProcIdentifier procIdentifier)
 {
     if (_scopeMode == "static")
     {
         Result = new Expressions.GlobalProc(procIdentifier.Location, procIdentifier.Identifier);
     }
     else
     {
         if (_dmObject.HasProc(procIdentifier.Identifier))
         {
             Result = new Expressions.Proc(procIdentifier.Location, procIdentifier.Identifier);
         }
         else if (DMObjectTree.TryGetGlobalProc(procIdentifier.Identifier, out _))
         {
             Result = new Expressions.GlobalProc(procIdentifier.Location, procIdentifier.Identifier);
         }
         else
         {
             throw new CompileErrorException(procIdentifier.Location, $"Type {_dmObject.Path} does not have a proc named \"{procIdentifier.Identifier}\"");
         }
     }
 }
Exemplo n.º 5
0
        public void ProcessProcDefinition(DMASTProcDefinition procDefinition)
        {
            string   procName = procDefinition.Name;
            DMObject dmObject = _currentObject;

            try {
                if (procDefinition.ObjectPath.HasValue)
                {
                    dmObject = DMObjectTree.GetDMObject(_currentObject.Path.Combine(procDefinition.ObjectPath.Value));
                }

                if (!procDefinition.IsOverride && dmObject.HasProc(procName))
                {
                    throw new CompileErrorException(procDefinition.Location, $"Type {dmObject.Path} already has a proc named \"{procName}\"");
                }

                DMProc proc;

                if (procDefinition.ObjectPath == null)
                {
                    if (DMObjectTree.TryGetGlobalProc(procDefinition.Name, out _))
                    {
                        throw new CompileErrorException(new CompilerError(procDefinition.Location, $"proc {procDefinition.Name} is already defined in global scope"));
                    }

                    proc = DMObjectTree.CreateDMProc(dmObject, procDefinition);
                    DMObjectTree.AddGlobalProc(proc.Name, proc.Id);
                }
                else
                {
                    proc = DMObjectTree.CreateDMProc(dmObject, procDefinition);
                    dmObject.AddProc(procName, proc);
                }

                if (procDefinition.Body != null)
                {
                    foreach (var stmt in GetStatements(procDefinition.Body))
                    {
                        // TODO multiple var definitions.
                        if (stmt is DMASTProcStatementVarDeclaration varDeclaration && varDeclaration.IsGlobal)
                        {
                            DMVariable variable = proc.CreateGlobalVariable(varDeclaration.Type, varDeclaration.Name, varDeclaration.IsConst);
                            variable.Value = new Expressions.Null(varDeclaration.Location);

                            if (varDeclaration.Value != null)
                            {
                                DMVisitorExpression._scopeMode = "static";
                                DMExpression expression = DMExpression.Create(dmObject, proc, varDeclaration.Value, varDeclaration.Type);
                                DMVisitorExpression._scopeMode = "normal";
                                DMObjectTree.AddGlobalInitAssign(dmObject, proc.GetGlobalVariableId(varDeclaration.Name).Value, expression);
                            }
                        }
                    }
                }

                if (procDefinition.IsVerb && (dmObject.IsSubtypeOf(DreamPath.Atom) || dmObject.IsSubtypeOf(DreamPath.Client)) && !DMCompiler.Settings.NoStandard)
                {
                    Expressions.Field  field    = new Expressions.Field(Location.Unknown, dmObject.GetVariable("verbs"));
                    DreamPath          procPath = new DreamPath(".proc/" + procName);
                    Expressions.Append append   = new Expressions.Append(Location.Unknown, field, new Expressions.Path(Location.Unknown, procPath));

                    dmObject.InitializationProcExpressions.Add(append);
                }
            } catch (CompileErrorException e) {
                DMCompiler.Error(e.Error);
            }
        }