实现 12.7 类型检查:表达式类型、语句规则、FUNCTION 禁写全局。
- Typecheck.h/cpp:三型(BOOL/INT/TIME)求值,AND/OR/NOT 只吃 BOOL、算术只吃 INT(TIME 无算术)、比较同型、IF/WHILE 条件必须 BOOL - FUNCTION 禁写全局(含经 VAR_EXTERNAL)——用例 14 点亮;函数名赋值=返回类型 - FB 命名实参匹配字段类型;FB 实例不能当值 - typecheck_test:23 断言(用例 14 + 8 类负例 + 13 个正例),ctest 8/8
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @file Typecheck.h
|
||||
* @brief 类型检查
|
||||
* @author
|
||||
* @date 2026-08-21
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "compiler/Linker.h"
|
||||
#include "compiler/Parser.h"
|
||||
#include "compiler/Project.h"
|
||||
|
||||
namespace compiler {
|
||||
|
||||
// 表达式求值类型(v1 三型,无隐式宽化)
|
||||
enum class TType { Bool, Int, Time };
|
||||
|
||||
// 对工程做类型检查(在链接成功后调用)。
|
||||
// 规则见 Doc/compiler/类型检查.md。失败返回 false,err 前缀 "type error"。
|
||||
bool check_project(const Project& proj, const std::vector<SourceUnit>& units,
|
||||
const LinkResult& link, std::string* err);
|
||||
}
|
||||
Reference in New Issue
Block a user