@@ -20,6 +20,7 @@ intrude import literal
20
20
intrude import parser
21
21
intrude import semantize ::scope
22
22
intrude import modelbuilder_base
23
+ intrude import modelize_property
23
24
24
25
# General factory to build semantic nodes in the AST of expressions
25
26
class ASTBuilder
@@ -165,6 +166,41 @@ class ASTBuilder
165
166
return new ANotExpr .make (expr )
166
167
end
167
168
169
+ # Make a new attribute
170
+ fun make_attribute (name : String ,
171
+ n_type : nullable AType ,
172
+ n_visibility : nullable AVisibility ,
173
+ initial_value : nullable AExpr ,
174
+ n_block : nullable AExpr ,
175
+ m_attributedef : nullable MAttributeDef ,
176
+ m_setterdef : nullable MMethodDef ,
177
+ m_getterdef : nullable MMethodDef ): AAttrPropdef
178
+ do
179
+ return new AAttrPropdef .make (name , n_type , n_visibility , initial_value , n_block , m_attributedef , m_setterdef , m_getterdef )
180
+ end
181
+
182
+ # Make a new class (AStdClassdef)
183
+ fun make_class (mclassdef : nullable MClassDef ,
184
+ n_visibility : nullable AVisibility ,
185
+ n_formaldefs : Collection [AFormaldef ],
186
+ n_extern_code_block : nullable AExternCodeBlock ,
187
+ n_propdefs : Collection [APropdef ],
188
+ n_classkind : nullable AClasskind ): AStdClassdef
189
+ do
190
+ return new AStdClassdef .make (mclassdef , n_visibility , n_formaldefs , n_extern_code_block , n_propdefs , n_classkind )
191
+ end
192
+
193
+ fun make_var (variable : Variable , mtype : MType ): AVarExpr
194
+ do
195
+ return new AVarExpr .make (variable , mtype )
196
+ end
197
+
198
+ # Make a call assignment i.e `a = 10`
199
+ fun make_call_assign (recv : AExpr , callsite : CallSite , n_args : nullable Collection [AExpr ], n_value : AExpr ): ACallAssignExpr
200
+ do
201
+ return new ACallAssignExpr .make (recv , callsite , n_args , n_value )
202
+ end
203
+
168
204
# Build a callsite to call the `mproperty` in the current method `caller_method`.
169
205
# `is_self_call` indicate if the method caller is a property of `self`
170
206
fun create_callsite (modelbuilder : ModelBuilder , caller_method : AMethPropdef , mproperty : MMethod , is_self_call : Bool ): CallSite
@@ -262,6 +298,68 @@ class APlaceholderExpr
262
298
end
263
299
end
264
300
301
+ redef class ACallAssignExpr
302
+ private init make (recv : AExpr , callsite : CallSite , args : nullable Collection [AExpr ], n_value : AExpr )
303
+ do
304
+ _callsite = callsite
305
+ _mtype = callsite .recv
306
+ _is_typed = true
307
+ var n_args = new AListExprs
308
+ if args != null then
309
+ n_args .n_exprs .add_all (args )
310
+ end
311
+ var n_qid = new AQid
312
+ n_qid .n_id = new TId
313
+ n_qid .n_id .text = callsite .mproperty .name
314
+ init_acallassignexpr (recv , n_qid , n_args , new TAssign , n_value )
315
+ end
316
+ end
317
+
318
+ redef class AStdClassdef
319
+ private init make (mclassdef : nullable MClassDef ,
320
+ n_visibility : nullable AVisibility ,
321
+ n_formaldefs : Collection [Object ],
322
+ n_extern_code_block : nullable AExternCodeBlock ,
323
+ n_propdefs : Collection [Object ],
324
+ n_classkind : nullable AClasskind )
325
+ do
326
+ if n_visibility == null then n_visibility = new APublicVisibility
327
+ if n_classkind == null then n_classkind = new AConcreteClasskind .init_aconcreteclasskind (new TKwclass )
328
+ var n_qid = new AQclassid .init_aqclassid (null , new TClassid )
329
+ init_astdclassdef (null , null , n_visibility , n_classkind , n_qid , null , n_formaldefs , null , n_extern_code_block , n_propdefs , new TKwend )
330
+ _mclassdef = mclassdef
331
+ _mclass = mclassdef .mclass
332
+ end
333
+ end
334
+
335
+ redef class AAttrPropdef
336
+
337
+ # Create a new `AAttrPropdef`
338
+ # Note: By default if the `AVisibility` is not given the visibility is set to public
339
+ private init make (name : String ,
340
+ n_type : nullable AType ,
341
+ n_visibility : nullable AVisibility ,
342
+ initial_value : nullable AExpr ,
343
+ n_block : nullable AExpr ,
344
+ m_attributedef : nullable MAttributeDef ,
345
+ m_setterdef : nullable MMethodDef ,
346
+ m_getterdef : nullable MMethodDef )
347
+ do
348
+ # Set the model type
349
+ if n_type != null then mtype = n_type .mtype
350
+ # Define the visibility default is public
351
+ if n_visibility == null then n_visibility = new APublicVisibility
352
+ init_aattrpropdef (null , null , n_visibility , new TKwvar , new TId , n_type , null , initial_value , null , null , n_block , null )
353
+ # Set the name of the attribute
354
+ _n_id2 .text = name
355
+ _mpropdef = m_attributedef
356
+ _mreadpropdef = m_getterdef
357
+ _mwritepropdef = m_setterdef
358
+ if initial_value != null or n_block != null then has_value = true
359
+ if m_attributedef != null then self .location = m_attributedef .location
360
+ end
361
+ end
362
+
265
363
redef class ANotExpr
266
364
private init make (expr : AExpr )
267
365
do
@@ -318,6 +416,7 @@ redef class AMethPropdef
318
416
if n_visibility == null then n_visibility = new APublicVisibility
319
417
self .init_amethpropdef (null ,tk_redef ,n_visibility ,new TKwmeth ,null ,null ,null ,n_methid ,n_signature ,n_annotations ,n_extern_calls ,n_extern_code_block ,new TKwdo ,n_block ,new TKwend )
320
418
self .mpropdef = mmethoddef
419
+ if mpropdef != null then self .location = mmethoddef .location
321
420
end
322
421
end
323
422
@@ -538,13 +637,6 @@ redef class ACallExpr
538
637
end
539
638
end
540
639
541
- redef class AAsCastExpr
542
- private init make (n_expr : AExpr , n_type : AType )
543
- do
544
- init_aascastexpr (n_expr , new TKwas , null , n_type , null )
545
- end
546
- end
547
-
548
640
redef class AAsNotnullExpr
549
641
private init make (n_expr : AExpr , t : nullable MType )
550
642
do
@@ -642,6 +734,20 @@ redef class AVarAssignExpr
642
734
end
643
735
644
736
redef class ASignature
737
+
738
+ init make_from_msignature (msignature : MSignature )
739
+ do
740
+ var nparams = new Array [AParam ]
741
+ for mparam in msignature .mparameters do
742
+ var variable = new Variable (mparam .name )
743
+ variable .declared_type = mparam .mtype
744
+ n_params .add (new AParam .make (variable , new AType .make (mparam .mtype )))
745
+ end
746
+ var return_type = null
747
+ if msignature .return_mtype != null then return_type = new AType .make (msignature .return_mtype )
748
+ init_asignature (null , nparams , null , return_type )
749
+ end
750
+
645
751
redef fun clone : SELF
646
752
do
647
753
var ntype = n_type
@@ -655,6 +761,7 @@ redef class AParam
655
761
private init make (v : nullable Variable , t : nullable AType )
656
762
do
657
763
_n_id = new TId
764
+ if v != null then _n_id .text = v .name
658
765
_variable = v
659
766
_n_type = t
660
767
end
0 commit comments