Zen-C
Loading...
Searching...
No Matches
parser_utils.c File Reference
#include "../codegen/codegen.h"
#include "../plugins/plugin_manager.h"
#include "parser.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for parser_utils.c:

Functions

void instantiate_methods (ParserContext *ctx, GenericImplTemplate *it, const char *mangled_struct_name, const char *arg, const char *unmangled_arg)
 
Token expect (Lexer *l, TokenType type, const char *msg)
 Expects a token of a specific type.
 
int is_token (Token t, const char *s)
 Checks if a token matches a string.
 
char * token_strdup (Token t)
 Duplicates a token.
 
void skip_comments (Lexer *l)
 Skips comments in the lexer.
 
int is_c_reserved_word (const char *name)
 Checks if a name is a C reserved word.
 
void warn_c_reserved_word (Token t, const char *name)
 Warns about a C reserved word.
 
char * consume_until_semicolon (Lexer *l)
 Consumes tokens until a semicolon is found.
 
void enter_scope (ParserContext *ctx)
 Enters a new scope (pushes to scope stack).
 
void exit_scope (ParserContext *ctx)
 Exits the current scope (pops from scope stack).
 
void add_symbol (ParserContext *ctx, const char *n, const char *t, Type *type_info)
 Adds a symbol to the current scope.
 
void add_symbol_with_token (ParserContext *ctx, const char *n, const char *t, Type *type_info, Token tok)
 Adds a symbol with definition token location.
 
Typefind_symbol_type_info (ParserContext *ctx, const char *n)
 Finds a symbol's type information.
 
char * find_symbol_type (ParserContext *ctx, const char *n)
 Finds a symbol's type.
 
ZenSymbolfind_symbol_entry (ParserContext *ctx, const char *n)
 Finds a symbol's entry.
 
ZenSymbolfind_symbol_in_all (ParserContext *ctx, const char *n)
 Finds a symbol in all scopes.
 
void init_builtins ()
 Initializes built-in types and symbols.
 
void register_func (ParserContext *ctx, const char *name, int count, char **defaults, Type **arg_types, Type *ret_type, int is_varargs, int is_async, Token decl_token)
 Registers a function.
 
void register_func_template (ParserContext *ctx, const char *name, const char *param, ASTNode *node)
 Registers a function template.
 
void register_deprecated_func (ParserContext *ctx, const char *name, const char *reason)
 Registers a deprecated function.
 
DeprecatedFuncfind_deprecated_func (ParserContext *ctx, const char *name)
 Finds a deprecated function.
 
GenericFuncTemplatefind_func_template (ParserContext *ctx, const char *name)
 Finds a function template.
 
void register_generic (ParserContext *ctx, char *name)
 Registers a known generic type parameter.
 
int is_known_generic (ParserContext *ctx, char *name)
 Checks if a name is a known generic parameter.
 
void register_impl_template (ParserContext *ctx, const char *sname, const char *param, ASTNode *node)
 
void add_to_struct_list (ParserContext *ctx, ASTNode *node)
 
void register_type_alias (ParserContext *ctx, const char *alias, const char *original, int is_opaque, const char *defined_in_file)
 
const char * find_type_alias (ParserContext *ctx, const char *alias)
 Finds a type alias.
 
TypeAliasfind_type_alias_node (ParserContext *ctx, const char *alias)
 Registers a type alias.
 
void add_to_enum_list (ParserContext *ctx, ASTNode *node)
 
void add_to_func_list (ParserContext *ctx, ASTNode *node)
 
void add_to_impl_list (ParserContext *ctx, ASTNode *node)
 
void add_to_global_list (ParserContext *ctx, ASTNode *node)
 
void register_builtins (ParserContext *ctx)
 
void add_instantiated_func (ParserContext *ctx, ASTNode *fn)
 
void register_enum_variant (ParserContext *ctx, const char *ename, const char *vname, int tag)
 Registers an enum variant.
 
