Commit 8eb493f2 authored by Ronny Wichers Schreur's avatar Ronny Wichers Schreur

don't allow local nodedefs (defined with =:) with a specified type

parent 14874217
...@@ -557,8 +557,13 @@ where ...@@ -557,8 +557,13 @@ where
| isIclContext parseContext && isLocalContext parseContext && (token == EqualToken || token == DefinesColonToken) && | isIclContext parseContext && isLocalContext parseContext && (token == EqualToken || token == DefinesColonToken) &&
/* PK isLowerCaseName name.id_name && */ not (isClassOrInstanceDefsContext parseContext) /* PK isLowerCaseName name.id_name && */ not (isClassOrInstanceDefsContext parseContext)
# (rhs, _, pState) = wantRhs False (RhsDefiningSymbolExact token) (tokenBack pState) # (rhs, _, pState) = wantRhs False (RhsDefiningSymbolExact token) (tokenBack pState)
= (PD_NodeDef pos (PE_Ident name) rhs, pState) | token == EqualToken
= (PD_Function pos name False [] rhs FK_NodeDefOrFunction, pState)
// otherwise // token == DefinesColonToken
| isGlobalContext parseContext
= (PD_Function pos name False [] rhs FK_Caf, pState)
// otherwise
= (PD_NodeDef pos (PE_Ident name) rhs, pState)
want_rhs_of_def parseContext (Yes (name, is_infix), args) token pos pState want_rhs_of_def parseContext (Yes (name, is_infix), args) token pos pState
# code_allowed = code_block_allowed token # code_allowed = code_block_allowed token
(token, pState) = nextToken FunctionContext pState (token, pState) = nextToken FunctionContext pState
...@@ -782,21 +787,22 @@ isDefiningSymbol RhsDefiningSymbolRuleOrMacro observed ...@@ -782,21 +787,22 @@ isDefiningSymbol RhsDefiningSymbolRuleOrMacro observed
definingSymbolToFunKind :: RhsDefiningSymbol -> FunKind definingSymbolToFunKind :: RhsDefiningSymbol -> FunKind
definingSymbolToFunKind (RhsDefiningSymbolExact defining_token) definingSymbolToFunKind (RhsDefiningSymbolExact defining_token)
= token_to_fun_kind defining_token = definingTokenToFunKind defining_token
where
token_to_fun_kind ColonDefinesToken
= FK_Macro
token_to_fun_kind EqualToken
= FK_Function cNameNotLocationDependent
token_to_fun_kind DoubleArrowToken
= FK_Function cNameNotLocationDependent
token_to_fun_kind DefinesColonToken
= FK_Caf
token_to_fun_kind _
= FK_Unknown
definingSymbolToFunKind _ definingSymbolToFunKind _
= FK_Unknown = FK_Unknown
definingTokenToFunKind :: Token -> FunKind
definingTokenToFunKind ColonDefinesToken
= FK_Macro
definingTokenToFunKind EqualToken
= FK_Function cNameNotLocationDependent
definingTokenToFunKind DoubleArrowToken
= FK_Function cNameNotLocationDependent
definingTokenToFunKind DefinesColonToken
= FK_Caf
definingTokenToFunKind _
= FK_Unknown
wantRhs :: !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) // FunctionAltDefRhs wantRhs :: !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) // FunctionAltDefRhs
wantRhs localsExpected definingSymbol pState wantRhs localsExpected definingSymbol pState
# (alts, definingSymbol, pState) = want_LetsFunctionBody definingSymbol pState # (alts, definingSymbol, pState) = want_LetsFunctionBody definingSymbol pState
......
...@@ -25,15 +25,17 @@ optGuardedAltToRhs optGuardedAlt ...@@ -25,15 +25,17 @@ optGuardedAltToRhs optGuardedAlt
} }
exprToRhs expr exprToRhs expr
:== { rhs_alts = UnGuardedExpr :== { rhs_alts = UnGuardedExpr (exprToExprWithLocalDefs expr)
{ ewl_nodes = []
, ewl_expr = expr
, ewl_locals = LocalParsedDefs []
, ewl_position= NoPos
}
, rhs_locals = LocalParsedDefs [] , rhs_locals = LocalParsedDefs []
} }
exprToExprWithLocalDefs expr
:== { ewl_nodes = []
, ewl_expr = expr
, ewl_locals = LocalParsedDefs []
, ewl_position= NoPos
}
prefixAndPositionToIdent :: !String !LineAndColumn !*CollectAdmin -> (!Ident, !*CollectAdmin) prefixAndPositionToIdent :: !String !LineAndColumn !*CollectAdmin -> (!Ident, !*CollectAdmin)
prefixAndPositionToIdent prefix {lc_line, lc_column} ca=:{ca_hash_table} prefixAndPositionToIdent prefix {lc_line, lc_column} ca=:{ca_hash_table}
# ({boxed_ident=ident}, ca_hash_table) = putIdentInHashTable (prefix +++ ";" +++ toString lc_line +++ ";" +++ toString lc_column) IC_Expression ca_hash_table # ({boxed_ident=ident}, ca_hash_table) = putIdentInHashTable (prefix +++ ";" +++ toString lc_line +++ ";" +++ toString lc_column) IC_Expression ca_hash_table
...@@ -278,6 +280,11 @@ where ...@@ -278,6 +280,11 @@ where
reorganiseLocalDefinitions [PD_NodeDef pos pattern {rhs_alts,rhs_locals} : defs] ca reorganiseLocalDefinitions [PD_NodeDef pos pattern {rhs_alts,rhs_locals} : defs] ca
# (fun_defs, node_defs, ca) = reorganiseLocalDefinitions defs ca # (fun_defs, node_defs, ca) = reorganiseLocalDefinitions defs ca
= (fun_defs, [{ nd_dst = pattern, nd_alts = rhs_alts, nd_locals = rhs_locals, nd_position = pos } : node_defs], ca) = (fun_defs, [{ nd_dst = pattern, nd_alts = rhs_alts, nd_locals = rhs_locals, nd_position = pos } : node_defs], ca)
reorganiseLocalDefinitions [PD_Function pos name is_infix [] {rhs_alts, rhs_locals} FK_NodeDefOrFunction : defs] ca
# (fun_defs, node_defs, ca) = reorganiseLocalDefinitions defs ca
= (fun_defs, [{ nd_dst = PE_Ident name, nd_alts = rhs_alts, nd_locals = rhs_locals, nd_position = pos } : node_defs], ca)
reorganiseLocalDefinitions [PD_Function pos name is_infix args rhs fun_kind : defs] ca reorganiseLocalDefinitions [PD_Function pos name is_infix args rhs fun_kind : defs] ca
# prio = if is_infix (Prio NoAssoc 9) NoPrio # prio = if is_infix (Prio NoAssoc 9) NoPrio
fun_arity = length args fun_arity = length args
......
...@@ -174,7 +174,7 @@ cIsNotAFunction :== False ...@@ -174,7 +174,7 @@ cIsNotAFunction :== False
| PD_ImportedObjects [ImportedObject] | PD_ImportedObjects [ImportedObject]
| PD_Erroneous | PD_Erroneous
:: FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_Unknown :: FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_NodeDefOrFunction | FK_Unknown
cNameNotLocationDependent :== False cNameNotLocationDependent :== False
cNameLocationDependent :== True cNameLocationDependent :== True
......
...@@ -172,7 +172,7 @@ cIsNotAFunction :== False ...@@ -172,7 +172,7 @@ cIsNotAFunction :== False
| PD_ImportedObjects [ImportedObject] | PD_ImportedObjects [ImportedObject]
| PD_Erroneous | PD_Erroneous
:: FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_Unknown :: FunKind = FK_Function !Bool | FK_Macro | FK_Caf | FK_NodeDefOrFunction | FK_Unknown
cNameNotLocationDependent :== False cNameNotLocationDependent :== False
cNameLocationDependent :== True cNameLocationDependent :== True
...@@ -1759,6 +1759,7 @@ instance <<< FunKind ...@@ -1759,6 +1759,7 @@ instance <<< FunKind
where where
(<<<) file (FK_Function False) = file <<< "FK_Function" (<<<) file (FK_Function False) = file <<< "FK_Function"
(<<<) file (FK_Function True) = file <<< "Lambda" (<<<) file (FK_Function True) = file <<< "Lambda"
(<<<) file FK_NodeDefOrFunction = file <<< "FK_NodeDefOrFunction"
(<<<) file FK_Macro = file <<< "FK_Macro" (<<<) file FK_Macro = file <<< "FK_Macro"
(<<<) file FK_Caf = file <<< "FK_Caf" (<<<) file FK_Caf = file <<< "FK_Caf"
(<<<) file FK_Unknown = file <<< "FK_Unknown" (<<<) file FK_Unknown = file <<< "FK_Unknown"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment