Beispiel #1
0
        public CStatment GetDefinitionStatment()
        {
            CStatment.BeginCompoundStatement();

            int stats = 0;

            foreach (CIdentifier ident in idents)
            {
                if (ident.Init != null)
                {
                    CStatment.PushStatement(ident.GetDefinitionStatment());
                    stats++;
                }
            }

            List <CCompoundStatmentItemType> items = new List <CCompoundStatmentItemType>();

            for (int i = 0; i < stats; i++)
            {
                items.Add(CCompoundStatmentItemType.Statment);
            }

            CStatment.EndCompoundStatement(items);

            return(CStatment.PopStatement());
        }
Beispiel #2
0
        internal static void DefineFunction(CType signature, string name, CStorageClass cStorageClass)
        {
            //cStorageClass (static, extern, or none)
            //ignore for now

            if (currentFunctionScope != null || BlockScopes.Count > 0)
            {
                throw new SemanticException("can only define function at file scope");
            }
            else
            {
                if (fileScope.ContainsKey(name))
                {
                    if (fileScope[name].functionBody == null && fileScope[name].type.Equals(signature))
                    {
                        fileScope[name].functionBody = CStatment.PopStatement();
                    }
                    else
                    {
                        throw new SemanticException("canot redifein function");
                    }
                }
                else
                {
                    fileScope[name] = new CIdentifier(signature, name, CStatment.PopStatement());
                }
            }
        }