EnumVariantRegfind_enum_variant (ParserContext *ctx, const char *vname)
 Finds an enum variant.
 
void register_lambda (ParserContext *ctx, ASTNode *node)
 Registers a lambda.
 
void register_extern_symbol (ParserContext *ctx, const char *name)
 Registers an external symbol.
 
int is_extern_symbol (ParserContext *ctx, const char *name)
 Checks if a symbol is external.
 
int should_suppress_undef_warning (ParserContext *ctx, const char *name)
 Checks if a symbol should suppress an undefined warning.
 
void register_slice (ParserContext *ctx, const char *type)
 Registers a slice type.
 
void register_tuple (ParserContext *ctx, const char *sig)
 Registers a tuple type.
 
void register_struct_def (ParserContext *ctx, const char *name, ASTNode *node)
 Registers a struct definition.
 
ASTNodefind_struct_def (ParserContext *ctx, const char *name)
 Finds a struct definition.
 
Modulefind_module (ParserContext *ctx, const char *alias)
 Finds a module.
 
void register_module (ParserContext *ctx, const char *alias, const char *path)
 Registers a module.
 
void register_selective_import (ParserContext *ctx, const char *symbol, const char *alias, const char *source_module)
 Registers a selective import.
 
SelectiveImportfind_selective_import (ParserContext *ctx, const char *name)
 Finds a selective import.
 
char * extract_module_name (const char *path)
 
int is_ident_char (char c)
 
ASTNodecopy_fields (ASTNode *fields)
 
char * replace_in_string (const char *src, const char *old_w, const char *new_w)
 Replaces a substring in a string.
 
char * replace_type_str (const char *src, const char *param, const char *concrete, const char *old_struct, const char *new_struct)
 Replaces a type string in a string.
 
ASTNodecopy_ast_replacing (ASTNode *n, const char *p, const char *c, const char *os, const char *ns)
 Copies an AST node and replaces its type parameters.
 
Typetype_from_string_helper (const char *c)
 
Typereplace_type_formal (Type *t, const char *p, const char *c, const char *os, const char *ns)
 Replaces a type formal in a type.
 
char * replace_mangled_part (const char *src, const char *param, const char *concrete)
 
char * sanitize_mangled_name (const char *s)
 Sanitizes a mangled name for use in codegen.
 
char * unmangle_ptr_suffix (const char *s)
 
FuncSigfind_func (ParserContext *ctx, const char *name)
 Finds a function.
 
char * instantiate_function_template (ParserContext *ctx, const char *name, const char *concrete_type, const char *unmangled_type)
 Instantiates a function template.
 
char * process_fstring (ParserContext *ctx, const char *content, char ***used_syms, int *count)
 Processes a formatted string.
 
void register_impl (ParserContext *ctx, const char *trait, const char *strct)
 Registers an implementation.
 
int check_impl (ParserContext *ctx, const char *trait, const char *strct)
 Checks if a type implements a trait.
 
void register_template (ParserContext *ctx, const char *name, ASTNode *node)
 Registers a template.
 
ASTNodecopy_fields_replacing (ParserContext *ctx, ASTNode *fields, const char *param, const char *concrete)
 
void instantiate_generic (ParserContext *ctx, const char *tpl, const char *arg, const char *unmangled_arg, Token token)
 Instantiates a generic struct/function.
 
void instantiate_generic_multi (ParserContext *ctx, const char *tpl, char **args, int arg_count, Token token)
 Instantiates a multi-parameter generic.
 
int is_file_imported (ParserContext *ctx, const char *p)
 Checks if a file has been imported.
 
void mark_file_imported (ParserContext *ctx, const char *p)
 Marks a file as imported.
 
char * parse_condition_raw (ParserContext *ctx, Lexer *l)
 Parses a condition.
 
char * rewrite_expr_methods (ParserContext *ctx, char *raw)
 Rewrites expression methods.
 
char * consume_and_rewrite (ParserContext *ctx, Lexer *l)
 Consumes and rewrites tokens.
 
char * parse_and_convert_args (ParserContext *ctx, Lexer *l, char ***defaults_out, int *count_out, Type ***types_out, char ***names_out, int *is_varargs_out, char ***ctype_overrides_out)
 Parses and converts arguments.
 
char * find_similar_symbol (ParserContext *ctx, const char *name)
 
void register_plugin (ParserContext *ctx, const char *name, const char *alias)
 Registers a plugin.
 
const char * resolve_plugin (ParserContext *ctx, const char *name_or_alias)
 Resolves a plugin by name or alias.
 
void register_type_usage (ParserContext *ctx, const char *name, Token t)
 Registers a type usage.
 
int validate_types (ParserContext *ctx)
 Validates types.
 

Function Documentation

◆ add_instantiated_func()

void add_instantiated_func ( ParserContext ctx,
ASTNode fn 
)
Here is the caller graph for this function:

◆ add_symbol()

void add_symbol ( ParserContext ctx,
const char *  n,
const char *  t,
Type type_info 
)

Adds a symbol to the current scope.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_symbol_with_token()

void add_symbol_with_token ( ParserContext ctx,
const char *  n,
const char *  t,
Type type_info,
Token  tok 
)

Adds a symbol with definition token location.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_enum_list()

void add_to_enum_list ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_func_list()

void add_to_func_list ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_global_list()

void add_to_global_list ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_impl_list()

void add_to_impl_list ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_struct_list()

void add_to_struct_list ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_impl()

int check_impl ( ParserContext ctx,
const char *  trait,
const char *  strct 
)

Checks if a type implements a trait.

Here is the caller graph for this function:

◆ consume_and_rewrite()

char * consume_and_rewrite ( ParserContext ctx,
Lexer l 
)

Consumes and rewrites tokens.

Here is the call graph for this function:

◆ consume_until_semicolon()

char * consume_until_semicolon ( Lexer l)

Consumes tokens until a semicolon is found.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_ast_replacing()

ASTNode * copy_ast_replacing ( ASTNode n,
const char *  p,
const char *  c,
const char *  os,
const char *  ns 
)

Copies an AST node and replaces its type parameters.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_fields()

ASTNode * copy_fields ( ASTNode fields)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_fields_replacing()

ASTNode * copy_fields_replacing ( ParserContext ctx,
ASTNode fields,
const char *  param,
const char *  concrete 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_scope()

void enter_scope ( ParserContext ctx)

Enters a new scope (pushes to scope stack).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exit_scope()

void exit_scope ( ParserContext ctx)

Exits the current scope (pops from scope stack).

Here is the caller graph for this function:

◆ expect()

Token expect ( Lexer l,
TokenType  type,
const char *  msg 
)

Expects a token of a specific type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_module_name()

char * extract_module_name ( const char *  path)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_deprecated_func()

DeprecatedFunc * find_deprecated_func ( ParserContext ctx,
const char *  name 
)

Finds a deprecated function.

◆ find_enum_variant()

EnumVariantReg * find_enum_variant ( ParserContext ctx,
const char *  vname 
)

Finds an enum variant.

Here is the caller graph for this function:

◆ find_func()

FuncSig * find_func ( ParserContext ctx,
const char *  name 
)

Finds a function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_func_template()

GenericFuncTemplate * find_func_template ( ParserContext ctx,
const char *  name 
)

Finds a function template.

Here is the caller graph for this function:

◆ find_module()

Module * find_module ( ParserContext ctx,
const char *  alias 
)

Finds a module.

Here is the caller graph for this function:

◆ find_selective_import()

SelectiveImport * find_selective_import ( ParserContext ctx,
const char *  name 
)

Finds a selective import.

Here is the caller graph for this function:

◆ find_similar_symbol()

char * find_similar_symbol ( ParserContext ctx,
const char *  name 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_struct_def()

ASTNode * find_struct_def ( ParserContext ctx,
const char *  name 
)

Finds a struct definition.

Here is the caller graph for this function:

◆ find_symbol_entry()

ZenSymbol * find_symbol_entry ( ParserContext ctx,
const char *  n 
)

Finds a symbol's entry.

Here is the caller graph for this function:

◆ find_symbol_in_all()

ZenSymbol * find_symbol_in_all ( ParserContext ctx,
const char *  n 
)

Finds a symbol in all scopes.

Here is the caller graph for this function:

◆ find_symbol_type()

char * find_symbol_type ( ParserContext ctx,
const char *  n 
)

Finds a symbol's type.

Here is the caller graph for this function:

◆ find_symbol_type_info()

Type * find_symbol_type_info ( ParserContext ctx,
const char *  n 
)

Finds a symbol's type information.

Here is the caller graph for this function:

◆ find_type_alias()

const char * find_type_alias ( ParserContext ctx,
const char *  alias 
)

Finds a type alias.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_type_alias_node()

TypeAlias * find_type_alias_node ( ParserContext ctx,
const char *  alias 
)

Registers a type alias.

Here is the caller graph for this function:

◆ init_builtins()

void init_builtins ( )

Initializes built-in types and symbols.

Here is the caller graph for this function:

◆ instantiate_function_template()

char * instantiate_function_template ( ParserContext ctx,
const char *  name,
const char *  concrete_type,
const char *  unmangled_type 
)

Instantiates a function template.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instantiate_generic()

void instantiate_generic ( ParserContext ctx,
const char *  tpl,
const char *  arg,
const char *  unmangled_arg,
Token  token 
)

Instantiates a generic struct/function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instantiate_generic_multi()

void instantiate_generic_multi ( ParserContext ctx,
const char *  tpl,
char **  args,
int  arg_count,
Token  token 
)

Instantiates a multi-parameter generic.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instantiate_methods()

void instantiate_methods ( ParserContext ctx,
GenericImplTemplate it,
const char *  mangled_struct_name,
const char *  arg,
const char *  unmangled_arg 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_c_reserved_word()

int is_c_reserved_word ( const char *  name)

Checks if a name is a C reserved word.

Here is the caller graph for this function:

◆ is_extern_symbol()

int is_extern_symbol ( ParserContext ctx,
const char *  name 
)

Checks if a symbol is external.

Here is the caller graph for this function:

◆ is_file_imported()

int is_file_imported ( ParserContext ctx,
const char *  p 
)

Checks if a file has been imported.

Here is the caller graph for this function:

◆ is_ident_char()

int is_ident_char ( char  c)
Here is the caller graph for this function:

◆ is_known_generic()

int is_known_generic ( ParserContext ctx,
char *  name 
)

Checks if a name is a known generic parameter.

Here is the caller graph for this function:

◆ is_token()

int is_token ( Token  t,
const char *  s 
)

Checks if a token matches a string.

Here is the caller graph for this function:

◆ mark_file_imported()

void mark_file_imported ( ParserContext ctx,
const char *  p 
)

Marks a file as imported.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_and_convert_args()

char * parse_and_convert_args ( ParserContext ctx,
Lexer l,
char ***  defaults_out,
int *  count_out,
Type ***  types_out,
char ***  names_out,
int *  is_varargs_out,
char ***  ctype_overrides_out 
)

Parses and converts arguments.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_condition_raw()

char * parse_condition_raw ( ParserContext ctx,
Lexer l 
)

Parses a condition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_fstring()

char * process_fstring ( ParserContext ctx,
const char *  content,
char ***  used_syms,
int *  count 
)

Processes a formatted string.

Here is the call graph for this function:

◆ register_builtins()

void register_builtins ( ParserContext ctx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_deprecated_func()

void register_deprecated_func ( ParserContext ctx,
const char *  name,
const char *  reason 
)

Registers a deprecated function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_enum_variant()

void register_enum_variant ( ParserContext ctx,
const char *  ename,
const char *  vname,
int  tag 
)

Registers an enum variant.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_extern_symbol()

void register_extern_symbol ( ParserContext ctx,
const char *  name 
)

Registers an external symbol.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_func()

void register_func ( ParserContext ctx,
const char *  name,
int  count,
char **  defaults,
Type **  arg_types,
Type ret_type,
int  is_varargs,
int  is_async,
Token  decl_token 
)

Registers a function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_func_template()

void register_func_template ( ParserContext ctx,
const char *  name,
const char *  param,
ASTNode node 
)

Registers a function template.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_generic()

void register_generic ( ParserContext ctx,
char *  name 
)

Registers a known generic type parameter.

Here is the caller graph for this function:

◆ register_impl()

void register_impl ( ParserContext ctx,
const char *  trait,
const char *  strct 
)

Registers an implementation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_impl_template()

void register_impl_template ( ParserContext ctx,
const char *  sname,
const char *  param,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_lambda()

void register_lambda ( ParserContext ctx,
ASTNode node 
)

Registers a lambda.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_module()

void register_module ( ParserContext ctx,
const char *  alias,
const char *  path 
)

Registers a module.

Here is the call graph for this function:

◆ register_plugin()

void register_plugin ( ParserContext ctx,
const char *  name,
const char *  alias 
)

Registers a plugin.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_selective_import()

void register_selective_import ( ParserContext ctx,
const char *  symbol,
const char *  alias,
const char *  source_module 
)

Registers a selective import.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_slice()

void register_slice ( ParserContext ctx,
const char *  type 
)

Registers a slice type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_struct_def()

void register_struct_def ( ParserContext ctx,
const char *  name,
ASTNode node 
)

Registers a struct definition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_template()

void register_template ( ParserContext ctx,
const char *  name,
ASTNode node 
)

Registers a template.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_tuple()

void register_tuple ( ParserContext ctx,
const char *  sig 
)

Registers a tuple type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_type_alias()

void register_type_alias ( ParserContext ctx,
const char *  alias,
const char *  original,
int  is_opaque,
const char *  defined_in_file 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_type_usage()

void register_type_usage ( ParserContext ctx,
const char *  name,
Token  t 
)

Registers a type usage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_in_string()

char * replace_in_string ( const char *  src,
const char *  old_w,
const char *  new_w 
)

Replaces a substring in a string.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_mangled_part()

char * replace_mangled_part ( const char *  src,
const char *  param,
const char *  concrete 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_type_formal()

Type * replace_type_formal ( Type t,
const char *  p,
const char *  c,
const char *  os,
const char *  ns 
)

Replaces a type formal in a type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_type_str()

char * replace_type_str ( const char *  src,
const char *  param,
const char *  concrete,
const char *  old_struct,
const char *  new_struct 
)

Replaces a type string in a string.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolve_plugin()

const char * resolve_plugin ( ParserContext ctx,
const char *  name_or_alias 
)

Resolves a plugin by name or alias.

Here is the caller graph for this function:

◆ rewrite_expr_methods()

char * rewrite_expr_methods ( ParserContext ctx,
char *  raw 
)

Rewrites expression methods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sanitize_mangled_name()

char * sanitize_mangled_name ( const char *  s)

Sanitizes a mangled name for use in codegen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ should_suppress_undef_warning()

int should_suppress_undef_warning ( ParserContext ctx,
const char *  name 
)

Checks if a symbol should suppress an undefined warning.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skip_comments()

void skip_comments ( Lexer l)

Skips comments in the lexer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ token_strdup()

char * token_strdup ( Token  t)

Duplicates a token.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type_from_string_helper()

Type * type_from_string_helper ( const char *  c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmangle_ptr_suffix()

char * unmangle_ptr_suffix ( const char *  s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_types()

int validate_types ( ParserContext ctx)

Validates types.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warn_c_reserved_word()

void warn_c_reserved_word ( Token  t,
const char *  name 
)

Warns about a C reserved word.

Here is the call graph for this function:
Here is the caller graph for this function: