aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/patio/PatioFunctionDeclaration.java
blob: 18241108ec7ebaa5690a96a9d06d4921e2f5b779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.shedlang.compiler.patio;

import org.pcollections.PVector;
import org.shedlang.compiler.patio.types.PatioType;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.util.P;

import java.util.List;

public record PatioFunctionDeclaration(
    String name,
    List<PatioLocal> params,
    List<PatioType> returnTypes,
    Source source
) implements PatioCompilationUnitElement {
    public static Builder builder() {
        return new Builder(
            "f",
            P.vector(),
            P.vector()
        );
    }

    public record Builder(
        String name,
        PVector<PatioLocal> params,
        PVector<PatioType> returnTypes
    ) {
        public Builder withName(String name) {
            return new Builder(
                name,
                this.params,
                this.returnTypes
            );
        }

        public Builder addParam(PatioLocal param) {
            return new Builder(
                this.name,
                this.params.plus(param),
                this.returnTypes
            );
        }

        public Builder addReturnType(PatioType returnType) {
            return new Builder(
                this.name,
                this.params,
                this.returnTypes.plus(returnType)
            );
        }

        public PatioFunctionDeclaration build() {
            return new PatioFunctionDeclaration(
                this.name,
                this.params,
                this.returnTypes,
                Sources.NULL
            );
        }
    }
}