MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_struct

Method extract_struct

atomic-semantic/src/parsers/cpp.rs:380–409  ·  view source on GitHub ↗

Extract a struct specifier. Returns `(Entity, raw_name)` where `raw_name` is the unscoped name for use in building child scopes.

(
        &self,
        node: &Node,
        source: &str,
        file_path: &str,
        scope: Option<&str>,
    )

Source from the content-addressed store, hash-verified

378 /// Returns `(Entity, raw_name)` where `raw_name` is the unscoped name
379 /// for use in building child scopes.
380 fn extract_struct(
381 &self,
382 node: &Node,
383 source: &str,
384 file_path: &str,
385 scope: Option<&str>,
386 ) -> Option<(Entity, String)> {
387 let name_node = node.child_by_field_name("name")?;
388 let name = self.node_text(&name_node, source);
389
390 if name.is_empty() {
391 return None;
392 }
393
394 let line = node.start_position().row as u32 + 1;
395 let end_line = node.end_position().row as u32 + 1;
396
397 let full_name = match scope {
398 Some(s) => format!("{}::{}", s, name),
399 None => name.clone(),
400 };
401
402 let signature = format!("struct {}", name);
403
404 let mut entity = Entity::new(full_name, EntityKind::Class, file_path, line, end_line);
405 entity = entity.with_signature(signature);
406 entity.exported = true;
407
408 Some((entity, name))
409 }
410
411 /// Extract a namespace definition.
412 ///

Callers 1

walk_treeMethod · 0.45

Calls 4

with_signatureMethod · 0.80
node_textMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected