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

package main

var funcs = map[string]struct{}{}
var localConsts = map[string]map[string]string{}
var localMuts = map[string]map[string]struct{}{}

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
}