//1// gravity_semacheck2.h2// gravity3//4// Created by Marco Bambini on 12/09/14.5// Copyright (c) 2014 CreoLabs. All rights reserved.6//78#ifndef __GRAVITY_SEMACHECK2__9#define __GRAVITY_SEMACHECK2__1011#include "gravity_ast.h"12#include "gravity_delegate.h"1314// Responsible to gather and check local identifiers15// Complete check for all identifiers and report not found errors1617bool gravity_semacheck2(gnode_t *node, gravity_delegate_t *delegate);1819/*2021The following table summarizes what can be defined inside a declaration:2223-------+---------------------------------------------------------+24| func | var | enum | class | module |25-------+---------------------------------------------------------+26func | YES | YES | NO | YES | YES |27-------+---------------------------------------------------------+28var | YES | NO | NO | YES | YES |29-------+---------------------------------------------------------+30enum | YES | NO | NO | YES | YES |31-------+---------------------------------------------------------+32class | YES | NO | NO | YES | YES |33-------+---------------------------------------------------------+34module | NO | NO | NO | NO | NO |35-------+---------------------------------------------------------+3637Everything declared inside a func is a local, so for example:3839func foo {40func a...;41enum b...;42class c..;43}4445is converted by codegen to:4647func foo {48var a = func...;49var b = enum...;50var c = class..;51}5253Even if the ONLY valid syntax is anonymous func assignment, user will not be able54to assign an anonymous enum or class to a variable. Restriction is applied by parser55and reported as a syntax error.56Define a module inside a function is not allowed (no real technical reason but I found57it a very bad programming practice), restriction is applied by samantic checker.5859*/606162// TECH NOTE:63// At the end of semacheck2:64//65// Each declaration and compound statement will have its own symbol table (symtable field)66// symtable in:67// NODE_LIST_STAT and NODE_COMPOUND_STAT68// FUNCTION_DECL and FUNCTION_EXPR69// ENUM_DECL70// CLASS_DECL71// MODULE_DECL72//73// Each identifier will have a reference to its declaration (symbol field)74// symbol field in:75// NODE_FILE76// NODE_IDENTIFIER77// NODE_ID78//79// Each declaration will have a reference to its enclosing declaration (env field)80// env field in:81// FUNCTION_DECL and FUNCTION_EXPR82// VARIABLE83// ENUM_DECL84// CLASS_DECL85// MODULE_DECL8687#endif888990