FunctionDefinition
using CLanguage.Compiler;
using CLanguage.Interpreter;
using CLanguage.Types;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace CLanguage.Syntax
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class FunctionDefinition : Statement
{
public DeclarationSpecifiers Specifiers { get; set; }
public Declarator Declarator { get; set; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
public List<Declaration> ParameterDeclarations {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
set;
}
public Block Body { get; set; }
public override bool AlwaysReturns => false;
public FunctionDefinition(DeclarationSpecifiers specifiers, Declarator declarator, [System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})] List<Declaration> parameterDeclarations, Block body)
{
if (specifiers == null)
throw new ArgumentNullException("specifiers");
Specifiers = specifiers;
if (declarator == null)
throw new ArgumentNullException("declarator");
Declarator = declarator;
ParameterDeclarations = parameterDeclarations;
if (body == null)
throw new ArgumentNullException("body");
Body = body;
}
public override void AddDeclarationToBlock(BlockContext context)
{
Block block = context.Block;
CFunctionType cFunctionType = context.MakeCType(Specifiers, Declarator, null, block) as CFunctionType;
if (cFunctionType != null) {
CompiledFunction item = new CompiledFunction(Declarator.DeclaredIdentifier, cFunctionType, Body);
block.Functions.Add(item);
}
}
protected override void DoEmit(EmitContext ec)
{
}
}
}