-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { AstNode } from './node'; | ||
import { AstType } from './expression/type'; | ||
import { stringify } from './../../../../serializer'; | ||
import { AstFunctionArgument } from './function/function_argument'; | ||
|
||
export class AstExtern extends AstNode { | ||
name: string; | ||
args: AstFunctionArgument[]; | ||
return_type: AstType; | ||
generate_name: string; | ||
|
||
constructor(name: string, args: AstFunctionArgument[], return_type: AstType, generate_name: string) { | ||
super("Extern"); | ||
this.name = name; | ||
this.args = args; | ||
this.generate_name = generate_name; | ||
this.return_type = return_type; | ||
} | ||
|
||
stringify(wantsJson: boolean = true): string | object { | ||
const obj: object = { | ||
name: this.name, | ||
args: this.args, | ||
return_type: this.return_type.stringify(false), | ||
generate_name: this.generate_name, | ||
}; | ||
return stringify(obj, wantsJson); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Parser } from './parser'; | ||
import { AstBlock } from './ast/block'; | ||
import { AstExtern } from './ast/extern'; | ||
import { parseType } from './expression/type'; | ||
import { AstType } from './ast/expression/type'; | ||
import { AstFunctionArgument } from './ast/function/function_argument'; | ||
import { parserMessageRenderer } from '../../../common/message/message'; | ||
import { ParserMessageKeys } from '../../../common/message/parser/parser'; | ||
import { parserParseFunctionArguments } from './function/function_attributes'; | ||
import { TokenKeywordType, TokenOperatorType } from '../../lexer/tokenizer/type'; | ||
|
||
export function parserParseExtern(parser: Parser, parent_block: AstBlock): AstExtern | undefined { | ||
parser.expect(TokenKeywordType.TOKEN_EXTERN); | ||
|
||
if (parser.skip(TokenKeywordType.TOKEN_FN)) { | ||
|
||
} | ||
if (! parser.currentToken.isKeyword) { | ||
parser.pushError(parserMessageRenderer(parser.getLanguageId(), ParserMessageKeys.PARSER_FUNCTION_NAME_IS_NOT_VALID_IDENTIFIER)); | ||
return undefined; | ||
} else if (parser.currentToken.isDefinedIdentifier) { | ||
parser.pushError(parserMessageRenderer(parser.getLanguageId(), ParserMessageKeys.PARSER_FUNCTION_NAME_IS_RESERVED_IN_SALAM)); | ||
return undefined; | ||
} | ||
|
||
const name: string | undefined = parser.currentToken.data?.getValueString(); | ||
if (name === undefined) { | ||
parser.pushError(parserMessageRenderer(parser.getLanguageId(), ParserMessageKeys.PARSER_FUNCTION_NAME_IS_NOT_VALID)); | ||
return undefined; | ||
} | ||
|
||
// Eating function name | ||
parser.next(); | ||
|
||
const params: AstFunctionArgument[] | undefined = parserParseFunctionArguments(parser); | ||
if (! params) { | ||
parser.pushError(parserMessageRenderer(parser.getLanguageId(), ParserMessageKeys.PARSER_FUNCTION_PARAMETERS_ARE_NOT_VALID)); | ||
return undefined; | ||
} | ||
|
||
let return_type: AstType | undefined = undefined; | ||
if (parser.skip(TokenOperatorType.TOKEN_MEMBER_POINTER)) { | ||
return_type = parseType(parser); | ||
if (return_type === undefined) { | ||
parser.pushError("Invalid data type as return type of function " + name); | ||
return undefined; | ||
} | ||
} | ||
|
||
if (return_type === undefined) { | ||
return_type = AstType.createVoid(); | ||
} | ||
|
||
parser.expect(TokenOperatorType.TOKEN_COLON); | ||
const generate_name: string | undefined = parser.currentToken.data?.getValueString(); | ||
if (generate_name === undefined) { | ||
parser.pushError("Invalid data as generate name of an externed function."); | ||
return undefined; | ||
} | ||
parser.expect(TokenKeywordType.TOKEN_IDENTIFIER); | ||
|
||
const ast: AstExtern = new AstExtern(name, params, return_type, generate_name); | ||
return ast; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters