Replace main_fndecl with current_function_decl
This commit is contained in:
77
source.elna
77
source.elna
@ -174,14 +174,12 @@ begin
|
||||
return c = ' ' or c = '\n' or c = '\t'
|
||||
end
|
||||
|
||||
proc string_equals_chars(this: String, that: pointer to Char, length: Word): Bool;
|
||||
var
|
||||
i: Word;
|
||||
proc string_equals(this: String, that: String): Bool;
|
||||
begin
|
||||
if this.length <> length then
|
||||
if this.length <> that.length then
|
||||
return false
|
||||
end;
|
||||
return strncmp(this.ptr, that, length) = 0
|
||||
return strncmp(this.ptr, that.ptr, this.length) = 0
|
||||
end
|
||||
|
||||
proc open_substring(string: String, start: Word): String;
|
||||
@ -482,7 +480,7 @@ begin
|
||||
write_s("SIZEOF")
|
||||
elsif current_token^.kind = TOKEN_IDENTIFIER then
|
||||
write_c('<');
|
||||
write_z(current_token^.value.string_value);
|
||||
write_s(current_token^.value.string);
|
||||
write_c('>')
|
||||
elsif current_token^.kind = TOKEN_LEFT_PAREN then
|
||||
write_s("(")
|
||||
@ -558,76 +556,75 @@ begin
|
||||
write_c('\n')
|
||||
end
|
||||
|
||||
proc categorize_identifier(input_pointer: pointer to Char, token_length: Int): Token;
|
||||
proc categorize_identifier(token_content: String): Token;
|
||||
var
|
||||
current_token: Token;
|
||||
begin
|
||||
if string_equals_chars("if", input_pointer, token_length) then
|
||||
if string_equals("if", token_content) then
|
||||
current_token.kind := TOKEN_IF
|
||||
elsif string_equals_chars("then", input_pointer, token_length) then
|
||||
elsif string_equals("then", token_content) then
|
||||
current_token.kind := TOKEN_THEN
|
||||
elsif string_equals_chars("else", input_pointer, token_length) then
|
||||
elsif string_equals("else", token_content) then
|
||||
current_token.kind := TOKEN_ELSE
|
||||
elsif string_equals_chars("elsif", input_pointer, token_length) then
|
||||
elsif string_equals("elsif", token_content) then
|
||||
current_token.kind := TOKEN_ELSIF
|
||||
elsif string_equals_chars("while", input_pointer, token_length) then
|
||||
elsif string_equals("while", token_content) then
|
||||
current_token.kind := TOKEN_WHILE
|
||||
elsif string_equals_chars("do", input_pointer, token_length) then
|
||||
elsif string_equals("do", token_content) then
|
||||
current_token.kind := TOKEN_DO
|
||||
elsif string_equals_chars("proc", input_pointer, token_length) then
|
||||
elsif string_equals("proc", token_content) then
|
||||
current_token.kind := TOKEN_PROC
|
||||
elsif string_equals_chars("begin", input_pointer, token_length) then
|
||||
elsif string_equals("begin", token_content) then
|
||||
current_token.kind := TOKEN_BEGIN
|
||||
elsif string_equals_chars("end", input_pointer, token_length) then
|
||||
elsif string_equals("end", token_content) then
|
||||
current_token.kind := TOKEN_END
|
||||
elsif string_equals_chars("extern", input_pointer, token_length) then
|
||||
elsif string_equals("extern", token_content) then
|
||||
current_token.kind := TOKEN_EXTERN
|
||||
elsif string_equals_chars("const", input_pointer, token_length) then
|
||||
elsif string_equals("const", token_content) then
|
||||
current_token.kind := TOKEN_CONST
|
||||
elsif string_equals_chars("var", input_pointer, token_length) then
|
||||
elsif string_equals("var", token_content) then
|
||||
current_token.kind := TOKEN_VAR
|
||||
elsif string_equals_chars("array", input_pointer, token_length) then
|
||||
elsif string_equals("array", token_content) then
|
||||
current_token.kind := TOKEN_ARRAY
|
||||
elsif string_equals_chars("of", input_pointer, token_length) then
|
||||
elsif string_equals("of", token_content) then
|
||||
current_token.kind := TOKEN_OF
|
||||
elsif string_equals_chars("type", input_pointer, token_length) then
|
||||
elsif string_equals("type", token_content) then
|
||||
current_token.kind := TOKEN_TYPE
|
||||
elsif string_equals_chars("record", input_pointer, token_length) then
|
||||
elsif string_equals("record", token_content) then
|
||||
current_token.kind := TOKEN_RECORD
|
||||
elsif string_equals_chars("union", input_pointer, token_length) then
|
||||
elsif string_equals("union", token_content) then
|
||||
current_token.kind := TOKEN_UNION
|
||||
elsif string_equals_chars("pointer", input_pointer, token_length) then
|
||||
elsif string_equals("pointer", token_content) then
|
||||
current_token.kind := TOKEN_POINTER
|
||||
elsif string_equals_chars("to", input_pointer, token_length) then
|
||||
elsif string_equals("to", token_content) then
|
||||
current_token.kind := TOKEN_TO
|
||||
elsif string_equals_chars("true", input_pointer, token_length) then
|
||||
elsif string_equals("true", token_content) then
|
||||
current_token.kind := TOKEN_BOOLEAN;
|
||||
current_token.value.boolean_value := true
|
||||
elsif string_equals_chars("false", input_pointer, token_length) then
|
||||
elsif string_equals("false", token_content) then
|
||||
current_token.kind := TOKEN_BOOLEAN;
|
||||
current_token.value.boolean_value := false
|
||||
elsif string_equals_chars("nil", input_pointer, token_length) then
|
||||
elsif string_equals("nil", token_content) then
|
||||
current_token.kind := TOKEN_NIL
|
||||
elsif string_equals_chars("and", input_pointer, token_length) then
|
||||
elsif string_equals("and", token_content) then
|
||||
current_token.kind := TOKEN_AND
|
||||
elsif string_equals_chars("or", input_pointer, token_length) then
|
||||
elsif string_equals("or", token_content) then
|
||||
current_token.kind := TOKEN_OR
|
||||
elsif string_equals_chars("not", input_pointer, token_length) then
|
||||
elsif string_equals("not", token_content) then
|
||||
current_token.kind := TOKEN_NOT
|
||||
elsif string_equals_chars("return", input_pointer, token_length) then
|
||||
elsif string_equals("return", token_content) then
|
||||
current_token.kind := TOKEN_RETURN
|
||||
elsif string_equals_chars("cast", input_pointer, token_length) then
|
||||
elsif string_equals("cast", token_content) then
|
||||
current_token.kind := TOKEN_CAST
|
||||
elsif string_equals_chars("as", input_pointer, token_length) then
|
||||
elsif string_equals("as", token_content) then
|
||||
current_token.kind := TOKEN_AS
|
||||
elsif string_equals_chars("sizeof", input_pointer, token_length) then
|
||||
elsif string_equals("sizeof", token_content) then
|
||||
current_token.kind := TOKEN_SIZEOF
|
||||
elsif string_equals_chars("defer", input_pointer, token_length) then
|
||||
elsif string_equals("defer", token_content) then
|
||||
current_token.kind := TOKEN_DEFER
|
||||
else
|
||||
current_token.kind := TOKEN_IDENTIFIER;
|
||||
current_token.value.string_value := cast(calloc(token_length + 1, 1) as pointer to Char);
|
||||
strncpy(current_token.value.string_value, input_pointer, token_length)
|
||||
current_token.value.string := string_dup(token_content)
|
||||
end;
|
||||
|
||||
return current_token
|
||||
@ -653,7 +650,7 @@ begin
|
||||
|
||||
if is_alpha(first_char) or first_char = '_' then
|
||||
lex_identifier(@source_code, @token_content);
|
||||
current_token^ := categorize_identifier(token_content.ptr, token_content.length);
|
||||
current_token^ := categorize_identifier(token_content);
|
||||
|
||||
source_code := advance_source(source_code, 1u)
|
||||
elsif is_digit(first_char) then
|
||||
|
Reference in New Issue
Block a user