aboutsummaryrefslogtreecommitdiff
path: root/decl.go
blob: 53c6c7472dc2e75264b71720a354689e6f90e9bc (plain) (blame)
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
// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
//
// SPDX-License-Identifier: GPL-3.0-or-later

package main

var funcs = map[string]*funcInfo{}
var localConsts = map[string]map[string]*localConst{}
var localMuts = map[string]map[string]*localMut{}

type funcInfo struct {
	params     []paramInfo
	returnType cerType
}

type paramInfo struct {
	typ cerType
}

type localConst struct {
	typ cerType
}

type localMut struct {
	typ cerType
}

func isDeclared(name string, toplevel bool) (ok bool, mutable bool) {
	if toplevel {
		return isDeclaredToplevel(name)
	}

	return isDeclaredLocal(currentFunc, name)
}

func isDeclaredToplevel(name string) (ok bool, mutable bool) {
	_, ok = funcs[name]
	return
}

func isDeclaredLocal(function string, local string) (ok bool, mutable bool) {
	_, constant := localConsts[function][local]
	_, mutable = localMuts[function][local]
	return constant || mutable, mutable
}