pub(crate) fn process_function_header(
    func_def: &YulFunctionDefinition,
    functions_table: &mut FunctionsTable,
    ns: &mut Namespace,
) {
    if let Some(defined_func) = functions_table.find(&func_def.id.name) {
        ns.diagnostics.push(Diagnostic {
            level: Level::Error,
            ty: ErrorType::DeclarationError,
            pos: func_def.id.loc,
            message: format!("function '{}' is already defined", func_def.id.name),
            notes: vec![Note {
                pos: defined_func.id.loc,
                message: "found definition here".to_string(),
            }],
        });
        return;
    } else if parse_builtin_keyword(&func_def.id.name).is_some()
        || yul_unsupported_builtin(&func_def.id.name)
    {
        ns.diagnostics.push(Diagnostic::error(
            func_def.loc,
            format!(
                "function '{}' is a built-in function and cannot be redefined",
                func_def.id.name
            ),
        ));
        return;
    } else if func_def.id.name.starts_with("verbatim") {
        ns.diagnostics.push(Diagnostic::error(
            func_def.id.loc,
            "the prefix 'verbatim' is reserved for verbatim functions".to_string(),
        ));
        return;
    }

    let params = process_parameters(&func_def.params, ns);
    let returns = process_parameters(&func_def.returns, ns);

    if let Some(diagnostic) = functions_table.add_function_header(&func_def.id, params, returns) {
        ns.diagnostics.push(diagnostic);
    }
}
/// Resolve the function header of a declaration and add it to the functions table
Resolve the function header of a declaration and add it to the functions table
Resolve the function header of a declaration and add it to the functions table
pub(crate) fn process_function_header(
    func_def: &YulFunctionDefinition,
    functions_table: &mut FunctionsTable,
    ns: &mut Namespace,
) {
    if let Some(defined_func) = functions_table.find(&func_def.id.name) {
        ns.diagnostics.push(Diagnostic {
            level: Level::Error,
            ty: ErrorType::DeclarationError,
            pos: func_def.id.loc,
            message: format!("function '{}' is already defined", func_def.id.name),
            notes: vec![Note {
                pos: defined_func.id.loc,
                message: "found definition here".to_string(),
            }],
        });
        return;
    } else if parse_builtin_keyword(&func_def.id.name).is_some()
        || yul_unsupported_builtin(&func_def.id.name)
    {
        ns.diagnostics.push(Diagnostic::error(
            func_def.loc,
            format!(
                "function '{}' is a built-in function and cannot be redefined",
                func_def.id.name
            ),
        ));
        return;
    } else if func_def.id.name.starts_with("verbatim") {
        ns.diagnostics.push(Diagnostic::error(
            func_def.id.loc,
            "the prefix 'verbatim' is reserved for verbatim functions".to_string(),
        ));
        return;
    }
    let params = process_parameters(&func_def.params, ns);
    let returns = process_parameters(&func_def.returns, ns);
    if let Some(diagnostic) = functions_table.add_function_header(&func_def.id, params, returns) {
        ns.diagnostics.push(diagnostic);
    }
}
pub ( crate ) fn process_function_header ( func_def : & YulFunctionDefinition , functions_table : & mut FunctionsTable , ns : & mut Namespace , ) { if let Some ( defined_func ) = functions_table . find ( & func_def . id . name ) { ns . diagnostics . push ( Diagnostic { level : Level :: Error , ty : ErrorType :: DeclarationError , pos : func_def . id . loc , message : format ! ( " " func_def id name ) , notes : vec ! [ Note { pos defined_func id loc message " " to_string ( ) } ] , } ) ; return ; } else if parse_builtin_keyword ( & func_def . id . name ) . is_some ( ) || yul_unsupported_builtin ( & func_def . id . name ) { ns . diagnostics . push ( Diagnostic :: error ( func_def . loc , format ! ( " " func_def id name ) , ) ) ; return ; } else if func_def . id . name . starts_with ( " " ) { ns . diagnostics . push ( Diagnostic :: error ( func_def . id . loc , " " . to_string ( ) , ) ) ; return ; } let params = process_parameters ( & func_def . params , ns ) ; let returns = process_parameters ( & func_def . returns , ns ) ; if let Some ( diagnostic ) = functions_table . add_function_header ( & func_def . id , params , returns ) { ns . diagnostics . push ( diagnostic ) ; } }
Resolve the function header of a declaration and add it to the functions table
Resolve the function header of a declaration and add it to the functions table
func_def
&YulFunctionDefinition
functions_table
&mut FunctionsTable
ns
&mut Namespace
func_def
&YulFunctionDefinition
functions_table
&mut FunctionsTable
ns
&mut Namespace