コード例 #1
0
 public FunctionContext(Executable exe, FunctionDeclaration fdecl, CompiledFunction fexe, CompilerContext context)
     : base(context.MachineInfo, context.Report, fdecl)
 {
     this.exe     = exe;
     this.fdecl   = fdecl;
     this.fexe    = fexe;
     this.context = context;
     blocks       = new List <Block> ();
     blockLocals  = new Dictionary <Block, BlockLocals> ();
     allLocals    = new List <VariableDeclaration> ();
 }
コード例 #2
0
 public virtual void DeclareFunction(FunctionDeclaration f)
 {
 }
コード例 #3
0
 public EmitContext(MachineInfo machineInfo, Report report, FunctionDeclaration fdecl = null)
     : base(machineInfo, report)
 {
     FunctionDecl = fdecl;
 }
コード例 #4
0
ファイル: Block.cs プロジェクト: arlm/CLanguage
 public void AddFunction(FunctionDeclaration dec)
 {
     Declarations.Add(dec);
     Functions.Add(dec);
 }
コード例 #5
0
        void AddDeclaration(object a, Block block)
        {
            if (a is CParser.MultiDeclaration)
            {
                var d = (CParser.MultiDeclaration)a;

                foreach (var idecl in d.InitDeclarators)
                {
                    if ((d.Specifiers.StorageClassSpecifier & StorageClassSpecifier.Typedef) != 0)
                    {
                        if (idecl.Declarator != null)
                        {
                            var name = idecl.Declarator.DeclaredIdentifier;
                            //Typedefs[name] = decl;
                        }
                    }
                    else
                    {
                        var ctype = MakeCType(d.Specifiers, idecl.Declarator);
                        var name  = idecl.Declarator.DeclaredIdentifier;

                        if (ctype is CFunctionType && !HasStronglyBoundPointer(idecl.Declarator))
                        {
                            var ftype = (CFunctionType)ctype;
                            var f     = new FunctionDeclaration(name, ftype);

                            for (var i = 0; i < ftype.Parameters.Count; i++)
                            {
                                f.ParameterInfos[i].Name = ftype.Parameters[i].Name;
                            }

                            block.AddFunction(f);
                        }
                        else
                        {
                            if ((ctype is CArrayType) &&
                                (((CArrayType)ctype).LengthExpression == null) &&
                                (idecl.Initializer != null))
                            {
                                if (idecl.Initializer is StructuredInitializer)
                                {
                                    var atype = (CArrayType)ctype;
                                    var len   = 0;
                                    foreach (var i in ((StructuredInitializer)idecl.Initializer).Initializers)
                                    {
                                        if (i.Designation == null)
                                        {
                                            len++;
                                        }
                                        else
                                        {
                                            foreach (var de in i.Designation.Designators)
                                            {
                                                // TODO: Pay attention to designators
                                                len++;
                                            }
                                        }
                                    }
                                    atype.LengthExpression = new ConstantExpression(len);
                                }
                                else
                                {
                                    //Report.Error();
                                }
                            }
                            //var init = GetInitExpression(idecl.Initializer);
                            var vdecl = new VariableDeclaration(name, ctype);
                            block.AddVariable(vdecl);
                        }

                        if (idecl.Initializer != null)
                        {
                            var varExpr  = new VariableExpression(name);
                            var initExpr = GetInitializerExpression(idecl.Initializer);
                            block.AddStatement(new ExpressionStatement(new AssignExpression(varExpr, initExpr)));
                        }
                    }
                }
            }
            else if (a is FunctionDefinition)
            {
                var fdef = (FunctionDefinition)a;

                var ftype = (CFunctionType)MakeCType(fdef.Specifiers, fdef.Declarator);
                var name  = fdef.Declarator.DeclaredIdentifier;

                var f = new FunctionDeclaration(name, ftype);

                for (var i = 0; i < ftype.Parameters.Count; i++)
                {
                    f.ParameterInfos[i].Name = ftype.Parameters[i].Name;
                }

                f.Body = fdef.Body;

                block.AddFunction(f);
            }
        }